Skip to content

Commit 2e529f7

Browse files
madsbuviMads Buvik Sandvei
authored andcommitted
Add sized depth and stencil formats. Fix OSG calling glTexImage3D on immutable textures already allocated using glTexStorage3D.
1 parent 6561e05 commit 2e529f7

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

include/osg/Texture

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@
415415

416416
//#define OSG_COLLECT_TEXTURE_APPLIED_STATS 1
417417

418+
#define OSG_TEXTURE_HAS_SIZED_DEPTH_AND_STENCIL_INTERNAL_FORMATS
419+
418420
namespace osg {
419421

420422

src/osg/Texture.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@
5454
#define GL_RGB565 0x8D62
5555
#endif
5656

57+
#ifndef GL_DEPTH32F_STENCIL8
58+
#define GL_DEPTH32F_STENCIL8 0x8CAD
59+
#endif
60+
61+
#ifndef GL_FLOAT_32_UNSIGNED_INT_24_8_REV
62+
#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD
63+
#endif
64+
65+
#ifndef GL_DEPTH24_STENCIL8
66+
#define GL_DEPTH24_STENCIL8 0x88F0
67+
#endif
68+
69+
#ifndef GL_DEPTH_STENCIL_EXT
70+
#define GL_DEPTH_STENCIL_EXT 0x84F9
71+
#endif
72+
5773
#if 0
5874
#define CHECK_CONSISTENCY checkConsistency();
5975
#else
@@ -173,8 +189,8 @@ InternalPixelRelations sizedDepthAndStencilInternalFormats[] = {
173189
, { GL_DEPTH_COMPONENT24 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT }
174190
, { GL_DEPTH_COMPONENT32 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT }
175191
, { GL_DEPTH_COMPONENT32F , GL_DEPTH_COMPONENT , GL_FLOAT }
176-
// , { GL_DEPTH24_STENCIL8 , GL_DEPTH_STENCIL , GL_UNSIGNED_INT_24_8 }
177-
// , { GL_DEPTH32F_STENCIL8 , GL_DEPTH_STENCIL , GL_FLOAT_32_UNSIGNED_INT_24_8_REV }
192+
, { GL_DEPTH24_STENCIL8 , GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT }
193+
, { GL_DEPTH32F_STENCIL8 , GL_DEPTH_STENCIL_EXT, GL_FLOAT_32_UNSIGNED_INT_24_8_REV }
178194
};
179195

180196
InternalPixelRelations compressedInternalFormats[] = {
@@ -236,14 +252,22 @@ InternalPixelRelations compressedInternalFormats[] = {
236252

237253
bool isSizedInternalFormat(GLint internalFormat)
238254
{
239-
const size_t formatsCount = sizeof(sizedInternalFormats) / sizeof(sizedInternalFormats[0]);
255+
size_t formatsCount = sizeof(sizedInternalFormats) / sizeof(sizedInternalFormats[0]);
240256

241257
for (size_t i=0; i < formatsCount; ++i)
242258
{
243259
if((GLenum)internalFormat == sizedInternalFormats[i].sizedInternalFormat)
244260
return true;
245261
}
246262

263+
formatsCount = sizeof(sizedDepthAndStencilInternalFormats) / sizeof(sizedDepthAndStencilInternalFormats[0]);
264+
265+
for (size_t i=0; i < formatsCount; ++i)
266+
{
267+
if((GLenum)internalFormat == sizedDepthAndStencilInternalFormats[i].sizedInternalFormat)
268+
return true;
269+
}
270+
247271
return false;
248272
}
249273

src/osg/Texture2DArray.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -440,26 +440,29 @@ void Texture2DArray::apply(State& state) const
440440
// generate texture
441441
GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled ? selectSizedInternalFormat() : 0;
442442

443-
textureObject = generateAndAssignTextureObject(
444-
contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels,
445-
texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat :_internalFormat,
446-
_textureWidth, _textureHeight, _textureDepth, 0);
447-
448-
textureObject->bind();
449-
450-
applyTexParameters(GL_TEXTURE_2D_ARRAY,state);
451-
452-
if (texStorageSizedInternalFormat!=0 && !textureObject->_allocated)
443+
if (texStorageSizedInternalFormat != 0)
453444
{
454-
extensions->glTexStorage3D( GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth);
445+
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth, 0);
446+
textureObject->bind();
447+
applyTexParameters(GL_TEXTURE_2D_ARRAY, state);
448+
if (!textureObject->_allocated)
449+
{
450+
extensions->glTexStorage3D(GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels, 1), texStorageSizedInternalFormat,
451+
_textureWidth, _textureHeight, _textureDepth);
452+
}
455453
}
456454
else
457-
extensions->glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, _internalFormat,
458-
_textureWidth, _textureHeight, _textureDepth,
459-
_borderWidth,
460-
_sourceFormat ? _sourceFormat : _internalFormat,
461-
_sourceType ? _sourceType : GL_UNSIGNED_BYTE,
462-
0);
455+
{
456+
GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat;
457+
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels, internalFormat, _textureWidth, _textureHeight, _textureDepth, 0);
458+
textureObject->bind();
459+
applyTexParameters(GL_TEXTURE_2D_ARRAY, state);
460+
extensions->glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, _internalFormat,
461+
_textureWidth, _textureHeight, _textureDepth, _borderWidth,
462+
internalFormat,
463+
_sourceType ? _sourceType : GL_UNSIGNED_BYTE,
464+
0);
465+
}
463466

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

0 commit comments

Comments
 (0)