aboutsummaryrefslogtreecommitdiff
path: root/src/graphics
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-28 17:10:41 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-28 17:32:34 +0200
commit14e3617736c63bd22b0785ad418acef825db221f (patch)
treedc18c593a1e74c4218657136772e4409094414af /src/graphics
parent1e3df56a5c91bce2ef7b03e31156721e2f76a063 (diff)
Use a separate glx context for every window
Fix vertex buffer causing crash on render if update is called with an empty list.
Diffstat (limited to 'src/graphics')
-rw-r--r--src/graphics/vertex_buffer.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/graphics/vertex_buffer.c b/src/graphics/vertex_buffer.c
index 1f122c3..aa4fdbb 100644
--- a/src/graphics/vertex_buffer.c
+++ b/src/graphics/vertex_buffer.c
@@ -56,6 +56,7 @@ static int mgl_vertex_buffer_resize(mgl_vertex_buffer *self, const mgl_vertex *v
self->usage = usage;
context->gl.glBindBuffer(GL_ARRAY_BUFFER, self->id);
+ /* TODO: Optimize by calling with NULL data first? or do that in |mgl_vertex_buffer_update| */
context->gl.glBufferData(GL_ARRAY_BUFFER, sizeof(mgl_vertex) * vertex_count, vertices, mgl_vertex_buffer_usage_to_gl_usage(self->usage));
mgl_vertex_buffer_set_gl_buffer_pointers(context);
context->gl.glBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -69,10 +70,22 @@ void mgl_vertex_buffer_set_position(mgl_vertex_buffer *self, mgl_vec2f position)
/* TODO: Check for glBufferSubData error */
int mgl_vertex_buffer_update(mgl_vertex_buffer *self, const mgl_vertex *vertices, size_t vertex_count, mgl_primitive_type primitive_type, mgl_vertex_buffer_usage usage) {
+ mgl_context *context = mgl_get_context();
+
+ if(vertex_count == 0) {
+ if(self->id) {
+ context->gl.glDeleteBuffers(1, &self->id);
+ self->id = 0;
+ }
+ self->vertex_count = vertex_count;
+ self->primitive_type = primitive_type;
+ self->usage = usage;
+ return 0;
+ }
+
if(vertex_count != self->vertex_count || primitive_type != self->primitive_type || usage != self->usage)
return mgl_vertex_buffer_resize(self, vertices, vertex_count, primitive_type, usage);
- mgl_context *context = mgl_get_context();
context->gl.glBindBuffer(GL_ARRAY_BUFFER, self->id);
context->gl.glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(mgl_vertex) * vertex_count, vertices);
mgl_vertex_buffer_set_gl_buffer_pointers(context);