From f47b92347c6e73aa47537947c64863b377889017 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 19 May 2020 21:57:15 +0200 Subject: [PATCH] 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. --- panda/src/glstuff/glGraphicsStateGuardian_src.cxx | 8 ++++++++ panda/src/glstuff/glGraphicsStateGuardian_src.h | 1 + 2 files changed, 9 insertions(+) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 5ee98c62f7..33c69ad8ad 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -1304,10 +1304,12 @@ reset() { // Note that these extensions only offer support for GL_BGRA, not GL_BGR. _supports_bgr = has_extension("GL_EXT_texture_format_BGRA8888") || has_extension("GL_APPLE_texture_format_BGRA8888"); + _supports_bgra_read = has_extension("GL_EXT_read_format_bgra"); #else // In regular OpenGL, we have both GL_BGRA and GL_BGR. _supports_bgr = is_at_least_gl_version(1, 2) || has_extension("GL_EXT_bgra"); + _supports_bgra_read = _supports_bgr; #endif #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); + // 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()) { GLCAT.spam() << "glReadPixels(" << xo << ", " << yo << ", " << w << ", " << h << ", "; diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index 4efb8f9998..58c50176a3 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -815,6 +815,7 @@ public: PFNGLGETCOMPRESSEDTEXIMAGEPROC _glGetCompressedTexImage; bool _supports_bgr; + bool _supports_bgra_read; bool _supports_packed_dabc; bool _supports_packed_ufloat;