From: Frederic Bouvier Date: Fri, 18 May 2012 10:27:08 +0000 (+0200) Subject: Allow to change texture buffer name on the fly X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=38c335c33942a9251140f442c229217144481599;p=simgear.git Allow to change texture buffer name on the fly --- diff --git a/simgear/scene/material/TextureBuilder.cxx b/simgear/scene/material/TextureBuilder.cxx index a361fee1..da788d6e 100644 --- a/simgear/scene/material/TextureBuilder.cxx +++ b/simgear/scene/material/TextureBuilder.cxx @@ -839,6 +839,38 @@ private: string buffer; }; +class BufferNameChangeListener : public SGPropertyChangeListener, public InitializeWhenAdded, + public Effect::Updater { +public: + BufferNameChangeListener(Pass* p, int u, const std::string& pn) : pass(p), unit(u) + { + propName = new std::string(pn); + } + ~BufferNameChangeListener() + { + delete propName; + propName = 0; + } + void valueChanged(SGPropertyNode* node) + { + const char* buffer = node->getStringValue(); + pass->setBufferUnit(unit, buffer); + } + void initOnAddImpl(Effect* effect, SGPropertyNode* propRoot) + { + SGPropertyNode* listenProp = makeNode(propRoot, *propName); + delete propName; + propName = 0; + if (listenProp) + listenProp->addChangeListener(this, true); + } + +private: + ref_ptr pass; + int unit; + std::string* propName; +}; + Texture* GBufferBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode* prop, const SGReaderWriterOptions* options) { @@ -853,9 +885,15 @@ Texture* GBufferBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode* "name"); if (!nameProp) return 0; - buffer = nameProp->getStringValue(); - pass->setBufferUnit( unit, buffer ); + if (nameProp->nChildren() == 0) { + buffer = nameProp->getStringValue(); + pass->setBufferUnit( unit, buffer ); + } else { + std::string propName = getGlobalProperty(nameProp, options); + BufferNameChangeListener* listener = new BufferNameChangeListener(pass, unit, propName); + effect->addUpdater(listener); + } // Return white for now. Would be overridden in Technique::ProcessDrawable return StateAttributeFactory::instance()->getWhiteTexture();