[gtk/wip/otte/glcontext: 3/7] ngl: Fix glTexImage2D() usage on GLES




commit 76420d71461c1aa4f65e6d7ae186be8a8647d81a
Author: Benjamin Otte <otte redhat com>
Date:   Fri Oct 8 03:29:45 2021 +0200

    ngl: Fix glTexImage2D() usage on GLES
    
    GLES is very adamant about the format and type matching the internal
    format, even if the data is NULL.

 gsk/ngl/gsknglcommandqueue.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/gsk/ngl/gsknglcommandqueue.c b/gsk/ngl/gsknglcommandqueue.c
index 8dde9ff269..f7db75016d 100644
--- a/gsk/ngl/gsknglcommandqueue.c
+++ b/gsk/ngl/gsknglcommandqueue.c
@@ -1299,10 +1299,26 @@ gsk_ngl_command_queue_create_texture (GskNglCommandQueue *self,
   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
-  if (gdk_gl_context_get_use_es (self->context))
-    glTexImage2D (GL_TEXTURE_2D, 0, format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-  else
-    glTexImage2D (GL_TEXTURE_2D, 0, format, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
+  switch (format)
+  {
+    case GL_RGBA8:
+      glTexImage2D (GL_TEXTURE_2D, 0, format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+      break;
+    case GL_RGBA16F:
+      glTexImage2D (GL_TEXTURE_2D, 0, format, width, height, 0, GL_BGRA, GL_HALF_FLOAT, NULL);
+      break;
+    case GL_RGBA32F:
+      glTexImage2D (GL_TEXTURE_2D, 0, format, width, height, 0, GL_BGRA, GL_FLOAT, NULL);
+      break;
+    default:
+      /* If you add new formats, make sure to set the correct format and type here
+       * so that GLES doesn't barf invalid operations at you.
+       * Because it is very important that these 3 values match when data is set to
+       * NULL, do you hear me?
+       */
+      g_assert_not_reached ();
+      break;
+  }
 
   /* Restore the previous texture if it was set */
   if (self->attachments->textures[0].id != 0)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]