[gtk/wip/chergert/glproto: 504/526] add helper to grow/retract vertices




commit bc05ff168a21fb24703d4375020cb9fb87802e3d
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 10 17:37:48 2021 -0800

    add helper to grow/retract vertices
    
    sometimes we want to add vertices as a big batch, and then retract what
    we didnt use

 gsk/next/gskglbufferprivate.h       |  8 ++++++++
 gsk/next/gskglcommandqueueprivate.h | 15 +++++++++++++++
 2 files changed, 23 insertions(+)
---
diff --git a/gsk/next/gskglbufferprivate.h b/gsk/next/gskglbufferprivate.h
index eda4a5ed05..b0315724f9 100644
--- a/gsk/next/gskglbufferprivate.h
+++ b/gsk/next/gskglbufferprivate.h
@@ -62,6 +62,14 @@ gsk_gl_buffer_advance (GskGLBuffer *buffer,
   return ret;
 }
 
+static inline void
+gsk_gl_buffer_retract (GskGLBuffer *buffer,
+                       guint        count)
+{
+  buffer->buffer_pos -= count * buffer->element_size;
+  buffer->count -= count;
+}
+
 static inline guint
 gsk_gl_buffer_get_offset (GskGLBuffer *buffer)
 {
diff --git a/gsk/next/gskglcommandqueueprivate.h b/gsk/next/gskglcommandqueueprivate.h
index d2dc5aa06d..9bb799db07 100644
--- a/gsk/next/gskglcommandqueueprivate.h
+++ b/gsk/next/gskglcommandqueueprivate.h
@@ -318,6 +318,21 @@ gsk_gl_command_queue_add_vertices (GskGLCommandQueue *self)
   return gsk_gl_buffer_advance (&self->vertices, GSK_GL_N_VERTICES);
 }
 
+static inline GskGLDrawVertex *
+gsk_gl_command_queue_add_n_vertices (GskGLCommandQueue *self,
+                                     guint              count)
+{
+  self->batches[self->n_batches - 1].draw.vbo_count += GSK_GL_N_VERTICES * count;
+  return gsk_gl_buffer_advance (&self->vertices, GSK_GL_N_VERTICES * count);
+}
+
+static inline void
+gsk_gl_command_queue_retract_n_vertices (GskGLCommandQueue *self,
+                                         guint              count)
+{
+  self->batches[self->n_batches - 1].draw.vbo_count -= GSK_GL_N_VERTICES * count;
+  gsk_gl_buffer_retract (&self->vertices, GSK_GL_N_VERTICES * count);
+}
 
 static inline void
 gsk_gl_command_queue_bind_framebuffer (GskGLCommandQueue *self,


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