From 2b9072417bba4883805702eff42cbf5c4ee44583 Mon Sep 17 00:00:00 2001 From: Frederic Bouvier Date: Sun, 15 Apr 2012 14:51:20 +0200 Subject: [PATCH] Use names to identify deferred buffers Change effect syntax for buffers --- simgear/scene/material/Effect.hxx | 13 ---------- simgear/scene/material/EffectCullVisitor.cxx | 8 +++---- simgear/scene/material/EffectCullVisitor.hxx | 6 ++--- simgear/scene/material/Pass.hxx | 4 ++-- simgear/scene/material/TextureBuilder.cxx | 25 +++++--------------- 5 files changed, 15 insertions(+), 41 deletions(-) diff --git a/simgear/scene/material/Effect.hxx b/simgear/scene/material/Effect.hxx index 0a5ffe2b..740ec9dd 100644 --- a/simgear/scene/material/Effect.hxx +++ b/simgear/scene/material/Effect.hxx @@ -82,19 +82,6 @@ public: const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); osg::StateSet* getDefaultStateSet(); - enum Buffer - { - DEPTH_BUFFER, - NORMAL_BUFFER, - DIFFUSE_BUFFER, - SPEC_EMIS_BUFFER, - LIGHTING_BUFFER, - MIDDLE_BLOOM_BUFFER, - BLOOM_BUFFER, - AO_BUFFER, - SHADOW_BUFFER - }; - // Define what needs to be generated for this effect enum Generator { diff --git a/simgear/scene/material/EffectCullVisitor.cxx b/simgear/scene/material/EffectCullVisitor.cxx index c44d8d69..4f84552e 100644 --- a/simgear/scene/material/EffectCullVisitor.cxx +++ b/simgear/scene/material/EffectCullVisitor.cxx @@ -98,14 +98,14 @@ void EffectCullVisitor::clearBufferList() _bufferList.clear(); } -void EffectCullVisitor::addBuffer(int i, osg::Texture2D* tex) +void EffectCullVisitor::addBuffer(std::string b, osg::Texture2D* tex) { - _bufferList.insert(std::make_pair(i,tex)); + _bufferList.insert(std::make_pair(b,tex)); } -osg::Texture2D* EffectCullVisitor::getBuffer(int i) +osg::Texture2D* EffectCullVisitor::getBuffer(std::string b) { - return _bufferList[i]; + return _bufferList[b]; } } diff --git a/simgear/scene/material/EffectCullVisitor.hxx b/simgear/scene/material/EffectCullVisitor.hxx index c4d3c630..ec8f223a 100644 --- a/simgear/scene/material/EffectCullVisitor.hxx +++ b/simgear/scene/material/EffectCullVisitor.hxx @@ -41,11 +41,11 @@ public: virtual void reset(); void clearBufferList(); - void addBuffer(int i, osg::Texture2D* tex); - osg::Texture2D* getBuffer(int i); + void addBuffer(std::string b, osg::Texture2D* tex); + osg::Texture2D* getBuffer(std::string b); private: - std::map > _bufferList; + std::map > _bufferList; std::vector > _lightList; bool _collectLights; }; diff --git a/simgear/scene/material/Pass.hxx b/simgear/scene/material/Pass.hxx index a2c901dd..7b5bb3e4 100644 --- a/simgear/scene/material/Pass.hxx +++ b/simgear/scene/material/Pass.hxx @@ -26,7 +26,7 @@ namespace simgear class Pass : public osg::StateSet { public: - typedef std::list > BufferUnitList; + typedef std::list > BufferUnitList; typedef std::map PositionedUniformMap; META_Object(simgear,Pass); @@ -34,7 +34,7 @@ public: Pass(const Pass& rhs, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); - void setBufferUnit( int unit, int buffer ) { _bufferUnitList.push_back( std::make_pair(unit,buffer) ); } + void setBufferUnit( int unit, std::string buffer ) { _bufferUnitList.push_back( std::make_pair(unit,buffer) ); } const BufferUnitList& getBufferUnitList() const { return _bufferUnitList; } void addPositionedUniform( const std::string& name, const osg::Vec4& offset ) { _positionedUniforms[name] = offset; } diff --git a/simgear/scene/material/TextureBuilder.cxx b/simgear/scene/material/TextureBuilder.cxx index 99527fcb..5ee5836a 100644 --- a/simgear/scene/material/TextureBuilder.cxx +++ b/simgear/scene/material/TextureBuilder.cxx @@ -832,11 +832,11 @@ bool makeTextureParameters(SGPropertyNode* paramRoot, const StateSet* ss) class GBufferBuilder : public TextureBuilder { public: - GBufferBuilder(int b) : buffer(b) {} + GBufferBuilder() {} Texture* build(Effect* effect, Pass* pass, const SGPropertyNode*, const SGReaderWriterOptions* options); private: - int buffer; + string buffer; }; Texture* GBufferBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode* prop, @@ -847,15 +847,10 @@ Texture* GBufferBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode* if (pUnit) { unit = pUnit->getValue(); } else { - const SGPropertyNode* pName = prop->getChild("name"); - if (pName) - try { - unit = boost::lexical_cast(pName->getStringValue()); - } catch (boost::bad_lexical_cast& lex) { - SG_LOG(SG_INPUT, SG_ALERT, "can't decode name as texture unit " - << lex.what()); - } + SG_LOG(SG_INPUT, SG_ALERT, "no texture unit"); } + buffer = prop->getStringValue("name"); + pass->setBufferUnit( unit, buffer ); // Return white for now. Would be overridden in Technique::ProcessDrawable @@ -864,15 +859,7 @@ Texture* GBufferBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode* namespace { - TextureBuilder::Registrar installDepthBuffer("depth-buffer", new GBufferBuilder(Effect::DEPTH_BUFFER)); - TextureBuilder::Registrar installNormalBuffer("normal-buffer", new GBufferBuilder(Effect::NORMAL_BUFFER)); - TextureBuilder::Registrar installDiffuseBuffer("diffuse-buffer", new GBufferBuilder(Effect::DIFFUSE_BUFFER)); - TextureBuilder::Registrar installSpecularBuffer("spec-emis-buffer", new GBufferBuilder(Effect::SPEC_EMIS_BUFFER)); - TextureBuilder::Registrar installLightingBuffer("lighting-buffer", new GBufferBuilder(Effect::LIGHTING_BUFFER)); - TextureBuilder::Registrar installMiddleBloomBuffer("middle-bloom-buffer", new GBufferBuilder(Effect::MIDDLE_BLOOM_BUFFER)); - TextureBuilder::Registrar installBloomBuffer("bloom-buffer", new GBufferBuilder(Effect::BLOOM_BUFFER)); - TextureBuilder::Registrar installAoBuffer("ao-buffer", new GBufferBuilder(Effect::AO_BUFFER)); - TextureBuilder::Registrar installShadowBuffer("shadow-buffer", new GBufferBuilder(Effect::SHADOW_BUFFER)); + TextureBuilder::Registrar installBuffer("buffer", new GBufferBuilder); } } -- 2.39.5