summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOmniscient <omniscient.oce@gmail.com>2024-06-07 12:10:53 +1000
committerOmniscient <omniscient.oce@gmail.com>2024-06-07 12:10:53 +1000
commit4976c723a7add3a1409eb529d088868a2c568fbb (patch)
tree1ca0f1fb33cb97d79722cae5b5571653b9e1689b /src
parentf553d66891e6f77b0fa78c279f51a44d1c51ff9f (diff)
add vertex/index buffer binding in opengl
Diffstat (limited to 'src')
-rw-r--r--src/renderer/backends/backend_vulkan.c16
-rw-r--r--src/renderer/backends/opengl/backend_opengl.c29
-rw-r--r--src/renderer/backends/opengl/backend_opengl.h14
-rw-r--r--src/renderer/ral_types.h8
-rw-r--r--src/resources/gltf.c5
-rw-r--r--src/resources/obj.c4
6 files changed, 49 insertions, 27 deletions
diff --git a/src/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c
index 25a78e7..4ef1e31 100644
--- a/src/renderer/backends/backend_vulkan.c
+++ b/src/renderer/backends/backend_vulkan.c
@@ -1690,15 +1690,15 @@ void vulkan_transition_image_layout(gpu_texture* texture, VkFormat format, VkIma
/* TYPED_POOL(gpu_buffer, buffer); */
/* TYPED_POOL(gpu_texture, texture); */
-void resource_pools_init(arena* a, struct resource_pools* res_pools) {
- buffer_pool buf_pool = buffer_pool_create(a, MAX_BUFFERS, sizeof(gpu_buffer));
- res_pools->buffers = buf_pool;
- texture_pool tex_pool = texture_pool_create(a, MAX_TEXTURES, sizeof(gpu_texture));
- res_pools->textures = tex_pool;
+/* void resource_pools_init(arena* a, struct resource_pools* res_pools) { */
+/* buffer_pool buf_pool = buffer_pool_create(a, MAX_BUFFERS, sizeof(gpu_buffer)); */
+/* res_pools->buffers = buf_pool; */
+/* texture_pool tex_pool = texture_pool_create(a, MAX_TEXTURES, sizeof(gpu_texture)); */
+/* res_pools->textures = tex_pool; */
- context.resource_pools = res_pools;
-}
+/* context.resource_pools = res_pools; */
+/* } */
-#endif \ No newline at end of file
+#endif
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c
index a933462..cb25b46 100644
--- a/src/renderer/backends/opengl/backend_opengl.c
+++ b/src/renderer/backends/opengl/backend_opengl.c
@@ -18,7 +18,9 @@
typedef struct opengl_context {
GLFWwindow* window;
arena pool_arena;
+ gpu_cmd_encoder command_buffer;
gpu_backend_pools gpu_pools;
+ struct resource_pools* resource_pools;
} opengl_context;
static opengl_context context;
@@ -35,13 +37,15 @@ bool gpu_backend_init(const char* window_name, struct GLFWwindow* window) {
context.pool_arena = arena_create(malloc(pool_buffer_size), pool_buffer_size);
backend_pools_init(&context.pool_arena, &context.gpu_pools);
+ context.resource_pools = malloc(sizeof(struct resource_pools));
+ resource_pools_init(&context.pool_arena, context.resource_pools);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
- // glad: load all OpenGL function pointers
+ // glad: load all opengl function pointers
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
ERROR("Failed to initialise GLAD \n");
return false;
@@ -53,7 +57,6 @@ bool gpu_backend_init(const char* window_name, struct GLFWwindow* window) {
}
void gpu_backend_shutdown() {}
-void resource_pools_init(arena* a, struct resource_pools* res_pools) {}
bool gpu_device_create(gpu_device* out_device) {}
void gpu_device_destroy() {}
@@ -102,7 +105,9 @@ void gpu_cmd_encoder_begin_render(gpu_cmd_encoder* encoder, gpu_renderpass* rend
}
void gpu_cmd_encoder_end_render(gpu_cmd_encoder* encoder) {}
void gpu_cmd_encoder_begin_compute() {}
-gpu_cmd_encoder* gpu_get_default_cmd_encoder() {}
+gpu_cmd_encoder* gpu_get_default_cmd_encoder() {
+ return &context.command_buffer;
+}
/** @brief Finish recording and return a command buffer that can be submitted to a queue */
gpu_cmd_buffer gpu_cmd_encoder_finish(gpu_cmd_encoder* encoder) {}
@@ -152,19 +157,23 @@ buffer_handle gpu_buffer_create(u64 size, gpu_buffer_type buf_type, gpu_buffer_f
switch (buf_type) {
case CEL_BUFFER_UNIFORM:
glBindBuffer(GL_UNIFORM_BUFFER, gl_buffer_id);
+ break;
case CEL_BUFFER_DEFAULT:
case CEL_BUFFER_VERTEX:
+ glBindBuffer(GL_ARRAY_BUFFER, gl_buffer_id);
+ break;
case CEL_BUFFER_INDEX:
- WARN("Unimplemented gpu_buffer_type!");
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl_buffer_id);
break;
- case CEL_BUFFER_COUNT:
- WARN("Incorrect gpu_buffer_type provided.");
+ default:
+ WARN("Unimplemented gpu_buffer_type provided %s", buffer_type_names[buf_type]);
break;
}
buffer_handle handle;
- gpu_buffer* buffer = buffer_pool_alloc(&context.resource_pools, &handle);
-
+ gpu_buffer* buffer = buffer_pool_alloc(&context.resource_pools->buffers, &handle);
+
+ return handle;
}
void gpu_buffer_destroy(buffer_handle buffer) {}
@@ -395,4 +404,4 @@ void uniform_mat4f(u32 program_id, const char *uniform_name, mat4 *value) {
// void set_shader(shader s) { glUseProgram(s.program_id); }
-#endif \ No newline at end of file
+#endif
diff --git a/src/renderer/backends/opengl/backend_opengl.h b/src/renderer/backends/opengl/backend_opengl.h
index 784c061..0ce765a 100644
--- a/src/renderer/backends/opengl/backend_opengl.h
+++ b/src/renderer/backends/opengl/backend_opengl.h
@@ -9,21 +9,23 @@ typedef struct gpu_swapchain {
u32x2 dimensions;
} gpu_swapchain;
typedef struct gpu_device {} gpu_device;
-typedef struct gpu_pipeline_layout {} gpu_pipeline_layout;
+typedef struct gpu_pipeline_layout { void* pad } gpu_pipeline_layout;
typedef struct gpu_pipeline {
u32 shader_id;
+ u32 pad;
} gpu_pipeline;
-typedef struct gpu_renderpass {} gpu_renderpass;
-typedef struct gpu_cmd_encoder {} gpu_cmd_encoder; // Recording
-typedef struct gpu_cmd_buffer {} gpu_cmd_buffer; // Ready for submission
+typedef struct gpu_renderpass { void* pad } gpu_renderpass;
+typedef struct gpu_cmd_encoder { void* pad } gpu_cmd_encoder; // Recording
+typedef struct gpu_cmd_buffer { void* pad } gpu_cmd_buffer; // Ready for submission
typedef struct gpu_buffer {
union {
u32 vbo;
u32 ibo;
} id;
+ u32 pad;
} gpu_buffer;
-typedef struct gpu_texture {} gpu_texture;
+typedef struct gpu_texture { void* pad } gpu_texture;
u32 shader_create_separate(const char *vert_shader, const char *frag_shader);
@@ -32,4 +34,4 @@ void uniform_vec3f(u32 program_id, const char *uniform_name, vec3 *value);
void uniform_f32(u32 program_id, const char *uniform_name, f32 value);
void uniform_i32(u32 program_id, const char *uniform_name, i32 value);
void uniform_mat4f(u32 program_id, const char *uniform_name, mat4 *value);
-#endif \ No newline at end of file
+#endif
diff --git a/src/renderer/ral_types.h b/src/renderer/ral_types.h
index 704f2cb..5cbf6fd 100644
--- a/src/renderer/ral_types.h
+++ b/src/renderer/ral_types.h
@@ -77,6 +77,14 @@ typedef enum gpu_buffer_type {
CEL_BUFFER_COUNT
} gpu_buffer_type;
+static const char* buffer_type_names[] = {
+ "RAL Buffer Default",
+ "RAL Buffer Vertex",
+ "RAL Buffer Index",
+ "RAL Buffer Uniform",
+ "RAL Buffer Count",
+};
+
typedef enum gpu_buffer_flag {
CEL_BUFFER_FLAG_CPU = 1 << 0,
CEL_BUFFER_FLAG_GPU = 1 << 1,
diff --git a/src/resources/gltf.c b/src/resources/gltf.c
index 022bf95..61b99d7 100644
--- a/src/resources/gltf.c
+++ b/src/resources/gltf.c
@@ -47,7 +47,8 @@ model_handle model_load_gltf(struct core *core, const char *path, bool invert_te
model model = { 0 };
model.name = str8_cstr_view(path);
- model.meshes = mesh_darray_new(1);
+ // FIXME: Use mesh* malloc'd
+ /* model.meshes = mesh_darray_new(1); */
// model.materials = material_darray_new(1);
bool success =
@@ -771,4 +772,4 @@ bool model_load_gltf(const char *path, model *out_model) {
TRACE("Finished loading GLTF");
return true;
}
-*/ \ No newline at end of file
+*/
diff --git a/src/resources/obj.c b/src/resources/obj.c
index 888e16e..19d8657 100644
--- a/src/resources/obj.c
+++ b/src/resources/obj.c
@@ -54,7 +54,7 @@ model_handle model_load_obj(core *core, const char *path, bool invert_textures_y
model model = { 0 };
model.name = str8_cstr_view(path);
- model.meshes = mesh_darray_new(1);
+ /* model.meshes = mallocmesh_darray_new(1); */
// model.materials = material_darray_new(1);
bool success = model_load_obj_str(file_string, relative_path.path, &model, invert_textures_y);
@@ -228,6 +228,8 @@ bool model_load_obj_str(const char *file_string, str8 relative_path, model *out_
// // TODO: bounding box calculation for each mesh
// // TODO: bounding box calculation for model
+ // TODO: copy from mesh_darray to malloc'd mesh* array
+
return true;
}