• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

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)
00036         {
00037             // ïðåäûäóùÿ òåêñòóðà
00038             static std::string old_texture;
00039             static IntSize old_size;
00040 
00041             if (old_texture == _texture) return old_size;
00042             old_texture = _texture;
00043             old_size.clear();
00044 
00045             if (_texture.empty()) return old_size;
00046 
00047             RenderManager& render = RenderManager::getInstance();
00048 
00049             if (nullptr == render.getTexture(_texture))
00050             {
00051                 if (!DataManager::getInstance().isDataExist(_texture))
00052                 {
00053                     MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
00054                     return old_size;
00055                 }
00056                 else
00057                 {
00058                     ITexture* texture = render.createTexture(_texture);
00059                     texture->loadFromFile(_texture);
00060                 }
00061             }
00062 
00063             ITexture* texture = render.getTexture(_texture);
00064             if (texture == nullptr)
00065             {
00066                 MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
00067                 return old_size;
00068             }
00069 
00070             old_size.set(texture->getWidth(), texture->getHeight());
00071 
00072     #if MYGUI_DEBUG_MODE == 1
00073             if (!Bitwise::isPO2(old_size.width) || !Bitwise::isPO2(old_size.height))
00074             {
00075                 MYGUI_LOG(Warning, "Texture '" + _texture + "' have non power of two size");
00076             }
00077     #endif
00078 
00079             return old_size;
00080         }
00081 
00082         uint32 toColourARGB(const Colour& _colour)
00083         {
00084             uint32 val32 = uint8(_colour.alpha * 255);
00085             val32 <<= 8;
00086             val32 += uint8(_colour.red * 255);
00087             val32 <<= 8;
00088             val32 += uint8(_colour.green * 255);
00089             val32 <<= 8;
00090             val32 += uint8(_colour.blue * 255);
00091             return val32;
00092         }
00093 
00094     } // namespace texture_utility
00095 
00096 } // namespace MyGUI

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1