Skip to content

Commit

Permalink
Add sized depth and stencil formats. Fix OSG calling glTexImage3D on …
Browse files Browse the repository at this point in the history
…immutable textures already allocated using glTexStorage3D.
  • Loading branch information
madsbuvi authored and Mads Buvik Sandvei committed Jan 11, 2025
1 parent 6561e05 commit 2e529f7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
2 changes: 2 additions & 0 deletions include/osg/Texture
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@

//#define OSG_COLLECT_TEXTURE_APPLIED_STATS 1

#define OSG_TEXTURE_HAS_SIZED_DEPTH_AND_STENCIL_INTERNAL_FORMATS

namespace osg {


Expand Down
30 changes: 27 additions & 3 deletions src/osg/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@
#define GL_RGB565 0x8D62
#endif

#ifndef GL_DEPTH32F_STENCIL8
#define GL_DEPTH32F_STENCIL8 0x8CAD
#endif

#ifndef GL_FLOAT_32_UNSIGNED_INT_24_8_REV
#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD
#endif

#ifndef GL_DEPTH24_STENCIL8
#define GL_DEPTH24_STENCIL8 0x88F0
#endif

#ifndef GL_DEPTH_STENCIL_EXT
#define GL_DEPTH_STENCIL_EXT 0x84F9
#endif

#if 0
#define CHECK_CONSISTENCY checkConsistency();
#else
Expand Down Expand Up @@ -173,8 +189,8 @@ InternalPixelRelations sizedDepthAndStencilInternalFormats[] = {
, { GL_DEPTH_COMPONENT24 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT }
, { GL_DEPTH_COMPONENT32 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT }
, { GL_DEPTH_COMPONENT32F , GL_DEPTH_COMPONENT , GL_FLOAT }
// , { GL_DEPTH24_STENCIL8 , GL_DEPTH_STENCIL , GL_UNSIGNED_INT_24_8 }
// , { GL_DEPTH32F_STENCIL8 , GL_DEPTH_STENCIL , GL_FLOAT_32_UNSIGNED_INT_24_8_REV }
, { GL_DEPTH24_STENCIL8 , GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT }
, { GL_DEPTH32F_STENCIL8 , GL_DEPTH_STENCIL_EXT, GL_FLOAT_32_UNSIGNED_INT_24_8_REV }
};

InternalPixelRelations compressedInternalFormats[] = {
Expand Down Expand Up @@ -236,14 +252,22 @@ InternalPixelRelations compressedInternalFormats[] = {

bool isSizedInternalFormat(GLint internalFormat)
{
const size_t formatsCount = sizeof(sizedInternalFormats) / sizeof(sizedInternalFormats[0]);
size_t formatsCount = sizeof(sizedInternalFormats) / sizeof(sizedInternalFormats[0]);

for (size_t i=0; i < formatsCount; ++i)
{
if((GLenum)internalFormat == sizedInternalFormats[i].sizedInternalFormat)
return true;
}

formatsCount = sizeof(sizedDepthAndStencilInternalFormats) / sizeof(sizedDepthAndStencilInternalFormats[0]);

for (size_t i=0; i < formatsCount; ++i)
{
if((GLenum)internalFormat == sizedDepthAndStencilInternalFormats[i].sizedInternalFormat)
return true;
}

return false;
}

Expand Down
37 changes: 20 additions & 17 deletions src/osg/Texture2DArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,26 +440,29 @@ void Texture2DArray::apply(State& state) const
// generate texture
GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled ? selectSizedInternalFormat() : 0;

textureObject = generateAndAssignTextureObject(
contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels,
texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat :_internalFormat,
_textureWidth, _textureHeight, _textureDepth, 0);

textureObject->bind();

applyTexParameters(GL_TEXTURE_2D_ARRAY,state);

if (texStorageSizedInternalFormat!=0 && !textureObject->_allocated)
if (texStorageSizedInternalFormat != 0)
{
extensions->glTexStorage3D( GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth);
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth, 0);
textureObject->bind();
applyTexParameters(GL_TEXTURE_2D_ARRAY, state);
if (!textureObject->_allocated)
{
extensions->glTexStorage3D(GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels, 1), texStorageSizedInternalFormat,
_textureWidth, _textureHeight, _textureDepth);
}
}
else
extensions->glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, _internalFormat,
_textureWidth, _textureHeight, _textureDepth,
_borderWidth,
_sourceFormat ? _sourceFormat : _internalFormat,
_sourceType ? _sourceType : GL_UNSIGNED_BYTE,
0);
{
GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat;
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels, internalFormat, _textureWidth, _textureHeight, _textureDepth, 0);
textureObject->bind();
applyTexParameters(GL_TEXTURE_2D_ARRAY, state);
extensions->glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, _internalFormat,
_textureWidth, _textureHeight, _textureDepth, _borderWidth,
internalFormat,
_sourceType ? _sourceType : GL_UNSIGNED_BYTE,
0);
}

textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat :_internalFormat, _textureWidth, _textureHeight, _textureDepth, 0);
}
Expand Down

0 comments on commit 2e529f7

Please sign in to comment.