Browse Source

glgsg: Support floating-point FBOs in OpenGL ES 2+

See issue #1296
rdb 3 years ago
parent
commit
d2fc682fd7

+ 53 - 0
panda/src/glstuff/glGraphicsBuffer_src.cxx

@@ -861,6 +861,50 @@ bind_slot(int layer, bool rb_resize, Texture **attach, RenderTexturePlane slot,
     // case RTP_stencil: gl_format = GL_STENCIL_INDEX8; break
     default:
       if (_fb_properties.get_alpha_bits() == 0) {
+#ifndef OPENGLES_1
+        if (_fb_properties.get_float_color() &&
+            glgsg->has_extension("GL_EXT_color_buffer_float")) {
+          // This extension supports the full range of floating-point formats.
+          if (_fb_properties.get_color_bits() > 16 * 3 ||
+              _fb_properties.get_red_bits() > 16 ||
+              _fb_properties.get_green_bits() > 16 ||
+              _fb_properties.get_blue_bits() > 16) {
+            // 32-bit, which is always floating-point.
+            if (_fb_properties.get_blue_bits() > 0 ||
+                _fb_properties.get_color_bits() == 1 ||
+                _fb_properties.get_color_bits() > 32 * 2) {
+              gl_format = GL_RGB32F;
+            } else if (_fb_properties.get_green_bits() > 0 ||
+                       _fb_properties.get_color_bits() > 32) {
+              gl_format = GL_RG32F;
+            } else {
+              gl_format = GL_R32F;
+            }
+          } else {
+            // 16-bit floating-point.
+            if (_fb_properties.get_blue_bits() > 10 ||
+                _fb_properties.get_color_bits() == 1 ||
+                _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;
+            } else {
+              gl_format = GL_R16F;
+            }
+          }
+        } else if (_fb_properties.get_float_color() &&
+                   glgsg->has_extension("GL_EXT_color_buffer_half_float")) {
+          gl_format = GL_RGB16F_EXT;
+        } else
+#endif
         if (_fb_properties.get_color_bits() <= 16) {
           gl_format = GL_RGB565_OES;
         } else if (_fb_properties.get_color_bits() <= 24) {
@@ -868,6 +912,15 @@ bind_slot(int layer, bool rb_resize, Texture **attach, RenderTexturePlane slot,
         } else {
           gl_format = GL_RGB10_EXT;
         }
+#ifndef OPENGLES_1
+      } else if (_fb_properties.get_float_color() &&
+                 _fb_properties.get_color_bits() > 16 * 3 &&
+                 glgsg->has_extension("GL_EXT_color_buffer_float")) {
+        gl_format = GL_RGBA32F_EXT;
+      } else if (_fb_properties.get_float_color() &&
+                 glgsg->has_extension("GL_EXT_color_buffer_half_float")) {
+        gl_format = GL_RGBA16F_EXT;
+#endif
       } else if (_fb_properties.get_color_bits() == 0) {
         gl_format = GL_ALPHA8_EXT;
       } else if (_fb_properties.get_color_bits() <= 12

+ 7 - 1
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -10322,9 +10322,15 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
     } else {
       return GL_RGBA16_SNORM;
     }
+#elif !defined(OPENGLES_1)
+  case Texture::F_rgba16:
+    return GL_RGBA16F;
+#endif  // OPENGLES
+
+#ifndef OPENGLES_1
   case Texture::F_rgba32:
     return GL_RGBA32F;
-#endif  // OPENGLES
+#endif
 
   case Texture::F_rgb:
     switch (component_type) {