diff --git a/include/osg/Texture b/include/osg/Texture index ba6d874e932..e972db6eb61 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -415,6 +415,8 @@ //#define OSG_COLLECT_TEXTURE_APPLIED_STATS 1 +#define OSG_TEXTURE_HAS_SIZED_DEPTH_AND_STENCIL_INTERNAL_FORMATS + namespace osg { diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 2c0bd4b4ebb..4a102e1d3aa 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -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 @@ -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[] = { @@ -236,7 +252,7 @@ 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) { @@ -244,6 +260,14 @@ bool isSizedInternalFormat(GLint internalFormat) 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; } diff --git a/src/osg/Texture2DArray.cpp b/src/osg/Texture2DArray.cpp index 1ee98df4b4e..bb16976488e 100644 --- a/src/osg/Texture2DArray.cpp +++ b/src/osg/Texture2DArray.cpp @@ -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); }