From eee1426e376ffc49f847f664d2fd433e38385342 Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 8 Apr 2021 18:44:52 +0200 Subject: [PATCH 1/5] glgsg: Fix ability to get r11g11b10 float renderbuffer --- panda/src/glstuff/glGraphicsBuffer_src.cxx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/panda/src/glstuff/glGraphicsBuffer_src.cxx b/panda/src/glstuff/glGraphicsBuffer_src.cxx index 032c4ed2a3..e6d508ee9f 100644 --- a/panda/src/glstuff/glGraphicsBuffer_src.cxx +++ b/panda/src/glstuff/glGraphicsBuffer_src.cxx @@ -954,10 +954,17 @@ bind_slot(int layer, bool rb_resize, Texture **attach, RenderTexturePlane slot, } } else if (_fb_properties.get_float_color()) { // 16-bit floating-point. - if (_fb_properties.get_blue_bits() > 0 || + if (_fb_properties.get_blue_bits() > 10 || _fb_properties.get_color_bits() == 1 || - _fb_properties.get_color_bits() > 16 * 2) { + _fb_properties.get_color_bits() > 32) { gl_format = GL_RGB16F; + } else if (_fb_properties.get_blue_bits() > 0) { + if (_fb_properties.get_red_bits() > 11 || + _fb_properties.get_green_bits() > 11) { + gl_format = GL_RGB16F; + } else { + gl_format = GL_R11F_G11F_B10F; + } } else if (_fb_properties.get_green_bits() > 0 || _fb_properties.get_color_bits() > 16) { gl_format = GL_RG16F; From 31feeb9b9fb9bad726c9c81910035a7310890d0a Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 8 Apr 2021 18:45:29 +0200 Subject: [PATCH 2/5] glgsg: Fixes to format selection for copy-to-ram of framebuffer Fixes #1141 --- .../glstuff/glGraphicsStateGuardian_src.cxx | 59 ++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 1f6fed0ba0..fb38891a59 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -7210,21 +7210,66 @@ framebuffer_copy_to_ram(Texture *tex, int view, int z, } } else if (_current_properties->get_float_color()) { if (_current_properties->get_alpha_bits()) { - format = Texture::F_rgba32; + if (_current_properties->get_red_bits() == 16 && + _current_properties->get_green_bits() == 16 && + _current_properties->get_blue_bits() == 16 && + _current_properties->get_alpha_bits() == 16) { + format = Texture::F_rgba16; + } else { + format = Texture::F_rgba32; + } } else if (_current_properties->get_blue_bits()) { - format = Texture::F_rgb32; + if (_current_properties->get_red_bits() == 11 && + _current_properties->get_green_bits() == 11 && + _current_properties->get_blue_bits() == 10) { + format = Texture::F_r11_g11_b10; + } else if (_current_properties->get_red_bits() == 16 && + _current_properties->get_green_bits() == 16 && + _current_properties->get_blue_bits() == 16) { + format = Texture::F_rgb16; + } else { + format = Texture::F_rgb32; + } } else if (_current_properties->get_green_bits()) { - format = Texture::F_rg32; + if (_current_properties->get_red_bits() == 16 && + _current_properties->get_green_bits() == 16) { + format = Texture::F_rg16; + } else { + format = Texture::F_rg32; + } } else { - format = Texture::F_r32; + if (_current_properties->get_red_bits() == 16) { + format = Texture::F_r16; + } else { + format = Texture::F_r32; + } + } + } else if (_current_properties->get_alpha_bits()) { + if (_current_properties->get_red_bits() == 10 && + _current_properties->get_green_bits() == 10 && + _current_properties->get_blue_bits() == 10 && + _current_properties->get_alpha_bits() == 2) { + format = Texture::F_rgb10_a2; + } else { + format = Texture::F_rgba; + } + } else if (_current_properties->get_blue_bits()) { + format = Texture::F_rgb; + } else if (_current_properties->get_green_bits()) { + if (_current_properties->get_red_bits() == 16 && + _current_properties->get_green_bits() == 16) { + format = Texture::F_rg16; + } else { + format = Texture::F_rg; } } else { - if (_current_properties->get_alpha_bits()) { - format = Texture::F_rgba; + if (_current_properties->get_color_bits() == 16) { + format = Texture::F_r16; } else { - format = Texture::F_rgb; + format = Texture::F_red; } } + if (_current_properties->get_float_color()) { component_type = Texture::T_float; } else if (_current_properties->get_color_bits() <= 24 From 99a3188af20b4fa43ac508220149033302c66a91 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 9 Apr 2021 10:30:45 +0200 Subject: [PATCH 3/5] glgsg: Fix missing component types in glReadPixels spam message --- .../glstuff/glGraphicsStateGuardian_src.cxx | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index fb38891a59..4ea487626a 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -7316,6 +7316,7 @@ framebuffer_copy_to_ram(Texture *tex, int view, int z, GLenum external_format = get_external_image_format(tex); +#ifndef NDEBUG if (GLCAT.is_spam()) { GLCAT.spam() << "glReadPixels(" << xo << ", " << yo << ", " << w << ", " << h << ", "; @@ -7359,10 +7360,72 @@ framebuffer_copy_to_ram(Texture *tex, int view, int z, case GL_FLOAT: GLCAT.spam(false) << "GL_FLOAT"; break; + case GL_UNSIGNED_SHORT_4_4_4_4: + GLCAT.spam(false) << "GL_UNSIGNED_SHORT_4_4_4_4"; + break; + case GL_UNSIGNED_SHORT_5_5_5_1: + GLCAT.spam(false) << "GL_UNSIGNED_SHORT_5_5_5_1"; + break; + case GL_UNSIGNED_SHORT_5_6_5: + GLCAT.spam(false) << "GL_UNSIGNED_SHORT_5_6_5"; + break; #ifndef OPENGLES_1 case GL_INT: GLCAT.spam(false) << "GL_INT"; break; + case GL_BYTE: + GLCAT.spam(false) << "GL_BYTE"; + break; + case GL_SHORT: + GLCAT.spam(false) << "GL_SHORT"; + break; + case GL_UNSIGNED_INT: + GLCAT.spam(false) << "GL_UNSIGNED_INT"; + break; + case GL_HALF_FLOAT: + GLCAT.spam(false) << "GL_HALF_FLOAT"; + break; +#endif +#ifndef OPENGLES + case GL_UNSIGNED_BYTE_3_3_2: + GLCAT.spam(false) << "GL_UNSIGNED_BYTE_3_3_2"; + break; + case GL_UNSIGNED_BYTE_2_3_3_REV: + GLCAT.spam(false) << "GL_UNSIGNED_BYTE_2_3_3_REV"; + break; + case GL_UNSIGNED_SHORT_5_6_5_REV: + GLCAT.spam(false) << "GL_UNSIGNED_SHORT_5_6_5_REV"; + break; + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + GLCAT.spam(false) << "GL_UNSIGNED_SHORT_4_4_4_4_REV"; + break; + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + GLCAT.spam(false) << "GL_UNSIGNED_SHORT_1_5_5_5_REV"; + break; + case GL_UNSIGNED_INT_8_8_8_8: + GLCAT.spam(false) << "GL_UNSIGNED_INT_8_8_8_8"; + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + GLCAT.spam(false) << "GL_UNSIGNED_INT_8_8_8_8_REV"; + break; + case GL_UNSIGNED_INT_10_10_10_2: + GLCAT.spam(false) << "GL_UNSIGNED_INT_10_10_10_2"; + break; + case GL_UNSIGNED_INT_2_10_10_10_REV: + GLCAT.spam(false) << "GL_UNSIGNED_INT_2_10_10_10_REV"; + break; + case GL_UNSIGNED_INT_24_8: + GLCAT.spam(false) << "GL_UNSIGNED_INT_24_8"; + break; + case GL_UNSIGNED_INT_10F_11F_11F_REV: + GLCAT.spam(false) << "GL_UNSIGNED_INT_10F_11F_11F_REV"; + break; + case GL_UNSIGNED_INT_5_9_9_9_REV: + GLCAT.spam(false) << "GL_UNSIGNED_INT_5_9_9_9_REV"; + break; + case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: + GLCAT.spam(false) << "GL_FLOAT_32_UNSIGNED_INT_24_8_REV"; + break; #endif default: GLCAT.spam(false) << "unknown"; @@ -7371,6 +7434,7 @@ framebuffer_copy_to_ram(Texture *tex, int view, int z, GLCAT.spam(false) << ")" << endl; } +#endif // NDEBUG unsigned char *image_ptr = tex->modify_ram_image(); size_t image_size = tex->get_ram_image_size(); From 715d7868135bcd1eab97e4afe43b26968f1cd022 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 9 Apr 2021 10:45:22 +0200 Subject: [PATCH 4/5] display: Prevent attempt to copy depth from non-depth framebuffer Fixes case 1 of #1142 --- panda/src/display/graphicsOutput.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/panda/src/display/graphicsOutput.cxx b/panda/src/display/graphicsOutput.cxx index 529a053d00..1f97ade9e7 100644 --- a/panda/src/display/graphicsOutput.cxx +++ b/panda/src/display/graphicsOutput.cxx @@ -359,6 +359,12 @@ add_render_texture(Texture *tex, RenderTextureMode mode, // If we're still planning on binding, indicate it in texture properly. tex->set_render_to_texture(true); } + else if ((plane == RTP_depth || plane == RTP_depth_stencil) && _fb_properties.get_depth_bits() == 0) { + // If we're not providing the depth buffer, we need something to copy from. + display_cat.error() + << "add_render_texture: can't copy depth from framebuffer without depth bits!\n"; + return; + } CDWriter cdata(_cycler, true); RenderTexture result; From 69c6050fa88abf8a129657b8838be377cde8b13d Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 9 Apr 2021 10:45:47 +0200 Subject: [PATCH 5/5] glgsg: Only copy depth of 32-bit float depth-stencil framebuffer We don't support float-32-unsigned-int-24-8 component types in texture yet, so this is the only choice. Avoids a GL error when binding to RTP_depth_stencil slot. Fixes case 2 of #1142 --- panda/src/glstuff/glGraphicsStateGuardian_src.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 4ea487626a..e97755acc2 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -7174,7 +7174,10 @@ framebuffer_copy_to_ram(Texture *tex, int view, int z, switch (format) { case Texture::F_depth_stencil: if (_current_properties->get_float_depth()) { + //NB. In the future we may need a T_float_32_unsigned_int_24_8 format, but + // for now we'll just try to grab the depth component. component_type = Texture::T_float; + format = Texture::F_depth_component32; } else { component_type = Texture::T_unsigned_int_24_8; }