aboutsummaryrefslogtreecommitdiff
path: root/src/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics')
-rw-r--r--src/graphics/font.c2
-rw-r--r--src/graphics/vertex_buffer.c31
2 files changed, 18 insertions, 15 deletions
diff --git a/src/graphics/font.c b/src/graphics/font.c
index f55144a..669c2ac 100644
--- a/src/graphics/font.c
+++ b/src/graphics/font.c
@@ -111,7 +111,7 @@ void mgl_font_unload(mgl_font *self) {
self->num_packed_chars = 0;
}
-int mgl_font_get_glyph(mgl_font *self, uint32_t codepoint, mgl_font_glyph *glyph) {
+int mgl_font_get_glyph(const mgl_font *self, uint32_t codepoint, mgl_font_glyph *glyph) {
stbtt_packedchar *packed_chars = self->packed_chars;
if(codepoint >= self->num_packed_chars)
return -1;
diff --git a/src/graphics/vertex_buffer.c b/src/graphics/vertex_buffer.c
index 5a8e768..1f122c3 100644
--- a/src/graphics/vertex_buffer.c
+++ b/src/graphics/vertex_buffer.c
@@ -17,19 +17,12 @@ static unsigned int mgl_vertex_buffer_usage_to_gl_usage(mgl_vertex_buffer_usage
return 0;
}
-int mgl_vertex_buffer_init(mgl_vertex_buffer *self, mgl_primitive_type primitive_type, mgl_vertex_buffer_usage usage) {
+void mgl_vertex_buffer_init(mgl_vertex_buffer *self) {
self->id = 0;
self->vertex_count = 0;
- self->primitive_type = primitive_type;
- self->usage = usage;
+ self->primitive_type = -1;
+ self->usage = -1;
self->position = (mgl_vec2f){ 0.0f, 0.0f };
-
- mgl_context *context = mgl_get_context();
- context->gl.glGenBuffers(1, &self->id);
- if(self->id == 0)
- return -1;
-
- return 0;
}
void mgl_vertex_buffer_deinit(mgl_vertex_buffer *self) {
@@ -50,8 +43,18 @@ static void mgl_vertex_buffer_set_gl_buffer_pointers(mgl_context *context) {
}
/* TODO: Check for glBufferData error */
-static int mgl_vertex_buffer_resize(mgl_vertex_buffer *self, const mgl_vertex *vertices, size_t vertex_count) {
+static int mgl_vertex_buffer_resize(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(self->id == 0) {
+ context->gl.glGenBuffers(1, &self->id);
+ if(self->id == 0)
+ return -1;
+ }
+
+ self->primitive_type = primitive_type;
+ self->usage = usage;
+
context->gl.glBindBuffer(GL_ARRAY_BUFFER, self->id);
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);
@@ -65,9 +68,9 @@ 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) {
- if(vertex_count != self->vertex_count)
- return mgl_vertex_buffer_resize(self, vertices, vertex_count);
+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) {
+ 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);