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
"
This commit is contained in:
Robert Osfield 2007-05-15 11:25:14 +00:00
parent dd1f6982dd
commit ab4398e440
2 changed files with 18 additions and 2 deletions

View File

@ -1293,6 +1293,8 @@ class OSG_EXPORT State : public Referenced
bool _extensionProcsInitialized; bool _extensionProcsInitialized;
GLint _glMaxTextureCoords;
GLint _glMaxTextureUnits;
ActiveTextureProc _glClientActiveTexture; ActiveTextureProc _glClientActiveTexture;
ActiveTextureProc _glActiveTexture; ActiveTextureProc _glActiveTexture;
FogCoordPointerProc _glFogCoordPointer; FogCoordPointerProc _glFogCoordPointer;

View File

@ -15,6 +15,13 @@
#include <osg/GLU> #include <osg/GLU>
#include <osg/GLExtensions> #include <osg/GLExtensions>
#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 std;
using namespace osg; using namespace osg;
@ -734,6 +741,13 @@ void State::initializeExtensionProcs()
_glDisableVertexAttribArray = (DisableVertexAttribProc) osg::getGLExtensionFuncPtr("glDisableVertexAttribArray","glDisableVertexAttribArrayARB"); _glDisableVertexAttribArray = (DisableVertexAttribProc) osg::getGLExtensionFuncPtr("glDisableVertexAttribArray","glDisableVertexAttribArrayARB");
_glBindBuffer = (BindBufferProc) osg::getGLExtensionFuncPtr("glBindBuffer","glBindBufferARB"); _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; _extensionProcsInitialized = true;
} }
@ -741,7 +755,7 @@ bool State::setClientActiveTextureUnit( unsigned int unit )
{ {
if (unit!=_currentClientActiveTextureUnit) if (unit!=_currentClientActiveTextureUnit)
{ {
if (_glClientActiveTexture) if (_glClientActiveTexture && unit < (unsigned int)_glMaxTextureCoords)
{ {
_glClientActiveTexture(GL_TEXTURE0+unit); _glClientActiveTexture(GL_TEXTURE0+unit);
_currentClientActiveTextureUnit = unit; _currentClientActiveTextureUnit = unit;
@ -761,7 +775,7 @@ bool State::setActiveTextureUnit( unsigned int unit )
{ {
if (unit!=_currentActiveTextureUnit) if (unit!=_currentActiveTextureUnit)
{ {
if (_glActiveTexture) if (_glActiveTexture && unit < (unsigned int)_glMaxTextureUnits)
{ {
_glActiveTexture(GL_TEXTURE0+unit); _glActiveTexture(GL_TEXTURE0+unit);
_currentActiveTextureUnit = unit; _currentActiveTextureUnit = unit;