[gtk+/wip/baedert/gl: 68/96] gl renderer: Rework program creation



commit d928af52e0c55c9fe10823034c502e94a2f848a7
Author: Timm Bäder <mail baedert org>
Date:   Thu Nov 30 18:47:55 2017 +0100

    gl renderer: Rework program creation
    
    Make sure all uniform names have to match between the shader names and
    the _location integers we save in every Program struct.

 gsk/gl/gskglrenderer.c                     |  272 +++++++++++-----------------
 gsk/gl/gskglrenderops.c                    |    2 -
 gsk/gl/gskglrenderopsprivate.h             |   39 ++--
 gsk/resources/glsl/blend.fs.glsl           |    6 +-
 gsk/resources/glsl/blend.vs.glsl           |    2 +-
 gsk/resources/glsl/blit.fs.glsl            |    4 +-
 gsk/resources/glsl/blit.vs.glsl            |    2 +-
 gsk/resources/glsl/blur.fs.glsl            |   14 +-
 gsk/resources/glsl/color.fs.glsl           |    6 +-
 gsk/resources/glsl/color_matrix.fs.glsl    |   10 +-
 gsk/resources/glsl/coloring.fs.glsl        |    8 +-
 gsk/resources/glsl/gl3_common.fs.glsl      |   26 ++--
 gsk/resources/glsl/gl3_common.vs.glsl      |    4 +-
 gsk/resources/glsl/inset_shadow.fs.glsl    |   33 ++--
 gsk/resources/glsl/linear_gradient.fs.glsl |   30 ++--
 15 files changed, 192 insertions(+), 266 deletions(-)
---
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index 4a2211e..948e4eb 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -36,12 +36,20 @@
 #define OP_PRINT(format, ...)
 #endif
 
-#define INIT_PROGRAM_UNIFORM_LOCATION(program_name, location_name, uniform_name) \
+#define INIT_PROGRAM_UNIFORM_LOCATION2(program_name, uniform_basename) \
               G_STMT_START{\
-                self->program_name.location_name = glGetUniformLocation(self->program_name.id, 
uniform_name);\
-                g_assert (self->program_name.location_name != 0); \
+                self->program_name ## _program.program_name.uniform_basename ## _location = \
+                              glGetUniformLocation(self->program_name ## _program.id, "u_" 
#uniform_basename);\
+                g_assert_cmpint (self->program_name ## _program.program_name.uniform_basename ## _location, 
, -1); \
               }G_STMT_END
 
+#define INIT_COMMON_UNIFORM_LOCATION(program_ptr, uniform_basename) \
+              G_STMT_START{\
+                program_ptr->uniform_basename ## _location =  \
+                              glGetUniformLocation(program_ptr->id, "u_" #uniform_basename);\
+              }G_STMT_END
+
+
 static void G_GNUC_UNUSED
 dump_framebuffer (const char *filename, int w, int h)
 {
@@ -244,33 +252,27 @@ gsk_gl_renderer_destroy_buffers (GskGLRenderer *self)
   self->has_buffers = FALSE;
 }
 
-static void
-init_common_locations (GskGLRenderer    *self,
-                       GskShaderBuilder *builder,
-                       Program          *prog)
-{
-  prog->source_location = glGetUniformLocation (prog->id, "uSource");
-  prog->mask_location = glGetUniformLocation (prog->id, "uMask");
-  prog->alpha_location = glGetUniformLocation (prog->id, "uAlpha");
-  prog->blend_mode_location = glGetUniformLocation (prog->id, "uBlendMode");
-  prog->viewport_location = glGetUniformLocation (prog->id, "uViewport");
-  prog->projection_location = glGetUniformLocation (prog->id, "uProjection");
-  prog->modelview_location = glGetUniformLocation (prog->id, "uModelview");
-  prog->clip_location = glGetUniformLocation (prog->id, "uClip");
-  prog->clip_corner_widths_location = glGetUniformLocation (prog->id, "uClipCornerWidths");
-  prog->clip_corner_heights_location = glGetUniformLocation (prog->id, "uClipCornerHeights");
-
-  prog->position_location = glGetAttribLocation (prog->id, "aPosition");
-  prog->uv_location = glGetAttribLocation (prog->id, "aUv");
-}
-
 static gboolean
 gsk_gl_renderer_create_programs (GskGLRenderer  *self,
                                  GError        **error)
 {
   GskShaderBuilder *builder;
   GError *shader_error = NULL;
-  gboolean res = FALSE;
+  int i;
+  static struct {
+    const char *name;
+    const char *vs;
+    const char *fs;
+  } program_definitions[] = {
+      { "blend",           "blend.vs.glsl", "blend.fs.glsl" },
+      { "blit",            "blit.vs.glsl",  "blit.fs.glsl" },
+      { "color",           "blit.vs.glsl",  "color.fs.glsl" },
+      { "coloring",        "blit.vs.glsl",  "coloring.fs.glsl" },
+      { "color matrix",    "blit.vs.glsl",  "color_matrix.fs.glsl" },
+      { "linear gradient", "blit.vs.glsl",  "linear_gradient.fs.glsl" },
+      { "blur",            "blit.vs.glsl",  "blur.fs.glsl" },
+      { "inset shadow",    "blit.vs.glsl",  "inset_shadow.fs.glsl" },
+  };
 
   builder = gsk_shader_builder_new ();
 
@@ -310,140 +312,70 @@ gsk_gl_renderer_create_programs (GskGLRenderer  *self,
     gsk_shader_builder_add_define (builder, "GSK_DEBUG", "1");
 #endif
 
-  self->blend_program.id =  gsk_shader_builder_create_program (builder,
-                                                               "blend.vs.glsl", "blend.fs.glsl",
-                                                               &shader_error);
-  if (shader_error != NULL)
-    {
-      g_propagate_prefixed_error (error,
-                                  shader_error,
-                                  "Unable to create 'blend' program: ");
-      goto out;
-    }
-  self->blend_program.index = 0;
-  self->blend_program.name = "blend";
-  init_common_locations (self, builder, &self->blend_program);
-
-  self->blit_program.id = gsk_shader_builder_create_program (builder,
-                                                             "blit.vs.glsl", "blit.fs.glsl",
-                                                             &shader_error);
-  if (shader_error != NULL)
-    {
-      g_propagate_prefixed_error (error,
-                                  shader_error,
-                                  "Unable to create 'blit' program: ");
-      goto out;
-    }
-  self->blit_program.index = 1;
-  self->blit_program.name = "blit";
-  init_common_locations (self, builder, &self->blit_program);
-
-  self->color_program.id = gsk_shader_builder_create_program (builder,
-                                                              "blit.vs.glsl", "color.fs.glsl",
-                                                              &shader_error);
-  if (shader_error != NULL)
-    {
-      g_propagate_prefixed_error (error,
-                                  shader_error,
-                                  "Unable to create 'color' program: ");
-      goto out;
-    }
-  self->color_program.index = 2;
-  self->color_program.name = "color";
-  init_common_locations (self, builder, &self->color_program);
-  INIT_PROGRAM_UNIFORM_LOCATION (color_program, color_location, "uColor");
-
-  self->coloring_program.id = gsk_shader_builder_create_program (builder,
-                                                                 "blit.vs.glsl", "coloring.fs.glsl",
-                                                                 &shader_error);
-  if (shader_error != NULL)
-    {
-      g_propagate_prefixed_error (error,
-                                  shader_error,
-                                  "Unable to create 'coloring' program: ");
-      goto out;
-    }
-  self->coloring_program.index = 3;
-  self->coloring_program.name = "coloring";
-  init_common_locations (self, builder, &self->coloring_program);
-  INIT_PROGRAM_UNIFORM_LOCATION (coloring_program, color_location, "uColor");
-
-  self->color_matrix_program.id = gsk_shader_builder_create_program (builder,
-                                                                     "blit.vs.glsl", "color_matrix.fs.glsl",
-                                                                     &shader_error);
-  if (shader_error != NULL)
-    {
-      g_propagate_prefixed_error (error,
-                                  shader_error,
-                                  "Unable to create 'color_matrix' program: ");
-      goto out;
-    }
-  self->color_matrix_program.index = 4;
-  self->color_matrix_program.name = "color matrix";
-  init_common_locations (self, builder, &self->color_matrix_program);
-  INIT_PROGRAM_UNIFORM_LOCATION (color_matrix_program, color_matrix_location, "uColorMatrix");
-  INIT_PROGRAM_UNIFORM_LOCATION (color_matrix_program, color_offset_location, "uColorOffset");
-
-  self->linear_gradient_program.id = gsk_shader_builder_create_program (builder,
-                                                                        "blit.vs.glsl", 
"linear_gradient.fs.glsl",
-                                                                        &shader_error);
-  if (shader_error != NULL)
-    {
-      g_propagate_prefixed_error (error,
-                                  shader_error,
-                                  "Unable to create 'linear_gradient' program: ");
-      goto out;
-    }
-  self->linear_gradient_program.index = 5;
-  self->linear_gradient_program.name = "linear gradient";
-  init_common_locations (self, builder, &self->linear_gradient_program);
-  INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient_program, color_stops_location, "uColorStops");
-  INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient_program, color_offsets_location, "uColorOffsets");
-  INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient_program, n_color_stops_location, "uNumColorStops");
-  INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient_program, start_point_location, "uStartPoint");
-  INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient_program, end_point_location, "uEndPoint");
-
-  self->blur_program.id = gsk_shader_builder_create_program (builder,
-                                                             "blur.vs.glsl", "blur.fs.glsl",
-                                                             &shader_error);
-  if (shader_error != NULL)
+  for (i = 0; i < GL_N_PROGRAMS; i ++)
     {
-      g_propagate_prefixed_error (error,
-                                  shader_error,
-                                  "Unable to create 'blur' program: ");
-      goto out;
-    }
-  self->blur_program.index = 6;
-  self->blur_program.name = "blur";
-  init_common_locations (self, builder, &self->blur_program);
-  INIT_PROGRAM_UNIFORM_LOCATION (blur_program, blur_radius_location, "uBlurRadius");
-  INIT_PROGRAM_UNIFORM_LOCATION (blur_program, blur_size_location, "uSize");
-
-  self->inset_shadow_program.id = gsk_shader_builder_create_program (builder,
-                                                                     "blit.vs.glsl", "inset_shadow.fs.glsl",
-                                                                     &shader_error);
-  if (shader_error != NULL)
-    {
-      g_propagate_prefixed_error (error,
-                                  shader_error,
-                                  "Unable to create 'inset shadow' program: ");
-      goto out;
+      Program *prog = &self->programs[i];
+
+      prog->index = i;
+      prog->id = gsk_shader_builder_create_program (builder,
+                                                    program_definitions[i].vs,
+                                                    program_definitions[i].fs,
+                                                    &shader_error);
+
+      if (shader_error != NULL)
+        {
+          g_propagate_prefixed_error (error, shader_error,
+                                      "Unable to create '%s' program (from %s and %s):\n",
+                                      program_definitions[i].name,
+                                      program_definitions[i].vs,
+                                      program_definitions[i].fs);
+
+          g_object_unref (builder);
+          return FALSE;
+        }
+
+      INIT_COMMON_UNIFORM_LOCATION (prog, alpha);
+      INIT_COMMON_UNIFORM_LOCATION (prog, source);
+      INIT_COMMON_UNIFORM_LOCATION (prog, mask);
+      INIT_COMMON_UNIFORM_LOCATION (prog, clip);
+      INIT_COMMON_UNIFORM_LOCATION (prog, clip_corner_widths);
+      INIT_COMMON_UNIFORM_LOCATION (prog, clip_corner_heights);
+      INIT_COMMON_UNIFORM_LOCATION (prog, viewport);
+      INIT_COMMON_UNIFORM_LOCATION (prog, projection);
+      INIT_COMMON_UNIFORM_LOCATION (prog, modelview);
     }
-  self->blur_program.index = 7;
-  self->blur_program.name = "inset shadow";
-  init_common_locations (self, builder, &self->inset_shadow_program);
-  INIT_PROGRAM_UNIFORM_LOCATION (inset_shadow_program, inset_shadow_color_location, "uColor");
-  INIT_PROGRAM_UNIFORM_LOCATION (inset_shadow_program, inset_shadow_spread_location, "uSpread");
-  INIT_PROGRAM_UNIFORM_LOCATION (inset_shadow_program, inset_shadow_outline_location, "uOutline");
-  INIT_PROGRAM_UNIFORM_LOCATION (inset_shadow_program, inset_shadow_outline_corner_widths_location, 
"uOutlineCornerWidths");
-  INIT_PROGRAM_UNIFORM_LOCATION (inset_shadow_program, inset_shadow_outline_corner_heights_location, 
"uOutlineCornerHeights");
 
-  res = TRUE;
+  /* color */
+  INIT_PROGRAM_UNIFORM_LOCATION2 (color, color);
+
+  /* coloring */
+  INIT_PROGRAM_UNIFORM_LOCATION2 (coloring, color);
 
-out:
+  /* color matrix */
+  INIT_PROGRAM_UNIFORM_LOCATION2 (color_matrix, color_matrix);
+  INIT_PROGRAM_UNIFORM_LOCATION2 (color_matrix, color_offset);
+
+  /* linear gradient */
+  INIT_PROGRAM_UNIFORM_LOCATION2 (linear_gradient, color_stops);
+  INIT_PROGRAM_UNIFORM_LOCATION2 (linear_gradient, color_offsets);
+  INIT_PROGRAM_UNIFORM_LOCATION2 (linear_gradient, num_color_stops);
+  INIT_PROGRAM_UNIFORM_LOCATION2 (linear_gradient, start_point);
+  INIT_PROGRAM_UNIFORM_LOCATION2 (linear_gradient, end_point);
+
+  /* blur */
+  INIT_PROGRAM_UNIFORM_LOCATION2 (blur, blur_radius);
+  INIT_PROGRAM_UNIFORM_LOCATION2 (blur, blur_size);
+
+  /* inset shadow */
+  INIT_PROGRAM_UNIFORM_LOCATION2 (inset_shadow, color);
+  INIT_PROGRAM_UNIFORM_LOCATION2 (inset_shadow, spread);
+  INIT_PROGRAM_UNIFORM_LOCATION2 (inset_shadow, offset);
+  INIT_PROGRAM_UNIFORM_LOCATION2 (inset_shadow, outline);
+  INIT_PROGRAM_UNIFORM_LOCATION2 (inset_shadow, corner_widths);
+  INIT_PROGRAM_UNIFORM_LOCATION2 (inset_shadow, corner_heights);
 
   g_object_unref (builder);
-  return res;
+  return TRUE;
 }
 
 static gboolean
@@ -1071,8 +1003,8 @@ gsk_gl_renderer_add_render_ops (GskGLRenderer   *self,
                                 op.inset_shadow.corner_heights);
         op.inset_shadow.radius = gsk_inset_shadow_node_get_blur_radius (node);
         op.inset_shadow.spread = gsk_inset_shadow_node_get_spread (node);
-        op.inset_shadow.d[0] = gsk_inset_shadow_node_get_dx (node);
-        op.inset_shadow.d[1] = -gsk_inset_shadow_node_get_dy (node);
+        op.inset_shadow.offset[0] = gsk_inset_shadow_node_get_dx (node);
+        op.inset_shadow.offset[1] = -gsk_inset_shadow_node_get_dy (node);
 
         ops_set_program (builder, &self->inset_shadow_program);
         ops_add (builder, &op);
@@ -1318,16 +1250,16 @@ gsk_gl_renderer_render_ops (GskGLRenderer *self,
           OP_PRINT (" -> Color Matrix");
           g_assert (program == &self->color_matrix_program);
           graphene_matrix_to_float (&op->color_matrix.matrix, mat);
-          glUniformMatrix4fv (program->color_matrix_location, 1, GL_FALSE, mat);
+          glUniformMatrix4fv (program->color_matrix.color_matrix_location, 1, GL_FALSE, mat);
 
           graphene_vec4_to_float (&op->color_matrix.offset, vec);
-          glUniform4fv (program->color_offset_location, 1, vec);
+          glUniform4fv (program->color_matrix.color_offset_location, 1, vec);
           break;
 
         case OP_CHANGE_COLOR:
           OP_PRINT (" -> Color: (%f, %f, %f, %f)", op->color.red, op->color.green, op->color.blue, 
op->color.alpha);
           g_assert (program == &self->color_program || program == &self->coloring_program);
-          glUniform4f (program->color_location,
+          glUniform4f (program->color.color_location,
                        op->color.red, op->color.green, op->color.blue, op->color.alpha);
           break;
 
@@ -1361,34 +1293,34 @@ gsk_gl_renderer_render_ops (GskGLRenderer *self,
 
         case OP_CHANGE_LINEAR_GRADIENT:
             OP_PRINT (" -> Linear gradient");
-            glUniform1i (program->n_color_stops_location,
+            glUniform1i (program->linear_gradient.num_color_stops_location,
                          op->linear_gradient.n_color_stops);
-            glUniform4fv (program->color_stops_location,
+            glUniform4fv (program->linear_gradient.color_stops_location,
                           op->linear_gradient.n_color_stops,
                           op->linear_gradient.color_stops);
-            glUniform1fv (program->color_offsets_location,
+            glUniform1fv (program->linear_gradient.color_offsets_location,
                           op->linear_gradient.n_color_stops,
                           op->linear_gradient.color_offsets);
-            glUniform2f (program->start_point_location,
+            glUniform2f (program->linear_gradient.start_point_location,
                          op->linear_gradient.start_point.x, op->linear_gradient.start_point.y);
-            glUniform2f (program->end_point_location,
+            glUniform2f (program->linear_gradient.end_point_location,
                          op->linear_gradient.end_point.x, op->linear_gradient.end_point.y);
           break;
 
        case OP_CHANGE_BLUR:
           g_assert (program == &self->blur_program);
-          glUniform1f (program->blur_radius_location, op->blur.radius);
-          glUniform2f (program->blur_size_location, op->blur.size.width, op->blur.size.height);
+          glUniform1f (program->blur.blur_radius_location, op->blur.radius);
+          glUniform2f (program->blur.blur_size_location, op->blur.size.width, op->blur.size.height);
           break;
 
        case OP_CHANGE_INSET_SHADOW:
           g_assert (program == &self->inset_shadow_program);
-          glUniform4fv (program->inset_shadow_color_location, 1, op->inset_shadow.color);
-          glUniform2fv (program->inset_shadow_d_location, 1, op->inset_shadow.d);
-          glUniform1f (program->inset_shadow_spread_location, op->inset_shadow.spread);
-          glUniform4fv (program->inset_shadow_outline_location, 1, op->inset_shadow.outline);
-          glUniform4fv (program->inset_shadow_outline_corner_widths_location, 1, 
op->inset_shadow.corner_widths);
-          glUniform4fv (program->inset_shadow_outline_corner_heights_location, 1, 
op->inset_shadow.corner_heights);
+          glUniform4fv (program->inset_shadow.color_location, 1, op->inset_shadow.color);
+          glUniform2fv (program->inset_shadow.offset_location, 1, op->inset_shadow.offset);
+          glUniform1f (program->inset_shadow.spread_location, op->inset_shadow.spread);
+          glUniform4fv (program->inset_shadow.outline_location, 1, op->inset_shadow.outline);
+          glUniform4fv (program->inset_shadow.corner_widths_location, 1, op->inset_shadow.corner_widths);
+          glUniform4fv (program->inset_shadow.corner_heights_location, 1, op->inset_shadow.corner_heights);
           break;
 
         case OP_DRAW:
diff --git a/gsk/gl/gskglrenderops.c b/gsk/gl/gskglrenderops.c
index ed43240..a3e0d2f 100644
--- a/gsk/gl/gskglrenderops.c
+++ b/gsk/gl/gskglrenderops.c
@@ -216,8 +216,6 @@ ops_set_color (RenderOpBuilder *builder,
 {
   RenderOp op;
 
-  g_assert (builder->current_program->color_location != 0);
-
   if (gdk_rgba_equal (color, &builder->program_state[builder->current_program->index].color))
     return;
 
diff --git a/gsk/gl/gskglrenderopsprivate.h b/gsk/gl/gskglrenderopsprivate.h
index 56332ab..6ee4612 100644
--- a/gsk/gl/gskglrenderopsprivate.h
+++ b/gsk/gl/gskglrenderopsprivate.h
@@ -35,14 +35,13 @@ enum {
 typedef struct
 {
   int index;        /* Into the renderer's program array */
-  const char *name; /* For debugging */
 
   int id;
   /* Common locations (gl_common)*/
   int source_location;
   int mask_location;
-  int uv_location;
   int position_location;
+  int uv_location;
   int alpha_location;
   int blend_mode_location;
   int viewport_location;
@@ -52,40 +51,38 @@ typedef struct
   int clip_corner_widths_location;
   int clip_corner_heights_location;
 
-  /* Program-specific locations */
   union {
     struct {
       int color_location;
-    };
+    } color;
+    struct {
+      int color_location;
+    } coloring;
     struct {
       int color_matrix_location;
       int color_offset_location;
-    };
+    } color_matrix;
     struct {
-      int n_color_stops_location;
+      int num_color_stops_location;
       int color_stops_location;
       int color_offsets_location;
       int start_point_location;
       int end_point_location;
-    };
-    struct {
-      int clip_bounds_location;
-      int corner_widths_location;
-      int corner_heights_location;
-    };
+    } linear_gradient;
     struct {
       int blur_radius_location;
       int blur_size_location;
-    };
+    } blur;
     struct {
-      int inset_shadow_color_location;
-      int inset_shadow_spread_location;
-      int inset_shadow_d_location;
-      int inset_shadow_outline_location;
-      int inset_shadow_outline_corner_widths_location;
-      int inset_shadow_outline_corner_heights_location;
-    };
+      int color_location;
+      int spread_location;
+      int offset_location;
+      int outline_location;
+      int corner_widths_location;
+      int corner_heights_location;
+    } inset_shadow;
   };
+
 } Program;
 
 typedef struct
@@ -128,7 +125,7 @@ typedef struct
       float corner_heights[4];
       float radius;
       float spread;
-      float d[2];
+      float offset[2];
       float color[4];
     } inset_shadow;
   };
diff --git a/gsk/resources/glsl/blend.fs.glsl b/gsk/resources/glsl/blend.fs.glsl
index 1473d05..d179e44 100644
--- a/gsk/resources/glsl/blend.fs.glsl
+++ b/gsk/resources/glsl/blend.fs.glsl
@@ -28,8 +28,8 @@ vec3 BlendLighten(vec3 Cb, vec3 Cs) {
 }
 
 void main() {
-  vec4 Cs = Texture(uSource, vUv);
-  vec4 Cb = Texture(uMask, vUv);
+  vec4 Cs = Texture(u_source, vUv);
+  vec4 Cb = Texture(u_mask, vUv);
   vec3 res;
 
   if (uBlendMode == 0) {
@@ -57,5 +57,5 @@ void main() {
     // Use red for debugging missing blend modes
     res = vec3(1.0, 0.0, 0.0);
   }
-  setOutputColor(vec4(res, Cs.a) * uAlpha);
+  setOutputColor(vec4(res, Cs.a) * u_alpha);
 }
diff --git a/gsk/resources/glsl/blend.vs.glsl b/gsk/resources/glsl/blend.vs.glsl
index da1d541..24d8da3 100644
--- a/gsk/resources/glsl/blend.vs.glsl
+++ b/gsk/resources/glsl/blend.vs.glsl
@@ -1,5 +1,5 @@
 void main() {
-  gl_Position = uModelview * uProjection * vec4(aPosition, 0.0, 1.0);
+  gl_Position = u_modelview * u_projection * vec4(aPosition, 0.0, 1.0);
 
   vUv = vec2(aUv.x, aUv.y);
 }
diff --git a/gsk/resources/glsl/blit.fs.glsl b/gsk/resources/glsl/blit.fs.glsl
index 9f2eb4c..594739d 100644
--- a/gsk/resources/glsl/blit.fs.glsl
+++ b/gsk/resources/glsl/blit.fs.glsl
@@ -1,5 +1,5 @@
 void main() {
-  vec4 diffuse = Texture(uSource, vUv);
+  vec4 diffuse = Texture(u_source, vUv);
 
-  setOutputColor(diffuse * uAlpha);
+  setOutputColor(diffuse * u_alpha);
 }
diff --git a/gsk/resources/glsl/blit.vs.glsl b/gsk/resources/glsl/blit.vs.glsl
index 68a406d..02b3285 100644
--- a/gsk/resources/glsl/blit.vs.glsl
+++ b/gsk/resources/glsl/blit.vs.glsl
@@ -1,5 +1,5 @@
 void main() {
-  gl_Position = uProjection * uModelview * vec4(aPosition, 0.0, 1.0);
+  gl_Position = u_projection * u_modelview * vec4(aPosition, 0.0, 1.0);
 
   vUv = vec2(aUv.x, aUv.y);
 }
diff --git a/gsk/resources/glsl/blur.fs.glsl b/gsk/resources/glsl/blur.fs.glsl
index 16c2b6f..3ec7d9a 100644
--- a/gsk/resources/glsl/blur.fs.glsl
+++ b/gsk/resources/glsl/blur.fs.glsl
@@ -1,6 +1,6 @@
 
-uniform float uBlurRadius = 4.0;
-uniform vec2 uSize;
+uniform float u_blur_radius = 4.0;
+uniform vec2 u_blur_size;
 
 const int   samples_x    = 15;  // must be odd
 const int   samples_y    = 15;  // must be odd
@@ -17,19 +17,19 @@ vec4 blur_pixel (in vec2 uv)
 {
   float total = 0.0;
   vec4 ret = vec4 (0);
-  float pixel_size_x = (1.0 / uSize.x);
-  float pixel_size_y = (1.0 / uSize.y);
+  float pixel_size_x = (1.0 / u_blur_size.x);
+  float pixel_size_y = (1.0 / u_blur_size.y);
 
   for (int y = 0; y < samples_y; ++y)
     {
-      float fy = Gaussian (uBlurRadius, float(y) - float(half_samples_x));
+      float fy = Gaussian (u_blur_radius, float(y) - float(half_samples_x));
       float offset_y = float(y - half_samples_y) * pixel_size_y;
       for (int x = 0; x < samples_x; ++x)
         {
-          float fx = Gaussian (uBlurRadius, float(x) - float(half_samples_x));
+          float fx = Gaussian (u_blur_radius, float(x) - float(half_samples_x));
           float offset_x = float(x - half_samples_x) * pixel_size_x;
           total += fx * fy;
-          ret += Texture(uSource, uv + vec2(offset_x, offset_y)) * fx * fy;
+          ret += Texture(u_source, uv + vec2(offset_x, offset_y)) * fx * fy;
         }
     }
   return ret / total;
diff --git a/gsk/resources/glsl/color.fs.glsl b/gsk/resources/glsl/color.fs.glsl
index 6b7e34d..b98bc21 100644
--- a/gsk/resources/glsl/color.fs.glsl
+++ b/gsk/resources/glsl/color.fs.glsl
@@ -1,9 +1,9 @@
-uniform vec4 uColor;
+uniform vec4 u_color;
 
 void main() {
-  vec4 color = uColor;
+  vec4 color = u_color;
 
   // Pre-multiply alpha
   color.rgb *= color.a;
-  setOutputColor(color * uAlpha);
+  setOutputColor(color * u_alpha);
 }
diff --git a/gsk/resources/glsl/color_matrix.fs.glsl b/gsk/resources/glsl/color_matrix.fs.glsl
index 9025bfb..07875fe 100644
--- a/gsk/resources/glsl/color_matrix.fs.glsl
+++ b/gsk/resources/glsl/color_matrix.fs.glsl
@@ -1,8 +1,8 @@
-uniform mat4 uColorMatrix;
-uniform vec4 uColorOffset;
+uniform mat4 u_color_matrix;
+uniform vec4 u_color_offset;
 
 void main() {
-  vec4 diffuse = Texture(uSource, vUv);
+  vec4 diffuse = Texture(u_source, vUv);
   vec4 color;
 
   color = diffuse;
@@ -11,10 +11,10 @@ void main() {
   if (color.a != 0.0)
     color.rgb /= color.a;
 
-  color = uColorMatrix * diffuse + uColorOffset;
+  color = u_color_matrix * diffuse + u_color_offset;
   color = clamp(color, 0.0f, 1.0f);
 
   color.rgb *= color.a;
 
-  setOutputColor(color * uAlpha);
+  setOutputColor(color * u_alpha);
 }
diff --git a/gsk/resources/glsl/coloring.fs.glsl b/gsk/resources/glsl/coloring.fs.glsl
index 8bb1d63..120c13c 100644
--- a/gsk/resources/glsl/coloring.fs.glsl
+++ b/gsk/resources/glsl/coloring.fs.glsl
@@ -1,12 +1,12 @@
 
-uniform vec4 uColor;
+uniform vec4 u_color;
 
 void main() {
-  vec4 diffuse = Texture(uSource, vUv);
-  vec4 color = uColor;
+  vec4 diffuse = Texture(u_source, vUv);
+  vec4 color = u_color;
 
   // pre-multiply
   color.rgb *= color.a;
 
-  setOutputColor((diffuse * color) * uAlpha);
+  setOutputColor((diffuse * color) * u_alpha);
 }
diff --git a/gsk/resources/glsl/gl3_common.fs.glsl b/gsk/resources/glsl/gl3_common.fs.glsl
index 3eb4c7b..6bf5f4d 100644
--- a/gsk/resources/glsl/gl3_common.fs.glsl
+++ b/gsk/resources/glsl/gl3_common.fs.glsl
@@ -1,17 +1,17 @@
 precision highp float;
 
-uniform sampler2D uSource;
-uniform sampler2D uMask;
-uniform mat4 uProjection = mat4(1.0);
-uniform mat4 uModelview = mat4(1.0);
-uniform float uAlpha = 1.0;
+uniform sampler2D u_source;
+uniform sampler2D u_mask;
+uniform mat4 u_projection = mat4(1.0);
+uniform mat4 u_modelview = mat4(1.0);
+uniform float u_alpha = 1.0;
 uniform int uBlendMode;
-uniform vec4 uViewport;
+uniform vec4 u_viewport;
 
 // In GtkSnapshot coordinates
-uniform vec4 uClip;
-uniform vec4 uClipCornerWidths  = vec4(1, 1, 1, 1);
-uniform vec4 uClipCornerHeights = vec4(1, 1, 1, 1);
+uniform vec4 u_clip;
+uniform vec4 u_clip_corner_widths  = vec4(1, 1, 1, 1);
+uniform vec4 u_clip_corner_heights = vec4(1, 1, 1, 1);
 
 in vec2 vUv;
 
@@ -88,16 +88,16 @@ vec4 Texture(sampler2D sampler, vec2 texCoords) {
 }
 
 void setOutputColor(vec4 color) {
-  vec4 clipBounds = uClip;
+  vec4 clipBounds = u_clip;
   vec4 f = gl_FragCoord;
 
-  f.x += uViewport.x;
-  f.y = (uViewport.y + uViewport.w) - f.y;
+  f.x += u_viewport.x;
+  f.y = (u_viewport.y + u_viewport.w) - f.y;
 
   clipBounds.z = clipBounds.x + clipBounds.z;
   clipBounds.w = clipBounds.y + clipBounds.w;
 
-  RoundedRect r = RoundedRect(clipBounds, uClipCornerWidths, uClipCornerHeights);
+  RoundedRect r = RoundedRect(clipBounds, u_clip_corner_widths, u_clip_corner_heights);
 
   outputColor = color * rounded_rect_coverage(r, f.xy);
   /*outputColor = color;*/
diff --git a/gsk/resources/glsl/gl3_common.vs.glsl b/gsk/resources/glsl/gl3_common.vs.glsl
index 2fb825f..6630efe 100644
--- a/gsk/resources/glsl/gl3_common.vs.glsl
+++ b/gsk/resources/glsl/gl3_common.vs.glsl
@@ -1,5 +1,5 @@
-uniform mat4 uProjection;
-uniform mat4 uModelview;
+uniform mat4 u_projection;
+uniform mat4 u_modelview;
 
 in vec2 aPosition;
 in vec2 aUv;
diff --git a/gsk/resources/glsl/inset_shadow.fs.glsl b/gsk/resources/glsl/inset_shadow.fs.glsl
index 6cb4368..4337dac 100644
--- a/gsk/resources/glsl/inset_shadow.fs.glsl
+++ b/gsk/resources/glsl/inset_shadow.fs.glsl
@@ -1,28 +1,27 @@
-uniform float uSpread;
-uniform float uBlurRadius;
-uniform vec4 uColor;
-uniform vec2 uD;
-uniform vec4 uOutline;
-uniform vec4 uOutlineCornerWidths;
-uniform vec4 uOutlineCornerHeights;
+uniform float u_spread;
+uniform float u_blur_radius;
+uniform vec4 u_color;
+uniform vec2 u_offset;
+uniform vec4 u_outline;
+uniform vec4 u_corner_widths;
+uniform vec4 u_corner_heights;
 
 
 void main() {
   vec4 f = gl_FragCoord;
 
-  f.x += uViewport.x;
-  f.y = (uViewport.y + uViewport.w) - f.y;
+  f.x += u_viewport.x;
+  f.y = (u_viewport.y + u_viewport.w) - f.y;
 
-  RoundedRect outline = RoundedRect(vec4(uOutline.xy, uOutline.xy + uOutline.zw),
-                                    uOutlineCornerWidths, uOutlineCornerHeights);
-  RoundedRect inside = rounded_rect_shrink(outline, vec4(uSpread));
+  RoundedRect outline = RoundedRect(vec4(u_outline.xy, u_outline.xy + u_outline.zw),
+                                    u_corner_widths, u_corner_heights);
+  RoundedRect inside = rounded_rect_shrink(outline, vec4(u_spread));
 
-  vec4 color = vec4(uColor.rgb * uColor.a, uColor.a);
+
+
+  vec4 color = vec4(u_color.rgb * u_color.a, u_color.a);
   color = color * clamp (rounded_rect_coverage (outline, f.xy) -
-                         rounded_rect_coverage (inside, f.xy - uD),
+                         rounded_rect_coverage (inside, f.xy + u_offset),
                          0.0, 1.0);
   setOutputColor(color);
-
-  /*setOutputColor(vec4(1, 0, 0, 1) * rounded_rect_coverage (outline, f.xy));*/
-  /*setOutputColor(vec4(0, 0, 1, 1) * rounded_rect_coverage (inside, f.xy));*/
 }
diff --git a/gsk/resources/glsl/linear_gradient.fs.glsl b/gsk/resources/glsl/linear_gradient.fs.glsl
index f14b3eb..2e84507 100644
--- a/gsk/resources/glsl/linear_gradient.fs.glsl
+++ b/gsk/resources/glsl/linear_gradient.fs.glsl
@@ -1,19 +1,19 @@
-uniform vec4 uColorStops[8];
-uniform float uColorOffsets[8];
-uniform int uNumColorStops;
-uniform vec2 uStartPoint;
-uniform vec2 uEndPoint;
+uniform vec4 u_color_stops[8];
+uniform float u_color_offsets[8];
+uniform int u_num_color_stops;
+uniform vec2 u_start_point;
+uniform vec2 u_end_point;
 
 vec4 fragCoord() {
   vec4 f = gl_FragCoord;
-  f.x += uViewport.x;
-  f.y = (uViewport.y + uViewport.w) - f.y;
+  f.x += u_viewport.x;
+  f.y = (u_viewport.y + u_viewport.w) - f.y;
   return f;
 }
 
 void main() {
-  vec2 startPoint = (uModelview * vec4(uStartPoint, 0, 1)).xy;
-  vec2 endPoint   = (uModelview * vec4(uEndPoint,   0, 1)).xy;
+  vec2 startPoint = (u_modelview * vec4(u_start_point, 0, 1)).xy;
+  vec2 endPoint   = (u_modelview * vec4(u_end_point,   0, 1)).xy;
   float maxDist   = length(endPoint - startPoint);
 
   // Position relative to startPoint
@@ -30,16 +30,16 @@ void main() {
   // Offset of the current pixel
   float offset = length(proj) / maxDist;
 
-  vec4 color = uColorStops[0];
-  for (int i = 1; i < uNumColorStops; i ++) {
-    if (offset >= uColorOffsets[i - 1])  {
-      float o = (offset - uColorOffsets[i - 1]) / (uColorOffsets[i] - uColorOffsets[i - 1]);
-      color = mix(uColorStops[i - 1], uColorStops[i], o);
+  vec4 color = u_color_stops[0];
+  for (int i = 1; i < u_num_color_stops; i ++) {
+    if (offset >= u_color_offsets[i - 1])  {
+      float o = (offset - u_color_offsets[i - 1]) / (u_color_offsets[i] - u_color_offsets[i - 1]);
+      color = mix(u_color_stops[i - 1], u_color_stops[i], o);
     }
   }
 
   /* Pre-multiply */
   color.rgb *= color.a;
 
-  setOutputColor(color * uAlpha);
+  setOutputColor(color * u_alpha);
 }


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