]> git.mxchange.org Git - simgear.git/commitdiff
Use names to identify deferred buffers
authorFrederic Bouvier <fredfgfs01@free.fr>
Sun, 15 Apr 2012 12:51:20 +0000 (14:51 +0200)
committerFrederic Bouvier <fredfgfs01@free.fr>
Fri, 11 May 2012 22:16:17 +0000 (00:16 +0200)
Change effect syntax for buffers

simgear/scene/material/Effect.hxx
simgear/scene/material/EffectCullVisitor.cxx
simgear/scene/material/EffectCullVisitor.hxx
simgear/scene/material/Pass.hxx
simgear/scene/material/TextureBuilder.cxx

index 0a5ffe2b333008e7c86d3d479528a85576389fc8..740ec9dd9e38ef86dd7096793609b74975fdf27e 100644 (file)
@@ -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
     {
index c44d8d695c1cf086ba42793030a2d829c71f2db1..4f84552e56584dda0cc1ea3ee4ef583b869b0595 100644 (file)
@@ -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];
 }
 
 }
index c4d3c6300ad3181d80028afbffe2265d1a5662af..ec8f223a8a6fbe8b7138d1e04cd6aedee6dd56fd 100644 (file)
@@ -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<int,osg::ref_ptr<osg::Texture2D> > _bufferList;
+    std::map<std::string,osg::ref_ptr<osg::Texture2D> > _bufferList;
     std::vector<osg::ref_ptr<EffectGeode> > _lightList;
     bool _collectLights;
 };
index a2c901ddacb8f84ed40cb38c5303c5c0948de548..7b5bb3e4bef56d0796afd386b68c74cdcb5ffc10 100644 (file)
@@ -26,7 +26,7 @@ namespace simgear
 class Pass : public osg::StateSet
 {
 public:
-    typedef std::list<std::pair<int,int> > BufferUnitList;
+    typedef std::list<std::pair<int,std::string> > BufferUnitList;
     typedef std::map<std::string,osg::Vec4> 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; }
index 99527fcba92001b0aae438e65bf3c2508e98b653..5ee5836a38fd786eeaab8bb4d6e2b80ef252cccd 100644 (file)
@@ -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<int>();
     } else {
-        const SGPropertyNode* pName = prop->getChild("name");
-        if (pName)
-            try {
-                unit = boost::lexical_cast<int>(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);
 }
 
 }