[gtk/wip/matthiasc/vao-in-place: 2/3] Drop OP_CHANGE_VAO
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/vao-in-place: 2/3] Drop OP_CHANGE_VAO
- Date: Fri, 11 Oct 2019 18:45:29 +0000 (UTC)
commit 0acb26a076b89d95f3258f539f8defe59808bd98
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Oct 11 13:59:58 2019 -0400
Drop OP_CHANGE_VAO
Instead, we accumulate vertices in a separate
array, which simplifies various things and lets
us avoid the extra copying step for the vao.
gsk/gl/gskglrenderer.c | 24 ++----------------------
gsk/gl/gskglrenderops.c | 21 +++++----------------
gsk/gl/gskglrenderopsprivate.h | 1 +
gsk/gl/opbuffer.c | 3 +--
gsk/gl/opbuffer.h | 8 +-------
5 files changed, 10 insertions(+), 47 deletions(-)
---
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index c14e05c01c..78338db358 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -2992,9 +2992,7 @@ gsk_gl_renderer_render_ops (GskGLRenderer *self,
gsize vertex_data_size)
{
const Program *program = NULL;
- gsize buffer_index = 0;
- float *vertex_data = g_malloc (vertex_data_size);
- OpBuffer *buffer;
+ float *vertex_data = (float*)self->op_builder.vertices->data;
OpBufferIter iter;
OpKind kind;
gpointer ptr;
@@ -3009,20 +3007,6 @@ gsk_gl_renderer_render_ops (GskGLRenderer *self,
glGenBuffers (1, &buffer_id);
glBindBuffer (GL_ARRAY_BUFFER, buffer_id);
- // Fill buffer data
- buffer = ops_get_buffer (&self->op_builder);
- op_buffer_iter_init (&iter, buffer);
- while ((ptr = op_buffer_iter_next (&iter, &kind)))
- {
- if (kind == OP_CHANGE_VAO)
- {
- const OpVao *vao = ptr;
-
- memcpy (vertex_data + buffer_index, &vao->vertex_data, sizeof (GskQuadVertex) * GL_N_VERTICES);
- buffer_index += sizeof (GskQuadVertex) * GL_N_VERTICES / sizeof (float);
- }
- }
-
// Set buffer data
glBufferData (GL_ARRAY_BUFFER, vertex_data_size, vertex_data, GL_STATIC_DRAW);
@@ -3042,7 +3026,7 @@ gsk_gl_renderer_render_ops (GskGLRenderer *self,
op_buffer_iter_init (&iter, ops_get_buffer (&self->op_builder));
while ((ptr = op_buffer_iter_next (&iter, &kind)))
{
- if (kind == OP_NONE || kind == OP_CHANGE_VAO)
+ if (kind == OP_NONE)
continue;
if (program == NULL &&
@@ -3183,7 +3167,6 @@ gsk_gl_renderer_render_ops (GskGLRenderer *self,
gdk_gl_context_pop_debug_group (self->gl_context);
break;
- case OP_CHANGE_VAO:
case OP_NONE:
case OP_LAST:
default:
@@ -3193,9 +3176,6 @@ gsk_gl_renderer_render_ops (GskGLRenderer *self,
OP_PRINT ("\n");
}
- /* Done drawing, destroy the buffer again.
- * TODO: Can we reuse the memory, though? */
- g_free (vertex_data);
glDeleteVertexArrays (1, &vao_id);
glDeleteBuffers (1, &buffer_id);
}
diff --git a/gsk/gl/gskglrenderops.c b/gsk/gl/gskglrenderops.c
index 663403aa2b..724aacfa42 100644
--- a/gsk/gl/gskglrenderops.c
+++ b/gsk/gl/gskglrenderops.c
@@ -183,6 +183,7 @@ ops_init (RenderOpBuilder *builder)
builder->current_opacity = 1.0f;
op_buffer_init (&builder->render_ops);
+ builder->vertices = g_array_new (FALSE, TRUE, sizeof (GskQuadVertex));
for (i = 0; i < GL_N_PROGRAMS; i ++)
{
@@ -200,6 +201,7 @@ ops_free (RenderOpBuilder *builder)
gsk_transform_unref (builder->program_state[i].modelview);
}
+ g_array_unref (builder->vertices);
op_buffer_destroy (&builder->render_ops);
}
@@ -681,35 +683,21 @@ ops_draw (RenderOpBuilder *builder,
const GskQuadVertex vertex_data[GL_N_VERTICES])
{
OpDraw *op;
- OpVao *vao;
if ((op = op_buffer_peek_tail_checked (&builder->render_ops, OP_DRAW)))
{
- gsize old_vao_offset = op->vao_offset;
- gsize old_vao_size = op->vao_size;
-
- op_buffer_pop_tail (&builder->render_ops);
-
- vao = op_buffer_add (&builder->render_ops, OP_CHANGE_VAO);
- memcpy (vao->vertex_data, vertex_data, sizeof vao->vertex_data);
-
- op = op_buffer_add (&builder->render_ops, OP_DRAW);
- op->vao_offset = old_vao_offset;
- op->vao_size = old_vao_size + GL_N_VERTICES;
+ op->vao_size += GL_N_VERTICES;
}
else
{
gsize offset = builder->buffer_size / sizeof (GskQuadVertex);
- vao = op_buffer_add (&builder->render_ops, OP_CHANGE_VAO);
- memcpy (vao->vertex_data, vertex_data, sizeof vao->vertex_data);
-
op = op_buffer_add (&builder->render_ops, OP_DRAW);
op->vao_offset = offset;
op->vao_size = GL_N_VERTICES;
}
- /* We added new vertex data in both cases so increase the buffer size */
+ g_array_append_vals (builder->vertices, vertex_data, GL_N_VERTICES);
builder->buffer_size += sizeof (GskQuadVertex) * GL_N_VERTICES;
}
@@ -736,6 +724,7 @@ void
ops_reset (RenderOpBuilder *builder)
{
op_buffer_clear (&builder->render_ops);
+ g_array_set_size (builder->vertices, 0);
}
OpBuffer *
diff --git a/gsk/gl/gskglrenderopsprivate.h b/gsk/gl/gskglrenderopsprivate.h
index 85765ad44f..f01097b65f 100644
--- a/gsk/gl/gskglrenderopsprivate.h
+++ b/gsk/gl/gskglrenderopsprivate.h
@@ -156,6 +156,7 @@ typedef struct
gsize buffer_size;
OpBuffer render_ops;
+ GArray *vertices;
GskGLRenderer *renderer;
diff --git a/gsk/gl/opbuffer.c b/gsk/gl/opbuffer.c
index 2d3b16ffb6..b85127b5dd 100644
--- a/gsk/gl/opbuffer.c
+++ b/gsk/gl/opbuffer.c
@@ -13,7 +13,7 @@ static guint op_sizes[OP_LAST] = {
sizeof (OpClip),
sizeof (OpViewport),
sizeof (OpTexture),
- sizeof (OpVao),
+ sizeof (OpRepeat),
sizeof (OpLinearGradient),
sizeof (OpColorMatrix),
sizeof (OpBlur),
@@ -30,7 +30,6 @@ static guint op_sizes[OP_LAST] = {
sizeof (OpDebugGroup),
0,
sizeof (OpBlend),
- sizeof (OpRepeat),
};
void
diff --git a/gsk/gl/opbuffer.h b/gsk/gl/opbuffer.h
index d777e2ae41..5124291628 100644
--- a/gsk/gl/opbuffer.h
+++ b/gsk/gl/opbuffer.h
@@ -21,7 +21,7 @@ typedef enum
OP_CHANGE_CLIP = 7,
OP_CHANGE_VIEWPORT = 8,
OP_CHANGE_SOURCE_TEXTURE = 9,
- OP_CHANGE_VAO = 10,
+ OP_CHANGE_REPEAT = 10,
OP_CHANGE_LINEAR_GRADIENT = 11,
OP_CHANGE_COLOR_MATRIX = 12,
OP_CHANGE_BLUR = 13,
@@ -38,7 +38,6 @@ typedef enum
OP_PUSH_DEBUG_GROUP = 24,
OP_POP_DEBUG_GROUP = 25,
OP_CHANGE_BLEND = 26,
- OP_CHANGE_REPEAT = 27,
OP_LAST
} OpKind;
@@ -107,11 +106,6 @@ typedef struct
gsize vao_size;
} OpDraw;
-typedef struct
-{
- GskQuadVertex vertex_data[6];
-} OpVao;
-
typedef struct
{
float color_offsets[8];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]