summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOmniscient <omniscient.oce@gmail.com>2024-06-09 14:55:53 +1000
committerOmniscient <omniscient.oce@gmail.com>2024-06-09 14:55:53 +1000
commitd4ff15d9cd82a6e3bc71da9d04ee0f250460cef1 (patch)
tree9082af194033e5e3e4a770456209d3bac7784943 /src
parent64830ce51a185091f54c2b42b365110d89d44f1b (diff)
fix cube
Diffstat (limited to 'src')
-rw-r--r--src/maths/maths.h1
-rw-r--r--src/renderer/backends/opengl/backend_opengl.c39
-rw-r--r--src/renderer/backends/opengl/opengl_helpers.h2
-rw-r--r--src/renderer/render.c1
4 files changed, 29 insertions, 14 deletions
diff --git a/src/maths/maths.h b/src/maths/maths.h
index 217f2e0..45d69c1 100644
--- a/src/maths/maths.h
+++ b/src/maths/maths.h
@@ -10,6 +10,7 @@
#include <math.h>
#include <stdio.h>
+#include "defines.h"
#include "maths_types.h"
// --- Helpers
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c
index 073f343..17587a2 100644
--- a/src/renderer/backends/opengl/backend_opengl.c
+++ b/src/renderer/backends/opengl/backend_opengl.c
@@ -1,12 +1,11 @@
#include <stddef.h>
+#include <stdio.h>
#include "colours.h"
#include "opengl_helpers.h"
#include "ral_types.h"
-#define CEL_REND_BACKEND_OPENGL 1
#if defined(CEL_REND_BACKEND_OPENGL)
#include <assert.h>
#include <stdlib.h>
-#include "camera.h"
#include "backend_opengl.h"
#include "defines.h"
@@ -55,6 +54,7 @@ bool gpu_backend_init(const char* window_name, struct GLFWwindow* window) {
}
glEnable(GL_DEPTH_TEST);
+ // glFrontFace(GL_CW);
return true;
}
@@ -62,7 +62,7 @@ bool gpu_backend_init(const char* window_name, struct GLFWwindow* window) {
void gpu_backend_shutdown() {}
bool gpu_device_create(gpu_device* out_device) { /* No-op in OpenGL */ }
-void gpu_device_destroy() {}
+void gpu_device_destroy() { /* No-op in OpenGL */ }
// --- Render Pipeline
gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc description) {
@@ -91,8 +91,20 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip
NULL); // no data right now
pipeline->uniform_bindings[binding_id] = ubo_handle;
gpu_buffer* ubo_buf = BUFFER_GET(ubo_handle);
+
+ u32 blockIndex = glGetUniformBlockIndex(pipeline->shader_id, "Matrices");
+ printf("Block index for Matrices: %d", blockIndex);
+ u32 blocksize;
+ glGetActiveUniformBlockiv(pipeline->shader_id, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE,
+ &blocksize);
+ printf("\t with size %d bytes\n", blocksize);
+
glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo);
glBindBufferBase(GL_UNIFORM_BUFFER, binding_j, ubo_buf->id.ubo);
+ if (blockIndex != GL_INVALID_INDEX) {
+ printf("Here\n");
+ glUniformBlockBinding(pipeline->shader_id, blockIndex, 0);
+ }
// Now we want to store a handle associated with the shader for this
}
@@ -151,7 +163,7 @@ void copy_buffer_to_image_oneshot(buffer_handle src, texture_handle dst) {}
// --- Render commands
void encode_bind_pipeline(gpu_cmd_encoder* encoder, pipeline_kind kind, gpu_pipeline* pipeline) {
encoder->pipeline = pipeline;
- // In OpenGL this is more or less equivalent to just setting the shader
+ // In OpenGL binding a pipeline is more or less equivalent to just setting the shader
glUseProgram(pipeline->shader_id);
}
void encode_bind_shader_data(gpu_cmd_encoder* encoder, u32 group, shader_data* data) {
@@ -159,14 +171,16 @@ void encode_bind_shader_data(gpu_cmd_encoder* encoder, u32 group, shader_data* d
for (u32 i = 0; i < sdl.bindings_count; i++) {
shader_binding binding = sdl.bindings[i];
- print_shader_binding(binding);
+ /* print_shader_binding(binding); */
if (binding.type == SHADER_BINDING_BYTES) {
buffer_handle b = encoder->pipeline->uniform_bindings[i];
gpu_buffer* ubo_buf = BUFFER_GET(b);
glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo);
glBufferSubData(GL_UNIFORM_BUFFER, 0, ubo_buf->size, data->data);
- glBindBuffer(GL_UNIFORM_BUFFER, 0);
+ /* printf("Size %d\n", ubo_buf->size); */
+
+ /* glBindBuffer(GL_UNIFORM_BUFFER, 0); */
}
}
}
@@ -174,6 +188,7 @@ void encode_set_default_settings(gpu_cmd_encoder* encoder) {}
void encode_set_vertex_buffer(gpu_cmd_encoder* encoder, buffer_handle buf) {
gpu_buffer* buffer = BUFFER_GET(buf);
if (buffer->vao == 0) { // if no VAO for this vertex buffer, create it
+ INFO("Setting up VAO");
buffer->vao = opengl_bindcreate_vao(buffer, encoder->pipeline->vertex_desc);
}
glBindVertexArray(buffer->vao);
@@ -208,7 +223,7 @@ buffer_handle gpu_buffer_create(u64 size, gpu_buffer_type buf_type, gpu_buffer_f
case CEL_BUFFER_UNIFORM:
DEBUG("Creating Uniform buffer");
gl_buf_type = GL_UNIFORM_BUFFER;
- gl_buf_usage = GL_DYNAMIC_DRAW;
+ /* gl_buf_usage = GL_DYNAMIC_DRAW; */
buffer->id.ubo = gl_buffer_id;
break;
case CEL_BUFFER_DEFAULT:
@@ -254,7 +269,10 @@ bytebuffer vertices_as_bytebuffer(arena* a, vertex_format format, vertex_darray*
// --- TEMP
bool gpu_backend_begin_frame() { return true; }
-void gpu_backend_end_frame() { glfwSwapBuffers(context.window); }
+void gpu_backend_end_frame() {
+ // TODO: Reset all bindings
+ glfwSwapBuffers(context.window);
+}
void gpu_temp_draw(size_t n_verts) {}
u32 shader_create_separate(const char* vert_shader, const char* frag_shader) {
@@ -370,9 +388,4 @@ inline void uniform_mat4f(u32 program_id, const char* uniform_name, mat4* value)
// break;
// }
// }
-
-// void draw_primitives(cel_primitive_topology primitive, u32 start_index, u32 count) {
-// u32 gl_primitive = to_gl_prim_topology(primitive);
-// glDrawArrays(gl_primitive, start_index, count);
-// }
#endif
diff --git a/src/renderer/backends/opengl/opengl_helpers.h b/src/renderer/backends/opengl/opengl_helpers.h
index 405a8f1..a3c4014 100644
--- a/src/renderer/backends/opengl/opengl_helpers.h
+++ b/src/renderer/backends/opengl/opengl_helpers.h
@@ -54,7 +54,7 @@ static u32 opengl_bindcreate_vao(gpu_buffer* buf, vertex_description desc) {
u32 attr_count = desc.attributes_count;
printf("N attributes %d\n", attr_count);
u64 offset = 0;
- size_t vertex_size = desc.stride;
+ size_t vertex_size = desc.use_full_vertex_size ? sizeof(vertex) : desc.stride;
for (u32 i = 0; i < desc.attributes_count; i++) {
opengl_vertex_attr format = format_from_vertex_attr(desc.attributes[i]);
glVertexAttribPointer(i, format.count, format.data_type, GL_FALSE, vertex_size, (void*)offset);
diff --git a/src/renderer/render.c b/src/renderer/render.c
index 5723c9e..7833ac9 100644
--- a/src/renderer/render.c
+++ b/src/renderer/render.c
@@ -161,6 +161,7 @@ void draw_mesh(mesh* mesh, mat4* model) { // , mat4* view, mat4* proj) {
}
// Assume this has already been done
/* encode_bind_shader_data(enc, 0, &mvp_uniforms_data); */
+
encode_draw_indexed(enc, mesh->index_count);
}