Browse Source

glgsg: Fix framebuffer_copy_to_ram for OpenGL ES using BGRA format

Supporting BGRA doesn't necessarily mean that it supports using BGRA in glReadPixels, for OpenGL ES.  We need to check a separate extension.
rdb 5 years ago
parent
commit
f47b92347c

+ 8 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -1304,10 +1304,12 @@ reset() {
   // Note that these extensions only offer support for GL_BGRA, not GL_BGR.
   // Note that these extensions only offer support for GL_BGRA, not GL_BGR.
   _supports_bgr = has_extension("GL_EXT_texture_format_BGRA8888") ||
   _supports_bgr = has_extension("GL_EXT_texture_format_BGRA8888") ||
                   has_extension("GL_APPLE_texture_format_BGRA8888");
                   has_extension("GL_APPLE_texture_format_BGRA8888");
+  _supports_bgra_read = has_extension("GL_EXT_read_format_bgra");
 #else
 #else
   // In regular OpenGL, we have both GL_BGRA and GL_BGR.
   // In regular OpenGL, we have both GL_BGRA and GL_BGR.
   _supports_bgr =
   _supports_bgr =
     is_at_least_gl_version(1, 2) || has_extension("GL_EXT_bgra");
     is_at_least_gl_version(1, 2) || has_extension("GL_EXT_bgra");
+  _supports_bgra_read = _supports_bgr;
 #endif
 #endif
 
 
 #ifdef SUPPORT_FIXED_FUNCTION
 #ifdef SUPPORT_FIXED_FUNCTION
@@ -7418,6 +7420,12 @@ framebuffer_copy_to_ram(Texture *tex, int view, int z,
 
 
   GLenum external_format = get_external_image_format(tex);
   GLenum external_format = get_external_image_format(tex);
 
 
+  // OpenGL ES implementations may support BGRA, but that doesn't imply they
+  // also support it for glReadPixels specifically.
+  if (!_supports_bgra_read && external_format == GL_BGRA) {
+    external_format = GL_RGBA;
+  }
+
   if (GLCAT.is_spam()) {
   if (GLCAT.is_spam()) {
     GLCAT.spam()
     GLCAT.spam()
       << "glReadPixels(" << xo << ", " << yo << ", " << w << ", " << h << ", ";
       << "glReadPixels(" << xo << ", " << yo << ", " << w << ", " << h << ", ";

+ 1 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.h

@@ -815,6 +815,7 @@ public:
   PFNGLGETCOMPRESSEDTEXIMAGEPROC _glGetCompressedTexImage;
   PFNGLGETCOMPRESSEDTEXIMAGEPROC _glGetCompressedTexImage;
 
 
   bool _supports_bgr;
   bool _supports_bgr;
+  bool _supports_bgra_read;
   bool _supports_packed_dabc;
   bool _supports_packed_dabc;
   bool _supports_packed_ufloat;
   bool _supports_packed_ufloat;