diff --git a/include/osg/State b/include/osg/State index c530562be..f5adf348d 100644 --- a/include/osg/State +++ b/include/osg/State @@ -1499,6 +1499,9 @@ class OSG_EXPORT State : public Referenced bool isVertexBufferObjectSupported() const { return _isVertexBufferObjectSupportResolved?_isVertexBufferObjectSupported:computeVertexBufferObjectSupported(); } + bool isVertexArrayObjectSupported() const { return _isVertexArrayObjectSupported; } + + bool useVertexArrayObject() const { return _useVertexArrayObject; } inline void setLastAppliedProgramObject(const Program::PerContextProgram* program) { @@ -2093,6 +2096,9 @@ class OSG_EXPORT State : public Referenced mutable bool _isVertexBufferObjectSupported; bool computeVertexBufferObjectSupported() const; + bool _isVertexArrayObjectSupported; + bool _useVertexArrayObject; + typedef void (GL_APIENTRY * ActiveTextureProc) (GLenum texture); typedef void (GL_APIENTRY * FogCoordPointerProc) (GLenum type, GLsizei stride, const GLvoid *pointer); typedef void (GL_APIENTRY * SecondaryColorPointerProc) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 04f292288..31ef33b7f 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -632,10 +632,9 @@ void Drawable::draw(RenderInfo& renderInfo) const #if 1 State& state = *renderInfo.getState(); - const DisplaySettings* ds = state.getDisplaySettings() ? state.getDisplaySettings() : osg::DisplaySettings::instance(); - bool useVertexArrayObject = _useVertexBufferObjects && (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT); + bool useVertexArrayObject = _useVertexBufferObjects && state.useVertexArrayObject(); - if (useVertexArrayObject /*&& state.VAOSupported*/) + if (useVertexArrayObject) { unsigned int contextID = renderInfo.getContextID(); diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 84377c116..dc8641910 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -760,8 +760,7 @@ void Geometry::compileGLObjects(RenderInfo& renderInfo) const extensions->glBindBuffer(GL_ARRAY_BUFFER_ARB,0); extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0); - const DisplaySettings* ds = state.getDisplaySettings() ? state.getDisplaySettings() : osg::DisplaySettings::instance(); - if (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT && !bufferObjects.empty()) + if (state.useVertexArrayObject() && !bufferObjects.empty()) { VertexArrayState* vas = 0; @@ -808,8 +807,7 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const drawPrimitivesImplementation(renderInfo); - const DisplaySettings* ds = state.getDisplaySettings() ? state.getDisplaySettings() : osg::DisplaySettings::instance(); - bool useVertexArrayObject = _useVertexBufferObjects && (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT); + bool useVertexArrayObject = _useVertexBufferObjects && state.useVertexArrayObject(); unsigned int contextID = renderInfo.getContextID(); if (!useVertexArrayObject || _vertexArrayStateList[contextID]->getRequiresSetArrays()) { @@ -849,8 +847,7 @@ void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const arrayDispatchers.dispatch(osg::Array::BIND_OVERALL,0); - const DisplaySettings* ds = state.getDisplaySettings() ? state.getDisplaySettings() : osg::DisplaySettings::instance(); - bool useVertexArrayObject = _useVertexBufferObjects && (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT); + bool useVertexArrayObject = _useVertexBufferObjects && state.useVertexArrayObject(); unsigned int contextID = renderInfo.getContextID(); if (useVertexArrayObject) { diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 8fcaa8764..cdee4c49b 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -103,6 +103,9 @@ State::State(): _isVertexBufferObjectSupportResolved = false; _isVertexBufferObjectSupported = false; + _isVertexArrayObjectSupported = false; + _useVertexArrayObject = false; + _lastAppliedProgramObject = 0; _extensionProcsInitialized = false; @@ -157,6 +160,113 @@ State::~State() //_vertexAttribArrayList.clear(); } +void State::initializeExtensionProcs() +{ + if (_extensionProcsInitialized) return; + + const char* vendor = (const char*) glGetString( GL_VENDOR ); + if (vendor) + { + std::string str_vendor(vendor); + std::replace(str_vendor.begin(), str_vendor.end(), ' ', '_'); + OSG_INFO<<"GL_VENDOR = ["<isVAOSupported; + _useVertexArrayObject = _isVertexArrayObjectSupported && (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT); + + +#ifdef USE_VERTEXARRAYSTATE + _globalVertexArrayState = new VertexArrayState(_glExtensions.get()); + _globalVertexArrayState->assignAllDispatchers(); + setCurrentToGloabalVertexArrayState(); +#endif + + setGLExtensionFuncPtr(_glClientActiveTexture,"glClientActiveTexture","glClientActiveTextureARB"); + setGLExtensionFuncPtr(_glActiveTexture, "glActiveTexture","glActiveTextureARB"); + setGLExtensionFuncPtr(_glFogCoordPointer, "glFogCoordPointer","glFogCoordPointerEXT"); + setGLExtensionFuncPtr(_glSecondaryColorPointer, "glSecondaryColorPointer","glSecondaryColorPointerEXT"); + setGLExtensionFuncPtr(_glVertexAttribPointer, "glVertexAttribPointer","glVertexAttribPointerARB"); + setGLExtensionFuncPtr(_glVertexAttribIPointer, "glVertexAttribIPointer"); + setGLExtensionFuncPtr(_glVertexAttribLPointer, "glVertexAttribLPointer","glVertexAttribPointerARB"); + setGLExtensionFuncPtr(_glEnableVertexAttribArray, "glEnableVertexAttribArray","glEnableVertexAttribArrayARB"); + setGLExtensionFuncPtr(_glMultiTexCoord4f, "glMultiTexCoord4f","glMultiTexCoord4fARB"); + setGLExtensionFuncPtr(_glVertexAttrib4f, "glVertexAttrib4f"); + setGLExtensionFuncPtr(_glVertexAttrib4fv, "glVertexAttrib4fv"); + setGLExtensionFuncPtr(_glDisableVertexAttribArray, "glDisableVertexAttribArray","glDisableVertexAttribArrayARB"); + setGLExtensionFuncPtr(_glBindBuffer, "glBindBuffer","glBindBufferARB"); + + setGLExtensionFuncPtr(_glDrawArraysInstanced, "glDrawArraysInstanced","glDrawArraysInstancedARB","glDrawArraysInstancedEXT"); + setGLExtensionFuncPtr(_glDrawElementsInstanced, "glDrawElementsInstanced","glDrawElementsInstancedARB","glDrawElementsInstancedEXT"); + + if (osg::getGLVersionNumber() >= 2.0 || osg::isGLExtensionSupported(_contextID, "GL_ARB_vertex_shader") || OSG_GLES2_FEATURES || OSG_GL3_FEATURES) + { + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,&_glMaxTextureUnits); + #ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE + glGetIntegerv(GL_MAX_TEXTURE_COORDS, &_glMaxTextureCoords); + #else + _glMaxTextureCoords = _glMaxTextureUnits; + #endif + } + else if ( osg::getGLVersionNumber() >= 1.3 || + osg::isGLExtensionSupported(_contextID,"GL_ARB_multitexture") || + osg::isGLExtensionSupported(_contextID,"GL_EXT_multitexture") || + OSG_GLES1_FEATURES) + { + GLint maxTextureUnits = 0; + glGetIntegerv(GL_MAX_TEXTURE_UNITS,&maxTextureUnits); + _glMaxTextureUnits = maxTextureUnits; + _glMaxTextureCoords = maxTextureUnits; + } + else + { + _glMaxTextureUnits = 1; + _glMaxTextureCoords = 1; + } + + if (_glExtensions->isARBTimerQuerySupported) + { + const GLubyte* renderer = glGetString(GL_RENDERER); + std::string rendererString = renderer ? (const char*)renderer : ""; + if (rendererString.find("Radeon")!=std::string::npos || rendererString.find("RADEON")!=std::string::npos || rendererString.find("FirePro")!=std::string::npos) + { + // AMD/ATI drivers are producing an invalid enumerate error on the + // glGetQueryiv(GL_TIMESTAMP, GL_QUERY_COUNTER_BITS_ARB, &bits); + // call so work around it by assuming 64 bits for counter. + setTimestampBits(64); + //setTimestampBits(0); + } + else + { + GLint bits = 0; + _glExtensions->glGetQueryiv(GL_TIMESTAMP, GL_QUERY_COUNTER_BITS_ARB, &bits); + setTimestampBits(bits); + } + } + + + _extensionProcsInitialized = true; + + if (_graphicsCostEstimator.valid()) + { + RenderInfo renderInfo(this,0); + _graphicsCostEstimator->calibrate(renderInfo); + } +} + void State::releaseGLObjects() { // release any GL objects held by the shader composer @@ -966,101 +1076,6 @@ void State::setInterleavedArrays( GLenum format, GLsizei stride, const GLvoid* p dirtyAllVertexArrays(); } -void State::initializeExtensionProcs() -{ - if (_extensionProcsInitialized) return; - - const char* vendor = (const char*) glGetString( GL_VENDOR ); - if (vendor) - { - std::string str_vendor(vendor); - std::replace(str_vendor.begin(), str_vendor.end(), ' ', '_'); - OSG_INFO<<"GL_VENDOR = ["<assignAllDispatchers(); - setCurrentToGloabalVertexArrayState(); -#endif - - setGLExtensionFuncPtr(_glClientActiveTexture,"glClientActiveTexture","glClientActiveTextureARB"); - setGLExtensionFuncPtr(_glActiveTexture, "glActiveTexture","glActiveTextureARB"); - setGLExtensionFuncPtr(_glFogCoordPointer, "glFogCoordPointer","glFogCoordPointerEXT"); - setGLExtensionFuncPtr(_glSecondaryColorPointer, "glSecondaryColorPointer","glSecondaryColorPointerEXT"); - setGLExtensionFuncPtr(_glVertexAttribPointer, "glVertexAttribPointer","glVertexAttribPointerARB"); - setGLExtensionFuncPtr(_glVertexAttribIPointer, "glVertexAttribIPointer"); - setGLExtensionFuncPtr(_glVertexAttribLPointer, "glVertexAttribLPointer","glVertexAttribPointerARB"); - setGLExtensionFuncPtr(_glEnableVertexAttribArray, "glEnableVertexAttribArray","glEnableVertexAttribArrayARB"); - setGLExtensionFuncPtr(_glMultiTexCoord4f, "glMultiTexCoord4f","glMultiTexCoord4fARB"); - setGLExtensionFuncPtr(_glVertexAttrib4f, "glVertexAttrib4f"); - setGLExtensionFuncPtr(_glVertexAttrib4fv, "glVertexAttrib4fv"); - setGLExtensionFuncPtr(_glDisableVertexAttribArray, "glDisableVertexAttribArray","glDisableVertexAttribArrayARB"); - setGLExtensionFuncPtr(_glBindBuffer, "glBindBuffer","glBindBufferARB"); - - setGLExtensionFuncPtr(_glDrawArraysInstanced, "glDrawArraysInstanced","glDrawArraysInstancedARB","glDrawArraysInstancedEXT"); - setGLExtensionFuncPtr(_glDrawElementsInstanced, "glDrawElementsInstanced","glDrawElementsInstancedARB","glDrawElementsInstancedEXT"); - - if (osg::getGLVersionNumber() >= 2.0 || osg::isGLExtensionSupported(_contextID, "GL_ARB_vertex_shader") || OSG_GLES2_FEATURES || OSG_GL3_FEATURES) - { - glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,&_glMaxTextureUnits); - #ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE - glGetIntegerv(GL_MAX_TEXTURE_COORDS, &_glMaxTextureCoords); - #else - _glMaxTextureCoords = _glMaxTextureUnits; - #endif - } - else if ( osg::getGLVersionNumber() >= 1.3 || - osg::isGLExtensionSupported(_contextID,"GL_ARB_multitexture") || - osg::isGLExtensionSupported(_contextID,"GL_EXT_multitexture") || - OSG_GLES1_FEATURES) - { - GLint maxTextureUnits = 0; - glGetIntegerv(GL_MAX_TEXTURE_UNITS,&maxTextureUnits); - _glMaxTextureUnits = maxTextureUnits; - _glMaxTextureCoords = maxTextureUnits; - } - else - { - _glMaxTextureUnits = 1; - _glMaxTextureCoords = 1; - } - - if (_glExtensions->isARBTimerQuerySupported) - { - const GLubyte* renderer = glGetString(GL_RENDERER); - std::string rendererString = renderer ? (const char*)renderer : ""; - if (rendererString.find("Radeon")!=std::string::npos || rendererString.find("RADEON")!=std::string::npos || rendererString.find("FirePro")!=std::string::npos) - { - // AMD/ATI drivers are producing an invalid enumerate error on the - // glGetQueryiv(GL_TIMESTAMP, GL_QUERY_COUNTER_BITS_ARB, &bits); - // call so work around it by assuming 64 bits for counter. - setTimestampBits(64); - //setTimestampBits(0); - } - else - { - GLint bits = 0; - _glExtensions->glGetQueryiv(GL_TIMESTAMP, GL_QUERY_COUNTER_BITS_ARB, &bits); - setTimestampBits(bits); - } - } - - - _extensionProcsInitialized = true; - - if (_graphicsCostEstimator.valid()) - { - RenderInfo renderInfo(this,0); - _graphicsCostEstimator->calibrate(renderInfo); - } -} #if USE_VERTEXARRAYSTATE /////////////////////////////////////////////////////////////////////////