RigsofRods
Soft-body Physics Simulation
RTTLayer.cpp
Go to the documentation of this file.
1 // based on the MyGUI UnitTests
2 
3 #include "MyGUI_LayerItem.h"
4 #include "RTTLayer.h"
5 #include "MyGUI_Enumerator.h"
6 #include "MyGUI_FactoryManager.h"
7 #include "MyGUI_RenderManager.h"
8 #include "MyGUI_Gui.h"
9 #include "MyGUI_LayerNode.h"
10 
11 namespace MyGUI {
12 
14  mTexture(nullptr),
15  mOutOfDate(false)
16 {
17 }
18 
20 {
21  if (mTexture)
22  {
23  MyGUI::RenderManager::getInstance().destroyTexture(mTexture);
24  mTexture = nullptr;
25  }
26 }
27 
28 void RTTLayer::deserialization(xml::ElementPtr _node, Version _version)
29 {
30  Base::deserialization(_node, _version);
31 
32  MyGUI::xml::ElementEnumerator propert = _node->getElementEnumerator();
33  while (propert.next("Property"))
34  {
35  const std::string& key = propert->findAttribute("key");
36  const std::string& value = propert->findAttribute("value");
37  if (key == "TextureSize")
38  setTextureSize(utility::parseValue<IntSize>(value));
39  if (key == "TextureName")
40  setTextureName(value);
41  }
42 }
43 
44 void RTTLayer::renderToTarget(IRenderTarget* _target, bool _update)
45 {
46  bool outOfDate = mOutOfDate || isOutOfDate();
47 
48  if (outOfDate || _update)
49  {
50  MyGUI::IRenderTarget* target = mTexture->getRenderTarget();
51  if (target != nullptr)
52  {
53  target->begin();
54 
55  for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
56  (*iter)->renderToTarget(target, _update);
57 
58  target->end();
59  }
60  }
61 
62  mOutOfDate = false;
63 }
64 
65 void RTTLayer::setTextureSize(const IntSize& _size)
66 {
67  if (mTextureSize == _size)
68  return;
69 
70  mTextureSize = _size;
71  if (mTexture)
72  {
73  MyGUI::RenderManager::getInstance().destroyTexture(mTexture);
74  mTexture = nullptr;
75  }
76 
77  MYGUI_ASSERT(mTextureSize.width * mTextureSize.height, "RTTLayer texture size must have non-zero width and height");
78  std::string name = mTextureName.empty() ? MyGUI::utility::toString((size_t)this, getClassTypeName()) : mTextureName;
79  mTexture = MyGUI::RenderManager::getInstance().createTexture(name);
80  mTexture->createManual(mTextureSize.width, mTextureSize.height, MyGUI::TextureUsage::RenderTarget, MyGUI::PixelFormat::R8G8B8A8);
81 
82  mOutOfDate = true;
83 }
84 
85 void RTTLayer::setTextureName(const std::string& _name)
86 {
87  mTextureName = _name;
88 
89  if (mTexture != nullptr)
90  {
91  IntSize size = mTextureSize;
92  mTextureSize.clear();
93  setTextureSize(size);
94  }
95 
96  mOutOfDate = true;
97 }
98 
99 } // namespace MyGUI
MyGUI::RTTLayer::deserialization
virtual void deserialization(xml::ElementPtr _node, Version _version)
Definition: RTTLayer.cpp:28
MyGUI::RTTLayer::mTextureSize
IntSize mTextureSize
Definition: RTTLayer.h:28
MyGUI::RTTLayer::renderToTarget
virtual void renderToTarget(IRenderTarget *_target, bool _update)
Definition: RTTLayer.cpp:44
MyGUI::RTTLayer::mTexture
MyGUI::ITexture * mTexture
Definition: RTTLayer.h:27
MyGUI::RTTLayer::setTextureName
void setTextureName(const std::string &_name)
Definition: RTTLayer.cpp:85
RTTLayer.h
MyGUI::RTTLayer::mTextureName
std::string mTextureName
Definition: RTTLayer.h:29
MyGUI::RTTLayer::mOutOfDate
bool mOutOfDate
Definition: RTTLayer.h:30
MyGUI::RTTLayer::setTextureSize
void setTextureSize(const IntSize &_size)
Definition: RTTLayer.cpp:65
MyGUI
Definition: RTTLayer.cpp:11
MyGUI::RTTLayer::RTTLayer
RTTLayer()
Definition: RTTLayer.cpp:13
MyGUI::RTTLayer::~RTTLayer
virtual ~RTTLayer()
Definition: RTTLayer.cpp:19