Added Geometry::drawVertexArraysomplemetation(..) and drawPrimitivesImplemenation(..) methods that are called from drawImplementation(..). These new vertex methods

allow subclasses from osg::Geometry to specialize the vertex array setup or how the primitives are dispatched to OpenGL.
This commit is contained in:
Robert Osfield 2013-11-21 10:31:34 +00:00
parent dbf88cc209
commit a54b999ccc
2 changed files with 35 additions and 15 deletions

View File

@ -173,6 +173,12 @@ class OSG_EXPORT Geometry : public Drawable
*/
virtual void drawImplementation(RenderInfo& renderInfo) const;
/** 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; }

View File

@ -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