MyGUI 3.2.2

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

- File List
- Globals

MyGUI_TextureUtility.cpp
Go to the documentation of this file.
1 /*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7 #include "MyGUI_Precompiled.h"
8 #include "MyGUI_TextureUtility.h"
9 #include "MyGUI_RenderManager.h"
10 #include "MyGUI_DataManager.h"
11 #include "MyGUI_Bitwise.h"
12 #include "MyGUI_Constants.h"
13
14 namespace MyGUI
15 {
16
17 namespace texture_utility
18 {
19
20 const IntSize& getTextureSize(const std::string& _texture, bool _cache)
21 {
22 static std::string prevTexture;
23 static IntSize prevSize;
24
25 if (prevTexture == _texture && _cache)
26 return prevSize;
27
28 prevTexture.clear();
29 prevSize.clear();
30
31 if (_texture.empty())
32 return Constants::getZeroIntSize();
33
34 RenderManager& render = RenderManager::getInstance();
35
36 ITexture* texture = render.getTexture(_texture);
37 if (texture == nullptr)
38 {
39 if (!DataManager::getInstance().isDataExist(_texture))
40 {
41 MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
42 return Constants::getZeroIntSize();
43 }
44 else
45 {
46 texture = render.createTexture(_texture);
47 if (texture == nullptr)
48 {
49 MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
50 return Constants::getZeroIntSize();
51 }
52 texture->loadFromFile(_texture);
53 }
54 }
55
56 prevSize = IntSize(texture->getWidth(), texture->getHeight());
57 prevTexture = _texture;
58
59 #if MYGUI_DEBUG_MODE == 1
60 if (!Bitwise::isPO2(prevSize.width) || !Bitwise::isPO2(prevSize.height))
61 {
62 MYGUI_LOG(Warning, "Texture '" + _texture + "' have non power of two size");
63 }
64 #endif
65
66 return prevSize;
67 }
68
69 uint32 toColourARGB(const Colour& _colour)
70 {
71 uint32 val32 = uint8(_colour.alpha * 255);
72 val32 <<= 8;
73 val32 += uint8(_colour.red * 255);
74 val32 <<= 8;
75 val32 += uint8(_colour.green * 255);
76 val32 <<= 8;
77 val32 += uint8(_colour.blue * 255);
78 return val32;
79 }
80
81 } // namespace texture_utility
82
83 } // namespace MyGUI
MyGUI_TextureUtility.h
MyGUI::uint32
unsigned int uint32
Definition: MyGUI_Types.h:48
MyGUI::Colour::green
float green
Definition: MyGUI_Colour.h:50
MyGUI::IntSize
types::TSize< int > IntSize
Definition: MyGUI_Types.h:29
MyGUI_Precompiled.h
MyGUI_DataManager.h
MyGUI::types::TSize< int >
MyGUI::Singleton< RenderManager >::getInstance
static RenderManager & getInstance()
Definition: MyGUI_Singleton.h:38
MyGUI::texture_utility::getTextureSize
const IntSize & getTextureSize(const std::string &_texture, bool _cache=true)
Definition: MyGUI_TextureUtility.cpp:20
MyGUI::RenderManager::getTexture
virtual ITexture * getTexture(const std::string &_name)=0
MyGUI::types::TSize::clear
void clear()
Definition: MyGUI_TSize.h:90
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:22
MyGUI_Constants.h
MyGUI_RenderManager.h
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::types::TSize::width
T width
Definition: MyGUI_TSize.h:20
MyGUI::ITexture::getHeight
virtual int getHeight()=0
MyGUI::ITexture
Definition: MyGUI_ITexture.h:26
MyGUI::texture_utility::toColourARGB
uint32 toColourARGB(const Colour &_colour)
Definition: MyGUI_TextureUtility.cpp:69
MyGUI::Colour::red
float red
Definition: MyGUI_Colour.h:49
MyGUI::Bitwise::isPO2
static __inline bool isPO2(Type _value)
Definition: MyGUI_Bitwise.h:35
MyGUI::Colour
Definition: MyGUI_Colour.h:16
MyGUI_Bitwise.h
MyGUI::types::TSize::height
T height
Definition: MyGUI_TSize.h:21
MyGUI::Constants::getZeroIntSize
static const IntSize & getZeroIntSize()
Definition: MyGUI_Constants.h:28
MyGUI::ITexture::loadFromFile
virtual void loadFromFile(const std::string &_filename)=0
MyGUI::uint8
unsigned char uint8
Definition: MyGUI_Types.h:46
MyGUI::RenderManager::createTexture
virtual ITexture * createTexture(const std::string &_name)=0
MyGUI::Colour::alpha
float alpha
Definition: MyGUI_Colour.h:52
MyGUI::Colour::blue
float blue
Definition: MyGUI_Colour.h:51
MyGUI::RenderManager
Definition: MyGUI_RenderManager.h:20
MyGUI::ITexture::getWidth
virtual int getWidth()=0