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.
This commit is contained in:
Matthias Clasen 2019-10-11 13:59:58 -04:00
parent a00d12c62a
commit 571068af12
5 changed files with 10 additions and 47 deletions

View File

@ -2976,9 +2976,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;
@ -2993,20 +2991,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);
@ -3026,7 +3010,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 &&
@ -3167,7 +3151,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:
@ -3177,9 +3160,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);
}

View File

@ -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 *

View File

@ -156,6 +156,7 @@ typedef struct
gsize buffer_size;
OpBuffer render_ops;
GArray *vertices;
GskGLRenderer *renderer;

View File

@ -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

View File

@ -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];