[gtk/wip/chergert/glproto] setup matrix uniform for modelview



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

    setup matrix uniform for modelview

 gsk/next/gskglprogramprivate.h      |  4 ++-
 gsk/next/gskglrenderjob.c           | 70 ++++++++++++++++++++-----------------
 gsk/next/gskgluniformstate.c        | 17 +++++----
 gsk/next/gskgluniformstateprivate.h |  1 +
 4 files changed, 52 insertions(+), 40 deletions(-)
---
diff --git a/gsk/next/gskglprogramprivate.h b/gsk/next/gskglprogramprivate.h
index c8218a16e3..70ffc96115 100644
--- a/gsk/next/gskglprogramprivate.h
+++ b/gsk/next/gskglprogramprivate.h
@@ -87,7 +87,9 @@ void             gsk_gl_program_set_uniform_rounded_rect (GskGLProgram
                                                           guint                    key,
                                                           const GskRoundedRect    *rounded_rect);
 void             gsk_gl_program_begin_draw               (GskGLProgram            *self,
-                                                          const graphene_rect_t   *viewport);
+                                                          const graphene_rect_t   *viewport,
+                                                          const graphene_matrix_t *projection,
+                                                          const graphene_matrix_t *modelview);
 void             gsk_gl_program_end_draw                 (GskGLProgram            *self);
 
 G_END_DECLS
diff --git a/gsk/next/gskglrenderjob.c b/gsk/next/gskglrenderjob.c
index b30fb5f2eb..05fb3e5478 100644
--- a/gsk/next/gskglrenderjob.c
+++ b/gsk/next/gskglrenderjob.c
@@ -66,6 +66,7 @@ typedef struct _GskGLRenderModelview
   float scale_y;
   float offset_x_before;
   float offset_y_before;
+  graphene_matrix_t matrix;
 } GskGLRenderModelview;
 
 static void
@@ -88,15 +89,21 @@ init_projection_matrix (graphene_matrix_t     *projection,
 static inline GskGLRenderModelview *
 gsk_gl_render_job_get_modelview (GskGLRenderJob *job)
 {
-  return &g_array_index (job->modelview,
-                         GskGLRenderModelview,
-                         job->modelview->len - 1);
+  if (job->modelview->len > 0)
+    return &g_array_index (job->modelview,
+                           GskGLRenderModelview,
+                           job->modelview->len - 1);
+  else
+    return NULL;
 }
 
 static void
 extract_matrix_metadata (GskGLRenderModelview *modelview)
 {
   float dummy;
+  graphene_matrix_t m;
+
+  gsk_transform_to_matrix (modelview->transform, &modelview->matrix);
 
   switch (gsk_transform_get_category (modelview->transform))
     {
@@ -119,9 +126,6 @@ extract_matrix_metadata (GskGLRenderModelview *modelview)
       {
         graphene_vec3_t col1;
         graphene_vec3_t col2;
-        graphene_matrix_t m;
-
-        gsk_transform_to_matrix (modelview->transform, &m);
 
         /* TODO: 90% sure this is incorrect. But we should never hit this code
          * path anyway. */
@@ -313,9 +317,10 @@ gsk_gl_render_job_transform_bounds (GskGLRenderJob        *job,
   r.size.width = rect->size.width;
   r.size.height = rect->size.width;
 
-  modelview = gsk_gl_render_job_get_modelview (job);
-
-  gsk_transform_transform_bounds (modelview->transform, &r, out_rect);
+  if ((modelview = gsk_gl_render_job_get_modelview (job)))
+    gsk_transform_transform_bounds (modelview->transform, &r, out_rect);
+  else
+    g_critical ("Attempt to transform with NULL modelview");
 }
 
 GskGLRenderJob *
@@ -486,7 +491,7 @@ static void
 gsk_gl_render_job_visit_node (GskGLRenderJob *job,
                               GskRenderNode  *node)
 {
-  GskGLProgram *program;
+  GskGLRenderModelview *modelview;
 
   g_assert (job != NULL);
   g_assert (node != NULL);
@@ -497,6 +502,8 @@ gsk_gl_render_job_visit_node (GskGLRenderJob *job,
       !gsk_gl_render_job_node_overlaps_clip (job, node))
     return;
 
+  modelview = gsk_gl_render_job_get_modelview (job);
+
   switch (gsk_render_node_get_node_type (node))
     {
     case GSK_CONTAINER_NODE:
@@ -529,40 +536,41 @@ gsk_gl_render_job_visit_node (GskGLRenderJob *job,
     break;
 
     case GSK_COLOR_NODE:
-      program = job->driver->color;
-
-      /* TODO: determine how we want to update mv/projection */
+      g_assert (modelview != NULL);
 
-      gsk_gl_program_begin_draw (program, &job->viewport);
-      gsk_gl_program_set_uniform_color (program,
+      gsk_gl_program_begin_draw (job->driver->color,
+                                 &job->viewport,
+                                 &job->projection,
+                                 &modelview->matrix);
+      gsk_gl_program_set_uniform_color (job->driver->color,
                                         UNIFORM_COLOR_COLOR,
                                         gsk_color_node_get_color (node));
       gsk_gl_render_job_draw_rect (job, &node->bounds);
-      gsk_gl_program_end_draw (program);
+      gsk_gl_program_end_draw (job->driver->color);
     break;
 
+    case GSK_BLEND_NODE:
+    case GSK_BLUR_NODE:
+    case GSK_BORDER_NODE:
     case GSK_CAIRO_NODE:
-    case GSK_LINEAR_GRADIENT_NODE:
-    case GSK_REPEATING_LINEAR_GRADIENT_NODE:
-    case GSK_RADIAL_GRADIENT_NODE:
-    case GSK_REPEATING_RADIAL_GRADIENT_NODE:
+    case GSK_CLIP_NODE:
+    case GSK_COLOR_MATRIX_NODE:
     case GSK_CONIC_GRADIENT_NODE:
-    case GSK_BORDER_NODE:
-    case GSK_TEXTURE_NODE:
+    case GSK_CROSS_FADE_NODE:
+    case GSK_GL_SHADER_NODE:
     case GSK_INSET_SHADOW_NODE:
-    case GSK_OUTSET_SHADOW_NODE:
-    case GSK_TRANSFORM_NODE:
+    case GSK_LINEAR_GRADIENT_NODE:
     case GSK_OPACITY_NODE:
-    case GSK_COLOR_MATRIX_NODE:
+    case GSK_OUTSET_SHADOW_NODE:
+    case GSK_RADIAL_GRADIENT_NODE:
+    case GSK_REPEATING_LINEAR_GRADIENT_NODE:
+    case GSK_REPEATING_RADIAL_GRADIENT_NODE:
     case GSK_REPEAT_NODE:
-    case GSK_CLIP_NODE:
     case GSK_ROUNDED_CLIP_NODE:
     case GSK_SHADOW_NODE:
-    case GSK_BLEND_NODE:
-    case GSK_CROSS_FADE_NODE:
+    case GSK_TEXTURE_NODE:
     case GSK_TEXT_NODE:
-    case GSK_BLUR_NODE:
-    case GSK_GL_SHADER_NODE:
+    case GSK_TRANSFORM_NODE:
     break;
 
     case GSK_NOT_A_RENDER_NODE:
@@ -570,8 +578,6 @@ gsk_gl_render_job_visit_node (GskGLRenderJob *job,
       g_assert_not_reached ();
     break;
     }
-
-
 }
 
 void
diff --git a/gsk/next/gskgluniformstate.c b/gsk/next/gskgluniformstate.c
index da16550065..ad980b517e 100644
--- a/gsk/next/gskgluniformstate.c
+++ b/gsk/next/gskgluniformstate.c
@@ -102,6 +102,8 @@ program_changed (GskGLUniformState *state,
   if (!info->changed)
     {
       info->changed = TRUE;
+      if (info->format == GSK_GL_UNIFORM_FORMAT_MATRIX)
+        info->flags |= GSK_GL_UNIFORM_FLAGS_MATRIX_SET;
       g_array_index (state->program_info, ProgramInfo, program).n_changed++;
     }
 }
@@ -486,15 +488,16 @@ gsk_gl_uniform_state_set_matrix (GskGLUniformState       *state,
 
   if ((u = get_uniform (state, program, GSK_GL_UNIFORM_FORMAT_MATRIX, 1, location, &info)))
     {
-      if (graphene_matrix_equal_fast (u, matrix))
-        return;
-
-      if (!graphene_matrix_equal (u, matrix))
+      if (info->flags & GSK_GL_UNIFORM_FLAGS_MATRIX_SET)
         {
-          REPLACE_UNIFORM (info, u, GSK_GL_UNIFORM_FORMAT_MATRIX, 1);
-          memcpy (u, matrix, sizeof *matrix);
-          program_changed (state, info, program);
+          if (graphene_matrix_equal_fast (u, matrix) ||
+              graphene_matrix_equal (u, matrix))
+            return;
         }
+
+      REPLACE_UNIFORM (info, u, GSK_GL_UNIFORM_FORMAT_MATRIX, 1);
+      memcpy (u, matrix, sizeof *matrix);
+      program_changed (state, info, program);
     }
 }
 
diff --git a/gsk/next/gskgluniformstateprivate.h b/gsk/next/gskgluniformstateprivate.h
index 2fea9dbd3e..74b5869d0c 100644
--- a/gsk/next/gskgluniformstateprivate.h
+++ b/gsk/next/gskgluniformstateprivate.h
@@ -59,6 +59,7 @@ typedef void (*GskGLUniformStateCallback) (const GskGLUniformInfo *info,
 typedef enum _GskGLUniformFlags
 {
   GSK_GL_UNIFORM_FLAGS_SEND_CORNERS = 1 << 0,
+  GSK_GL_UNIFORM_FLAGS_MATRIX_SET   = 1 << 1,
 } GskGLUniformFlags;
 
 typedef enum _GskGLUniformKind


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