From e3c663bb0252655425f6075896661ac0ab605f8e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 5 Aug 2016 21:59:34 +0100 Subject: [PATCH] Removed deprecated code paths and moved implementations into headers --- include/osg/State | 948 ++---------------------------- include/osg/VertexArrayState | 15 +- src/osg/Geometry.cpp | 2 +- src/osg/State.cpp | 1074 +--------------------------------- src/osg/VertexArrayState.cpp | 106 +++- src/osgText/Text.cpp | 52 +- 6 files changed, 185 insertions(+), 2012 deletions(-) diff --git a/include/osg/State b/include/osg/State index 485e0a8d7..4297c70bd 100644 --- a/include/osg/State +++ b/include/osg/State @@ -509,80 +509,34 @@ class OSG_EXPORT State : public Referenced /** Set the CurrentVetexArrayState object that take which vertex arrays are bound.*/ - void setCurrentVertexArrayState(VertexArrayState* vas) { _currentVertexArrayState = vas; } + void setCurrentVertexArrayState(VertexArrayState* vas) { _vas = vas; } /** Get the CurrentVetexArrayState object that take which vertex arrays are bound.*/ - VertexArrayState* getCurrentVertexArrayState() const { return _currentVertexArrayState; } + VertexArrayState* getCurrentVertexArrayState() const { return _vas; } /** Set the getCurrentVertexArrayState to the GloabalVertexArrayState.*/ - void setCurrentToGloabalVertexArrayState() { _currentVertexArrayState = _globalVertexArrayState.get(); } + void setCurrentToGloabalVertexArrayState() { _vas = _globalVertexArrayState.get(); } /** disable the vertex, normal, color, tex coords, secondary color, fog coord and index arrays.*/ void disableAllVertexArrays(); + void lazyDisablingOfVertexAttributes() { _vas->lazyDisablingOfVertexAttributes(); } + void applyDisablingOfVertexAttributes() { _vas->applyDisablingOfVertexAttributes(*this); } + void setCurrentVertexBufferObject(osg::GLBufferObject* vbo) { _vas->setCurrentVertexBufferObject(vbo); } + const GLBufferObject* getCurrentVertexBufferObject() { return _vas->getCurrentVertexBufferObject(); } -#if 1 - void setCurrentVertexBufferObject(osg::GLBufferObject* vbo); - const GLBufferObject* getCurrentVertexBufferObject(); + void bindVertexBufferObject(osg::GLBufferObject* vbo) { _vas->bindVertexBufferObject(vbo); } + void unbindVertexBufferObject() { _vas->unbindVertexBufferObject(); } - void bindVertexBufferObject(osg::GLBufferObject* vbo); - void unbindVertexBufferObject(); -#else - void setCurrentVertexBufferObject(osg::GLBufferObject* vbo) { _currentVBO = vbo; } - const GLBufferObject* getCurrentVertexBufferObject() { return _currentVBO; } + void setCurrentElementBufferObject(osg::GLBufferObject* ebo) { _vas->setCurrentElementBufferObject(ebo); } + const GLBufferObject* getCurrentElementBufferObject() { return _vas->getCurrentElementBufferObject(); } - inline void bindVertexBufferObject(osg::GLBufferObject* vbo) - { - if (vbo) - { - if (vbo == _currentVBO) return; - if (vbo->isDirty()) vbo->compileBuffer(); - else vbo->bindBuffer(); - _currentVBO = vbo; - } - else unbindVertexBufferObject(); - } + void bindElementBufferObject(osg::GLBufferObject* ebo) { _vas->bindElementBufferObject(ebo); } + void unbindElementBufferObject() { _vas->unbindElementBufferObject(); } - inline void unbindVertexBufferObject() - { - if (!_currentVBO) return; - _glBindBuffer(GL_ARRAY_BUFFER_ARB,0); - _currentVBO = 0; - } -#endif - -#if 1 - void setCurrentElementBufferObject(osg::GLBufferObject* ebo); - const GLBufferObject* getCurrentElementBufferObject(); - - void bindElementBufferObject(osg::GLBufferObject* ebo); - void unbindElementBufferObject(); -#else - void setCurrentElementBufferObject(osg::GLBufferObject* ebo) { _currentEBO = ebo; } - const GLBufferObject* getCurrentElementBufferObject() { return _currentEBO; } - - inline void bindElementBufferObject(osg::GLBufferObject* ebo) - { - if (ebo) - { - if (ebo == _currentEBO) return; - if (ebo->isDirty()) ebo->compileBuffer(); - else ebo->bindBuffer(); - _currentEBO = ebo; - } - else unbindElementBufferObject(); - } - - inline void unbindElementBufferObject() - { - //if (!_currentEBO) return; - _glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0); - _currentEBO = 0; - } -#endif void setCurrentPixelBufferObject(osg::GLBufferObject* pbo) { _currentPBO = pbo; } const GLBufferObject* getCurrentPixelBufferObject() { return _currentPBO; } @@ -693,518 +647,38 @@ class OSG_EXPORT State : public Referenced } - /** Mark all the vertex attributes as being disabled but leave the disabling till a later call to applyDisablingOfVertexAttributes.*/ - void lazyDisablingOfVertexAttributes(); - - /** Disable all the vertex attributes that have been marked as to be disabled.*/ - void applyDisablingOfVertexAttributes(); - /** Wrapper around glInterleavedArrays(..). * also resets the internal array points and modes within osg::State to keep the other * vertex array operations consistent. */ - void setInterleavedArrays( GLenum format, GLsizei stride, const GLvoid* pointer); + void setInterleavedArrays( GLenum format, GLsizei stride, const GLvoid* pointer) { _vas->setInterleavedArrays( *this, format, stride, pointer); } /** Set the vertex pointer using an osg::Array, and manage any VBO that are required.*/ -#if 1 - inline void setVertexPointer(const Array* array); -#else - inline void setVertexPointer(const Array* array) - { - if (array) - { - GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0; - if (vbo) - { - bindVertexBufferObject(vbo); - setVertexPointer(array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())),array->getNormalize()); - } - else - { - unbindVertexBufferObject(); - setVertexPointer(array->getDataSize(),array->getDataType(),0,array->getDataPointer(),array->getNormalize()); - } - } - } -#endif - /** wrapper around glEnableClientState(GL_VERTEX_ARRAY);glVertexPointer(..); - * note, only updates values that change.*/ - inline void setVertexPointer( GLint size, GLenum type, - GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE ) - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - setVertexAttribPointer(_vertexAlias._location, size, type, normalized, stride, ptr); - } - else - { - if (!_vertexArray._enabled || _vertexArray._dirty) - { - _vertexArray._enabled = true; - glEnableClientState(GL_VERTEX_ARRAY); - } - //if (_vertexArray._pointer!=ptr || _vertexArray._dirty) - { - _vertexArray._pointer=ptr; - glVertexPointer( size, type, stride, ptr ); - } - _vertexArray._lazy_disable = false; - _vertexArray._dirty = false; - _vertexArray._normalized = normalized; - } - #else - setVertexAttribPointer(_vertexAlias._location, size, type, normalized, stride, ptr); - #endif - } - -#if 1 - inline void disableVertexPointer(); -#else - /** wrapper around glDisableClientState(GL_VERTEX_ARRAY). - * note, only updates values that change.*/ - inline void disableVertexPointer() - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - disableVertexAttribPointer(_vertexAlias._location); - } - else - { - if (_vertexArray._enabled || _vertexArray._dirty) - { - _vertexArray._lazy_disable = false; - _vertexArray._enabled = false; - _vertexArray._dirty = false; - glDisableClientState(GL_VERTEX_ARRAY); - } - } - #else - disableVertexAttribPointer(_vertexAlias._location); - #endif - } -#endif + inline void setVertexPointer(const Array* array) { _vas->setVertexArray(*this, array); } + inline void setVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE) { _vas->setVertexArray( *this, size, type, stride, ptr, normalized); } + inline void disableVertexPointer() { _vas->disableVertexArray(*this); } + inline void setNormalPointer(const Array* array) { _vas->setNormalArray(*this, array); } + inline void setNormalPointer( GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE ) { _vas->setNormalArray( *this, type, stride, ptr, normalized); } + inline void disableNormalPointer() { _vas->disableNormalArray(*this); } -#if 1 - inline void setNormalPointer(const Array* array); -#else - /** Set the normal pointer using an osg::Array, and manage any VBO that are required.*/ - inline void setNormalPointer(const Array* array) - { - if (array) - { - GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0; - if (vbo) - { - bindVertexBufferObject(vbo); - setNormalPointer(array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())),array->getNormalize()); - } - else - { - unbindVertexBufferObject(); - setNormalPointer(array->getDataType(),0,array->getDataPointer(),array->getNormalize()); - } - } - } -#endif - /** wrapper around glEnableClientState(GL_NORMAL_ARRAY);glNormalPointer(..); - * note, only updates values that change.*/ - inline void setNormalPointer( GLenum type, GLsizei stride, - const GLvoid *ptr, GLboolean normalized=GL_FALSE ) - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - setVertexAttribPointer(_normalAlias._location, 3, type, normalized, stride, ptr); - } - else - { - if (!_normalArray._enabled || _normalArray._dirty) - { - _normalArray._enabled = true; - glEnableClientState(GL_NORMAL_ARRAY); - } - //if (_normalArray._pointer!=ptr || _normalArray._dirty) - { - _normalArray._pointer=ptr; - glNormalPointer( type, stride, ptr ); - } - _normalArray._lazy_disable = false; - _normalArray._dirty = false; - _normalArray._normalized = normalized; - } - #else - setVertexAttribPointer(_normalAlias._location, 3, type, normalized, stride, ptr); - #endif - } + inline void setColorPointer(const Array* array) { _vas->setColorArray(*this, array); } + inline void setColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_TRUE ) { _vas->setColorArray(*this, size, type, stride, ptr, normalized); } + inline void disableColorPointer() { _vas->disableColorArray(*this); } -#if 1 - void disableNormalPointer(); -#else - /** wrapper around glDisableClientState(GL_NORMAL_ARRAY); - * note, only updates values that change.*/ - inline void disableNormalPointer() - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - disableVertexAttribPointer(_normalAlias._location); - } - else - { - if (_normalArray._enabled || _normalArray._dirty) - { - _normalArray._lazy_disable = false; - _normalArray._enabled = false; - _normalArray._dirty = false; - glDisableClientState(GL_NORMAL_ARRAY); - } - } - #else - disableVertexAttribPointer(_normalAlias._location); - #endif - } -#endif + inline bool isSecondaryColorSupported() const { return _isSecondaryColorSupported; } + inline void setSecondaryColorPointer(const Array* array) { _vas->setSecondaryColorArray(*this, array); } + inline void disableSecondaryColorPointer() { _vas->disableSecondaryColorArray(*this); } -#if 1 - inline void setColorPointer(const Array* array); -#else - /** Set the color pointer using an osg::Array, and manage any VBO that are required.*/ - inline void setColorPointer(const Array* array) - { - if (array) - { - GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0; - if (vbo) - { - bindVertexBufferObject(vbo); - setColorPointer(array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())),array->getNormalize()); - } - else - { - unbindVertexBufferObject(); - setColorPointer(array->getDataSize(),array->getDataType(),0,array->getDataPointer(),array->getNormalize()); - } - } - } -#endif - - /** wrapper around glEnableClientState(GL_COLOR_ARRAY);glColorPointer(..); - * note, only updates values that change.*/ - inline void setColorPointer( GLint size, GLenum type, - GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_TRUE ) - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - setVertexAttribPointer(_colorAlias._location, size, type, normalized, stride, ptr); - } - else - { - if (!_colorArray._enabled || _colorArray._dirty) - { - _colorArray._enabled = true; - glEnableClientState(GL_COLOR_ARRAY); - } - //if (_colorArray._pointer!=ptr || _colorArray._dirty) - { - _colorArray._pointer=ptr; - glColorPointer( size, type, stride, ptr ); - } - _colorArray._lazy_disable = false; - _colorArray._dirty = false; - _colorArray._normalized = normalized; - } - #else - setVertexAttribPointer(_colorAlias._location, size, type, normalized, stride, ptr); - #endif - } - -#if 1 - inline void disableColorPointer(); -#else - /** wrapper around glDisableClientState(GL_COLOR_ARRAY); - * note, only updates values that change.*/ - inline void disableColorPointer() - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - disableVertexAttribPointer(_colorAlias._location); - } - else - { - if (_colorArray._enabled || _colorArray._dirty) - { - _colorArray._lazy_disable = false; - _colorArray._enabled = false; - _colorArray._dirty = false; - glDisableClientState(GL_COLOR_ARRAY); - } - } - #else - disableVertexAttribPointer(_colorAlias._location); - #endif - } -#endif - -#if 1 - inline void dirtyColorPointer(); -#else - inline void dirtyColorPointer() - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - dirtyVertexAttribPointer(_colorAlias._location); - } - else - { - _colorArray._pointer = 0; - _colorArray._dirty = true; - } - #else - dirtyVertexAttribPointer(_colorAlias._location); - #endif - } -#endif - - inline bool isSecondaryColorSupported() const { return _isSecondaryColorSupportResolved?_isSecondaryColorSupported:computeSecondaryColorSupported(); } + inline bool isFogCoordSupported() const { return _isFogCoordSupported; } + inline void setFogCoordPointer(const Array* array) { _vas->setFogCoordArray(*this, array); } + inline void disableFogCoordPointer() { _vas->disableFogCoordArray(*this); } -#if 1 - inline void setSecondaryColorPointer(const Array* array); -#else - /** Set the secondary color pointer using an osg::Array, and manage any VBO that are required.*/ - inline void setSecondaryColorPointer(const Array* array) - { - if (array) - { - GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0; - if (vbo) - { - bindVertexBufferObject(vbo); - setSecondaryColorPointer(array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())),array->getNormalize()); - } - else - { - unbindVertexBufferObject(); - setSecondaryColorPointer(array->getDataSize(),array->getDataType(),0,array->getDataPointer(),array->getNormalize()); - } - } - } -#endif - - /** wrapper around glEnableClientState(GL_SECONDARY_COLOR_ARRAY);glSecondayColorPointer(..); - * note, only updates values that change.*/ - void setSecondaryColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_TRUE ); - -#if 1 - inline void disableSecondaryColorPointer(); -#else - /** wrapper around glDisableClientState(GL_SECONDARY_COLOR_ARRAY); - * note, only updates values that change.*/ - inline void disableSecondaryColorPointer() - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - disableVertexAttribPointer(_secondaryColorAlias._location); - } - else - { - if (_secondaryColorArray._enabled || _secondaryColorArray._dirty) - { - _secondaryColorArray._lazy_disable = false; - _secondaryColorArray._enabled = false; - _secondaryColorArray._dirty = false; - if (isSecondaryColorSupported()) glDisableClientState(GL_SECONDARY_COLOR_ARRAY); - } - } - #else - disableVertexAttribPointer(_secondaryColorAlias._location); - #endif - } -#endif - -#if 1 - inline void dirtySecondaryColorPointer(); -#else - inline void dirtySecondaryColorPointer() - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - dirtyVertexAttribPointer(_secondaryColorAlias._location); - } - else - { - _secondaryColorArray._pointer = 0; - _secondaryColorArray._dirty = true; - } - #else - dirtyVertexAttribPointer(_secondaryColorAlias._location); - #endif - } -#endif - - inline bool isFogCoordSupported() const { return _isFogCoordSupportResolved?_isFogCoordSupported:computeFogCoordSupported(); } - - -#if 1 - inline void setFogCoordPointer(const Array* array); -#else - /** Set the fog coord pointer using an osg::Array, and manage any VBO that are required.*/ - inline void setFogCoordPointer(const Array* array) - { - if (array) - { - GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0; - if (vbo) - { - bindVertexBufferObject(vbo); - setFogCoordPointer(array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())),array->getNormalize()); - } - else - { - unbindVertexBufferObject(); - setFogCoordPointer(array->getDataType(),0,array->getDataPointer(),array->getNormalize()); - } - } - } -#endif - - /** wrapper around glEnableClientState(GL_FOG_COORDINATE_ARRAY);glFogCoordPointer(..); - * note, only updates values that change.*/ - void setFogCoordPointer( GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE ); - -#if 1 - inline void disableFogCoordPointer(); -#else - /** wrapper around glDisableClientState(GL_FOG_COORDINATE_ARRAY); - * note, only updates values that change.*/ - inline void disableFogCoordPointer() - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - disableVertexAttribPointer(_fogCoordAlias._location); - } - else - { - if (_fogArray._enabled || _fogArray._dirty) - { - _fogArray._lazy_disable = false; - _fogArray._enabled = false; - _fogArray._dirty = false; - if (isFogCoordSupported()) glDisableClientState(GL_FOG_COORDINATE_ARRAY); - } - } - #else - disableVertexAttribPointer(_fogCoordAlias._location); - #endif - } -#endif - - - - -#if 1 - inline void setTexCoordPointer(unsigned int unit, const Array* array); -#else - /** Set the tex coord pointer using an osg::Array, and manage any VBO that are required.*/ - inline void setTexCoordPointer(unsigned int unit, const Array* array) - { - if (array) - { - GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0; - if (vbo) - { - bindVertexBufferObject(vbo); - setTexCoordPointer(unit, array->getDataSize(),array->getDataType(),0, (const GLvoid *)(vbo->getOffset(array->getBufferIndex())),array->getNormalize()); - } - else - { - unbindVertexBufferObject(); - setTexCoordPointer(unit, array->getDataSize(),array->getDataType(),0,array->getDataPointer(),array->getNormalize()); - } - } - } -#endif - /** wrapper around glEnableClientState(GL_TEXTURE_COORD_ARRAY);glTexCoordPointer(..); - * note, only updates values that change.*/ - inline void setTexCoordPointer( unsigned int unit, - GLint size, GLenum type, - GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE ) - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - setVertexAttribPointer(_texCoordAliasList[unit]._location, size, type, normalized, stride, ptr); - } - else - { - if (setClientActiveTextureUnit(unit)) - { - if ( unit >= _texCoordArrayList.size()) _texCoordArrayList.resize(unit+1); - EnabledArrayPair& eap = _texCoordArrayList[unit]; - - if (!eap._enabled || eap._dirty) - { - eap._enabled = true; - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - } - //if (eap._pointer!=ptr || eap._dirty) - { - glTexCoordPointer( size, type, stride, ptr ); - eap._pointer = ptr; - } - eap._lazy_disable = false; - eap._dirty = false; - eap._normalized = normalized; - } - } - #else - setVertexAttribPointer(_texCoordAliasList[unit]._location, size, type, normalized, stride, ptr); - #endif - } - -#if 1 - inline void disableTexCoordPointersAboveAndIncluding( unsigned int unit ); -#else - inline void disableTexCoordPointersAboveAndIncluding( unsigned int unit ) - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - disableVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location); - } - else - { - while (unit<_texCoordArrayList.size()) - { - EnabledArrayPair& eap = _texCoordArrayList[unit]; - if (eap._enabled || eap._dirty) - { - if (setClientActiveTextureUnit(unit)) - { - eap._lazy_disable = false; - eap._enabled = false; - eap._dirty = false; - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - } - ++unit; - } - } - #else - disableVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location); - #endif - } -#endif - + inline void setTexCoordPointer(unsigned int unit, const Array* array) { _vas->setTexCoordArray(*this, unit, array); } + inline void setTexCoordPointer( unsigned int unit, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE ) { _vas->setTexCoordArray(*this, unit, size, type, stride, ptr, normalized); } + inline void disableTexCoordPointer( unsigned int unit ) { _vas->disableTexCoordArray(*this, unit); } + inline void disableTexCoordPointersAboveAndIncluding( unsigned int unit ) { _vas->disableTexCoordArrayAboveAndIncluding(*this, unit); } /// For GL>=2.0 uses GL_MAX_TEXTURE_COORDS, for GL<2 uses GL_MAX_TEXTURE_UNITS inline GLint getMaxTextureCoords() const { return _glMaxTextureCoords; } @@ -1229,286 +703,23 @@ class OSG_EXPORT State : public Referenced /** Get the current tex coord array texture unit.*/ unsigned int getClientActiveTextureUnit() const; -#if 1 - void setVertexAttribPointer(unsigned int unit, const Array* array); -#else - /** Set the vertex attrib pointer using an osg::Array, and manage any VBO that are required.*/ - inline void setVertexAttribPointer(unsigned int unit, const Array* array) - { - if (array) - { - GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0; - if (vbo) - { - bindVertexBufferObject(vbo); - setVertexAttribPointer(unit, array->getDataSize(),array->getDataType(),array->getNormalize(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex()))); - } - else - { - unbindVertexBufferObject(); - setVertexAttribPointer(unit, array->getDataSize(),array->getDataType(),array->getNormalize(),0,array->getDataPointer()); - } - } - } -#endif + inline void setVertexAttribPointer(unsigned int unit, const Array* array) { _vas->setVertexAttribArray(*this, unit, array); } + inline void setVertexAttribLPointer(unsigned int unit, const Array* array) { _vas->setVertexAttribArray(*this, unit, array); } + inline void setVertexAttribIPointer(unsigned int unit, const Array* array) { _vas->setVertexAttribArray(*this, unit, array); } -#if 1 - void setVertexAttribLPointer(unsigned int unit, const Array* array); -#else - /** Set the vertex attrib pointer using an osg::Array, and manage any VBO that are required.*/ - inline void setVertexAttribLPointer(unsigned int unit, const Array* array) - { - if (array) - { - GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID); - if (vbo) - { - bindVertexBufferObject(vbo); - setVertexAttribLPointer(unit, array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex()))); - } - else - { - unbindVertexBufferObject(); - setVertexAttribLPointer(unit, array->getDataSize(),array->getDataType(),0,array->getDataPointer()); - } - } - } -#endif + inline void disableVertexAttribPointer( unsigned int index ) { _vas->disableVertexAttribArray(*this, index); } + inline void disableVertexAttribPointersAboveAndIncluding( unsigned int index ) { _vas->disableVertexAttribArray(*this, index); } -#if 1 - void setVertexAttribIPointer(unsigned int unit, const Array* array); -#else - /** Set the vertex attrib pointer using an osg::Array, and manage any VBO that are required.*/ - inline void setVertexAttribIPointer(unsigned int unit, const Array* array) - { - if (array) - { - GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID); - if (vbo) - { - bindVertexBufferObject(vbo); - setVertexAttribIPointer(unit, array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex()))); - } - else - { - unbindVertexBufferObject(); - setVertexAttribIPointer(unit, array->getDataSize(),array->getDataType(),0,array->getDataPointer()); - } - } - } -#endif - - /** wrapper around glEnableVertexAttribArrayARB(index);glVertexAttribPointerARB(..); - * note, only updates values that change.*/ - void setVertexAttribPointer( unsigned int index, - GLint size, GLenum type, GLboolean normalized, - GLsizei stride, const GLvoid *ptr ); - - /** wrapper around glEnableVertexAttribArrayARB(index);glVertexAttribIPointer(..); - * note, only updates values that change.*/ - void setVertexAttribIPointer( unsigned int index, - GLint size, GLenum type, - GLsizei stride, const GLvoid *ptr ); - - /** wrapper around glEnableVertexAttribArrayARB(index);glVertexAttribLPointer(..); - * note, only updates values that change.*/ - void setVertexAttribLPointer( unsigned int index, - GLint size, GLenum type, - GLsizei stride, const GLvoid *ptr ); - - /** wrapper around DisableVertexAttribArrayARB(index); - * note, only updates values that change.*/ - void disableVertexAttribPointer( unsigned int index ); - - void disableVertexAttribPointersAboveAndIncluding( unsigned int index ); - -#if 1 - void disableTexCoordPointer( unsigned int unit ); -#else - /** wrapper around glDisableClientState(GL_TEXTURE_COORD_ARRAY); - * note, only updates values that change.*/ - inline void disableTexCoordPointer( unsigned int unit ) - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - disableVertexAttribPointer(_texCoordAliasList[unit]._location); - } - else - { - if ( unit >= _texCoordArrayList.size()) _texCoordArrayList.resize(unit+1); - EnabledArrayPair& eap = _texCoordArrayList[unit]; - - if (eap._enabled || eap._dirty) - { - if(setClientActiveTextureUnit(unit)) - { - eap._lazy_disable = false; - eap._enabled = false; - eap._dirty = false; - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - } - } - #else - disableVertexAttribPointer(_texCoordAliasList[unit]._location); - #endif - } -#endif /** dirty the vertex, normal, color, tex coords, secondary color, fog coord and index arrays.*/ void dirtyAllVertexArrays(); -#if 0 -#if 1 - void dirtyNormalPointer(); -#else - inline void dirtyNormalPointer() - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - dirtyVertexAttribPointer(_normalAlias._location); - } - else - { - _normalArray._pointer = 0; - _normalArray._dirty = true; - } - #else - dirtyVertexAttribPointer(_normalAlias._location); - #endif - } -#endif + inline bool isVertexBufferObjectSupported() const { return _isVertexBufferObjectSupportResolved?_isVertexBufferObjectSupported:computeVertexBufferObjectSupported(); } -#if 1 - void dirtyVertexPointer(); -#else - inline void dirtyVertexPointer() - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - dirtyVertexAttribPointer(_vertexAlias._location); - } - else - { - _vertexArray._pointer = 0; - _vertexArray._dirty = true; - } - #else - dirtyVertexAttribPointer(_vertexAlias._location); - #endif - } -#endif + inline bool isVertexArrayObjectSupported() const { return _isVertexArrayObjectSupported; } -#if 1 - void dirtyFogCoordPointer(); -#else - inline void dirtyFogCoordPointer() - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - dirtyVertexAttribPointer(_fogCoordAlias._location); - } - else - { - _fogArray._pointer = 0; - _fogArray._dirty = true; - } - #else - dirtyVertexAttribPointer(_fogCoordAlias._location); - #endif - } -#endif - -#if 1 - void dirtyTexCoordPointer( unsigned int unit ); -#else - inline void dirtyTexCoordPointer( unsigned int unit ) - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - dirtyVertexAttribPointer(_texCoordAliasList[unit]._location); - } - else - { - if ( unit >= _texCoordArrayList.size()) return; // _texCoordArrayList.resize(unit+1); - EnabledArrayPair& eap = _texCoordArrayList[unit]; - eap._pointer = 0; - eap._dirty = true; - } - #else - dirtyVertexAttribPointer(_texCoordAliasList[unit]._location); - #endif - } -#endif - -#if 1 - void dirtyTexCoordPointersAboveAndIncluding( unsigned int unit ); -#else - inline void dirtyTexCoordPointersAboveAndIncluding( unsigned int unit ) - { - #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (_useVertexAttributeAliasing) - { - dirtyVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location); - } - else - { - while (unit<_texCoordArrayList.size()) - { - EnabledArrayPair& eap = _texCoordArrayList[unit]; - eap._pointer = 0; - eap._dirty = true; - ++unit; - } - } - #else - dirtyVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location); - #endif - } -#endif - -#if 1 - void dirtyVertexAttribPointer( unsigned int index ); -#else - inline void dirtyVertexAttribPointer( unsigned int index ) - { - if (index<_vertexAttribArrayList.size()) - { - EnabledArrayPair& eap = _vertexAttribArrayList[index]; - eap._pointer = 0; - eap._dirty = true; - } - } -#endif - -#if 1 - void dirtyVertexAttribPointersAboveAndIncluding( unsigned int index ); -#else - inline void dirtyVertexAttribPointersAboveAndIncluding( unsigned int index ) - { - while (index<_vertexAttribArrayList.size()) - { - EnabledArrayPair& eap = _vertexAttribArrayList[index]; - eap._pointer = 0; - eap._dirty = true; - ++index; - } - } -#endif - -#endif - - bool isVertexBufferObjectSupported() const { return _isVertexBufferObjectSupportResolved?_isVertexBufferObjectSupported:computeVertexBufferObjectSupported(); } - - bool isVertexArrayObjectSupported() const { return _isVertexArrayObjectSupported; } - - bool useVertexArrayObject() const { return _useVertexArrayObject; } + inline bool useVertexArrayObject() const { return _useVertexArrayObject; } inline void setLastAppliedProgramObject(const Program::PerContextProgram* program) { @@ -1801,7 +1012,7 @@ class OSG_EXPORT State : public Referenced unsigned int _contextID; osg::ref_ptr _globalVertexArrayState; - VertexArrayState* _currentVertexArrayState; + VertexArrayState* _vas; bool _shaderCompositionEnabled; bool _shaderCompositionDirty; @@ -3105,81 +2316,6 @@ inline bool State::setActiveTextureUnit( unsigned int unit ) } -///////////////////////////////////////////////////////////////////////// -// -// New VertexArrayState version -// -inline void State::setVertexPointer(const Array* array) -{ - _currentVertexArrayState->setVertexArray(*this, array); -} - -inline void State::disableVertexPointer() -{ - _currentVertexArrayState->disableVertexArray(*this); -} - -inline void State::setNormalPointer(const Array* array) -{ - _currentVertexArrayState->setNormalArray(*this, array); -} - -inline void State::disableNormalPointer() -{ - _currentVertexArrayState->disableNormalArray(*this); -} - - -inline void State::setColorPointer(const Array* array) -{ - _currentVertexArrayState->setColorArray(*this, array); -} - -inline void State::disableColorPointer() -{ - _currentVertexArrayState->disableColorArray(*this); -} - - - -inline void State::setSecondaryColorPointer(const Array* array) -{ - _currentVertexArrayState->setSecondaryColorArray(*this, array); -} - -inline void State::disableSecondaryColorPointer() -{ - _currentVertexArrayState->disableSecondaryColorArray(*this); -} - - -inline void State::setFogCoordPointer(const Array* array) -{ - _currentVertexArrayState->setFogCoordArray(*this, array); -} - - -inline void State::disableFogCoordPointer() -{ - _currentVertexArrayState->disableFogCoordArray(*this); -} - -inline void State::setTexCoordPointer(unsigned int unit, const Array* array) -{ - _currentVertexArrayState->setTexCoordArray(*this, unit, array); -} - -inline void State::disableTexCoordPointer( unsigned int unit ) -{ - _currentVertexArrayState->disableTexCoordArray(*this, unit); -} - -inline void State::disableTexCoordPointersAboveAndIncluding( unsigned int unit ) -{ - _currentVertexArrayState->disableTexCoordArrayAboveAndIncluding(*this, unit); -} - - // forward declare speciailization of State::get() method template<> inline GLExtensions* State::get() { return _glExtensions.get(); } diff --git a/include/osg/VertexArrayState b/include/osg/VertexArrayState index 73caaffff..62085b224 100644 --- a/include/osg/VertexArrayState +++ b/include/osg/VertexArrayState @@ -38,10 +38,14 @@ public: virtual void enable_and_dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/, const osg::GLBufferObject* /*vbo*/) {} // = 0; + virtual void enable_and_dispatch(osg::State& /*state*/, GLint /*size*/, GLenum /*type*/, GLsizei /*stride*/, const GLvoid * /*ptr*/, GLboolean /*normalized*/) {} // = 0; + virtual void dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/) {} // = 0; virtual void dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/, const osg::GLBufferObject* /*vbo*/) {} // = 0; + virtual void dispatch(osg::State& /*state*/, GLint /*size*/, GLenum /*type*/, GLsizei /*stride*/, const GLvoid * /*ptr*/, GLboolean /*normalized*/) {} // = 0; + virtual void disable(osg::State& /*state*/) {} // = 0; const osg::Array* array; @@ -103,16 +107,22 @@ public: inline bool isVertexBufferObjectSupported() const { return true; } 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 disable(ArrayDispatch* vad, osg::State& state) { vad->disable(state); vad->array=0; vad->modifiedCount=0xffffffff; vad->active=false; } + inline void disable(ArrayDispatch* vad, osg::State& state) { vad->disable(state); vad->array=0; vad->modifiedCount=0xffffffff; vad->active=false; } + + void setInterleavedArrays( osg::State& state, GLenum format, GLsizei stride, const GLvoid* pointer); inline void setVertexArray(osg::State& state, const osg::Array* array) { setArray(_vertexArray.get(), state, array); } + inline void setVertexArray(osg::State& state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE) { setArray(_vertexArray.get(), state, size, type, stride, ptr, normalized); } inline void disableVertexArray(osg::State& state) { disable(_vertexArray.get(), state); } inline void setNormalArray(osg::State& state, const osg::Array* array) { setArray(_normalArray.get(), state, array); } + inline void setNormalArray(osg::State& state, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE ) { setArray(_normalArray.get(), state, 3, type, stride, ptr, normalized); } inline void disableNormalArray(osg::State& state) { disable(_normalArray.get(), state); } inline void setColorArray(osg::State& state, const osg::Array* array) { setArray(_colorArray.get(), state, array); } + inline void setColorArray(osg::State& state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_TRUE ) { setArray(_colorArray.get(), state, size, type, stride, ptr, normalized); } inline void disableColorArray(osg::State& state) { disable(_colorArray.get(), state); } inline void setSecondaryColorArray(osg::State& state, const osg::Array* array) { setArray(_secondaryColorArray.get(), state, array); } @@ -122,6 +132,7 @@ public: inline void disableFogCoordArray(osg::State& state) { disable(_fogCoordArray.get(), state); } inline void setTexCoordArray(osg::State& state, unsigned int unit, const osg::Array* array) { setArray(_texCoordArrays[unit].get(), state, array); } + inline void setTexCoordArray(osg::State& state, unsigned int unit, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE ) { setArray(_texCoordArrays[unit].get(), state, size, type, stride, ptr, normalized); } inline void disableTexCoordArray(osg::State& state, unsigned int unit) { disable(_texCoordArrays[unit].get(),state); } inline void disableTexCoordArrayAboveAndIncluding(osg::State& state, unsigned int index); @@ -136,7 +147,7 @@ public: inline void applyDisablingOfVertexAttributes(osg::State& state); // Verex Array Object methods. - void generateVretexArrayObject(); + void generateVertexArrayObject(); void deleteVertexArrayObject(); diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index a9c308ab4..b320e6e67 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -686,7 +686,7 @@ VertexArrayState* Geometry::createVertexArrayState(RenderInfo& renderInfo, bool { OSG_NOTICE<<" Setup VertexArrayState to use VAO"<generateVretexArrayObject(); + vas->generateVertexArrayObject(); } else { diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 18afa2c3a..157764210 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -34,8 +34,6 @@ #define GL_MAX_TEXTURE_UNITS 0x84E2 #endif -#define USE_VERTEXARRAYSTATE 1 - using namespace std; using namespace osg; @@ -143,7 +141,7 @@ State::State(): _gpuTimestamp = 0; _timestampBits = 0; - _currentVertexArrayState = 0; + _vas = 0; } State::~State() @@ -188,11 +186,13 @@ void State::initializeExtensionProcs() _useVertexArrayObject = _isVertexArrayObjectSupported && (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT); -#ifdef USE_VERTEXARRAYSTATE + // Set up up global VertexArrayState object _globalVertexArrayState = new VertexArrayState(this); _globalVertexArrayState->assignAllDispatchers(); + // if (_useVertexArrayObject) _globalVertexArrayState->generateVertexArrayObject(); + setCurrentToGloabalVertexArrayState(); -#endif + setGLExtensionFuncPtr(_glClientActiveTexture,"glClientActiveTexture","glClientActiveTextureARB"); setGLExtensionFuncPtr(_glActiveTexture, "glActiveTexture","glActiveTextureARB"); @@ -1049,164 +1049,6 @@ void State::disableAllVertexArrays() disableVertexAttribPointersAboveAndIncluding(0); } - -void State::setInterleavedArrays( GLenum format, GLsizei stride, const GLvoid* pointer) -{ - disableAllVertexArrays(); - -#if defined(OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE) && !defined(OSG_GLES1_AVAILABLE) - glInterleavedArrays( format, stride, pointer); -#else - OSG_NOTICE<<"Warning: State::setInterleavedArrays(..) not implemented."<setVertexArray(*this, array); -} - -void State::disableVertexPointer() -{ - _currentVertexArrayState->disableVertexArray(*this); -} - -void State::setNormalPointer(const Array* array) -{ - _currentVertexArrayState->setNormalArray(*this, array); -} - -void State::disableNormalPointer() -{ - _currentVertexArrayState->disableNormalArray(*this); -} - - -void State::setColorPointer(const Array* array) -{ - _currentVertexArrayState->setColorArray(*this, array); -} - -void State::disableColorPointer() -{ - _currentVertexArrayState->disableColorArray(*this); -} - - - -void State::setSecondaryColorPointer(const Array* array) -{ - _currentVertexArrayState->setSecondaryColorArray(*this, array); -} - -void State::disableSecondaryColorPointer() -{ - _currentVertexArrayState->disableSecondaryColorArray(*this); -} - - -void State::setFogCoordPointer(const Array* array) -{ - _currentVertexArrayState->setFogCoordArray(*this, array); -} - - -void State::disableFogCoordPointer() -{ - _currentVertexArrayState->disableFogCoordArray(*this); -} - -void State::setTexCoordPointer(unsigned int unit, const Array* array) -{ - _currentVertexArrayState->setTexCoordArray(*this, unit, array); -} - -void State::disableTexCoordPointer( unsigned int unit ) -{ - _currentVertexArrayState->disableTexCoordArray(*this, unit); -} - -void State::disableTexCoordPointersAboveAndIncluding( unsigned int unit ) -{ - _currentVertexArrayState->disableTexCoordArrayAboveAndIncluding(*this, unit); -} -#endif - -#if 0 -void State::dirtyVertexPointer() -{ - OSG_NOTICE<<"NOT IMPLEMENTED YET, dirtyVertexPointer() "<<__LINE__<setVertexAttribArray(*this, unit, array); -} -void State::setVertexAttribPointer( unsigned int index, - GLint size, GLenum type, GLboolean normalized, - GLsizei stride, const GLvoid *ptr ) -{ - OSG_NOTICE<<"NOT IMPLEMENTED YET "<<__LINE__<setVertexAttribArray(*this, unit, array); -} - -void State::setVertexAttribIPointer( unsigned int index, - GLint size, GLenum type, - GLsizei stride, const GLvoid *ptr ) -{ - OSG_NOTICE<<"NOT IMPLEMENTED YET "<<__LINE__<setVertexAttribArray(*this, unit, array); -} - -void State::setVertexAttribLPointer( unsigned int index, - GLint size, GLenum type, - GLsizei stride, const GLvoid *ptr ) -{ - OSG_NOTICE<<"NOT IMPLEMENTED YET "<<__LINE__<disableVertexAttribArray(*this, index); -} - -void State::disableVertexAttribPointersAboveAndIncluding( unsigned int index ) -{ - _currentVertexArrayState->disableVertexAttribArrayAboveAndIncluding(*this, index); -} - - -void State::lazyDisablingOfVertexAttributes() -{ - _currentVertexArrayState->lazyDisablingOfVertexAttributes();; -} - -void State::applyDisablingOfVertexAttributes() -{ - _currentVertexArrayState->applyDisablingOfVertexAttributes(*this); -} - -void State::setCurrentVertexBufferObject(osg::GLBufferObject* vbo) -{ - _currentVertexArrayState->setCurrentVertexBufferObject(vbo); -} - -const GLBufferObject* State::getCurrentVertexBufferObject() -{ - return _currentVertexArrayState->getCurrentVertexBufferObject(); -} - -void State::bindVertexBufferObject(osg::GLBufferObject* vbo) -{ - _currentVertexArrayState->bindVertexBufferObject(vbo); -} - -void State::unbindVertexBufferObject() -{ - _currentVertexArrayState->unbindVertexBufferObject(); -} - -void State::setCurrentElementBufferObject(osg::GLBufferObject* ebo) -{ - _currentVertexArrayState->setCurrentElementBufferObject(ebo); -} - -const GLBufferObject* State::getCurrentElementBufferObject() -{ - return _currentVertexArrayState->getCurrentElementBufferObject(); -} - -void State::bindElementBufferObject(osg::GLBufferObject* ebo) -{ - _currentVertexArrayState->bindElementBufferObject(ebo); -} - -void State::unbindElementBufferObject() -{ - _currentVertexArrayState->unbindElementBufferObject(); -} - -#else -///////////////////////////////////////////////////////////////////////// -// -// Moved from State header -// -void State::setVertexPointer(const Array* array) -{ - if (array) - { - GLBufferObject* vbo = isVertexBufferObjectSupported() ? array->getOrCreateGLBufferObject(_contextID) : 0; - if (vbo) - { - OSG_NOTICE<<" State::setVertexPointer("<= _vertexAttribArrayList.size()) _vertexAttribArrayList.resize(index+1); - EnabledArrayPair& eap = _vertexAttribArrayList[index]; - - if (!eap._enabled || eap._dirty) - { - eap._enabled = true; - // OSG_NOTICE<<" _glEnableVertexAttribArray( "<getOrCreateGLBufferObject(_contextID); - if (vbo) - { - bindVertexBufferObject(vbo); - setVertexAttribIPointer(unit, array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex()))); - } - else - { - unbindVertexBufferObject(); - setVertexAttribIPointer(unit, array->getDataSize(),array->getDataType(),0,array->getDataPointer()); - } - } -} - -/** wrapper around glEnableVertexAttribArrayARB(index);glVertexAttribIPointer(..); -* note, only updates values that change.*/ -void State::setVertexAttribIPointer( unsigned int index, - GLint size, GLenum type, - GLsizei stride, const GLvoid *ptr ) -{ - if (_glVertexAttribIPointer) - { - // OSG_NOTICE<<"State::setVertexAttribIPointer("<= _vertexAttribArrayList.size()) _vertexAttribArrayList.resize(index+1); - EnabledArrayPair& eap = _vertexAttribArrayList[index]; - - if (!eap._enabled || eap._dirty) - { - eap._enabled = true; - // OSG_NOTICE<<" _glEnableVertexAttribArray( "<getOrCreateGLBufferObject(_contextID); - if (vbo) - { - bindVertexBufferObject(vbo); - setVertexAttribLPointer(unit, array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex()))); - } - else - { - unbindVertexBufferObject(); - setVertexAttribLPointer(unit, array->getDataSize(),array->getDataType(),0,array->getDataPointer()); - } - } -} - -void State::setVertexAttribLPointer( unsigned int index, - GLint size, GLenum type, - GLsizei stride, const GLvoid *ptr ) -{ - if (_glVertexAttribLPointer) - { - // OSG_NOTICE<<"State::setVertexAttribLPointer("<= _vertexAttribArrayList.size()) _vertexAttribArrayList.resize(index+1); - EnabledArrayPair& eap = _vertexAttribArrayList[index]; - - if (!eap._enabled || eap._dirty) - { - eap._enabled = true; - // OSG_NOTICE<<" _glEnableVertexAttribArray( "<= _vertexAttribArrayList.size()) _vertexAttribArrayList.resize(index+1); - EnabledArrayPair& eap = _vertexAttribArrayList[index]; - - if (eap._enabled || eap._dirty) - { - eap._enabled = false; - eap._dirty = false; - // OSG_NOTICE<<" _glDisableVertexAttribArray( "<_lazy_disable = true; - } - } - - for(EnabledVertexAttribArrayList::iterator itr = _vertexAttribArrayList.begin(); - itr != _vertexAttribArrayList.end(); - ++itr) - { - itr->_lazy_disable = true; - } -} - -void State::applyDisablingOfVertexAttributes() -{ - //OSG_NOTICE<<"start of applyDisablingOfVertexAttributes()"<bindBuffer(); - OSG_NOTICE<<" done bind of "<getNumElements()<<")"<getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); } + virtual void dispatch(osg::State& /*state*/, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean /*normalized*/) + { + glVertexPointer(size, type, stride, ptr); + } + virtual void disable(osg::State& state) { VAS_NOTICE<<" VertexArrayDispatch::disable()"<getDataSize(), new_array->getDataType(), 0, new_array->getDataPointer()); } + virtual void enable_and_dispatch(osg::State& /*state*/, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean /*normalized*/) + { + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(size, type, stride, ptr); + } + virtual void enable_and_dispatch(osg::State&, const osg::Array* new_array, const osg::GLBufferObject* vbo) { VAS_NOTICE<<" ColorArrayDispatch::enable_and_dispatch("<getNumElements()<<", vbo="<getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); } + virtual void dispatch(osg::State& /*state*/, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean /*normalized*/) + { + glColorPointer(size, type, stride, ptr); + } + virtual void disable(osg::State& state) { VAS_NOTICE<<" ColorArrayDispatch::disable()"<getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); } + virtual void enable_and_dispatch(osg::State& /*state*/, GLint /*size*/, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean /*normalized*/) + { + glEnableClientState(GL_NORMAL_ARRAY); + glNormalPointer(type, stride, ptr); + } + virtual void dispatch(osg::State& state, const osg::Array* new_array) { VAS_NOTICE<<" NormalArrayDispatch::dispatch("<getNumElements()<<")"<getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); } + virtual void dispatch(osg::State& /*state*/, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean /*normalized*/) + { + glNormalPointer(type, stride, ptr); + } + virtual void disable(osg::State& state) { VAS_NOTICE<<" NormalArrayDispatch::disable()"<getNumElements()<<") unit="<(GL_TEXTURE0+unit)); - //state.setClientActiveTextureUnit(unit); + state.setClientActiveTextureUnit(unit); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(new_array->getDataSize(), new_array->getDataType(), 0, new_array->getDataPointer()); } @@ -329,17 +361,22 @@ struct TexCoordArrayDispatch : public VertexArrayState::ArrayDispatch { VAS_NOTICE<<" TexCoordArrayDispatch::enable_and_dispatch("<getNumElements()<<", vbo="<getNumElements()<<") unit="<(GL_TEXTURE0+unit)); state.setClientActiveTextureUnit(unit); glTexCoordPointer(new_array->getDataSize(), new_array->getDataType(), 0, new_array->getDataPointer()); } @@ -348,11 +385,16 @@ struct TexCoordArrayDispatch : public VertexArrayState::ArrayDispatch { VAS_NOTICE<<" TexCoordArrayDispatch::dispatch("<getNumElements()<<", vbo="<getUseVertexAttributeAliasing()="<<_state->getUseVertexAttributeAliasing()<getUseVertexAttributeAliasing()) { @@ -629,3 +669,53 @@ void VertexArrayState::setArray(ArrayDispatch* vad, osg::State& state, const osg disable(vad, state); } } + +void VertexArrayState::setArray(ArrayDispatch* vad, osg::State& state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized) +{ + if (ptr) + { + if (!vad->active) + { + vad->active = true; + _activeDispatchers.push_back(vad); + } + + if (vad->array==0) + { + unbindVertexBufferObject(); + vad->enable_and_dispatch(state, size, type, stride, ptr, normalized); + } + else + { + unbindVertexBufferObject(); + vad->dispatch(state, size, type, stride, ptr, normalized); + } + + vad->array = 0; + vad->modifiedCount = 0xffffffff; + + } + else if (vad->array) + { + disable(vad, state); + } +} + +void VertexArrayState::setInterleavedArrays( osg::State& state, GLenum format, GLsizei stride, const GLvoid* pointer) +{ + OSG_NOTICE<<"Warning: VertexArrayState::setInterleavedArrays() NOT IMPLEMENTATED YET"<second; //OSG_NOTICE<<"Text::computePositions("<size(); i += 4) { _quadIndices->push_back(i); @@ -2161,9 +2161,9 @@ void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize) } } } - + _quadIndices->resizeGLObjectBuffers(maxSize); - + initGPUBufferObjects(); } @@ -2180,5 +2180,5 @@ void Text::GlyphQuads::releaseGLObjects(osg::State* state) const } } - _quadIndices->releaseGLObjects(state); + _quadIndices->releaseGLObjects(state); }