MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_TextureUtility.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_TextureUtility.h"
24 #include "MyGUI_RenderManager.h"
25 #include "MyGUI_DataManager.h"
26 #include "MyGUI_Bitwise.h"
27
28 namespace MyGUI
29 {
30
31 namespace texture_utility
32 {
33
34 const IntSize& getTextureSize(const std::string& _texture, bool _cache)
35 {
36 // предыдущя текстура
37 static std::string old_texture;
38 static IntSize old_size;
39
40 if (old_texture == _texture && _cache)
41 return old_size;
42 old_texture = _texture;
43 old_size.clear();
44
45 if (_texture.empty())
46 return old_size;
47
48 RenderManager& render = RenderManager::getInstance();
49
50 if (nullptr == render.getTexture(_texture))
51 {
52 if (!DataManager::getInstance().isDataExist(_texture))
53 {
54 MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
55 return old_size;
56 }
57 else
58 {
59 ITexture* texture = render.createTexture(_texture);
60 texture->loadFromFile(_texture);
61 }
62 }
63
64 ITexture* texture = render.getTexture(_texture);
65 if (texture == nullptr)
66 {
67 MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
68 return old_size;
69 }
70
71 old_size.set(texture->getWidth(), texture->getHeight());
72
73 #if MYGUI_DEBUG_MODE == 1
74 if (!Bitwise::isPO2(old_size.width) || !Bitwise::isPO2(old_size.height))
75 {
76 MYGUI_LOG(Warning, "Texture '" + _texture + "' have non power of two size");
77 }
78 #endif
79
80 return old_size;
81 }
82
83 uint32 toColourARGB(const Colour& _colour)
84 {
85 uint32 val32 = uint8(_colour.alpha * 255);
86 val32 <<= 8;
87 val32 += uint8(_colour.red * 255);
88 val32 <<= 8;
89 val32 += uint8(_colour.green * 255);
90 val32 <<= 8;
91 val32 += uint8(_colour.blue * 255);
92 return val32;
93 }
94
95 } // namespace texture_utility
96
97 } // namespace MyGUI
MyGUI_TextureUtility.h
MyGUI::uint32
unsigned int uint32
Definition: MyGUI_Types.h:63
MyGUI::Colour::green
float green
Definition: MyGUI_Colour.h:65
MyGUI_Precompiled.h
MyGUI_DataManager.h
MyGUI::types::TSize< int >
MyGUI::Singleton< RenderManager >::getInstance
static RenderManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI::texture_utility::getTextureSize
const IntSize & getTextureSize(const std::string &_texture, bool _cache=true)
Definition: MyGUI_TextureUtility.cpp:34
MyGUI::RenderManager::getTexture
virtual ITexture * getTexture(const std::string &_name)=0
MyGUI::types::TSize::set
void set(T const &_width, T const &_height)
Definition: MyGUI_TSize.h:110
MyGUI::types::TSize::clear
void clear()
Definition: MyGUI_TSize.h:105
MyGUI::DataManager::isDataExist
virtual bool isDataExist(const std::string &_name)=0
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:38
MyGUI_RenderManager.h
MyGUI::types::TSize::width
T width
Definition: MyGUI_TSize.h:35
MyGUI::ITexture::getHeight
virtual int getHeight()=0
MyGUI::ITexture
Definition: MyGUI_ITexture.h:41
MyGUI::texture_utility::toColourARGB
uint32 toColourARGB(const Colour &_colour)
Definition: MyGUI_TextureUtility.cpp:83
MyGUI::Colour::red
float red
Definition: MyGUI_Colour.h:64
MyGUI::Bitwise::isPO2
static __inline bool isPO2(Type _value)
Definition: MyGUI_Bitwise.h:50
MyGUI::Colour
Definition: MyGUI_Colour.h:31
MyGUI_Bitwise.h
MyGUI::types::TSize::height
T height
Definition: MyGUI_TSize.h:36
MyGUI::ITexture::loadFromFile
virtual void loadFromFile(const std::string &_filename)=0
MyGUI::uint8
unsigned char uint8
Definition: MyGUI_Types.h:61
MyGUI::RenderManager::createTexture
virtual ITexture * createTexture(const std::string &_name)=0
MyGUI::Colour::alpha
float alpha
Definition: MyGUI_Colour.h:67
MyGUI::Colour::blue
float blue
Definition: MyGUI_Colour.h:66
MyGUI::RenderManager
Definition: MyGUI_RenderManager.h:35
MyGUI::ITexture::getWidth
virtual int getWidth()=0