MyGUI: MyGUI_TextureUtility.cpp Source File

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"
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
14namespace MyGUI::texture_utility
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())
29 return Constants::getZeroIntSize();
30
31 RenderManager& render = RenderManager::getInstance();
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");
39 return Constants::getZeroIntSize();
40 }
41
42 texture = render.createTexture(_texture);
43 if (texture == nullptr)
44 {
45 MYGUI_LOG(Error, "Texture '" + _texture + "' cannot be created");
46 return Constants::getZeroIntSize();
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
63 uint32 toNativeColour(const Colour& _colour, VertexColourType _format)
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
MyGUI_Bitwise.h
MyGUI_Constants.h
MyGUI_DataManager.h
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition MyGUI_Diagnostic.h:17
MyGUI_Precompiled.h
MyGUI_RenderManager.h
MyGUI_TextureUtility.h
MyGUI::Constants::getZeroIntSize
static const IntSize & getZeroIntSize()
Definition MyGUI_Constants.h:28
MyGUI::DataManager::getInstance
static DataManager & getInstance()
MyGUI::ITexture
Definition MyGUI_ITexture.h:28
MyGUI::ITexture::getWidth
virtual int getWidth() const =0
MyGUI::ITexture::loadFromFile
virtual void loadFromFile(const std::string &_filename)=0
MyGUI::ITexture::getHeight
virtual int getHeight() const =0
MyGUI::RenderManager
Definition MyGUI_RenderManager.h:21
MyGUI::RenderManager::getTexture
virtual ITexture * getTexture(const std::string &_name)=0
MyGUI::RenderManager::createTexture
virtual ITexture * createTexture(const std::string &_name)=0
MyGUI::RenderManager::getInstance
static RenderManager & getInstance()
MyGUI::Bitwise::isPO2
static bool isPO2(Type _value)
Definition MyGUI_Bitwise.h:30
MyGUI::texture_utility
Definition MyGUI_TextureUtility.h:15
MyGUI::texture_utility::convertColour
void convertColour(uint32 &_colour, VertexColourType _format)
Convert from 32-bit ARGB to native colour (ABGR or ARGB)
Definition MyGUI_TextureUtility.cpp:86
MyGUI::texture_utility::getTextureSize
const IntSize & getTextureSize(const std::string &_texture, bool _cache=true)
Definition MyGUI_TextureUtility.cpp:17
MyGUI::texture_utility::toNativeColour
uint32 toNativeColour(const Colour &_colour, VertexColourType _format)
Convert Colour to 32-bit representation.
Definition MyGUI_TextureUtility.cpp:63
MyGUI::uint32
uint32_t uint32
Definition MyGUI_Types.h:48
MyGUI::uint8
uint8_t uint8
Definition MyGUI_Types.h:46
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::Colour
Definition MyGUI_Colour.h:17
MyGUI::Colour::green
float green
Definition MyGUI_Colour.h:49
MyGUI::Colour::blue
float blue
Definition MyGUI_Colour.h:50
MyGUI::Colour::alpha
float alpha
Definition MyGUI_Colour.h:51
MyGUI::Colour::red
float red
Definition MyGUI_Colour.h:48
MyGUI::VertexColourType
Definition MyGUI_RenderFormat.h:16
MyGUI::VertexColourType::ColourABGR
@ ColourABGR
Definition MyGUI_RenderFormat.h:21
MyGUI::types::TSize::width
T width
Definition MyGUI_TSize.h:19
MyGUI::types::TSize::height
T height
Definition MyGUI_TSize.h:20
MyGUI::types::TSize::clear
void clear()
Definition MyGUI_TSize.h:72