Changeset 10860

Show
Ignore:
Timestamp:
12/08/09 15:25:16 (4 years ago)
Author:
robert
Message:

Added catch for changes in image pixel format and dimensions so that the texture object is released when the image changes enough to warrant a new texture object.

Files:
1 modified

Legend:

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

    r10732 r10860  
    144144    TextureObject* textureObject = getTextureObject(contextID); 
    145145 
    146     if (textureObject != 0) 
    147     { 
    148         textureObject->bind(); 
    149          
     146    if (textureObject) 
     147    { 
     148        if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount()) 
     149        { 
     150            // compute the internal texture format, this set the _internalFormat to an appropriate value. 
     151            computeInternalFormat(); 
     152 
     153            GLsizei new_width, new_height, new_numMipmapLevels; 
     154 
     155            // compute the dimensions of the texture. 
     156            computeRequiredTextureDimensions(state, *_image, new_width, new_height, new_numMipmapLevels); 
     157 
     158            if (!textureObject->match(GL_TEXTURE_2D, new_numMipmapLevels, _internalFormat, new_width, new_height, 1, _borderWidth)) 
     159            { 
     160                Texture::releaseTextureObject(contextID, _textureObjectBuffer[contextID].get()); 
     161                _textureObjectBuffer[contextID] = 0; 
     162                textureObject = 0; 
     163            } 
     164        } 
     165    } 
     166 
     167 
     168    if (textureObject) 
     169    { 
     170        textureObject->bind(); 
     171 
    150172        if (getTextureParameterDirty(state.getContextID())) 
    151173            applyTexParameters(GL_TEXTURE_2D,state); 
     
    181203        _subloadCallback->load(*this,state); 
    182204         
    183         textureObject->setAllocated(_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); 
     205        textureObject->setAllocated(_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,_borderWidth); 
    184206 
    185207        // in theory the following line is redundent, but in practice 
     
    203225 
    204226        _textureObjectBuffer[contextID] = textureObject = generateTextureObject( 
    205                 this, contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); 
     227                this, contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,_borderWidth); 
    206228 
    207229        textureObject->bind(); 
     
    246268    { 
    247269        _textureObjectBuffer[contextID] = textureObject = generateTextureObject( 
    248                 this, contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); 
     270                this, contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,_borderWidth); 
    249271         
    250272        textureObject->bind();