MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #include "MyGUI_Precompiled.h" 00008 #include "MyGUI_TextureUtility.h" 00009 #include "MyGUI_RenderManager.h" 00010 #include "MyGUI_DataManager.h" 00011 #include "MyGUI_Bitwise.h" 00012 #include "MyGUI_Constants.h" 00013 00014 namespace MyGUI 00015 { 00016 00017 namespace texture_utility 00018 { 00019 00020 const IntSize& getTextureSize(const std::string& _texture, bool _cache) 00021 { 00022 static std::string prevTexture; 00023 static IntSize prevSize; 00024 00025 if (prevTexture == _texture && _cache) 00026 return prevSize; 00027 00028 prevTexture.clear(); 00029 prevSize.clear(); 00030 00031 if (_texture.empty()) 00032 return Constants::getZeroIntSize(); 00033 00034 RenderManager& render = RenderManager::getInstance(); 00035 00036 ITexture* texture = render.getTexture(_texture); 00037 if (texture == nullptr) 00038 { 00039 if (!DataManager::getInstance().isDataExist(_texture)) 00040 { 00041 MYGUI_LOG(Error, "Texture '" + _texture + "' not found"); 00042 return Constants::getZeroIntSize(); 00043 } 00044 else 00045 { 00046 texture = render.createTexture(_texture); 00047 if (texture == nullptr) 00048 { 00049 MYGUI_LOG(Error, "Texture '" + _texture + "' not found"); 00050 return Constants::getZeroIntSize(); 00051 } 00052 texture->loadFromFile(_texture); 00053 } 00054 } 00055 00056 prevSize = IntSize(texture->getWidth(), texture->getHeight()); 00057 prevTexture = _texture; 00058 00059 #if MYGUI_DEBUG_MODE == 1 00060 if (!Bitwise::isPO2(prevSize.width) || !Bitwise::isPO2(prevSize.height)) 00061 { 00062 MYGUI_LOG(Warning, "Texture '" + _texture + "' have non power of two size"); 00063 } 00064 #endif 00065 00066 return prevSize; 00067 } 00068 00069 uint32 toColourARGB(const Colour& _colour) 00070 { 00071 uint32 val32 = uint8(_colour.alpha * 255); 00072 val32 <<= 8; 00073 val32 += uint8(_colour.red * 255); 00074 val32 <<= 8; 00075 val32 += uint8(_colour.green * 255); 00076 val32 <<= 8; 00077 val32 += uint8(_colour.blue * 255); 00078 return val32; 00079 } 00080 00081 } // namespace texture_utility 00082 00083 } // namespace MyGUI