Added lazy state updating for vertex array object binding/unbinding

This commit is contained in:
Robert Osfield 2017-03-13 11:44:34 +00:00
parent a6453ad877
commit ffbc1167de
6 changed files with 26 additions and 9 deletions

View File

@ -563,7 +563,7 @@ class OSG_EXPORT State : public Referenced
void setCurrentPixelBufferObject(osg::GLBufferObject* pbo) { _currentPBO = pbo; }
const GLBufferObject* getCurrentPixelBufferObject() { return _currentPBO; }
const GLBufferObject* getCurrentPixelBufferObject() const { return _currentPBO; }
inline void bindPixelBufferObject(osg::GLBufferObject* pbo)
{
@ -590,6 +590,17 @@ class OSG_EXPORT State : public Referenced
_currentPBO = 0;
}
void setCurrentVertexArrayObject(GLuint vao) { _currentVAO = vao; }
GLuint getCurrentVertexArrayObject() const { return _currentVAO; }
inline void bindVertexArrayObject(const VertexArrayState* vas) { bindVertexArrayObject(vas->getVertexArrayObject()); }
inline void bindVertexArrayObject(GLuint vao) { if (_currentVAO!=vao) { _glExtensions->glBindVertexArray(vao); _currentVAO = vao; } }
inline void unbindVertexArrayObject() { if (_currentVAO!=0) { _glExtensions->glBindVertexArray(0); _currentVAO = 0; } }
typedef std::vector<GLushort> IndicesGLushort;
IndicesGLushort _quadIndicesGLushort[4];
@ -1248,6 +1259,7 @@ class OSG_EXPORT State : public Referenced
unsigned int _currentActiveTextureUnit;
unsigned int _currentClientActiveTextureUnit;
GLBufferObject* _currentPBO;
GLuint _currentVAO;
inline ModeMap& getOrCreateTextureModeMap(unsigned int unit)

View File

@ -164,10 +164,6 @@ public:
void deleteVertexArrayObject();
inline void bindVertexArrayObject() const { _ext->glBindVertexArray (_vertexArrayObject); }
inline void unbindVertexArrayObject() const { _ext->glBindVertexArray (0); }
GLuint getVertexArrayObject() const { return _vertexArrayObject; }

View File

@ -642,7 +642,7 @@ void Drawable::draw(RenderInfo& renderInfo) const
State::SetCurrentVertexArrayStateProxy setVASProxy(state, vas);
vas->bindVertexArrayObject();
state.bindVertexArrayObject(vas);
drawInner(renderInfo);
@ -652,7 +652,11 @@ void Drawable::draw(RenderInfo& renderInfo) const
}
// TODO, add check against whether VAO is active and supported
if (state.getCurrentVertexArrayState()) state.getCurrentVertexArrayState()->bindVertexArrayObject();
if (state.getCurrentVertexArrayState())
{
//OSG_NOTICE<<"state.getCurrentVertexArrayState()->getVertexArrayObject()="<< state.getCurrentVertexArrayState()->getVertexArrayObject()<<std::endl;
state.bindVertexArrayObject(state.getCurrentVertexArrayState());
}
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE

View File

@ -820,9 +820,11 @@ void Geometry::compileGLObjects(RenderInfo& renderInfo) const
State::SetCurrentVertexArrayStateProxy setVASProxy(state, vas);
vas->bindVertexArrayObject();
state.bindVertexArrayObject(vas);
drawVertexArraysImplementation(renderInfo);
state.unbindVertexArrayObject();
}
}
else

View File

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

View File

@ -861,10 +861,12 @@ void SharedGeometry::compileGLObjects(osg::RenderInfo& renderInfo) const
osg::State::SetCurrentVertexArrayStateProxy setVASProxy(state, vas);
vas->bindVertexArrayObject();
state.bindVertexArrayObject(vas);
if (vbo_glBufferObject) vas->bindVertexBufferObject(vbo_glBufferObject);
if (ebo_glBufferObject) vas->bindElementBufferObject(ebo_glBufferObject);
state.unbindVertexArrayObject();
}
}