summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmniscient <omniscient.oce@gmail.com>2024-06-07 12:37:52 +1000
committerOmniscient <omniscient.oce@gmail.com>2024-06-07 12:37:52 +1000
commit037cb840dfb90264cd1bef36736cefb3cf7f2dd9 (patch)
tree2e688d3a113bf3bf763e63813dfc00e6ca98c898
parent4cbb8a9ec77620e6d3c0e4063b249e9cd8df46af (diff)
upload data when available on buffer creation
-rw-r--r--src/renderer/backends/opengl/backend_opengl.c17
-rw-r--r--src/renderer/backends/opengl/backend_opengl.h3
-rw-r--r--src/renderer/backends/opengl/opengl_helpers.h1
3 files changed, 17 insertions, 4 deletions
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c
index 0cd2925..529a0d9 100644
--- a/src/renderer/backends/opengl/backend_opengl.c
+++ b/src/renderer/backends/opengl/backend_opengl.c
@@ -151,24 +151,35 @@ buffer_handle gpu_buffer_create(u64 size, gpu_buffer_type buf_type, gpu_buffer_f
GLuint gl_buffer_id;
glGenBuffers(1, &gl_buffer_id);
+ GLenum gl_buf_type;
+
switch (buf_type) {
case CEL_BUFFER_UNIFORM:
- glBindBuffer(GL_UNIFORM_BUFFER, gl_buffer_id);
+ gl_buf_type = GL_UNIFORM_BUFFER;
break;
case CEL_BUFFER_DEFAULT:
case CEL_BUFFER_VERTEX:
- glBindBuffer(GL_ARRAY_BUFFER, gl_buffer_id);
+ gl_buf_type = GL_ARRAY_BUFFER;
break;
case CEL_BUFFER_INDEX:
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl_buffer_id);
+ gl_buf_type = GL_ELEMENT_ARRAY_BUFFER;
break;
default:
WARN("Unimplemented gpu_buffer_type provided %s", buffer_type_names[buf_type]);
break;
}
+ // bind buffer
+ glBindBuffer(gl_buf_type, gl_buffer_id);
+ // "allocating" the cpu-side buffer struct
buffer_handle handle;
gpu_buffer* buffer = buffer_pool_alloc(&context.resource_pools->buffers, &handle);
+ buffer->size = size;
+
+ if (data) {
+ TRACE("Upload data as part of buffer creation");
+ glBufferData(gl_buf_type, buffer->size, data, GL_STATIC_DRAW);
+ }
return handle;
}
diff --git a/src/renderer/backends/opengl/backend_opengl.h b/src/renderer/backends/opengl/backend_opengl.h
index 14a46f9..876cfe4 100644
--- a/src/renderer/backends/opengl/backend_opengl.h
+++ b/src/renderer/backends/opengl/backend_opengl.h
@@ -32,7 +32,8 @@ typedef struct gpu_buffer {
u32 vbo;
u32 ibo;
} id;
- u32 pad;
+ u32 vao; // Optional
+ u64 size;
} gpu_buffer;
typedef struct gpu_texture {
void *pad
diff --git a/src/renderer/backends/opengl/opengl_helpers.h b/src/renderer/backends/opengl/opengl_helpers.h
new file mode 100644
index 0000000..6f70f09
--- /dev/null
+++ b/src/renderer/backends/opengl/opengl_helpers.h
@@ -0,0 +1 @@
+#pragma once