[gtk/wip/chergert/glproto: 572/920] cache commonly used location at known offset




commit 51c58a25d3b6e446d67406e402166688841e6329
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 26 14:52:26 2020 -0800

    cache commonly used location at known offset

 gsk/next/gskglprogram.c | 38 +++++++++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 7 deletions(-)
---
diff --git a/gsk/next/gskglprogram.c b/gsk/next/gskglprogram.c
index 52b962ff8c..1f266cfdec 100644
--- a/gsk/next/gskglprogram.c
+++ b/gsk/next/gskglprogram.c
@@ -32,6 +32,9 @@ struct _GskGLProgram
   char                 *name;
   GArray               *uniform_locations;
   GskGLCommandQueue   *command_queue;
+  int                  projection_location;
+  int                  modelview_location;
+  int                  viewport_location;
 };
 
 G_DEFINE_TYPE (GskGLProgram, gsk_gl_program, G_TYPE_OBJECT)
@@ -83,6 +86,9 @@ 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;
 }
 
 /**
@@ -131,6 +137,13 @@ gsk_gl_program_add_uniform (GskGLProgram *self,
     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;
+
   return TRUE;
 }
 
@@ -337,24 +350,35 @@ gsk_gl_program_set_uniform_matrix (GskGLProgram            *self,
 }
 
 void
-gsk_gl_program_begin_draw (GskGLProgram          *self,
-                           const graphene_rect_t *viewport)
+gsk_gl_program_begin_draw (GskGLProgram            *self,
+                           const graphene_rect_t   *viewport,
+                           const graphene_matrix_t *projection,
+                           const graphene_matrix_t *modelview)
 {
-  int viewport_location;
-
   g_assert (GSK_IS_GL_PROGRAM (self));
   g_assert (viewport != NULL);
 
-  viewport_location = get_uniform_location (self, UNIFORM_SHARED_VIEWPORT);
-  if (viewport_location >= 0)
+  if (self->viewport_location > -1)
     gsk_gl_command_queue_set_uniform4f (self->command_queue,
                                         self->id,
-                                        viewport_location,
+                                        self->viewport_location,
                                         viewport->origin.x,
                                         viewport->origin.y,
                                         viewport->size.width,
                                         viewport->size.height);
 
+  if (self->modelview_location > -1)
+    gsk_gl_command_queue_set_uniform_matrix (self->command_queue,
+                                             self->id,
+                                             self->modelview_location,
+                                             modelview);
+
+  if (self->projection_location > -1)
+    gsk_gl_command_queue_set_uniform_matrix (self->command_queue,
+                                             self->id,
+                                             self->projection_location,
+                                             projection);
+
   gsk_gl_command_queue_begin_draw (self->command_queue, self->id, viewport);
 }
 


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