MyGUI  3.2.0
MyGUI_TextureUtility.cpp
Go to the documentation of this file.
00001 
00006 /*
00007     This file is part of MyGUI.
00008 
00009     MyGUI is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     MyGUI is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 #include "MyGUI_Precompiled.h"
00023 #include "MyGUI_TextureUtility.h"
00024 #include "MyGUI_RenderManager.h"
00025 #include "MyGUI_DataManager.h"
00026 #include "MyGUI_Bitwise.h"
00027 
00028 namespace MyGUI
00029 {
00030 
00031     namespace texture_utility
00032     {
00033 
00034         const IntSize& getTextureSize(const std::string& _texture, bool _cache)
00035         {
00036             // предыдущя текстура
00037             static std::string old_texture;
00038             static IntSize old_size;
00039 
00040             if (old_texture == _texture && _cache)
00041                 return old_size;
00042             old_texture = _texture;
00043             old_size.clear();
00044 
00045             if (_texture.empty())
00046                 return old_size;
00047 
00048             RenderManager& render = RenderManager::getInstance();
00049 
00050             if (nullptr == render.getTexture(_texture))
00051             {
00052                 if (!DataManager::getInstance().isDataExist(_texture))
00053                 {
00054                     MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
00055                     return old_size;
00056                 }
00057                 else
00058                 {
00059                     ITexture* texture = render.createTexture(_texture);
00060                     texture->loadFromFile(_texture);
00061                 }
00062             }
00063 
00064             ITexture* texture = render.getTexture(_texture);
00065             if (texture == nullptr)
00066             {
00067                 MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
00068                 return old_size;
00069             }
00070 
00071             old_size.set(texture->getWidth(), texture->getHeight());
00072 
00073     #if MYGUI_DEBUG_MODE == 1
00074             if (!Bitwise::isPO2(old_size.width) || !Bitwise::isPO2(old_size.height))
00075             {
00076                 MYGUI_LOG(Warning, "Texture '" + _texture + "' have non power of two size");
00077             }
00078     #endif
00079 
00080             return old_size;
00081         }
00082 
00083         uint32 toColourARGB(const Colour& _colour)
00084         {
00085             uint32 val32 = uint8(_colour.alpha * 255);
00086             val32 <<= 8;
00087             val32 += uint8(_colour.red * 255);
00088             val32 <<= 8;
00089             val32 += uint8(_colour.green * 255);
00090             val32 <<= 8;
00091             val32 += uint8(_colour.blue * 255);
00092             return val32;
00093         }
00094 
00095     } // namespace texture_utility
00096 
00097 } // namespace MyGUI