[gtk/wip/chergert/glproto] remove a pointer chase
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/glproto] remove a pointer chase
- Date: Tue, 9 Feb 2021 19:20:48 +0000 (UTC)
commit 09efcddb00cf5daab574372f25a936d1fb6f946a
Author: Christian Hergert <chergert redhat com>
Date: Tue Feb 9 11:32:57 2021 -0800
remove a pointer chase
gsk/next/gskglbuffer.c | 34 ++++++++++++----------------------
gsk/next/gskglbufferprivate.h | 9 +++++----
gsk/next/gskglcommandqueue.c | 10 ++++++----
gsk/next/gskglcommandqueueprivate.h | 4 ++--
4 files changed, 25 insertions(+), 32 deletions(-)
---
diff --git a/gsk/next/gskglbuffer.c b/gsk/next/gskglbuffer.c
index 1e16b0b129..c285ae69e7 100644
--- a/gsk/next/gskglbuffer.c
+++ b/gsk/next/gskglbuffer.c
@@ -23,34 +23,25 @@
#include "gskglbufferprivate.h"
/**
- * gsk_gl_buffer_new:
+ * gsk_gl_buffer_init:
* @target: the target buffer such as %GL_ARRAY_BUFFER or %GL_UNIFORM_BUFFER
* @element_size: the size of elements within the buffer
*
* Creates a new #GskGLBuffer which can be used to deliver data to shaders
* within a GLSL program. You can use this to store vertices such as with
* %GL_ARRAY_BUFFER or uniform data with %GL_UNIFORM_BUFFER.
- *
- * Note that only writing to this buffer is allowed (see %GL_WRITE_ONLY for
- * more details).
- *
- * The buffer will be bound to target upon returning from this function.
*/
-GskGLBuffer *
-gsk_gl_buffer_new (GLenum target,
- guint element_size)
+void
+gsk_gl_buffer_init (GskGLBuffer *self,
+ GLenum target,
+ guint element_size)
{
- GskGLBuffer *buffer;
-
- buffer = g_new0 (GskGLBuffer, 1);
- buffer->buffer = g_malloc (8092);
- buffer->buffer_len = 8092;
- buffer->buffer_pos = 0;
- buffer->target = target;
- buffer->element_size = element_size;
- buffer->count = 0;
+ memset (self, 0, sizeof *self);
- return g_steal_pointer (&buffer);
+ self->buffer = g_malloc (8092);
+ self->buffer_len = 8092;
+ self->target = target;
+ self->element_size = element_size;
}
GLuint
@@ -69,8 +60,7 @@ gsk_gl_buffer_submit (GskGLBuffer *buffer)
}
void
-gsk_gl_buffer_free (GskGLBuffer *buffer)
+gsk_gl_buffer_destroy (GskGLBuffer *buffer)
{
- g_free (buffer->buffer);
- g_free (buffer);
+ g_clear_pointer (&buffer->buffer, g_free);
}
diff --git a/gsk/next/gskglbufferprivate.h b/gsk/next/gskglbufferprivate.h
index 2f6f149a0c..eda4a5ed05 100644
--- a/gsk/next/gskglbufferprivate.h
+++ b/gsk/next/gskglbufferprivate.h
@@ -35,10 +35,11 @@ typedef struct _GskGLBuffer
guint element_size;
} GskGLBuffer;
-GskGLBuffer *gsk_gl_buffer_new (GLenum target,
- guint element_size);
-void gsk_gl_buffer_free (GskGLBuffer *buffer);
-GLuint gsk_gl_buffer_submit (GskGLBuffer *buffer);
+void gsk_gl_buffer_init (GskGLBuffer *self,
+ GLenum target,
+ guint element_size);
+void gsk_gl_buffer_destroy (GskGLBuffer *buffer);
+GLuint gsk_gl_buffer_submit (GskGLBuffer *buffer);
static inline gpointer
gsk_gl_buffer_advance (GskGLBuffer *buffer,
diff --git a/gsk/next/gskglcommandqueue.c b/gsk/next/gskglcommandqueue.c
index eb7494d3f5..30bff3ef68 100644
--- a/gsk/next/gskglcommandqueue.c
+++ b/gsk/next/gskglcommandqueue.c
@@ -240,11 +240,12 @@ gsk_gl_command_queue_dispose (GObject *object)
g_clear_pointer (&self->batches, g_array_unref);
g_clear_pointer (&self->attachments, gsk_gl_attachment_state_unref);
g_clear_pointer (&self->uniforms, gsk_gl_uniform_state_unref);
- g_clear_pointer (&self->vertices, gsk_gl_buffer_free);
g_clear_pointer (&self->batch_draws, g_array_unref);
g_clear_pointer (&self->batch_binds, g_array_unref);
g_clear_pointer (&self->batch_uniforms, g_array_unref);
+ gsk_gl_buffer_destroy (&self->vertices);
+
G_OBJECT_CLASS (gsk_gl_command_queue_parent_class)->dispose (object);
}
@@ -265,8 +266,9 @@ gsk_gl_command_queue_init (GskGLCommandQueue *self)
self->batch_draws = g_array_new (FALSE, FALSE, sizeof (GskGLCommandDraw));
self->batch_binds = g_array_new (FALSE, FALSE, sizeof (GskGLCommandBind));
self->batch_uniforms = g_array_new (FALSE, FALSE, sizeof (GskGLCommandUniform));
- self->vertices = gsk_gl_buffer_new (GL_ARRAY_BUFFER, sizeof (GskGLDrawVertex));
self->debug_groups = g_string_chunk_new (4096);
+
+ gsk_gl_buffer_init (&self->vertices, GL_ARRAY_BUFFER, sizeof (GskGLDrawVertex));
}
GskGLCommandQueue *
@@ -363,7 +365,7 @@ gsk_gl_command_queue_begin_draw (GskGLCommandQueue *self,
batch->draw.bind_count = 0;
batch->draw.bind_offset = self->batch_binds->len;
batch->draw.vbo_count = 0;
- batch->draw.vbo_offset = gsk_gl_buffer_get_offset (self->vertices);
+ batch->draw.vbo_offset = gsk_gl_buffer_get_offset (&self->vertices);
self->in_draw = TRUE;
}
@@ -830,7 +832,7 @@ gsk_gl_command_queue_execute (GskGLCommandQueue *self,
glGenVertexArrays (1, &vao_id);
glBindVertexArray (vao_id);
- vbo_id = gsk_gl_buffer_submit (self->vertices);
+ vbo_id = gsk_gl_buffer_submit (&self->vertices);
/* 0 = position location */
glEnableVertexAttribArray (0);
diff --git a/gsk/next/gskglcommandqueueprivate.h b/gsk/next/gskglcommandqueueprivate.h
index 3147fa33a8..21cd84d0e1 100644
--- a/gsk/next/gskglcommandqueueprivate.h
+++ b/gsk/next/gskglcommandqueueprivate.h
@@ -183,7 +183,7 @@ struct _GskGLCommandQueue
* to the GL driver. We can also tweak this to use double buffered arrays
* if we find that to be faster on some hardware and/or drivers.
*/
- GskGLBuffer *vertices;
+ GskGLBuffer vertices;
/* The GskGLAttachmentState contains information about our FBO and texture
* attachments as we process incoming operations. We snapshot them into
@@ -308,7 +308,7 @@ static inline GskGLDrawVertex *
gsk_gl_command_queue_add_vertices (GskGLCommandQueue *self)
{
GskGLCommandBatch *batch = &g_array_index (self->batches, GskGLCommandBatch, self->batches->len - 1);
- GskGLDrawVertex *dest = gsk_gl_buffer_advance (self->vertices, GSK_GL_N_VERTICES);
+ GskGLDrawVertex *dest = gsk_gl_buffer_advance (&self->vertices, GSK_GL_N_VERTICES);
batch->draw.vbo_count += GSK_GL_N_VERTICES;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]