add DrawIndirectBufferObject as State variable in order to minimize call to glBindBuffer(GL_DRAW_INDIRECT_BUFFER,X)

TODO: Promote PrimitiveSetIndirect's VBO to target explicited DIBO (in order to benefit from BOSet queue management)
This commit is contained in:
mp3butcher 2017-07-27 01:54:25 +02:00
parent 9b53775840
commit 7606159a78
3 changed files with 31 additions and 8 deletions

View File

@ -591,6 +591,27 @@ class OSG_EXPORT State : public Referenced
} }
inline void bindDrawIndirectBufferObject(osg::GLBufferObject* ibo)
{
if (ibo->isDirty())
{
ibo->compileBuffer();
_currentDIBO = ibo;
}
else if (ibo != _currentDIBO)
{
_glBindBuffer(GL_DRAW_INDIRECT_BUFFER, ibo->getGLObjectID());
_currentDIBO = ibo;
}
}
inline void unbindDrawIndirectBufferObject()
{
if (!_currentDIBO) return;
_glBindBuffer(GL_DRAW_INDIRECT_BUFFER,0);
_currentDIBO = 0;
}
void setCurrentVertexArrayObject(GLuint vao) { _currentVAO = vao; } void setCurrentVertexArrayObject(GLuint vao) { _currentVAO = vao; }
GLuint getCurrentVertexArrayObject() const { return _currentVAO; } GLuint getCurrentVertexArrayObject() const { return _currentVAO; }
@ -1259,6 +1280,7 @@ class OSG_EXPORT State : public Referenced
unsigned int _currentActiveTextureUnit; unsigned int _currentActiveTextureUnit;
unsigned int _currentClientActiveTextureUnit; unsigned int _currentClientActiveTextureUnit;
GLBufferObject* _currentPBO; GLBufferObject* _currentPBO;
GLBufferObject* _currentDIBO;
GLuint _currentVAO; GLuint _currentVAO;

View File

@ -64,7 +64,7 @@ unsigned int DrawElementsIndirectUShort::getNumPrimitives() const{return getNumP
void DrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjects) const void DrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjects) const
{ GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() ); { GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID()); state.bindDrawIndirectBufferObject(dibo);
GLenum mode = _mode; GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
@ -122,7 +122,7 @@ void DrawElementsIndirectUInt::accept(PrimitiveIndexFunctor& functor) const
} }
void DrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObjects) const void DrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObjects) const
{ GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() ); { GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID()); state.bindDrawIndirectBufferObject(dibo);
GLenum mode = _mode; GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
@ -176,7 +176,7 @@ void DrawElementsIndirectUByte::accept(PrimitiveIndexFunctor& functor) const
} }
void DrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObjects) const void DrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObjects) const
{ GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() ); { GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID()); state.bindDrawIndirectBufferObject(dibo);
GLenum mode = _mode; GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
@ -282,7 +282,7 @@ void MultiDrawElementsIndirectUByte::draw(State& state, bool useVertexBufferObje
{ {
GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() ); GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID()); state.bindDrawIndirectBufferObject(dibo);
GLenum mode = _mode; GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN; if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN;
@ -340,7 +340,7 @@ MultiDrawElementsIndirectUShort::~MultiDrawElementsIndirectUShort()
void MultiDrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObjects) const void MultiDrawElementsIndirectUShort::draw(State& state, bool useVertexBufferObjects) const
{ GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() ); { GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID()); state.bindDrawIndirectBufferObject(dibo);
GLenum mode = _mode; GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
@ -397,7 +397,7 @@ MultiDrawElementsIndirectUInt::~MultiDrawElementsIndirectUInt()
void MultiDrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjects) const void MultiDrawElementsIndirectUInt::draw(State& state, bool useVertexBufferObjects) const
{ {
GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() ); GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID()); state.bindDrawIndirectBufferObject(dibo);
GLenum mode = _mode; GLenum mode = _mode;
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN; if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN;
@ -450,7 +450,7 @@ void MultiDrawElementsIndirectUInt::accept(PrimitiveIndexFunctor& functor) const
void DrawArraysIndirect::draw(osg::State& state, bool) const void DrawArraysIndirect::draw(osg::State& state, bool) const
{ {
GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() ); GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID()); state.bindDrawIndirectBufferObject(dibo);
GLExtensions* ext = state.get<GLExtensions>(); GLExtensions* ext = state.get<GLExtensions>();
@ -517,7 +517,7 @@ unsigned int DrawArraysIndirect::getNumPrimitives() const
void MultiDrawArraysIndirect::draw(osg::State& state, bool) const void MultiDrawArraysIndirect::draw(osg::State& state, bool) const
{ {
GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() ); GLBufferObject* dibo = _indirectCommandArray->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
state.get<GLExtensions>()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dibo->getGLObjectID()); state.bindDrawIndirectBufferObject(dibo);
GLExtensions* ext = state.get<GLExtensions>(); GLExtensions* ext = state.get<GLExtensions>();

View File

@ -89,6 +89,7 @@ State::State():
_currentClientActiveTextureUnit=0; _currentClientActiveTextureUnit=0;
_currentPBO = 0; _currentPBO = 0;
_currentDIBO = 0;
_currentVAO = 0; _currentVAO = 0;
_isSecondaryColorSupported = false; _isSecondaryColorSupported = false;