[gtk+] gsk: Rename uniforms and attributes in shaders



commit 03ab560fae288ffa33265d1b421c6547c56671a4
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Jul 21 17:17:49 2016 +0100

    gsk: Rename uniforms and attributes in shaders
    
    Use appropriate names, and annotate the names with the types — 'u' for
    uniforms, 'a' for attributes. The common preambles for shaders are split
    from the bodies, so we need some way to distinguish the uniforms and the
    attributes just from their name.

 gsk/gskglrenderer.c                   |   38 ++++++++++++++++++--------------
 gsk/resources/glsl/blend.fs.glsl      |   20 ++++++++--------
 gsk/resources/glsl/blend.vs.glsl      |    4 +-
 gsk/resources/glsl/blit.fs.glsl       |    4 +-
 gsk/resources/glsl/blit.vs.glsl       |    4 +-
 gsk/resources/glsl/es2_common.fs.glsl |    9 ++++---
 gsk/resources/glsl/es2_common.vs.glsl |    7 ++---
 gsk/resources/glsl/gl3_common.fs.glsl |   10 ++++----
 gsk/resources/glsl/gl3_common.vs.glsl |    7 ++---
 gsk/resources/glsl/gl_common.fs.glsl  |    9 ++++---
 gsk/resources/glsl/gl_common.vs.glsl  |    7 ++---
 11 files changed, 61 insertions(+), 58 deletions(-)
---
diff --git a/gsk/gskglrenderer.c b/gsk/gskglrenderer.c
index ac156ca..0c11900 100644
--- a/gsk/gskglrenderer.c
+++ b/gsk/gskglrenderer.c
@@ -20,14 +20,15 @@
 #define SHADER_VERSION_GL3              150
 
 typedef struct {
+  int render_target_id;
   int vao_id;
   int buffer_id;
   int texture_id;
   int program_id;
 
   int mvp_location;
-  int map_location;
-  int parentMap_location;
+  int source_location;
+  int mask_location;
   int uv_location;
   int position_location;
   int alpha_location;
@@ -59,8 +60,8 @@ typedef struct {
 
 enum {
   MVP,
-  MAP,
-  PARENT_MAP,
+  SOURCE,
+  MASK,
   ALPHA,
   BLEND_MODE,
   N_UNIFORMS
@@ -176,14 +177,14 @@ gsk_gl_renderer_create_programs (GskGLRenderer *self)
 
   gsk_shader_builder_set_resource_base_path (builder, "/org/gtk/libgsk/glsl");
 
-  self->uniforms[MVP] = gsk_shader_builder_add_uniform (builder, "mvp");
-  self->uniforms[MAP] = gsk_shader_builder_add_uniform (builder, "map");
-  self->uniforms[PARENT_MAP] = gsk_shader_builder_add_uniform (builder, "parentMap");
-  self->uniforms[ALPHA] = gsk_shader_builder_add_uniform (builder, "alpha");
-  self->uniforms[BLEND_MODE] = gsk_shader_builder_add_uniform (builder, "blendMode");
+  self->uniforms[MVP] = gsk_shader_builder_add_uniform (builder, "uMVP");
+  self->uniforms[SOURCE] = gsk_shader_builder_add_uniform (builder, "uSource");
+  self->uniforms[MASK] = gsk_shader_builder_add_uniform (builder, "uMask");
+  self->uniforms[ALPHA] = gsk_shader_builder_add_uniform (builder, "uAlpha");
+  self->uniforms[BLEND_MODE] = gsk_shader_builder_add_uniform (builder, "uBlendMode");
   
-  self->attributes[POSITION] = gsk_shader_builder_add_attribute (builder, "position");
-  self->attributes[UV] = gsk_shader_builder_add_attribute (builder, "uv");
+  self->attributes[POSITION] = gsk_shader_builder_add_attribute (builder, "aPosition");
+  self->attributes[UV] = gsk_shader_builder_add_attribute (builder, "aUv");
 
   if (gdk_gl_context_get_use_es (self->context))
     {
@@ -363,7 +364,7 @@ render_item (GskGLRenderer *self,
   glUseProgram (item->render_data.program_id);
 
   /* Use texture unit 0 for the source */
-  glUniform1i (item->render_data.map_location, 0);
+  glUniform1i (item->render_data.source_location, 0);
   gsk_gl_driver_bind_source_texture (self->gl_driver, item->render_data.texture_id);
 
   if (item->parent_data != NULL)
@@ -372,7 +373,10 @@ render_item (GskGLRenderer *self,
 
       /* Use texture unit 1 for the mask */
       if (item->parent_data->texture_id != 0)
-        gsk_gl_driver_bind_mask_texture (self->gl_driver, item->parent_data->texture_id);
+        {
+          glUniform1i (item->render_data.mask_location, 1);
+          gsk_gl_driver_bind_mask_texture (self->gl_driver, item->parent_data->texture_id);
+        }
     }
 
   /* Pass the opacity component */
@@ -528,10 +532,10 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
   item.render_data.program_id = program_id;
 
   /* Retrieve all the uniforms and attributes */
-  item.render_data.map_location =
-    gsk_shader_builder_get_uniform_location (self->shader_builder, program_id, self->uniforms[MAP]);
-  item.render_data.parentMap_location =
-    gsk_shader_builder_get_uniform_location (self->shader_builder, program_id, self->uniforms[PARENT_MAP]);
+  item.render_data.source_location =
+    gsk_shader_builder_get_uniform_location (self->shader_builder, program_id, self->uniforms[SOURCE]);
+  item.render_data.mask_location =
+    gsk_shader_builder_get_uniform_location (self->shader_builder, program_id, self->uniforms[MASK]);
   item.render_data.mvp_location =
     gsk_shader_builder_get_uniform_location (self->shader_builder, program_id, self->uniforms[MVP]);
   item.render_data.alpha_location =
diff --git a/gsk/resources/glsl/blend.fs.glsl b/gsk/resources/glsl/blend.fs.glsl
index cf1c256..102950b 100644
--- a/gsk/resources/glsl/blend.fs.glsl
+++ b/gsk/resources/glsl/blend.fs.glsl
@@ -28,29 +28,29 @@ vec3 BlendLighten(vec3 Cb, vec3 Cs) {
 }
 
 void main() {
-  vec4 Cb = Texture(parentMap, vUv);
-  vec4 Cs = Texture(map, vUv);
+  vec4 Cb = Texture(uSource, vUv);
+  vec4 Cs = Texture(uMask, vUv);
   vec3 res;
 
-  if (blendMode == 0) {
+  if (uBlendMode == 0) {
     res = Cs.xyz;
   }
-  else if (blendMode == 1) {
+  else if (uBlendMode == 1) {
     res = BlendMultiply(Cb.xyz, Cs.xyz);
   }
-  else if (blendMode == 2) {
+  else if (uBlendMode == 2) {
     res = BlendScreen(Cb.xyz, Cs.xyz);
   }
-  else if (blendMode == 3) {
+  else if (uBlendMode == 3) {
     res = BlendOverlay(Cb.xyz, Cs.xyz);
   }
-  else if (blendMode == 4) {
+  else if (uBlendMode == 4) {
     res = BlendDarken(Cb.xyz, Cs.xyz);
   }
-  else if (blendMode == 5) {
+  else if (uBlendMode == 5) {
     res = BlendLighten(Cb.xyz, Cs.xyz);
   }
-  else if (blendMode == 8) {
+  else if (uBlendMode == 8) {
     res = BlendHardLight(Cb.xyz, Cs.xyz);
   }
   else {
@@ -58,5 +58,5 @@ void main() {
     res = vec3(1.0, 0.0, 0.0);
   }
 
-  setOutputColor(vec4(res, Cs.a * alpha));
+  setOutputColor(vec4(res, Cs.a * uAlpha));
 }
diff --git a/gsk/resources/glsl/blend.vs.glsl b/gsk/resources/glsl/blend.vs.glsl
index e74a47c..b947a7a 100644
--- a/gsk/resources/glsl/blend.vs.glsl
+++ b/gsk/resources/glsl/blend.vs.glsl
@@ -1,6 +1,6 @@
 void main() {
-  gl_Position = mvp * vec4(position, 0.0, 1.0);
+  gl_Position = uMVP * vec4(aPosition, 0.0, 1.0);
 
   // Flip the sampling
-  vUv = vec2(uv.x, 1.0 - uv.y);
+  vUv = vec2(aUv.x, 1.0 - aUv.y);
 }
diff --git a/gsk/resources/glsl/blit.fs.glsl b/gsk/resources/glsl/blit.fs.glsl
index 8d2625e..ceb88ef 100644
--- a/gsk/resources/glsl/blit.fs.glsl
+++ b/gsk/resources/glsl/blit.fs.glsl
@@ -1,5 +1,5 @@
 void main() {
-  vec4 diffuse = Texture(map, vUv);
+  vec4 diffuse = Texture(uSource, vUv);
 
-  setOutputColor(vec4(diffuse.xyz, diffuse.a * alpha));
+  setOutputColor(vec4(diffuse.xyz, diffuse.a * uAlpha));
 }
diff --git a/gsk/resources/glsl/blit.vs.glsl b/gsk/resources/glsl/blit.vs.glsl
index e74a47c..b947a7a 100644
--- a/gsk/resources/glsl/blit.vs.glsl
+++ b/gsk/resources/glsl/blit.vs.glsl
@@ -1,6 +1,6 @@
 void main() {
-  gl_Position = mvp * vec4(position, 0.0, 1.0);
+  gl_Position = uMVP * vec4(aPosition, 0.0, 1.0);
 
   // Flip the sampling
-  vUv = vec2(uv.x, 1.0 - uv.y);
+  vUv = vec2(aUv.x, 1.0 - aUv.y);
 }
diff --git a/gsk/resources/glsl/es2_common.fs.glsl b/gsk/resources/glsl/es2_common.fs.glsl
index c09f75e..4cbe577 100644
--- a/gsk/resources/glsl/es2_common.fs.glsl
+++ b/gsk/resources/glsl/es2_common.fs.glsl
@@ -1,9 +1,10 @@
 precision mediump float;
 
-uniform mat4 mvp;
-uniform sampler2D map;
-uniform sampler2D parentMap;
-uniform float alpha;
+uniform mat4 uMVP;
+uniform sampler2D uSource;
+uniform sampler2D uMask;
+uniform float uAlpha;
+uniform int uBlendMode;
 
 varying vec2 vUv;
 
diff --git a/gsk/resources/glsl/es2_common.vs.glsl b/gsk/resources/glsl/es2_common.vs.glsl
index e52c153..3db2e4d 100644
--- a/gsk/resources/glsl/es2_common.vs.glsl
+++ b/gsk/resources/glsl/es2_common.vs.glsl
@@ -1,7 +1,6 @@
-uniform mat4 mvp;
-uniform float alpha;
+uniform mat4 uMVP;
 
-attribute vec2 position;
-attribute vec2 uv;
+attribute vec2 aPosition;
+attribute vec2 aUv;
 
 varying vec2 vUv;
diff --git a/gsk/resources/glsl/gl3_common.fs.glsl b/gsk/resources/glsl/gl3_common.fs.glsl
index 48134a3..50f72f5 100644
--- a/gsk/resources/glsl/gl3_common.fs.glsl
+++ b/gsk/resources/glsl/gl3_common.fs.glsl
@@ -1,10 +1,10 @@
 precision highp float;
 
-uniform sampler2D map;
-uniform sampler2D parentMap;
-uniform mat4 mvp;
-uniform float alpha;
-uniform int blendMode;
+uniform sampler2D uSource;
+uniform sampler2D uMask;
+uniform mat4 uMVP;
+uniform float uAlpha;
+uniform int uBlendMode;
 
 in vec2 vUv;
 
diff --git a/gsk/resources/glsl/gl3_common.vs.glsl b/gsk/resources/glsl/gl3_common.vs.glsl
index 96289e6..b90c2fe 100644
--- a/gsk/resources/glsl/gl3_common.vs.glsl
+++ b/gsk/resources/glsl/gl3_common.vs.glsl
@@ -1,7 +1,6 @@
-uniform mat4 mvp;
-uniform float alpha;
+uniform mat4 uMVP;
 
-in vec2 position;
-in vec2 uv;
+in vec2 aPosition;
+in vec2 aUv;
 
 out vec2 vUv;
diff --git a/gsk/resources/glsl/gl_common.fs.glsl b/gsk/resources/glsl/gl_common.fs.glsl
index e9cfa44..2ed6c75 100644
--- a/gsk/resources/glsl/gl_common.fs.glsl
+++ b/gsk/resources/glsl/gl_common.fs.glsl
@@ -1,7 +1,8 @@
-uniform mat4 mvp;
-uniform sampler2D map;
-uniform sampler2D parentMap;
-uniform float alpha;
+uniform mat4 uMVP;
+uniform sampler2D uSource;
+uniform sampler2D uMask;
+uniform float uAlpha;
+uniform int uBlendMode;
 
 varying vec2 vUv;
 
diff --git a/gsk/resources/glsl/gl_common.vs.glsl b/gsk/resources/glsl/gl_common.vs.glsl
index e52c153..3db2e4d 100644
--- a/gsk/resources/glsl/gl_common.vs.glsl
+++ b/gsk/resources/glsl/gl_common.vs.glsl
@@ -1,7 +1,6 @@
-uniform mat4 mvp;
-uniform float alpha;
+uniform mat4 uMVP;
 
-attribute vec2 position;
-attribute vec2 uv;
+attribute vec2 aPosition;
+attribute vec2 aUv;
 
 varying vec2 vUv;


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