MyGUI_TextureUtility.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_TextureUtility.h"
#include "MyGUI_RenderManager.h"
#include "MyGUI_DataManager.h"
#include "MyGUI_Bitwise.h"
#include "MyGUI_Constants.h"
namespace MyGUI::texture_utility
{
const IntSize& getTextureSize(const std::string& _texture, bool _cache)
{
static std::string prevTexture;
static IntSize prevSize;
if (prevTexture == _texture && _cache)
return prevSize;
prevTexture.clear();
prevSize.clear();
if (_texture.empty())
return Constants::getZeroIntSize();
RenderManager& render = RenderManager::getInstance();
ITexture* texture = render.getTexture(_texture);
if (texture == nullptr)
{
if (!DataManager::getInstance().isDataExist(_texture))
{
MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
return Constants::getZeroIntSize();
}
texture = render.createTexture(_texture);
if (texture == nullptr)
{
MYGUI_LOG(Error, "Texture '" + _texture + "' cannot be created");
return Constants::getZeroIntSize();
}
texture->loadFromFile(_texture);
#if MYGUI_DEBUG_MODE == 1
if (!Bitwise::isPO2(prevSize.width) || !Bitwise::isPO2(prevSize.height))
{
MYGUI_LOG(Warning, "Texture '" + _texture + "' have non power of two size");
}
#endif
}
prevSize = IntSize(texture->getWidth(), texture->getHeight());
prevTexture = _texture;
return prevSize;
}
uint32 toNativeColour(const Colour& _colour, VertexColourType _format)
{
uint32 val32 = uint8(_colour.alpha * 255);
val32 <<= 8;
if (_format == VertexColourType::ColourABGR)
{
val32 += uint8(_colour.blue * 255);
val32 <<= 8;
val32 += uint8(_colour.green * 255);
val32 <<= 8;
val32 += uint8(_colour.red * 255);
}
else
{
val32 += uint8(_colour.red * 255);
val32 <<= 8;
val32 += uint8(_colour.green * 255);
val32 <<= 8;
val32 += uint8(_colour.blue * 255);
}
return val32;
}
void convertColour(uint32& _colour, VertexColourType _format)
{
if (_format == VertexColourType::ColourABGR)
_colour = ((_colour & 0x00FF0000) >> 16) | ((_colour & 0x000000FF) << 16) | (_colour & 0xFF00FF00);
}
} // 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