[gtk/wip/matthiasc/gsk-hdr] ngl: Simplify framebuffer format handling



commit ef778c8fbba0f03097c4fde5654908146ba4ba96
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Oct 6 11:41:22 2021 -0400

    ngl: Simplify framebuffer format handling
    
    Just look at the depth of the framebuffer to decide
    on the intermediate format. Rename our field to
    target_format since we are not aiming to determine
    the framebuffer format accurately.

 gsk/ngl/gsknglrenderjob.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
---
diff --git a/gsk/ngl/gsknglrenderjob.c b/gsk/ngl/gsknglrenderjob.c
index 09135bc519..83b244d9a1 100644
--- a/gsk/ngl/gsknglrenderjob.c
+++ b/gsk/ngl/gsknglrenderjob.c
@@ -163,10 +163,10 @@ struct _GskNglRenderJob
   /* If we should be rendering red zones over fallback nodes */
   guint debug_fallback : 1;
 
-  /* Format of the framebuffer we are rendering on, used in
-   * determining the format for intermediate textures
+  /* Format we want to use for intermediate textures, determined by
+   * looking at the format of the framebuffer we are rendering on.
    */
-  int framebuffer_format;
+  int target_format;
 };
 
 typedef struct _GskNglRenderOffscreen
@@ -210,7 +210,7 @@ get_target_format (GskNglRenderJob     *job,
   if (!gsk_render_node_is_hdr (node))
     return GL_RGBA8;
 
-  return job->framebuffer_format;
+  return job->target_format;
 }
 
 static inline void
@@ -1273,7 +1273,7 @@ blur_offscreen (GskNglRenderJob       *job,
   if (!gsk_ngl_driver_create_render_target (job->driver,
                                              MAX (texture_to_blur_width, 1),
                                              MAX (texture_to_blur_height, 1),
-                                             job->framebuffer_format,
+                                             job->target_format,
                                              GL_NEAREST, GL_NEAREST,
                                              &pass1))
     return 0;
@@ -1284,7 +1284,7 @@ blur_offscreen (GskNglRenderJob       *job,
   if (!gsk_ngl_driver_create_render_target (job->driver,
                                              texture_to_blur_width,
                                              texture_to_blur_height,
-                                             job->framebuffer_format,
+                                             job->target_format,
                                              GL_NEAREST, GL_NEAREST,
                                              &pass2))
     return gsk_ngl_driver_release_render_target (job->driver, pass1, FALSE);
@@ -3974,7 +3974,7 @@ gsk_ngl_render_job_render_flipped (GskNglRenderJob *job,
   if (!gsk_ngl_command_queue_create_render_target (job->command_queue,
                                                   MAX (1, job->viewport.size.width),
                                                   MAX (1, job->viewport.size.height),
-                                                  job->framebuffer_format,
+                                                  job->target_format,
                                                   GL_NEAREST, GL_NEAREST,
                                                   &framebuffer_id, &texture_id))
     return;
@@ -4068,15 +4068,14 @@ gsk_ngl_render_job_set_debug_fallback (GskNglRenderJob *job,
 static int
 get_framebuffer_format (guint framebuffer)
 {
-  int type, size;
+  int size;
 
   glBindFramebuffer (GL_FRAMEBUFFER, framebuffer);
-  glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,  GL_COLOR_ATTACHMENT0, 
GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE, &type);
   glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,  GL_COLOR_ATTACHMENT0, 
GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &size);
 
-  if (type == GL_FLOAT && size == 32)
+  if (size >= 32)
     return GL_RGBA32F;
-  else if (size > 8)
+  else if (size >= 16)
     return GL_RGBA16F;
   else
     return GL_RGBA8;
@@ -4108,7 +4107,7 @@ gsk_ngl_render_job_new (GskNglDriver          *driver,
   job->scale_x = scale_factor;
   job->scale_y = scale_factor;
   job->viewport = *viewport;
-  job->framebuffer_format = get_framebuffer_format (framebuffer);
+  job->target_format = get_framebuffer_format (framebuffer);
 
   gsk_ngl_render_job_set_alpha (job, 1.0f);
   gsk_ngl_render_job_set_projection_from_rect (job, viewport, NULL);


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