From ab4398e4406c5b68332e45ce906830d1cc4d674e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 15 May 2007 11:25:14 +0000 Subject: [PATCH] From Farshid Lashkari, "I made a modification to the setClientActiveTextureUnit and setActiveTextureUnit methods of osg::State so they return false if the texture unit is outside the range of allowable units for the driver. Currently, the functions would return true even if the units are invalid. This would cause the osg::State to become out of sync with the actual driver state, which can cause some bugs in certain cases. The change I made would verify that the unit passed to setClientActiveTextureUnit is below GL_MAX_TEXTURE_COORDS, and the unit passed to setActiveTextureUnit is below max(GL_MAX_TEXTURE_COORDS,GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS). I modeled this behavior from the OpenGL docs for these commands which can be found here: http://www.opengl.org/sdk/docs/man/xhtml/glClientActiveTexture.xml http://www.opengl.org/sdk/docs/man/xhtml/glActiveTexture.xml " --- include/osg/State | 2 ++ src/osg/State.cpp | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/osg/State b/include/osg/State index d1da97c95..d25ff91f5 100644 --- a/include/osg/State +++ b/include/osg/State @@ -1293,6 +1293,8 @@ class OSG_EXPORT State : public Referenced bool _extensionProcsInitialized; + GLint _glMaxTextureCoords; + GLint _glMaxTextureUnits; ActiveTextureProc _glClientActiveTexture; ActiveTextureProc _glActiveTexture; FogCoordPointerProc _glFogCoordPointer; diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 62e441c33..ba19b1413 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -15,6 +15,13 @@ #include #include +#ifndef GL_MAX_TEXTURE_COORDS +#define GL_MAX_TEXTURE_COORDS 0x8871 +#endif + +#ifndef GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#endif using namespace std; using namespace osg; @@ -734,6 +741,13 @@ void State::initializeExtensionProcs() _glDisableVertexAttribArray = (DisableVertexAttribProc) osg::getGLExtensionFuncPtr("glDisableVertexAttribArray","glDisableVertexAttribArrayARB"); _glBindBuffer = (BindBufferProc) osg::getGLExtensionFuncPtr("glBindBuffer","glBindBufferARB"); + _glMaxTextureCoords = 1; + glGetIntegerv(GL_MAX_TEXTURE_COORDS,&_glMaxTextureCoords); + + _glMaxTextureUnits = 1; + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,&_glMaxTextureUnits); + _glMaxTextureUnits = maximum(_glMaxTextureCoords,_glMaxTextureUnits); + _extensionProcsInitialized = true; } @@ -741,7 +755,7 @@ bool State::setClientActiveTextureUnit( unsigned int unit ) { if (unit!=_currentClientActiveTextureUnit) { - if (_glClientActiveTexture) + if (_glClientActiveTexture && unit < (unsigned int)_glMaxTextureCoords) { _glClientActiveTexture(GL_TEXTURE0+unit); _currentClientActiveTextureUnit = unit; @@ -761,7 +775,7 @@ bool State::setActiveTextureUnit( unsigned int unit ) { if (unit!=_currentActiveTextureUnit) { - if (_glActiveTexture) + if (_glActiveTexture && unit < (unsigned int)_glMaxTextureUnits) { _glActiveTexture(GL_TEXTURE0+unit); _currentActiveTextureUnit = unit;