[gtk/matthiasc/color-profiles: 28/32] ngl: Support flipping gl textures




commit 05660a1c6d5c8a0408bb0566e6b8c1c36beed8b8
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Oct 3 16:02:26 2021 -0400

    ngl: Support flipping gl textures
    
    Add upside-down flipping to the list of supported
    conversions when handling GL textures.

 gsk/ngl/gsknglcommandqueueprivate.h |  1 +
 gsk/ngl/gskngldriver.c              | 19 ++++++++++---------
 2 files changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/gsk/ngl/gsknglcommandqueueprivate.h b/gsk/ngl/gsknglcommandqueueprivate.h
index 4e7ac594ad..1987229bd8 100644
--- a/gsk/ngl/gsknglcommandqueueprivate.h
+++ b/gsk/ngl/gsknglcommandqueueprivate.h
@@ -283,6 +283,7 @@ void                gsk_ngl_command_queue_execute              (GskNglCommandQue
 typedef enum {
   GSK_CONVERSION_LINEARIZE   = 1 << 0,
   GSK_CONVERSION_PREMULTIPLY = 1 << 1,
+  GSK_CONVERSION_FLIP        = 1 << 2,
 } GskConversion;
 
 int                 gsk_ngl_command_queue_upload_texture       (GskNglCommandQueue    *self,
diff --git a/gsk/ngl/gskngldriver.c b/gsk/ngl/gskngldriver.c
index a3e3e6b040..e92b5548c2 100644
--- a/gsk/ngl/gskngldriver.c
+++ b/gsk/ngl/gskngldriver.c
@@ -708,17 +708,18 @@ gsk_ngl_driver_cache_texture (GskNglDriver        *self,
 }
 
 static void
-draw_offscreen (GskNglCommandQueue *command_queue,
-                float               min_x,
-                float               min_y,
-                float               max_x,
-                float               max_y)
+draw_rect (GskNglCommandQueue *command_queue,
+           float               min_x,
+           float               min_y,
+           float               max_x,
+           float               max_y,
+           gboolean            flip)
 {
   GskNglDrawVertex *vertices = gsk_ngl_command_queue_add_vertices (command_queue);
   float min_u = 0;
-  float min_v = 1;
   float max_u = 1;
-  float max_v = 0;
+  float min_v = flip ? 0 : 1;
+  float max_v = flip ? 1 : 0;
   guint16 c[4] = { FP16_ZERO, FP16_ZERO, FP16_ZERO, FP16_ZERO };
 
   vertices[0] = (GskNglDrawVertex) { .position = { min_x, min_y }, .uv = { min_u, min_v }, .color = { c[0], 
c[1], c[2], c[3] } };
@@ -795,7 +796,7 @@ gsk_ngl_driver_convert_texture (GskNglDriver  *self,
   int prev_fbo;
   GskNglProgram *program;
 
-  if (conversion == (GSK_CONVERSION_LINEARIZE | GSK_CONVERSION_PREMULTIPLY))
+  if ((conversion & (GSK_CONVERSION_LINEARIZE|GSK_CONVERSION_PREMULTIPLY)) == 
(GSK_CONVERSION_LINEARIZE|GSK_CONVERSION_PREMULTIPLY))
     program = self->linearize_premultiply_no_clip;
   else if (conversion & GSK_CONVERSION_LINEARIZE)
     program = self->linearize_no_clip;
@@ -826,7 +827,7 @@ gsk_ngl_driver_convert_texture (GskNglDriver  *self,
   gsk_ngl_program_set_uniform_texture (program,
                                        UNIFORM_SHARED_SOURCE, 0,
                                        GL_TEXTURE_2D, GL_TEXTURE0, texture_id);
-  draw_offscreen (self->command_queue, 0, 0, width, height);
+  draw_rect (self->command_queue, 0, 0, width, height, (conversion & GSK_CONVERSION_FLIP) != 0);
 
   gsk_ngl_command_queue_end_draw (self->command_queue);
 


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