[gtk+/wip/baedert/gl: 46/94] gl renderer: Keep track of current program color value



commit f94ac1ceaa44e19046b51ee679ac4f0857d0f1be
Author: Timm Bäder <mail baedert org>
Date:   Fri Nov 24 13:18:45 2017 +0100

    gl renderer: Keep track of current program color value

 gsk/gl/gskglrenderer.c         |   13 ++-----------
 gsk/gl/gskglrenderops.c        |   18 ++++++++++++++++++
 gsk/gl/gskglrenderopsprivate.h |    6 ++++++
 3 files changed, 26 insertions(+), 11 deletions(-)
---
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index b0673bf..7e4a048 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -646,12 +646,8 @@ gsk_gl_renderer_add_render_ops (GskGLRenderer   *self,
 
     case GSK_COLOR_NODE:
       {
-        RenderOp op;
-
         ops_set_program (builder, &self->color_program);
-        op.op = OP_CHANGE_COLOR;
-        op.color = *gsk_color_node_peek_color (node);
-        ops_add (builder, &op);
+        ops_set_color (builder, gsk_color_node_peek_color (node));
         ops_draw (builder, vertex_data);
       }
     break;
@@ -851,13 +847,8 @@ gsk_gl_renderer_add_render_ops (GskGLRenderer   *self,
           }
         else
           {
-            RenderOp op;
-
             ops_set_program (builder, &self->coloring_program);
-
-            op.op = OP_CHANGE_COLOR;
-            op.color = *gsk_text_node_peek_color (node);
-            ops_add (builder, &op);
+            ops_set_color (builder, gsk_text_node_peek_color (node));
           }
 
         /* We use one quad per character, unlike the other nodes which
diff --git a/gsk/gl/gskglrenderops.c b/gsk/gl/gskglrenderops.c
index 93e7ad2..2b60653 100644
--- a/gsk/gl/gskglrenderops.c
+++ b/gsk/gl/gskglrenderops.c
@@ -211,6 +211,24 @@ ops_set_opacity (RenderOpBuilder *builder,
 }
 
 void
+ops_set_color (RenderOpBuilder *builder,
+               const GdkRGBA   *color)
+{
+  RenderOp op;
+
+  g_assert (builder->current_program->color_location != 0);
+
+  if (gdk_rgba_equal (color, &builder->program_state[builder->current_program->index].color))
+    return;
+
+  builder->program_state[builder->current_program->index].color = *color;
+
+  op.op = OP_CHANGE_COLOR;
+  op.color = *color;
+  g_array_append_val (builder->render_ops, op);
+}
+
+void
 ops_draw (RenderOpBuilder     *builder,
           const GskQuadVertex  vertex_data[GL_N_VERTICES])
 {
diff --git a/gsk/gl/gskglrenderopsprivate.h b/gsk/gl/gskglrenderopsprivate.h
index 85a19ec..c3958b9 100644
--- a/gsk/gl/gskglrenderopsprivate.h
+++ b/gsk/gl/gskglrenderopsprivate.h
@@ -116,6 +116,10 @@ typedef struct
     graphene_matrix_t projection;
     int source_texture;
     graphene_rect_t viewport;
+    /* Per-program state */
+    union {
+      GdkRGBA color;
+    };
   } program_state[GL_N_PROGRAMS];
 
   /* Current global state */
@@ -160,6 +164,8 @@ int               ops_set_render_target (RenderOpBuilder         *builder,
 
 float             ops_set_opacity        (RenderOpBuilder        *builder,
                                           float                   opacity);
+void              ops_set_color          (RenderOpBuilder        *builder,
+                                          const GdkRGBA          *color);
 
 void              ops_draw               (RenderOpBuilder        *builder,
                                           const GskQuadVertex     vertex_data[GL_N_VERTICES]);


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