MyGUI 3.4.2
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
14namespace 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())
33
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");
43 }
44 else
45 {
46 texture = render.createTexture(_texture);
47 if (texture == nullptr)
48 {
49 MYGUI_LOG(Error, "Texture '" + _texture + "' cannot be created");
51 }
52 texture->loadFromFile(_texture);
53#if MYGUI_DEBUG_MODE == 1
54 if (!Bitwise::isPO2(prevSize.width) || !Bitwise::isPO2(prevSize.height))
55 {
56 MYGUI_LOG(Warning, "Texture '" + _texture + "' have non power of two size");
57 }
58#endif
59 }
60 }
61
62 prevSize = IntSize(texture->getWidth(), texture->getHeight());
64
65 return prevSize;
66 }
67
69 {
70 uint32 val32 = uint8(_colour.alpha * 255);
71 val32 <<= 8;
73 {
74 val32 += uint8(_colour.blue * 255);
75 val32 <<= 8;
76 val32 += uint8(_colour.green * 255);
77 val32 <<= 8;
78 val32 += uint8(_colour.red * 255);
79 }
80 else
81 {
82 val32 += uint8(_colour.red * 255);
83 val32 <<= 8;
84 val32 += uint8(_colour.green * 255);
85 val32 <<= 8;
86 val32 += uint8(_colour.blue * 255);
87 }
88 return val32;
89 }
90
92 {
94 _colour = ((_colour & 0x00FF0000) >> 16) | ((_colour & 0x000000FF) << 16) | (_colour & 0xFF00FF00);
95 }
96
97 } // namespace texture_utility
98
99} // 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
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.
uint8_t uint8
Definition MyGUI_Types.h:46
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
uint32_t uint32
Definition MyGUI_Types.h:48