[gtk/wip/chergert/glproto: 421/493] give compile time access to location offset storage




commit d51fa475e45ce726235fafecdcd9e92ebf080f3f
Author: Christian Hergert <chergert redhat com>
Date:   Mon Feb 8 17:26:25 2021 -0800

    give compile time access to location offset storage
    
    while we cant know the offset post GL linkage, we can at least let ourselves know
    a fixed offset from the base pointer where we store that location.

 gsk/next/gskglprogram.c        | 58 ++++++++++++++----------------------------
 gsk/next/gskglprogramprivate.h | 14 ++++------
 2 files changed, 24 insertions(+), 48 deletions(-)
---
diff --git a/gsk/next/gskglprogram.c b/gsk/next/gskglprogram.c
index acdb4d891c..2a4339693b 100644
--- a/gsk/next/gskglprogram.c
+++ b/gsk/next/gskglprogram.c
@@ -55,7 +55,6 @@ gsk_gl_program_finalize (GObject *object)
                self->name ? self->name : "");
 
   g_clear_pointer (&self->name, g_free);
-  g_clear_pointer (&self->uniform_locations, g_array_unref);
   g_clear_object (&self->driver);
 
   G_OBJECT_CLASS (gsk_gl_program_parent_class)->finalize (object);
@@ -73,12 +72,9 @@ static void
 gsk_gl_program_init (GskGLProgram *self)
 {
   self->id = -1;
-  self->uniform_locations = g_array_new (FALSE, TRUE, sizeof (GLint));
-  self->viewport_location = -1;
-  self->projection_location = -1;
-  self->modelview_location = -1;
-  self->clip_rect_location = -1;
-  self->alpha_location = -1;
+
+  for (guint i = 0; i < G_N_ELEMENTS (self->uniform_locations); i++)
+    self->uniform_locations[i] = -1;
 }
 
 /**
@@ -113,7 +109,6 @@ gsk_gl_program_add_uniform (GskGLProgram *self,
                             const char   *name,
                             guint         key)
 {
-  const GLint invalid = -1;
   GLint location;
 
   g_return_val_if_fail (GSK_IS_GL_PROGRAM (self), FALSE);
@@ -123,20 +118,7 @@ gsk_gl_program_add_uniform (GskGLProgram *self,
   if (-1 == (location = glGetUniformLocation (self->id, name)))
     return FALSE;
 
-  while (key >= self->uniform_locations->len)
-    g_array_append_val (self->uniform_locations, invalid);
-  g_array_index (self->uniform_locations, GLint, key) = location;
-
-  if (key == UNIFORM_SHARED_MODELVIEW)
-    self->modelview_location = location;
-  else if (key == UNIFORM_SHARED_PROJECTION)
-    self->projection_location = location;
-  else if (key == UNIFORM_SHARED_VIEWPORT)
-    self->viewport_location = location;
-  else if (key == UNIFORM_SHARED_CLIP_RECT)
-    self->clip_rect_location = location;
-  else if (key == UNIFORM_SHARED_ALPHA)
-    self->alpha_location = location;
+  self->uniform_locations[key] = location;
 
 #if 0
   g_print ("program [%d] %s uniform %s at location %d.\n",
@@ -181,47 +163,45 @@ gsk_gl_program_begin_draw (GskGLProgram            *self,
 
   gsk_gl_command_queue_begin_draw (self->driver->command_queue, self->id, viewport);
 
-  if (self->viewport_location > -1)
-    gsk_gl_command_queue_set_uniform4f (self->driver->command_queue,
-                                        self->id,
-                                        self->viewport_location,
-                                        viewport->origin.x,
-                                        viewport->origin.y,
-                                        viewport->size.width,
-                                        viewport->size.height);
+  if (self->uniform_locations[UNIFORM_SHARED_VIEWPORT] > -1)
+    gsk_gl_command_queue_set_uniform4fv (self->driver->command_queue,
+                                         self->id,
+                                         self->uniform_locations[UNIFORM_SHARED_VIEWPORT],
+                                         1,
+                                         (const float *)viewport);
 
-  if (self->modelview_location > -1)
+  if (self->uniform_locations[UNIFORM_SHARED_MODELVIEW] > -1)
     gsk_gl_command_queue_set_uniform_matrix (self->driver->command_queue,
                                              self->id,
-                                             self->modelview_location,
+                                             self->uniform_locations[UNIFORM_SHARED_MODELVIEW],
                                              modelview);
 
-  if (self->projection_location > -1)
+  if (self->uniform_locations[UNIFORM_SHARED_PROJECTION] > -1)
     gsk_gl_command_queue_set_uniform_matrix (self->driver->command_queue,
                                              self->id,
-                                             self->projection_location,
+                                             self->uniform_locations[UNIFORM_SHARED_PROJECTION],
                                              projection);
 
-  if (self->clip_rect_location > -1)
+  if (self->uniform_locations[UNIFORM_SHARED_CLIP_RECT] > -1)
     {
       if (clip != NULL)
         gsk_gl_command_queue_set_uniform_rounded_rect (self->driver->command_queue,
                                                        self->id,
-                                                       self->clip_rect_location,
+                                                       self->uniform_locations[UNIFORM_SHARED_CLIP_RECT],
                                                        clip);
       else
         gsk_gl_command_queue_set_uniform_rounded_rect (self->driver->command_queue,
                                                        self->id,
-                                                       self->clip_rect_location,
+                                                       self->uniform_locations[UNIFORM_SHARED_CLIP_RECT],
                                                        &GSK_ROUNDED_RECT_INIT (0,
                                                                                0,
                                                                                viewport->size.width,
                                                                                viewport->size.height));
     }
 
-  if (self->alpha_location > -1)
+  if (self->uniform_locations[UNIFORM_SHARED_ALPHA] > -1)
     gsk_gl_command_queue_set_uniform1f (self->driver->command_queue,
                                         self->id,
-                                        self->alpha_location,
+                                        self->uniform_locations[UNIFORM_SHARED_ALPHA],
                                         alpha);
 }
diff --git a/gsk/next/gskglprogramprivate.h b/gsk/next/gskglprogramprivate.h
index 7e25d7473a..b7ef6ec5f6 100644
--- a/gsk/next/gskglprogramprivate.h
+++ b/gsk/next/gskglprogramprivate.h
@@ -38,16 +38,8 @@ struct _GskGLProgram
 
   int id;
   char *name;
-  GArray *uniform_locations;
   GskNextDriver *driver;
 
-  /* Cached shared locations */
-  int projection_location;
-  int modelview_location;
-  int viewport_location;
-  int clip_rect_location;
-  int alpha_location;
-
   /* For custom programs */
   int texture_locations[4];
   int args_locations[8];
@@ -55,6 +47,9 @@ struct _GskGLProgram
 
   /* Used to avoid comparing shared state */
   guint last_shared_state;
+
+  /* Static array for uniform locations (only support up to 32) */
+  int uniform_locations[32];
 };
 
 GskGLProgram *gsk_gl_program_new         (GskNextDriver           *driver,
@@ -87,7 +82,8 @@ static inline int
 gsk_gl_program_get_uniform_location (GskGLProgram *self,
                                      guint         key)
 {
-  return g_array_index (self->uniform_locations, GLint, key);
+  g_assert (key < 32);
+  return self->uniform_locations[key];
 }
 
 static inline void


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