From b0efd3c44d87ceda01d3908c48ce18022b664517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 28 Jul 2017 19:14:25 -0700 Subject: [PATCH] GL: Detect write only framebuffers. --- src/bgfx.cpp | 3 ++- src/renderer_gl.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/bgfx.cpp b/src/bgfx.cpp index da370480e..834bbbb71 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -3153,7 +3153,8 @@ error: srgbCaps = BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB; } - if (0 != (_flags & BGFX_TEXTURE_RT_MASK) ) + if (formatSupported + && 0 != (_flags & BGFX_TEXTURE_RT_MASK) ) { formatSupported = 0 != (g_caps.formats[_format] & (0 | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 1aedaa446..f1199e799 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1546,7 +1546,12 @@ namespace bgfx { namespace gl return 0 == err; } - static bool isFramebufferFormatValid(TextureFormat::Enum _format, bool _srgb = false, GLsizei _dim = 16) + static bool isFramebufferFormatValid( + TextureFormat::Enum _format + , bool _srgb = false + , bool _writeOnly = false + , GLsizei _dim = 16 + ) { const TextureFormatInfo& tfi = s_textureFormat[_format]; GLenum internalFmt = _srgb @@ -1559,6 +1564,24 @@ namespace bgfx { namespace gl return false; } + if (_writeOnly) + { + GLuint rbo; + glGenRenderbuffers(1, &rbo); + glBindRenderbuffer(GL_RENDERBUFFER, rbo); + + glRenderbufferStorage(GL_RENDERBUFFER + , s_rboFormat[_format] + , _dim + , _dim + ); + glBindRenderbuffer(GL_RENDERBUFFER, 0); + glDeleteRenderbuffers(1, &rbo); + + GLenum err = glGetError(); + return 0 == err; + } + GLuint fbo; GL_CHECK(glGenFramebuffers(1, &fbo) ); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, fbo) ); @@ -2166,6 +2189,11 @@ namespace bgfx { namespace gl : BGFX_CAPS_FORMAT_TEXTURE_NONE ; + supported |= isFramebufferFormatValid(TextureFormat::Enum(ii), false, true) + ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + if (NULL != glGetInternalformativ) { GLint maxSamples;