MyGUI 3.0.1

MyGUI_TextureUtility.cpp

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