[gtk/wip/chergert/glproto: 31/493] add clear helper




commit b5a6545a6ad34f1ff0783e0a2b515a98bf2e1282
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 19 14:47:36 2020 -0800

    add clear helper

 gsk/next/gskglcommandqueue.c        | 36 ++++++++++++++++++++++++++++++++++--
 gsk/next/gskglcommandqueueprivate.h |  1 +
 2 files changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/gsk/next/gskglcommandqueue.c b/gsk/next/gskglcommandqueue.c
index fbef0fcee0..4d82f8fccf 100644
--- a/gsk/next/gskglcommandqueue.c
+++ b/gsk/next/gskglcommandqueue.c
@@ -148,8 +148,9 @@ typedef struct _GskGLCommandBatch
     GskGLCommandUniform *uniforms;
   };
 
+  guint is_clear : 1;
   guint program_changed : 1;
-  guint program : 15;
+  guint program : 14;
   guint n_draws : 16;
   guint n_binds : 16;
   guint n_uniforms : 16;
@@ -410,7 +411,12 @@ gsk_gl_command_batch_execute (GskGLCommandBatch *batch,
         }
     }
 
-  if (batch->n_draws == 1)
+  if (batch->is_clear)
+    {
+      glClearColor (0, 0, 0, 0);
+      glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+    }
+  else if (batch->n_draws == 1)
     {
       glDrawArrays (GL_TRIANGLES, batch->draw.vao_offset, batch->draw.vao_count);
     }
@@ -571,6 +577,14 @@ gsk_gl_command_queue_advance (GskGLCommandQueue *self,
   return g_steal_pointer (&batch);
 }
 
+static inline gboolean
+gsk_gl_command_queue_batch_is_complete (GskGLCommandQueue *self)
+{
+  GskGLCommandBatch *batch = gsk_gl_command_queue_get_batch (self);
+
+  return batch->is_clear || (batch->program && batch->n_draws > 0);
+}
+
 static void
 gsk_gl_command_queue_dispose (GObject *object)
 {
@@ -1210,3 +1224,21 @@ gsk_gl_command_queue_autorelease_texture (GskGLCommandQueue *self,
 
   g_array_append_val (self->autorelease_textures, texture_id);
 }
+
+void
+gsk_gl_command_queue_clear (GskGLCommandQueue *self)
+{
+  GskGLCommandBatch *batch;
+
+  g_return_if_fail (GSK_IS_GL_COMMAND_QUEUE (self));
+
+  batch = gsk_gl_command_queue_get_batch (self);
+
+  if (batch->is_clear)
+    return;
+
+  if (gsk_gl_command_queue_batch_is_complete (self))
+    batch = gsk_gl_command_queue_advance (self, 0);
+
+  batch->is_clear = TRUE;
+}
diff --git a/gsk/next/gskglcommandqueueprivate.h b/gsk/next/gskglcommandqueueprivate.h
index 5e1c001bba..38b948f1b9 100644
--- a/gsk/next/gskglcommandqueueprivate.h
+++ b/gsk/next/gskglcommandqueueprivate.h
@@ -59,6 +59,7 @@ void               gsk_gl_command_queue_use_program              (GskGLCommandQu
                                                                   guint                     program_id);
 void               gsk_gl_command_queue_bind_framebuffer         (GskGLCommandQueue        *self,
                                                                   guint                     framebuffer);
+void               gsk_gl_command_queue_clear                    (GskGLCommandQueue        *self);
 void               gsk_gl_command_queue_set_uniform1i            (GskGLCommandQueue        *self,
                                                                   guint                     program,
                                                                   guint                     location,


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