diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-06-16 22:40:18 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-06-16 22:40:18 +1000 |
commit | dd1e090e1416f21537637dac0b4fda20d322cb56 (patch) | |
tree | 3900c679c1cc42946f2a5f3335e390b53a3bcc48 /src | |
parent | 3c9d08717cd129c1576ea91e5bd4b7b8e0af9885 (diff) |
store ubo binding points inside the gpu_buffer data
Diffstat (limited to 'src')
-rw-r--r-- | src/maths/primitives.c | 5 | ||||
-rw-r--r-- | src/renderer/backends/opengl/backend_opengl.c | 13 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/maths/primitives.c b/src/maths/primitives.c index 5d9c70f..327159d 100644 --- a/src/maths/primitives.c +++ b/src/maths/primitives.c @@ -179,8 +179,9 @@ geometry_data geo_create_uvsphere(f32 radius, u32 north_south_lines, u32 east_we // assert(d == radius); // all points on the sphere should be 'radius' away from the origin vertex v = { .static_3d = { .position = position, - .normal = vec3_normalise(position), // normal vector on sphere is same as position - .tex_coords = vec2(0, 0) // TODO + .normal = + vec3_normalise(position), // normal vector on sphere is same as position + .tex_coords = vec2(0, 0) // TODO } }; vertex_darray_push(vertices, v); } diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c index 9ae77b4..d9859b2 100644 --- a/src/renderer/backends/opengl/backend_opengl.c +++ b/src/renderer/backends/opengl/backend_opengl.c @@ -90,6 +90,7 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip assert(binding_id < MAX_PIPELINE_UNIFORM_BUFFERS); shader_binding binding = sdl.bindings[binding_j]; if (binding.type == SHADER_BINDING_BYTES) { + static u32 s_binding_point = 0; buffer_handle ubo_handle = gpu_buffer_create(binding.data.bytes.size, CEL_BUFFER_UNIFORM, CEL_BUFFER_FLAG_GPU, NULL); // no data right now @@ -97,7 +98,7 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip gpu_buffer* ubo_buf = BUFFER_GET(ubo_handle); i32 blockIndex = glGetUniformBlockIndex(pipeline->shader_id, binding.label); - printf("Block index for Matrices: %d", blockIndex); + printf("Block index for Matrices: %d", blockIndex); if (blockIndex < 0) { WARN("Couldn't retrieve block index for uniform block '%s'", binding.label); } else { @@ -109,10 +110,12 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip 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); + glBindBufferBase(GL_UNIFORM_BUFFER, s_binding_point, ubo_buf->id.ubo); if (blockIndex != GL_INVALID_INDEX) { - glUniformBlockBinding(pipeline->shader_id, blockIndex, binding_j); + glUniformBlockBinding(pipeline->shader_id, blockIndex, s_binding_point); } + ubo_buf->ubo_binding_point = s_binding_point; + s_binding_point++; // Now we want to store a handle associated with the shader for this } @@ -199,11 +202,11 @@ void encode_bind_shader_data(gpu_cmd_encoder* encoder, u32 group, shader_data* d if (blockIndex < 0) { WARN("Couldn't retrieve block index for uniform block '%s'", binding.label); } else { - DEBUG("Retrived block index %d for %s", blockIndex, binding.label); + // DEBUG("Retrived block index %d for %s", blockIndex, binding.label); } glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo); - glBindBufferBase(GL_UNIFORM_BUFFER, i, ubo_buf->id.ubo); + glBindBufferBase(GL_UNIFORM_BUFFER, ubo_buf->ubo_binding_point, ubo_buf->id.ubo); if (i == 2) { // pbr_params_light_uniforms* u = binding.data.bytes.data; // vec4* v = &u->viewPos; |