]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/EffectCullVisitor.cxx
Random buildings - initial commit.
[simgear.git] / simgear / scene / material / EffectCullVisitor.cxx
index 8d86d8e0ea6972b6c3716cbca6e1f81ea49578a8..c44d8d695c1cf086ba42793030a2d829c71f2db1 100644 (file)
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
+#include <osg/StateSet>
+#include <osg/Texture2D>
+
 #include "EffectCullVisitor.hxx"
 
 #include "EffectGeode.hxx"
 #include "Effect.hxx"
 #include "Technique.hxx"
 
+#include <simgear/scene/util/RenderConstants.hxx>
+
 namespace simgear
 {
 
 using osgUtil::CullVisitor;
 
-EffectCullVisitor::EffectCullVisitor()
+EffectCullVisitor::EffectCullVisitor(bool collectLights) :
+    _collectLights(collectLights)
 {
 }
 
 EffectCullVisitor::EffectCullVisitor(const EffectCullVisitor& rhs) :
+    osg::Referenced(rhs),
     CullVisitor(rhs)
 {
 }
@@ -48,16 +59,53 @@ void EffectCullVisitor::apply(osg::Geode& node)
         CullVisitor::apply(node);
         return;
     }
-    Technique* technique = eg->getEffect()->chooseTechnique(&getRenderInfo());
-    if (!technique) {
+    if (_collectLights && ( eg->getNodeMask() & MODELLIGHT_BIT ) ) {
+        _lightList.push_back( eg );
+    }
+    Effect* effect = eg->getEffect();
+    Technique* technique = 0;
+    if (!effect) {
         CullVisitor::apply(node);
         return;
+    } else if (!(technique = effect->chooseTechnique(&getRenderInfo()))) {
+        return;
     }
+    // push the node's state.
+    osg::StateSet* node_state = node.getStateSet();
+    if (node_state)
+        pushStateSet(node_state);
     for (EffectGeode::DrawablesIterator beginItr = eg->drawablesBegin(),
              e = eg->drawablesEnd();
          beginItr != e;
          beginItr = technique->processDrawables(beginItr, e, this,
                                                 eg->isCullingActive()))
         ;
+    // pop the node's state off the geostate stack.
+    if (node_state)
+        popStateSet();
+
+}
+
+void EffectCullVisitor::reset()
+{
+    _lightList.clear();
+
+    osgUtil::CullVisitor::reset();
 }
+
+void EffectCullVisitor::clearBufferList()
+{
+    _bufferList.clear();
+}
+
+void EffectCullVisitor::addBuffer(int i, osg::Texture2D* tex)
+{
+    _bufferList.insert(std::make_pair(i,tex));
+}
+
+osg::Texture2D* EffectCullVisitor::getBuffer(int i)
+{
+    return _bufferList[i];
+}
+
 }