MyGUI
3.0.1
Main Page
Related Pages
Namespaces
Data Structures
Files
Examples
File List
Globals
MyGUIEngine
src
MyGUI_TextureUtility.cpp
Go to the documentation of this file.
1
7
/*
8
This file is part of MyGUI.
9
10
MyGUI is free software: you can redistribute it and/or modify
11
it under the terms of the GNU Lesser General Public License as published by
12
the Free Software Foundation, either version 3 of the License, or
13
(at your option) any later version.
14
15
MyGUI is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU Lesser General Public License for more details.
19
20
You should have received a copy of the GNU Lesser General Public License
21
along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22
*/
23
#include "
MyGUI_Precompiled.h
"
24
#include "
MyGUI_TextureUtility.h
"
25
#include "
MyGUI_RenderManager.h
"
26
#include "
MyGUI_DataManager.h
"
27
#include "
MyGUI_Bitwise.h
"
28
29
namespace
MyGUI
30
{
31
32
namespace
texture_utility
33
{
34
35
const
IntSize
&
getTextureSize
(
const
std::string& _texture,
bool
_cache)
36
{
37
// ïðåäûäóùÿ òåêñòóðà
38
static
std::string old_texture;
39
static
IntSize
old_size;
40
41
if
(old_texture == _texture && _cache)
42
return
old_size;
43
old_texture = _texture;
44
old_size.
clear
();
45
46
if
(_texture.empty())
47
return
old_size;
48
49
RenderManager
& render =
RenderManager::getInstance
();
50
51
if
(
nullptr
== render.
getTexture
(_texture))
52
{
53
if
(!
DataManager::getInstance
().
isDataExist
(_texture))
54
{
55
MYGUI_LOG
(Error,
"Texture '"
+ _texture +
"' not found"
);
56
return
old_size;
57
}
58
else
59
{
60
ITexture
* texture = render.
createTexture
(_texture);
61
texture->
loadFromFile
(_texture);
62
}
63
}
64
65
ITexture
* texture = render.
getTexture
(_texture);
66
if
(texture ==
nullptr
)
67
{
68
MYGUI_LOG
(Error,
"Texture '"
+ _texture +
"' not found"
);
69
return
old_size;
70
}
71
72
old_size.
set
(texture->
getWidth
(), texture->
getHeight
());
73
74
#if MYGUI_DEBUG_MODE == 1
75
if
(!
Bitwise::isPO2
(old_size.
width
) || !
Bitwise::isPO2
(old_size.
height
))
76
{
77
MYGUI_LOG
(Warning,
"Texture '"
+ _texture +
"' have non power of two size"
);
78
}
79
#endif
80
81
return
old_size;
82
}
83
84
uint32
toColourARGB
(
const
Colour
& _colour)
85
{
86
uint32
val32 =
uint8
(_colour.
alpha
* 255);
87
val32 <<= 8;
88
val32 +=
uint8
(_colour.
red
* 255);
89
val32 <<= 8;
90
val32 +=
uint8
(_colour.
green
* 255);
91
val32 <<= 8;
92
val32 +=
uint8
(_colour.
blue
* 255);
93
return
val32;
94
}
95
96
}
// namespace texture_utility
97
98
}
// namespace MyGUI
Generated by
1.8.1.2