[gtk+/wip/ebassi/gsk-renderer: 61/83] Use the projection to flip around the content



commit 721420a9fbf8d8da2554bb67e0447088c04a1794
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Aug 2 16:58:47 2016 +0100

    Use the projection to flip around the content
    
    Since we use an FBO to render the contents of the render node tree, the
    coordinate space is going to be flipped in GL. We can undo the flip by
    using an appropriate projection matrix, instead of changing the sampling
    coordinates in the shaders and updating all our coordinates at render
    time.

 gsk/gskglrenderer.c              |    4 +---
 gsk/resources/glsl/blend.fs.glsl |    4 ++--
 gsk/resources/glsl/blend.vs.glsl |    2 +-
 gsk/resources/glsl/blit.vs.glsl  |    2 +-
 gtk/gtkwindow.c                  |   10 ++++++----
 5 files changed, 11 insertions(+), 11 deletions(-)
---
diff --git a/gsk/gskglrenderer.c b/gsk/gskglrenderer.c
index 093ed46..22e1558 100644
--- a/gsk/gskglrenderer.c
+++ b/gsk/gskglrenderer.c
@@ -618,7 +618,6 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
   else
     item.parent_data = NULL;
 
-  /* Select the render target; -1 is the default */
   if (render_node_needs_render_target (node))
     {
       item.render_data.render_target_id =
@@ -839,7 +838,6 @@ gsk_gl_renderer_render (GskRenderer *renderer,
   glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
   glBlendEquation (GL_FUNC_ADD);
 
-  /* Transparent pass: back-to-front */
   GSK_NOTE (OPENGL, g_print ("Rendering %u items\n", self->render_items->len));
   for (i = 0; i < self->render_items->len; i++)
     {
@@ -851,7 +849,7 @@ gsk_gl_renderer_render (GskRenderer *renderer,
   /* Draw the output of the GL rendering to the window */
   gsk_gl_driver_end_frame (self->gl_driver);
   gpu_time = gsk_gl_profiler_end_gpu_region (self->gl_profiler);
-  GSK_NOTE (OPENGL, g_print ("GPU time: %" G_GUINT64_FORMAT " nsec\n", gpu_time));
+  GSK_NOTE (OPENGL, g_print ("GPU time: %g usec\n", (double) gpu_time / 1000.0));
 
 out:
   /* XXX: Add GdkDrawingContext API */
diff --git a/gsk/resources/glsl/blend.fs.glsl b/gsk/resources/glsl/blend.fs.glsl
index 102950b..39b3e4c 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 Cb = Texture(uSource, vUv);
-  vec4 Cs = Texture(uMask, vUv);
+  vec4 Cs = Texture(uSource, vUv);
+  vec4 Cb = Texture(uMask, vUv);
   vec3 res;
 
   if (uBlendMode == 0) {
diff --git a/gsk/resources/glsl/blend.vs.glsl b/gsk/resources/glsl/blend.vs.glsl
index b947a7a..1208513 100644
--- a/gsk/resources/glsl/blend.vs.glsl
+++ b/gsk/resources/glsl/blend.vs.glsl
@@ -2,5 +2,5 @@ void main() {
   gl_Position = uMVP * vec4(aPosition, 0.0, 1.0);
 
   // Flip the sampling
-  vUv = vec2(aUv.x, 1.0 - aUv.y);
+  vUv = vec2(aUv.x, aUv.y);
 }
diff --git a/gsk/resources/glsl/blit.vs.glsl b/gsk/resources/glsl/blit.vs.glsl
index b947a7a..1208513 100644
--- a/gsk/resources/glsl/blit.vs.glsl
+++ b/gsk/resources/glsl/blit.vs.glsl
@@ -2,5 +2,5 @@ void main() {
   gl_Position = uMVP * vec4(aPosition, 0.0, 1.0);
 
   // Flip the sampling
-  vUv = vec2(aUv.x, 1.0 - aUv.y);
+  vUv = vec2(aUv.x, aUv.y);
 }
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 5ccc5a3..07dbf94 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -160,6 +160,9 @@
  * instead.
  */
 
+#define ORTHO_NEAR_PLANE        -10000
+#define ORTHO_FAR_PLANE          10000
+
 typedef struct _GtkWindowPopover GtkWindowPopover;
 
 struct _GtkWindowPopover
@@ -458,8 +461,6 @@ static void gtk_window_real_activate_focus   (GtkWindow         *window);
 static void gtk_window_keys_changed          (GtkWindow         *window);
 static gboolean gtk_window_enable_debugging  (GtkWindow         *window,
                                               gboolean           toggle);
-static gint gtk_window_draw                  (GtkWidget         *widget,
-                                             cairo_t           *cr);
 static GskRenderNode *gtk_window_get_render_node (GtkWidget   *widget,
                                                   GskRenderer *renderer);
 static void gtk_window_unset_transient_for         (GtkWindow  *window);
@@ -7608,8 +7609,9 @@ _gtk_window_set_allocation (GtkWindow           *window,
 
       graphene_matrix_init_ortho (&projection,
                                   0, allocation->width * scale,
-                                  0, allocation->height * scale,
-                                  -1, 1);
+                                  allocation->height * scale, 0,
+                                  ORTHO_NEAR_PLANE,
+                                  ORTHO_FAR_PLANE);
       gsk_renderer_set_projection (priv->renderer, &projection);
 
       graphene_matrix_init_translate (&modelview,


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