[gtk/f16c.msvc: 37/61] ngl: Reserve a pixel in texture atlases




commit eb0836dfab983c1bc5a137b25530519b8ed0bc89
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Apr 8 22:28:40 2021 -0400

    ngl: Reserve a pixel in texture atlases
    
    This will be used for coloring from the texture.

 gsk/ngl/gskngltexturelibrary.c | 48 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
---
diff --git a/gsk/ngl/gskngltexturelibrary.c b/gsk/ngl/gskngltexturelibrary.c
index 85449b3fa2..2de6e492c5 100644
--- a/gsk/ngl/gskngltexturelibrary.c
+++ b/gsk/ngl/gskngltexturelibrary.c
@@ -20,6 +20,7 @@
 
 #include "config.h"
 
+#include <gdk/gdkglcontextprivate.h>
 #include <gsk/gskdebugprivate.h>
 
 #include "gsknglcommandqueueprivate.h"
@@ -239,6 +240,51 @@ gsk_ngl_texture_atlas_pack (GskNglTextureAtlas *self,
   return rect.was_packed;
 }
 
+static void
+gsk_ngl_texture_atlas_initialize (GskNglDriver       *driver,
+                                  GskNglTextureAtlas *atlas)
+{
+  /* Insert a single pixel at 0,0 for use in coloring */
+
+  gboolean packed;
+  int x, y;
+  guint gl_format;
+  guint gl_type;
+  guint8 pixel_data[4 * 3 * 3];
+
+  gdk_gl_context_push_debug_group_printf (gdk_gl_context_get_current (),
+                                          "Initializing Atlas");
+
+  packed = gsk_ngl_texture_atlas_pack (atlas, 3, 3, &x, &y);
+  g_assert (packed);
+  g_assert (x == 0 && y == 0);
+
+  memset (pixel_data, 255, sizeof pixel_data);
+
+  if (gdk_gl_context_get_use_es (gdk_gl_context_get_current ()))
+    {
+      gl_format = GL_RGBA;
+      gl_type = GL_UNSIGNED_BYTE;
+    }
+  else
+    {
+      gl_format = GL_BGRA;
+      gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+    }
+
+  glBindTexture (GL_TEXTURE_2D, atlas->texture_id);
+
+  glTexSubImage2D (GL_TEXTURE_2D, 0,
+                   0, 0,
+                   3, 3,
+                   gl_format, gl_type,
+                   pixel_data);
+
+  gdk_gl_context_pop_debug_group (gdk_gl_context_get_current ());
+
+  driver->command_queue->n_uploads++;
+}
+
 static void
 gsk_ngl_texture_atlases_pack (GskNglDriver        *driver,
                               int                  width,
@@ -265,6 +311,8 @@ gsk_ngl_texture_atlases_pack (GskNglDriver        *driver,
       /* No atlas has enough space, so create a new one... */
       atlas = gsk_ngl_driver_create_atlas (driver);
 
+      gsk_ngl_texture_atlas_initialize (driver, atlas);
+
       /* Pack it onto that one, which surely has enough space... */
       if (!gsk_ngl_texture_atlas_pack (atlas, width, height, &x, &y))
         g_assert_not_reached ();


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