diff --git a/include/osg/Geometry b/include/osg/Geometry index 68246d92e..652b57b0c 100644 --- a/include/osg/Geometry +++ b/include/osg/Geometry @@ -173,7 +173,13 @@ class OSG_EXPORT Geometry : public Drawable */ virtual void drawImplementation(RenderInfo& renderInfo) const; - /** Return true, osg::Geometry does support accept(Drawable::AttributeFunctor&). */ + /** Set up the vertex arrays for the purpose of rendering, called by drawImplemtation() prior to it calling drawPrimitivesImplementation().*/ + void drawVertexArraysImplementation(RenderInfo& renderInfo) const; + + /** dispatch the primitives to OpenGL, called by drawImplemtation() after calling drawVertexArraysImplementation().*/ + void drawPrimitivesImplementation(RenderInfo& renderInfo) const; + + /** Return true, osg::Geometry does support accept(Drawable::AttributeFunctor&). */ virtual bool supports(const Drawable::AttributeFunctor&) const { return true; } /** Accept an Drawable::AttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has. */ diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 1df20446a..072832c14 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -703,7 +703,27 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE; if (checkForGLErrors) state.checkGLErrors("start of Geometry::drawImplementation()"); - bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported(); + drawVertexArraysImplementation(renderInfo); + + if (checkForGLErrors) state.checkGLErrors("Geometry::drawImplementation() after vertex arrays setup."); + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // draw the primitives themselves. + // + drawPrimitivesImplementation(renderInfo); + + // unbind the VBO's if any are used. + state.unbindVertexBufferObject(); + state.unbindElementBufferObject(); + + if (checkForGLErrors) state.checkGLErrors("end of Geometry::drawImplementation()."); +} + +void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const +{ + State& state = *renderInfo.getState(); + bool handleVertexAttributes = !_vertexAttribList.empty(); ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers(); @@ -777,15 +797,15 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const } state.applyDisablingOfVertexAttributes(); +} + +void Geometry::drawPrimitivesImplementation(RenderInfo& renderInfo) const +{ + State& state = *renderInfo.getState(); + ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers(); + bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported(); bool bindPerPrimitiveSetActive = arrayDispatchers.active(osg::Array::BIND_PER_PRIMITIVE_SET); - - if (checkForGLErrors) state.checkGLErrors("Geometry::drawImplementation() after vertex arrays setup."); - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // draw the primitives themselves. - // for(unsigned int primitiveSetNum=0; primitiveSetNum!=_primitives.size(); ++primitiveSetNum) { // dispatch any attributes that are bound per primitive @@ -795,12 +815,6 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const primitiveset->draw(state, usingVertexBufferObjects); } - - // unbind the VBO's if any are used. - state.unbindVertexBufferObject(); - state.unbindElementBufferObject(); - - if (checkForGLErrors) state.checkGLErrors("end of Geometry::drawImplementation()."); } class AttributeFunctorArrayVisitor : public ArrayVisitor