Fixed VertexArrayState::bind*BufferObject(..) methods so they correctly handle dirtied buffer objects

This commit is contained in:
Robert Osfield 2016-09-01 14:38:16 +01:00
parent a5e0398a29
commit 8febae1546
2 changed files with 33 additions and 17 deletions

View File

@ -60,10 +60,16 @@ public:
inline void bindVertexBufferObject(osg::GLBufferObject* vbo) inline void bindVertexBufferObject(osg::GLBufferObject* vbo)
{ {
if (vbo == _currentVBO) return; if (vbo->isDirty())
if (vbo->isDirty()) vbo->compileBuffer(); {
else vbo->bindBuffer(); vbo->compileBuffer();
_currentVBO = vbo; _currentVBO = vbo;
}
else if (vbo != _currentVBO)
{
vbo->bindBuffer();
_currentVBO = vbo;
}
} }
inline void unbindVertexBufferObject() inline void unbindVertexBufferObject()
@ -79,10 +85,16 @@ public:
inline void bindElementBufferObject(osg::GLBufferObject* ebo) inline void bindElementBufferObject(osg::GLBufferObject* ebo)
{ {
if (ebo == _currentEBO) return; if (ebo->isDirty())
if (ebo->isDirty()) ebo->compileBuffer(); {
else ebo->bindBuffer(); ebo->compileBuffer();
_currentEBO = ebo; _currentEBO = ebo;
}
else if (ebo != _currentEBO)
{
ebo->bindBuffer();
_currentEBO = ebo;
}
} }
inline void unbindElementBufferObject() inline void unbindElementBufferObject()
@ -104,7 +116,8 @@ public:
void assignTexCoordArrayDispatcher(unsigned int numUnits); void assignTexCoordArrayDispatcher(unsigned int numUnits);
void assignVertexAttribArrayDispatcher(unsigned int numUnits); void assignVertexAttribArrayDispatcher(unsigned int numUnits);
inline bool isVertexBufferObjectSupported() const { return true; } inline void setVertexBufferObjectSupported(bool flag) { _isVertexBufferObjectSupported = flag; }
inline bool isVertexBufferObjectSupported() const { return _isVertexBufferObjectSupported; }
void setArray(ArrayDispatch* vad, osg::State& state, const osg::Array* new_array); void setArray(ArrayDispatch* vad, osg::State& state, const osg::Array* new_array);
void setArray(ArrayDispatch* vad, osg::State& state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized); void setArray(ArrayDispatch* vad, osg::State& state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized);
@ -173,6 +186,8 @@ public:
osg::State* _state; osg::State* _state;
osg::ref_ptr<osg::GLExtensions> _ext; osg::ref_ptr<osg::GLExtensions> _ext;
bool _isVertexBufferObjectSupported;
GLuint _vertexArrayObject; GLuint _vertexArrayObject;

View File

@ -127,7 +127,7 @@ struct VertexArrayDispatch : public VertexArrayState::ArrayDispatch
virtual void enable_and_dispatch(osg::State&, const osg::Array* new_array, const osg::GLBufferObject* vbo) virtual void enable_and_dispatch(osg::State&, const osg::Array* new_array, const osg::GLBufferObject* vbo)
{ {
VAS_NOTICE<<" VertexArrayDispatch::enable_and_dispatch("<<new_array->getNumElements()<<", vbo="<<vbo<<")"<<std::endl; VAS_NOTICE<<" VertexArrayDispatch::enable_and_dispatch("<<new_array->getNumElements()<<", vbo="<<std::hex<<vbo<<std::dec<<")"<<std::endl;
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(new_array->getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); glVertexPointer(new_array->getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex())));
} }
@ -146,7 +146,7 @@ struct VertexArrayDispatch : public VertexArrayState::ArrayDispatch
virtual void dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo) virtual void dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo)
{ {
VAS_NOTICE<<" VertexArrayDispatch::dispatch("<<new_array->getNumElements()<<", vbo"<<vbo<<")"<<std::endl; VAS_NOTICE<<" VertexArrayDispatch::dispatch("<<new_array->getNumElements()<<", vbo"<<std::hex<<vbo<<std::dec<<")"<<std::endl;
glVertexPointer(new_array->getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); glVertexPointer(new_array->getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex())));
} }
@ -186,7 +186,7 @@ struct ColorArrayDispatch : public VertexArrayState::ArrayDispatch
virtual void enable_and_dispatch(osg::State&, const osg::Array* new_array, const osg::GLBufferObject* vbo) virtual void enable_and_dispatch(osg::State&, const osg::Array* new_array, const osg::GLBufferObject* vbo)
{ {
VAS_NOTICE<<" ColorArrayDispatch::enable_and_dispatch("<<new_array->getNumElements()<<", vbo="<<vbo<<")"<<std::endl; VAS_NOTICE<<" ColorArrayDispatch::enable_and_dispatch("<<new_array->getNumElements()<<", vbo="<<std::hex<<std::hex<<vbo<<std::dec<<std::dec<<")"<<std::endl;
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(new_array->getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); glColorPointer(new_array->getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex())));
@ -200,7 +200,7 @@ struct ColorArrayDispatch : public VertexArrayState::ArrayDispatch
virtual void dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo) virtual void dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo)
{ {
VAS_NOTICE<<" ColorArrayDispatch::dispatch("<<new_array->getNumElements()<<", vbo="<<vbo<<")"<<std::endl; VAS_NOTICE<<" ColorArrayDispatch::dispatch("<<new_array->getNumElements()<<", vbo="<<std::hex<<vbo<<std::dec<<")"<<std::endl;
glColorPointer(new_array->getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); glColorPointer(new_array->getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex())));
} }
@ -234,7 +234,7 @@ struct NormalArrayDispatch : public VertexArrayState::ArrayDispatch
virtual void enable_and_dispatch(osg::State&, const osg::Array* new_array, const osg::GLBufferObject* vbo) virtual void enable_and_dispatch(osg::State&, const osg::Array* new_array, const osg::GLBufferObject* vbo)
{ {
VAS_NOTICE<<" NormalArrayDispatch::enable_and_dispatch("<<new_array->getNumElements()<<", vbo="<<vbo<<")"<<std::endl; VAS_NOTICE<<" NormalArrayDispatch::enable_and_dispatch("<<new_array->getNumElements()<<", vbo="<<std::hex<<vbo<<std::dec<<")"<<std::endl;
glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); glNormalPointer(new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex())));
} }
@ -253,7 +253,7 @@ struct NormalArrayDispatch : public VertexArrayState::ArrayDispatch
virtual void dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo) virtual void dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo)
{ {
VAS_NOTICE<<" NormalArrayDispatch::dispatch("<<new_array->getNumElements()<<", vbo="<<vbo<<")"<<std::endl; VAS_NOTICE<<" NormalArrayDispatch::dispatch("<<new_array->getNumElements()<<", vbo="<<std::hex<<vbo<<std::dec<<")"<<std::endl;
glNormalPointer(new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); glNormalPointer(new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex())));
} }
@ -378,7 +378,7 @@ struct TexCoordArrayDispatch : public VertexArrayState::ArrayDispatch
virtual void enable_and_dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo) virtual void enable_and_dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo)
{ {
VAS_NOTICE<<" TexCoordArrayDispatch::enable_and_dispatch("<<new_array->getNumElements()<<", vbo="<<vbo<<") unit="<<unit<<std::endl; VAS_NOTICE<<" TexCoordArrayDispatch::enable_and_dispatch("<<new_array->getNumElements()<<", vbo="<<std::hex<<vbo<<std::dec<<") unit="<<unit<<std::endl;
state.setClientActiveTextureUnit(unit); state.setClientActiveTextureUnit(unit);
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@ -402,7 +402,7 @@ struct TexCoordArrayDispatch : public VertexArrayState::ArrayDispatch
virtual void dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo) virtual void dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo)
{ {
VAS_NOTICE<<" TexCoordArrayDispatch::dispatch("<<new_array->getNumElements()<<", vbo="<<vbo<<") unit="<<unit<<std::endl; VAS_NOTICE<<" TexCoordArrayDispatch::dispatch("<<new_array->getNumElements()<<", vbo="<<std::hex<<vbo<<std::dec<<") unit="<<unit<<std::endl;
state.setClientActiveTextureUnit(unit); state.setClientActiveTextureUnit(unit);
glTexCoordPointer(new_array->getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); glTexCoordPointer(new_array->getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex())));
@ -503,6 +503,7 @@ VertexArrayState::VertexArrayState(osg::State* state):
_requiresSetArrays(true) _requiresSetArrays(true)
{ {
_ext = _state->get<GLExtensions>(); _ext = _state->get<GLExtensions>();
_isVertexBufferObjectSupported = _ext->isBufferObjectSupported;
} }
void VertexArrayState::generateVertexArrayObject() void VertexArrayState::generateVertexArrayObject()