diff --git a/examples/osgshadow/osgshadow.cpp b/examples/osgshadow/osgshadow.cpp index 9319471e9..8f1183af3 100644 --- a/examples/osgshadow/osgshadow.cpp +++ b/examples/osgshadow/osgshadow.cpp @@ -54,10 +54,11 @@ int main(int argc, char** argv) } + osg::ref_ptr geode = new osg::Geode; + osg::ref_ptr occluder = new osgShadow::OccluderGeometry; occluder->computeOccluderGeometry(model.get()); - osg::ref_ptr geode = new osg::Geode; geode->addDrawable(occluder.get()); viewer.setSceneData(geode.get()); diff --git a/src/osgShadow/OccluderGeometry.cpp b/src/osgShadow/OccluderGeometry.cpp index c198bd9b1..734c9c005 100644 --- a/src/osgShadow/OccluderGeometry.cpp +++ b/src/osgShadow/OccluderGeometry.cpp @@ -12,11 +12,16 @@ */ #include + #include #include #include #include #include +#include +#include + +#include using namespace osgShadow; @@ -121,7 +126,7 @@ public: osg::StateAttribute::GLModeValue blendModeValue = _blendModeStack.empty() ? osg::StateAttribute::GLModeValue(osg::StateAttribute::INHERIT) : _blendModeStack.back(); if (blendModeValue & osg::StateAttribute::ON) { - osg::notify(osg::NOTICE)<<"Ignoring transparent drawable."<tick(); CollectOccludersVisitor cov(this, matrix, sampleRatio); subgraph->accept(cov); - osg::notify(osg::NOTICE)<<"done"<tick(); + + osg::notify(osg::NOTICE)<<"done in "<delta_m(startTick, endTick)<<" ms"< TriangleIndexCollectorFunctor; - struct TriangleCollector { OccluderGeometry::Vec3List* _vertices; @@ -187,6 +172,31 @@ struct TriangleCollector typedef std::vector VertexPointers; VertexPointers _vertexPointers; + struct IndexVec3PtrPair + { + IndexVec3PtrPair(): + vec(0), + index(0) {} + + IndexVec3PtrPair(const osg::Vec3* v, unsigned int i): + vec(v), + index(i) {} + + inline bool operator < (const IndexVec3PtrPair& rhs) const + { + return *vec < *rhs.vec; + } + + inline bool operator == (const IndexVec3PtrPair& rhs) const + { + return *vec == *rhs.vec; + } + + const osg::Vec3* vec; + unsigned int index; + }; + + OccluderGeometry::Vec3List _tempoaryTriangleVertices; TriangleCollector():_matrix(0) { } @@ -204,7 +214,7 @@ struct TriangleCollector { if (treatVertexDataAsTemporary) { - osg::notify(osg::NOTICE)<<"Triangle temp ("<size(); - unsigned int numberNewVertices = (maxVertex - minVertex); + unsigned int numberNewVertices = _vertexPointers.empty() ? 0 : (maxVertex - minVertex) + 1; - osg::notify(osg::NOTICE)<<"base = "<disableAllVertexArrays(); + + renderInfo.getState()->setVertexPointer( 3, GL_FLOAT, 0, &(_vertices.front()) ); + + glDrawElements(GL_TRIANGLES, _triangleIndices.size(), GL_UNSIGNED_INT, &(_triangleIndices.front()) ); } osg::BoundingBox OccluderGeometry::computeBound() const @@ -296,5 +364,8 @@ osg::BoundingBox OccluderGeometry::computeBound() const { bb.expandBy(*itr); } + + osg::notify(osg::NOTICE)<<"computeBB "<