Show
Ignore:
Timestamp:
01/07/10 17:49:12 (5 years ago)
Author:
robert
Message:

From Lilith Bryant, "As discussed previously on the users list. Fixes the redundant calls to
glActiveTexture on every State::apply after more than one texunits have been
used.

This is against 2.9.6 (I think SVN head is the same)

Quick Synopsis:

New functions:

State::applyModeOnTexUnit
State::applyAttributeOnTexUnit
State::applyModeMapOnTexUnit
State::applyAttributeMapOnTexUnit
State::applyModeListOnTexUnit
State::applyAttributeListOnTexUnit

All copies of the normal versions, but they also set the active tex unit if
absolutely necessary (i.e. only if they call something OpenGL).

State::apply (*2)
State::applyTextureAttribute

Changed to call the above functions and no longer call setActiveTextureUnit
themselves.

State::setActiveTextureUnit

Made inline, so the benefit of having applyModeOnTexUnit (etc) inline
is retained.
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osg/State.cpp

    r10765 r10926  
    502502        for(unit=0;unit<unitMax;++unit) 
    503503        { 
    504             if (setActiveTextureUnit(unit)) 
    505             { 
    506                 if (unit<ds_textureModeList.size()) applyModeList(getOrCreateTextureModeMap(unit),ds_textureModeList[unit]); 
    507                 else if (unit<_textureModeMapList.size()) applyModeMap(_textureModeMapList[unit]); 
    508  
    509                 if (unit<ds_textureAttributeList.size()) applyAttributeList(getOrCreateTextureAttributeMap(unit),ds_textureAttributeList[unit]); 
    510                 else if (unit<_textureAttributeMapList.size()) applyAttributeMap(_textureAttributeMapList[unit]); 
    511             } 
     504            if (unit<ds_textureModeList.size()) applyModeListOnTexUnit(unit,getOrCreateTextureModeMap(unit),ds_textureModeList[unit]); 
     505            else if (unit<_textureModeMapList.size()) applyModeMapOnTexUnit(unit,_textureModeMapList[unit]); 
     506 
     507            if (unit<ds_textureAttributeList.size()) applyAttributeListOnTexUnit(unit,getOrCreateTextureAttributeMap(unit),ds_textureAttributeList[unit]); 
     508            else if (unit<_textureAttributeMapList.size()) applyAttributeMapOnTexUnit(unit,_textureAttributeMapList[unit]); 
    512509        } 
    513510 
     
    539536    for(unit=0;unit<unitMax;++unit) 
    540537    { 
    541         if (setActiveTextureUnit(unit)) 
    542         { 
    543             if (unit<_textureModeMapList.size()) applyModeMap(_textureModeMapList[unit]); 
    544             if (unit<_textureAttributeMapList.size()) applyAttributeMap(_textureAttributeMapList[unit]); 
    545         } 
     538        if (unit<_textureModeMapList.size()) applyModeMapOnTexUnit(unit,_textureModeMapList[unit]); 
     539        if (unit<_textureAttributeMapList.size()) applyAttributeMapOnTexUnit(unit,_textureAttributeMapList[unit]); 
    546540    } 
    547541 
     
    849843            _glClientActiveTexture(GL_TEXTURE0+unit); 
    850844            _currentClientActiveTextureUnit = unit; 
    851         } 
    852         else 
    853         { 
    854             return unit==0; 
    855         } 
    856     } 
    857     return true; 
    858 } 
    859  
    860  
    861 /** set the current texture unit, return true if selected, false if selection failed such as when multitexturing is not supported. 
    862   * note, only updates values that change.*/ 
    863 bool State::setActiveTextureUnit( unsigned int unit ) 
    864 { 
    865     if (unit!=_currentActiveTextureUnit) 
    866     { 
    867         if (_glActiveTexture && unit < (unsigned int)(maximum(_glMaxTextureCoords,_glMaxTextureUnits)) ) 
    868         { 
    869             _glActiveTexture(GL_TEXTURE0+unit); 
    870             _currentActiveTextureUnit = unit; 
    871845        } 
    872846        else