From 13fb047a5150ebd7b80788bef909da5b72f6c57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 12 Mar 2015 22:35:45 -0700 Subject: [PATCH] GL: Fixed framebuffer with stencil attachment. --- src/image.cpp | 98 ++++++++++++++++++++++----------------------- src/image.h | 2 + src/renderer_gl.cpp | 17 +++++++- 3 files changed, 66 insertions(+), 51 deletions(-) diff --git a/src/image.cpp b/src/image.cpp index 53e3acbcd..c18d4e939 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -19,55 +19,55 @@ namespace bgfx // | | | | +----- min blocks x // | | | | | +-- min blocks y // | | | | | | - { 4, 4, 4, 8, 1, 1 }, // BC1 - { 8, 4, 4, 16, 1, 1 }, // BC2 - { 8, 4, 4, 16, 1, 1 }, // BC3 - { 4, 4, 4, 8, 1, 1 }, // BC4 - { 8, 4, 4, 16, 1, 1 }, // BC5 - { 8, 4, 4, 16, 1, 1 }, // BC6H - { 8, 4, 4, 16, 1, 1 }, // BC7 - { 4, 4, 4, 8, 1, 1 }, // ETC1 - { 4, 4, 4, 8, 1, 1 }, // ETC2 - { 8, 4, 4, 16, 1, 1 }, // ETC2A - { 4, 4, 4, 8, 1, 1 }, // ETC2A1 - { 2, 8, 4, 8, 2, 2 }, // PTC12 - { 4, 4, 4, 8, 2, 2 }, // PTC14 - { 2, 8, 4, 8, 2, 2 }, // PTC12A - { 4, 4, 4, 8, 2, 2 }, // PTC14A - { 2, 8, 4, 8, 2, 2 }, // PTC22 - { 4, 4, 4, 8, 2, 2 }, // PTC24 - { 0, 0, 0, 0, 1, 1 }, // Unknown - { 1, 8, 1, 1, 1, 1 }, // R1 - { 8, 1, 1, 1, 1, 1 }, // R8 - { 16, 1, 1, 2, 1, 1 }, // R16 - { 16, 1, 1, 2, 1, 1 }, // R16F - { 32, 1, 1, 4, 1, 1 }, // R32 - { 32, 1, 1, 4, 1, 1 }, // R32F - { 16, 1, 1, 2, 1, 1 }, // RG8 - { 32, 1, 1, 4, 1, 1 }, // RG16 - { 32, 1, 1, 4, 1, 1 }, // RG16F - { 64, 1, 1, 8, 1, 1 }, // RG32 - { 64, 1, 1, 8, 1, 1 }, // RG32F - { 32, 1, 1, 4, 1, 1 }, // BGRA8 - { 32, 1, 1, 4, 1, 1 }, // RGBA8 - { 64, 1, 1, 8, 1, 1 }, // RGBA16 - { 64, 1, 1, 8, 1, 1 }, // RGBA16F - { 128, 1, 1, 16, 1, 1 }, // RGBA32 - { 128, 1, 1, 16, 1, 1 }, // RGBA32F - { 16, 1, 1, 2, 1, 1 }, // R5G6B5 - { 16, 1, 1, 2, 1, 1 }, // RGBA4 - { 16, 1, 1, 2, 1, 1 }, // RGB5A1 - { 32, 1, 1, 4, 1, 1 }, // RGB10A2 - { 32, 1, 1, 4, 1, 1 }, // R11G11B10F - { 0, 0, 0, 0, 1, 1 }, // UnknownDepth - { 16, 1, 1, 2, 1, 1 }, // D16 - { 24, 1, 1, 3, 1, 1 }, // D24 - { 32, 1, 1, 4, 1, 1 }, // D24S8 - { 32, 1, 1, 4, 1, 1 }, // D32 - { 16, 1, 1, 2, 1, 1 }, // D16F - { 24, 1, 1, 3, 1, 1 }, // D24F - { 32, 1, 1, 4, 1, 1 }, // D32F - { 8, 1, 1, 1, 1, 1 }, // D0S8 + { 4, 4, 4, 8, 1, 1, 0, 0 }, // BC1 + { 8, 4, 4, 16, 1, 1, 0, 0 }, // BC2 + { 8, 4, 4, 16, 1, 1, 0, 0 }, // BC3 + { 4, 4, 4, 8, 1, 1, 0, 0 }, // BC4 + { 8, 4, 4, 16, 1, 1, 0, 0 }, // BC5 + { 8, 4, 4, 16, 1, 1, 0, 0 }, // BC6H + { 8, 4, 4, 16, 1, 1, 0, 0 }, // BC7 + { 4, 4, 4, 8, 1, 1, 0, 0 }, // ETC1 + { 4, 4, 4, 8, 1, 1, 0, 0 }, // ETC2 + { 8, 4, 4, 16, 1, 1, 0, 0 }, // ETC2A + { 4, 4, 4, 8, 1, 1, 0, 0 }, // ETC2A1 + { 2, 8, 4, 8, 2, 2, 0, 0 }, // PTC12 + { 4, 4, 4, 8, 2, 2, 0, 0 }, // PTC14 + { 2, 8, 4, 8, 2, 2, 0, 0 }, // PTC12A + { 4, 4, 4, 8, 2, 2, 0, 0 }, // PTC14A + { 2, 8, 4, 8, 2, 2, 0, 0 }, // PTC22 + { 4, 4, 4, 8, 2, 2, 0, 0 }, // PTC24 + { 0, 0, 0, 0, 1, 1, 0, 0 }, // Unknown + { 1, 8, 1, 1, 1, 1, 0, 0 }, // R1 + { 8, 1, 1, 1, 1, 1, 0, 0 }, // R8 + { 16, 1, 1, 2, 1, 1, 0, 0 }, // R16 + { 16, 1, 1, 2, 1, 1, 0, 0 }, // R16F + { 32, 1, 1, 4, 1, 1, 0, 0 }, // R32 + { 32, 1, 1, 4, 1, 1, 0, 0 }, // R32F + { 16, 1, 1, 2, 1, 1, 0, 0 }, // RG8 + { 32, 1, 1, 4, 1, 1, 0, 0 }, // RG16 + { 32, 1, 1, 4, 1, 1, 0, 0 }, // RG16F + { 64, 1, 1, 8, 1, 1, 0, 0 }, // RG32 + { 64, 1, 1, 8, 1, 1, 0, 0 }, // RG32F + { 32, 1, 1, 4, 1, 1, 0, 0 }, // BGRA8 + { 32, 1, 1, 4, 1, 1, 0, 0 }, // RGBA8 + { 64, 1, 1, 8, 1, 1, 0, 0 }, // RGBA16 + { 64, 1, 1, 8, 1, 1, 0, 0 }, // RGBA16F + { 128, 1, 1, 16, 1, 1, 0, 0 }, // RGBA32 + { 128, 1, 1, 16, 1, 1, 0, 0 }, // RGBA32F + { 16, 1, 1, 2, 1, 1, 0, 0 }, // R5G6B5 + { 16, 1, 1, 2, 1, 1, 0, 0 }, // RGBA4 + { 16, 1, 1, 2, 1, 1, 0, 0 }, // RGB5A1 + { 32, 1, 1, 4, 1, 1, 0, 0 }, // RGB10A2 + { 32, 1, 1, 4, 1, 1, 0, 0 }, // R11G11B10F + { 0, 0, 0, 0, 1, 1, 0, 0 }, // UnknownDepth + { 16, 1, 1, 2, 1, 1, 16, 0 }, // D16 + { 24, 1, 1, 3, 1, 1, 24, 0 }, // D24 + { 32, 1, 1, 4, 1, 1, 24, 8 }, // D24S8 + { 32, 1, 1, 4, 1, 1, 32, 0 }, // D32 + { 16, 1, 1, 2, 1, 1, 16, 0 }, // D16F + { 24, 1, 1, 3, 1, 1, 24, 0 }, // D24F + { 32, 1, 1, 4, 1, 1, 32, 0 }, // D32F + { 8, 1, 1, 1, 1, 1, 0, 8 }, // D0S8 }; BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_imageBlockInfo) ); diff --git a/src/image.h b/src/image.h index 3ddb1086f..ab1430c37 100644 --- a/src/image.h +++ b/src/image.h @@ -45,6 +45,8 @@ namespace bgfx uint8_t blockSize; uint8_t minBlockX; uint8_t minBlockY; + uint8_t depthBits; + uint8_t stencilBits; }; /// diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index c6cffc511..03503be7d 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -4072,9 +4072,22 @@ namespace bgfx } GLenum attachment = GL_COLOR_ATTACHMENT0 + colorIdx; - if (isDepth( (TextureFormat::Enum)texture.m_textureFormat) ) + TextureFormat::Enum format = (TextureFormat::Enum)texture.m_textureFormat; + if (isDepth(format) ) { - attachment = GL_DEPTH_ATTACHMENT; + const ImageBlockInfo& info = getBlockInfo(format); + if (0 < info.stencilBits) + { + attachment = GL_DEPTH_STENCIL_ATTACHMENT; + } + else if (0 == info.depthBits) + { + attachment = GL_STENCIL_ATTACHMENT; + } + else + { + attachment = GL_DEPTH_ATTACHMENT; + } } else {