Ver código fonte

GL: Detect write only framebuffers.

Branimir Karadžić 8 anos atrás
pai
commit
b0efd3c44d
2 arquivos alterados com 31 adições e 2 exclusões
  1. 2 1
      src/bgfx.cpp
  2. 29 1
      src/renderer_gl.cpp

+ 2 - 1
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

+ 29 - 1
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;