MyGUI  3.2.0
MyGUI_TextureUtility.cpp
Go to the documentation of this file.
1 
6 /*
7  This file is part of MyGUI.
8 
9  MyGUI is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  MyGUI is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_TextureUtility.h"
24 #include "MyGUI_RenderManager.h"
25 #include "MyGUI_DataManager.h"
26 #include "MyGUI_Bitwise.h"
27 
28 namespace MyGUI
29 {
30 
31  namespace texture_utility
32  {
33 
34  const IntSize& getTextureSize(const std::string& _texture, bool _cache)
35  {
36  // предыдущя текстура
37  static std::string old_texture;
38  static IntSize old_size;
39 
40  if (old_texture == _texture && _cache)
41  return old_size;
42  old_texture = _texture;
43  old_size.clear();
44 
45  if (_texture.empty())
46  return old_size;
47 
49 
50  if (nullptr == render.getTexture(_texture))
51  {
52  if (!DataManager::getInstance().isDataExist(_texture))
53  {
54  MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
55  return old_size;
56  }
57  else
58  {
59  ITexture* texture = render.createTexture(_texture);
60  texture->loadFromFile(_texture);
61  }
62  }
63 
64  ITexture* texture = render.getTexture(_texture);
65  if (texture == nullptr)
66  {
67  MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
68  return old_size;
69  }
70 
71  old_size.set(texture->getWidth(), texture->getHeight());
72 
73  #if MYGUI_DEBUG_MODE == 1
74  if (!Bitwise::isPO2(old_size.width) || !Bitwise::isPO2(old_size.height))
75  {
76  MYGUI_LOG(Warning, "Texture '" + _texture + "' have non power of two size");
77  }
78  #endif
79 
80  return old_size;
81  }
82 
83  uint32 toColourARGB(const Colour& _colour)
84  {
85  uint32 val32 = uint8(_colour.alpha * 255);
86  val32 <<= 8;
87  val32 += uint8(_colour.red * 255);
88  val32 <<= 8;
89  val32 += uint8(_colour.green * 255);
90  val32 <<= 8;
91  val32 += uint8(_colour.blue * 255);
92  return val32;
93  }
94 
95  } // namespace texture_utility
96 
97 } // namespace MyGUI
unsigned int uint32
Definition: MyGUI_Types.h:63
static RenderManager & getInstance()
const IntSize & getTextureSize(const std::string &_texture, bool _cache=true)
virtual ITexture * getTexture(const std::string &_name)=0
void set(T const &_width, T const &_height)
Definition: MyGUI_TSize.h:110
virtual bool isDataExist(const std::string &_name)=0
#define MYGUI_LOG(level, text)
virtual int getHeight()=0
uint32 toColourARGB(const Colour &_colour)
static __inline bool isPO2(Type _value)
Definition: MyGUI_Bitwise.h:50
virtual void loadFromFile(const std::string &_filename)=0
unsigned char uint8
Definition: MyGUI_Types.h:61
virtual ITexture * createTexture(const std::string &_name)=0
virtual int getWidth()=0