[gtk+/wip/ebassi/gsk-renderer: 102/194] gsk: Add 'blit' program



commit 2541ecc7b3f4e0ff9ec76e17309ddc206266973d
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Jul 4 13:55:00 2016 +0100

    gsk: Add 'blit' program
    
    For the root node we do not need to use blending, as it does not have
    any backdrop to blend into. We can use a simpler 'blit' program that
    only takes the content of the source and fills the texture quad with
    it.

 gsk/gskglrenderer.c              |   25 ++++++++++++++++++++++---
 gsk/resources/glsl/blend.vs.glsl |    2 +-
 gsk/resources/glsl/blit.fs.glsl  |    5 +++++
 gsk/resources/glsl/blit.vs.glsl  |    6 ++++++
 4 files changed, 34 insertions(+), 4 deletions(-)
---
diff --git a/gsk/gskglrenderer.c b/gsk/gskglrenderer.c
index 91589bc..07a0dbe 100644
--- a/gsk/gskglrenderer.c
+++ b/gsk/gskglrenderer.c
@@ -90,6 +90,7 @@ struct _GskGLRenderer
   GskShaderBuilder *shader_builder;
 
   int blend_program_id;
+  int blit_program_id;
 
   guint vao_id;
 
@@ -344,12 +345,25 @@ gsk_gl_renderer_create_programs (GskGLRenderer *self)
     gsk_shader_builder_create_program (builder, "blend.vs.glsl", "blend.fs.glsl", &error);
   if (error != NULL)
     {
-      g_critical ("Unable to create program: %s", error->message);
+      g_critical ("Unable to create 'blend' program: %s", error->message);
       g_error_free (error);
       g_object_unref (builder);
       goto out;
     }
 
+  self->blit_program_id =
+    gsk_shader_builder_create_program (builder, "blit.vs.glsl", "blit.fs.glsl", &error);
+  if (error != NULL)
+    {
+      g_critical ("Unable to create 'blit' program: %s", error->message);
+      g_error_free (error);
+      g_object_unref (builder);
+      goto out;
+    }
+
+  /* Keep a pointer to query for the uniform and attribute locations
+   * when rendering the scene
+   */
   self->shader_builder = builder;
 
   res = TRUE;
@@ -731,8 +745,11 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
   item.render_data.vao_id = self->vao_id;
   item.render_data.buffer_id = 0;
 
-  program_id = self->blend_program_id;
-  item.render_data.program_id = program_id;
+  /* Select the program to use */
+  if (parent != NULL)
+    program_id = self->blend_program_id;
+  else
+    program_id = self->blit_program_id;
 
   item.render_data.map_location =
     gsk_shader_builder_get_uniform_location (self->shader_builder, program_id, self->uniforms[MAP]);
@@ -750,6 +767,8 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
   item.render_data.uv_location =
     gsk_shader_builder_get_attribute_location (self->shader_builder, program_id, self->attributes[UV]);
 
+  item.render_data.program_id = program_id;
+
   if (parent != NULL)
     item.parent_data = &(parent->render_data);
   else
diff --git a/gsk/resources/glsl/blend.vs.glsl b/gsk/resources/glsl/blend.vs.glsl
index 7ec0594..e74a47c 100644
--- a/gsk/resources/glsl/blend.vs.glsl
+++ b/gsk/resources/glsl/blend.vs.glsl
@@ -2,5 +2,5 @@ void main() {
   gl_Position = mvp * vec4(position, 0.0, 1.0);
 
   // Flip the sampling
-  vUv = vec2(uv.x, 1 - uv.y);
+  vUv = vec2(uv.x, 1.0 - uv.y);
 }
diff --git a/gsk/resources/glsl/blit.fs.glsl b/gsk/resources/glsl/blit.fs.glsl
new file mode 100644
index 0000000..8d2625e
--- /dev/null
+++ b/gsk/resources/glsl/blit.fs.glsl
@@ -0,0 +1,5 @@
+void main() {
+  vec4 diffuse = Texture(map, vUv);
+
+  setOutputColor(vec4(diffuse.xyz, diffuse.a * alpha));
+}
diff --git a/gsk/resources/glsl/blit.vs.glsl b/gsk/resources/glsl/blit.vs.glsl
new file mode 100644
index 0000000..e74a47c
--- /dev/null
+++ b/gsk/resources/glsl/blit.vs.glsl
@@ -0,0 +1,6 @@
+void main() {
+  gl_Position = mvp * vec4(position, 0.0, 1.0);
+
+  // Flip the sampling
+  vUv = vec2(uv.x, 1.0 - uv.y);
+}


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