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