prevent immutability resetting when textureobject is taken from orphans

This commit is contained in:
Julien Valentin 2020-03-25 23:00:24 +01:00 committed by Robert Osfield
parent c29e2e4f40
commit b8416a7aa2
7 changed files with 56 additions and 33 deletions

View File

@ -238,13 +238,15 @@ void Texture1D::apply(State& state) const
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, 1, 1, 0); textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, 1, 1, 0);
textureObject->bind(state); textureObject->bind(state);
applyTexParameters(GL_TEXTURE_1D, state); applyTexParameters(GL_TEXTURE_1D, state);
if(!textureObject->_allocated)
extensions->glTexStorage1D( GL_TEXTURE_1D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth); {
extensions->glTexStorage1D( GL_TEXTURE_1D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth);
}
} }
else else
{ {
GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat; GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat;
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D, _numMipmapLevels, internalFormat, _textureWidth, 1, 1, 0); textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D, _numMipmapLevels, internalFormat, _textureWidth, 1, 1, _borderWidth);
textureObject->bind(state); textureObject->bind(state);
applyTexParameters(GL_TEXTURE_1D, state); applyTexParameters(GL_TEXTURE_1D, state);
@ -260,6 +262,8 @@ void Texture1D::apply(State& state) const
_readPBuffer->bindPBufferToTexture(GL_FRONT); _readPBuffer->bindPBufferToTexture(GL_FRONT);
} }
textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat: _internalFormat, _textureWidth, 1, 1, _borderWidth);
} }
else else
{ {

View File

@ -298,27 +298,30 @@ void Texture2D::apply(State& state) const
else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) ) else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) )
{ {
// no image present, but dimensions at set so lets create the texture // no image present, but dimensions at set so lets create the texture
GLExtensions * extensions = state.get<GLExtensions>(); GLExtensions * extensions = state.get<GLExtensions>();
GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled && (_borderWidth==0) ? selectSizedInternalFormat() : 0; GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled && (_borderWidth==0) ? selectSizedInternalFormat() : 0;
if (texStorageSizedInternalFormat!=0) if (texStorageSizedInternalFormat!=0)
{ {
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, _borderWidth); textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, _borderWidth);
textureObject->bind(state); textureObject->bind(state);
applyTexParameters(GL_TEXTURE_2D, state); applyTexParameters(GL_TEXTURE_2D, state);
extensions->glTexStorage2D( GL_TEXTURE_2D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, if(!textureObject->_allocated)
_textureWidth, _textureHeight); {
} extensions->glTexStorage2D( GL_TEXTURE_2D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat,
else _textureWidth, _textureHeight);
{ }
GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat; }
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D, _numMipmapLevels, internalFormat, _textureWidth, _textureHeight, 1, _borderWidth); else
textureObject->bind(state); {
applyTexParameters(GL_TEXTURE_2D, state); GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat;
glTexImage2D( GL_TEXTURE_2D, 0, _internalFormat, textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D, _numMipmapLevels, internalFormat, _textureWidth, _textureHeight, 1, _borderWidth);
_textureWidth, _textureHeight, _borderWidth, textureObject->bind(state);
internalFormat, applyTexParameters(GL_TEXTURE_2D, state);
_sourceType ? _sourceType : GL_UNSIGNED_BYTE, glTexImage2D( GL_TEXTURE_2D, 0, _internalFormat,
0); _textureWidth, _textureHeight, _borderWidth,
internalFormat,
_sourceType ? _sourceType : GL_UNSIGNED_BYTE,
0);
} }
if (_readPBuffer.valid()) if (_readPBuffer.valid())
@ -326,6 +329,7 @@ void Texture2D::apply(State& state) const
_readPBuffer->bindPBufferToTexture(GL_FRONT); _readPBuffer->bindPBufferToTexture(GL_FRONT);
} }
textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat: _internalFormat, _textureWidth, _textureHeight, 1, _borderWidth);
} }
else else
{ {

View File

@ -353,7 +353,7 @@ void Texture2DArray::apply(State& state) const
applyTexParameters(GL_TEXTURE_2D_ARRAY, state); applyTexParameters(GL_TEXTURE_2D_ARRAY, state);
// First we need to allocate the texture memory // First we need to allocate the texture memory
if(texStorageSizedInternalFormat!=0) if(texStorageSizedInternalFormat!=0 && !textureObject->_allocated)
{ {
extensions->glTexStorage3D(GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, textureDepth); extensions->glTexStorage3D(GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, textureDepth);
} }
@ -452,7 +452,7 @@ void Texture2DArray::apply(State& state) const
applyTexParameters(GL_TEXTURE_2D_ARRAY,state); applyTexParameters(GL_TEXTURE_2D_ARRAY,state);
if (texStorageSizedInternalFormat!=0) if (texStorageSizedInternalFormat!=0 && !textureObject->_allocated)
{ {
extensions->glTexStorage3D( GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth); extensions->glTexStorage3D( GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth);
} }
@ -463,6 +463,8 @@ void Texture2DArray::apply(State& state) const
_sourceFormat ? _sourceFormat : _internalFormat, _sourceFormat ? _sourceFormat : _internalFormat,
_sourceType ? _sourceType : GL_UNSIGNED_BYTE, _sourceType ? _sourceType : GL_UNSIGNED_BYTE,
0); 0);
textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat :_internalFormat, _textureWidth, _textureHeight, _textureDepth, 0);
} }
// nothing before, so just unbind the texture target // nothing before, so just unbind the texture target

View File

@ -108,8 +108,10 @@ void Texture2DMultisample::apply(State& state) const
{ {
textureObject = generateAndAssignTextureObject(contextID, getTextureTarget(), 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, 0); textureObject = generateAndAssignTextureObject(contextID, getTextureTarget(), 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, 0);
textureObject->bind(state); textureObject->bind(state);
if(!textureObject->_allocated)
extensions->glTexStorage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, _numSamples, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _fixedsamplelocations); {
extensions->glTexStorage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, _numSamples, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _fixedsamplelocations);
}
} }
else else
{ {
@ -123,6 +125,7 @@ void Texture2DMultisample::apply(State& state) const
_textureHeight, _textureHeight,
_fixedsamplelocations ); _fixedsamplelocations );
} }
textureObject->setAllocated(1, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat: _internalFormat, _textureWidth, _textureHeight, 1, _borderWidth);
} }
else else

View File

@ -322,8 +322,10 @@ void Texture3D::apply(State& state) const
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_3D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth,0); textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_3D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth,0);
textureObject->bind(state); textureObject->bind(state);
applyTexParameters(GL_TEXTURE_3D, state); applyTexParameters(GL_TEXTURE_3D, state);
if(!textureObject->_allocated)
extensions->glTexStorage3D( GL_TEXTURE_3D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth); {
extensions->glTexStorage3D( GL_TEXTURE_3D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth);
}
} }
else else
{ {
@ -345,6 +347,7 @@ void Texture3D::apply(State& state) const
_readPBuffer->bindPBufferToTexture(GL_FRONT); _readPBuffer->bindPBufferToTexture(GL_FRONT);
} }
textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat : _internalFormat, _textureWidth, _textureHeight, _textureDepth, _borderWidth);
} }
else else
{ {

View File

@ -353,7 +353,10 @@ void TextureCubeMap::apply(State& state) const
if(texStorageSizedInternalFormat!=0) if(texStorageSizedInternalFormat!=0)
{ {
extensions->glTexStorage2D(GL_TEXTURE_CUBE_MAP, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight); if(!textureObject->_allocated)
{
extensions->glTexStorage2D(GL_TEXTURE_CUBE_MAP, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight);
}
} }
else else
@ -367,6 +370,7 @@ void TextureCubeMap::apply(State& state) const
0); 0);
} }
textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat : _internalFormat, _textureWidth, _textureHeight, 1, 0);
} }
else else
{ {

View File

@ -281,8 +281,10 @@ void TextureRectangle::apply(State& state) const
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_RECTANGLE, 0, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, 0); textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_RECTANGLE, 0, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, 0);
textureObject->bind(state); textureObject->bind(state);
applyTexParameters(GL_TEXTURE_RECTANGLE, state); applyTexParameters(GL_TEXTURE_RECTANGLE, state);
if(!textureObject->_allocated)
extensions->glTexStorage2D( GL_TEXTURE_RECTANGLE, 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight); {
extensions->glTexStorage2D( GL_TEXTURE_RECTANGLE, 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight);
}
} }
else else
{ {
@ -303,6 +305,7 @@ void TextureRectangle::apply(State& state) const
_readPBuffer->bindPBufferToTexture(GL_FRONT); _readPBuffer->bindPBufferToTexture(GL_FRONT);
} }
textureObject->setAllocated(0, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat : _internalFormat, _textureWidth, _textureHeight, 1, 0);
} }
else else
{ {