GL: Detect write only framebuffers.

This commit is contained in:
Branimir Karadžić
2017-07-28 19:14:25 -07:00
parent 54c8d69590
commit b0efd3c44d
2 changed files with 31 additions and 2 deletions

View File

@@ -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

View File

@@ -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;