Skip to content

Commit

Permalink
prevent immutability resetting when textureobject is taken from orphans
Browse files Browse the repository at this point in the history
  • Loading branch information
juval committed Mar 26, 2020
1 parent 864b087 commit 4e7a67d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 16 deletions.
10 changes: 7 additions & 3 deletions include/osg/Texture
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute
_texture(texture),
_allocated(false),
_frameLastUsed(0),
_timeStamp(0) {}
_timeStamp(0),
_immutableSetted(false) {}

inline TextureObject(Texture* texture, GLuint id, const TextureProfile& profile):
_id(id),
Expand All @@ -1013,7 +1014,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute
_texture(texture),
_allocated(false),
_frameLastUsed(0),
_timeStamp(0) {}
_timeStamp(0),
_immutableSetted(false) {}

inline TextureObject(Texture* texture,
GLuint id,
Expand All @@ -1032,7 +1034,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute
_texture(texture),
_allocated(false),
_frameLastUsed(0),
_timeStamp(0) {}
_timeStamp(0),
_immutableSetted(false) {}

inline bool match(GLenum target,
GLint numMipmapLevels,
Expand Down Expand Up @@ -1085,6 +1088,7 @@ class OSG_EXPORT Texture : public osg::StateAttribute
bool _allocated;
unsigned int _frameLastUsed;
double _timeStamp;
bool _immutableSetted;

protected:
virtual ~TextureObject();
Expand Down
7 changes: 5 additions & 2 deletions src/osg/Texture1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,11 @@ void Texture1D::apply(State& state) const
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, 1, 1, 0);
textureObject->bind();
applyTexParameters(GL_TEXTURE_1D, state);

extensions->glTexStorage1D( GL_TEXTURE_1D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth);
if(!textureObject->_immutableSetted)
{
extensions->glTexStorage1D( GL_TEXTURE_1D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth);
textureObject->_immutableSetted = true;
}
}
else
{
Expand Down
8 changes: 6 additions & 2 deletions src/osg/Texture2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,12 @@ void Texture2D::apply(State& state) const
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, _borderWidth);
textureObject->bind();
applyTexParameters(GL_TEXTURE_2D, state);
extensions->glTexStorage2D( GL_TEXTURE_2D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat,
_textureWidth, _textureHeight);
if(!textureObject->_immutableSetted)
{
extensions->glTexStorage2D( GL_TEXTURE_2D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat,
_textureWidth, _textureHeight);
textureObject->_immutableSetted = true;
}
}
else
{
Expand Down
6 changes: 4 additions & 2 deletions src/osg/Texture2DArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,10 @@ void Texture2DArray::apply(State& state) const
applyTexParameters(GL_TEXTURE_2D_ARRAY, state);

// First we need to allocate the texture memory
if(texStorageSizedInternalFormat!=0)
if(texStorageSizedInternalFormat!=0 && !textureObject->_immutableSetted)
{
extensions->glTexStorage3D(GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, textureDepth);
textureObject->_immutableSetted = true;
}
else
{
Expand Down Expand Up @@ -452,9 +453,10 @@ void Texture2DArray::apply(State& state) const

applyTexParameters(GL_TEXTURE_2D_ARRAY,state);

if (texStorageSizedInternalFormat!=0)
if (texStorageSizedInternalFormat!=0 && !textureObject->_immutableSetted)
{
extensions->glTexStorage3D( GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth);
textureObject->_immutableSetted = true;
}
else
extensions->glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, _internalFormat,
Expand Down
7 changes: 5 additions & 2 deletions src/osg/Texture2DMultisample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ void Texture2DMultisample::apply(State& state) const
{
textureObject = generateAndAssignTextureObject(contextID, getTextureTarget(), 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, 0);
textureObject->bind();

extensions->glTexStorage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, _numSamples, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _fixedsamplelocations);
if(!textureObject->_immutableSetted)
{
extensions->glTexStorage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, _numSamples, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _fixedsamplelocations);
textureObject->_immutableSetted = true;
}
}
else
{
Expand Down
7 changes: 5 additions & 2 deletions src/osg/Texture3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,11 @@ void Texture3D::apply(State& state) const
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_3D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth,0);
textureObject->bind();
applyTexParameters(GL_TEXTURE_3D, state);

extensions->glTexStorage3D( GL_TEXTURE_3D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth);
if(!textureObject->_immutableSetted)
{
extensions->glTexStorage3D( GL_TEXTURE_3D, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth);
textureObject->_immutableSetted = true;
}
}
else
{
Expand Down
6 changes: 5 additions & 1 deletion src/osg/TextureCubeMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,11 @@ void TextureCubeMap::apply(State& state) const

if(texStorageSizedInternalFormat!=0)
{
extensions->glTexStorage2D(GL_TEXTURE_CUBE_MAP, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight);
if(!textureObject->_immutableSetted)
{
extensions->glTexStorage2D(GL_TEXTURE_CUBE_MAP, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight);
textureObject->_immutableSetted = true;
}

}
else
Expand Down
7 changes: 5 additions & 2 deletions src/osg/TextureRectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,11 @@ void TextureRectangle::apply(State& state) const
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_RECTANGLE, 0, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, 0);
textureObject->bind();
applyTexParameters(GL_TEXTURE_RECTANGLE, state);

extensions->glTexStorage2D( GL_TEXTURE_RECTANGLE, 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight);
if(!textureObject->_immutableSetted)
{
extensions->glTexStorage2D( GL_TEXTURE_RECTANGLE, 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight);
textureObject->_immutableSetted = true;
}
}
else
{
Expand Down

0 comments on commit 4e7a67d

Please sign in to comment.