MyGUI 3.4.3
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"
10#include "MyGUI_DataManager.h"
11#include "MyGUI_Bitwise.h"
12#include "MyGUI_Constants.h"
13
15{
16
17 const IntSize& getTextureSize(const std::string& _texture, bool _cache)
18 {
19 static std::string prevTexture;
20 static IntSize prevSize;
21
22 if (prevTexture == _texture && _cache)
23 return prevSize;
24
25 prevTexture.clear();
26 prevSize.clear();
27
28 if (_texture.empty())
30
32
33 ITexture* texture = render.getTexture(_texture);
34 if (texture == nullptr)
35 {
36 if (!DataManager::getInstance().isDataExist(_texture))
37 {
38 MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
40 }
41
42 texture = render.createTexture(_texture);
43 if (texture == nullptr)
44 {
45 MYGUI_LOG(Error, "Texture '" + _texture + "' cannot be created");
47 }
48 texture->loadFromFile(_texture);
49#if MYGUI_DEBUG_MODE == 1
50 if (!Bitwise::isPO2(prevSize.width) || !Bitwise::isPO2(prevSize.height))
51 {
52 MYGUI_LOG(Warning, "Texture '" + _texture + "' have non power of two size");
53 }
54#endif
55 }
56
57 prevSize = IntSize(texture->getWidth(), texture->getHeight());
58 prevTexture = _texture;
59
60 return prevSize;
61 }
62
64 {
65 uint32 val32 = uint8(_colour.alpha * 255);
66 val32 <<= 8;
67 if (_format == VertexColourType::ColourABGR)
68 {
69 val32 += uint8(_colour.blue * 255);
70 val32 <<= 8;
71 val32 += uint8(_colour.green * 255);
72 val32 <<= 8;
73 val32 += uint8(_colour.red * 255);
74 }
75 else
76 {
77 val32 += uint8(_colour.red * 255);
78 val32 <<= 8;
79 val32 += uint8(_colour.green * 255);
80 val32 <<= 8;
81 val32 += uint8(_colour.blue * 255);
82 }
83 return val32;
84 }
85
86 void convertColour(uint32& _colour, VertexColourType _format)
87 {
88 if (_format == VertexColourType::ColourABGR)
89 _colour = ((_colour & 0x00FF0000) >> 16) | ((_colour & 0x000000FF) << 16) | (_colour & 0xFF00FF00);
90 }
91
92} // namespace MyGUI
#define MYGUI_LOG(level, text)
static const IntSize & getZeroIntSize()
static DataManager & getInstance()
virtual int getWidth() const =0
virtual void loadFromFile(const std::string &_filename)=0
virtual int getHeight() const =0
virtual ITexture * getTexture(const std::string &_name)=0
virtual ITexture * createTexture(const std::string &_name)=0
static RenderManager & getInstance()
static bool isPO2(Type _value)
void convertColour(uint32 &_colour, VertexColourType _format)
Convert from 32-bit ARGB to native colour (ABGR or ARGB)
const IntSize & getTextureSize(const std::string &_texture, bool _cache=true)
uint32 toNativeColour(const Colour &_colour, VertexColourType _format)
Convert Colour to 32-bit representation.
uint32_t uint32
Definition MyGUI_Types.h:48
uint8_t uint8
Definition MyGUI_Types.h:46
types::TSize< int > IntSize
Definition MyGUI_Types.h:30