summaryrefslogtreecommitdiff
path: root/src/rendering
diff options
context:
space:
mode:
Diffstat (limited to 'src/rendering')
-rw-r--r--src/rendering/src/gl.c12
-rw-r--r--src/rendering/src/rendering.c22
2 files changed, 28 insertions, 6 deletions
diff --git a/src/rendering/src/gl.c b/src/rendering/src/gl.c
index 0468c8b..e57e949 100644
--- a/src/rendering/src/gl.c
+++ b/src/rendering/src/gl.c
@@ -232,10 +232,11 @@ RenderObject RenderObject_new(
/* The shader should be generalied, */
for (usize i = 0; i < num_buffers; i++) {
const usize sz = buffers[i].size_elem * buffers[i].count;
+ const u32 b_gl_type = ShaderBuffer_get_gl_type(buffers[i].buffertype);
gl->GenBuffers(1, &(buffers[i].buffername));
- gl->BindBuffer(GL_ARRAY_BUFFER, buffers[i].buffername);
- gl->BufferData(GL_ARRAY_BUFFER, (isize)sz, buffers[i].data, ShaderBuffer_get_gl_accesstype(buffers[i].buffertype));
+ gl->BindBuffer(b_gl_type, buffers[i].buffername);
+ gl->BufferData(b_gl_type, (isize)sz, buffers[i].data, ShaderBuffer_get_gl_accesstype(buffers[i].buffertype));
}
o.shader = *shader;
@@ -244,6 +245,13 @@ RenderObject RenderObject_new(
o.buffer_len = num_buffers;
o.mvp = gl->GetUniformLocation(o.shader.program, "MVP");
+ // It is very much a non-issue if we don't find the model view projection in
+ // the shader. In fact, it is removed from a shader program if it is not used.
+ // TODO: Add more uniforms, such as mouse coords and time. Could be cool idk.
+ //if (o.mvp == -1) {
+ // WARN("Unable to find \"MVP\" input in shader program");
+ //}
+
gl->BindVertexArray(0);
diff --git a/src/rendering/src/rendering.c b/src/rendering/src/rendering.c
index 571b9e0..0403928 100644
--- a/src/rendering/src/rendering.c
+++ b/src/rendering/src/rendering.c
@@ -495,9 +495,15 @@ void render_present(Window* w) {
// TODO the buffers need to be abstracted a bit more
gl->BindVertexArray(o->vao);
+ ShaderBuffer* ibo = NULL;
for (usize i = 0; i < o->buffer_len; i++) {
+ const u32 b_gl_type = ShaderBuffer_get_gl_type(o->buffer[i].buffertype);
+ if (b_gl_type == GL_ELEMENT_ARRAY_BUFFER) {
+ ibo = &o->buffer[i];
+ }
+
gl->EnableVertexAttribArray((u32)i);
- gl->BindBuffer(GL_ARRAY_BUFFER, o->buffer[i].buffername);
+ gl->BindBuffer(b_gl_type, o->buffer[i].buffername);
gl->VertexAttribPointer(
// index of the attribute
(u32)i,
@@ -515,15 +521,23 @@ void render_present(Window* w) {
}
// Draw the model !
- // TODO: Use DrawElements and an index buffer!
const i32 sz = (i32)(o->buffer->count * o->buffer->size_elem);
- gl->DrawArrays(GL_TRIANGLES, 0, sz); // Starting from vertex 0; 3 vertices total -> 1 triangle
+ if (ibo) {
+ gl->DrawElements(
+ GL_TRIANGLES,
+ (i32)ibo->count,
+ ShaderBuffer_get_gl_datatype(ibo->buffertype),
+ (void*)0
+ );
+ } else {
+ // Starting from vertex 0; 3 vertices total -> 1 triangle
+ gl->DrawArrays(GL_TRIANGLES, 0, sz);
+ }
for (u32 i = 0; i < o->buffer_len; i++) {
gl->DisableVertexAttribArray(i);
}
- //gl->DisableVertexAttribArray(1);
gl->BindVertexArray(0);
//if (i == 8) {