summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-16 22:40:18 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-16 22:40:18 +1000
commitdd1e090e1416f21537637dac0b4fda20d322cb56 (patch)
tree3900c679c1cc42946f2a5f3335e390b53a3bcc48
parent3c9d08717cd129c1576ea91e5bd4b7b8e0af9885 (diff)
store ubo binding points inside the gpu_buffer data
-rw-r--r--examples/pbr_params/ex_pbr_params.c33
-rw-r--r--src/maths/primitives.c5
-rw-r--r--src/renderer/backends/opengl/backend_opengl.c13
3 files changed, 27 insertions, 24 deletions
diff --git a/examples/pbr_params/ex_pbr_params.c b/examples/pbr_params/ex_pbr_params.c
index fbe5f3a..0d8ade4 100644
--- a/examples/pbr_params/ex_pbr_params.c
+++ b/examples/pbr_params/ex_pbr_params.c
@@ -49,7 +49,7 @@ int main() {
point_lights[i].color = vec3(300.0, 300.0, 300.0);
}
- vec3 camera_pos = vec3(1.,1., -25.);
+ vec3 camera_pos = vec3(1., 1., -25.);
vec3 camera_front = vec3_normalise(vec3_negate(camera_pos));
camera cam = camera_create(camera_pos, camera_front, VEC3_Y, deg_to_rad(45.0));
@@ -120,45 +120,44 @@ int main() {
pbr_bind_data.lights = (pbr_params_light_uniforms){
.viewPos = vec4(cam.position.x, cam.position.y, cam.position.z, 1.0),
// .viewPos = cam.position,
- .pointLights = { point_lights[0], point_lights[1],
- point_lights[2], point_lights[3] }
+ .pointLights = { point_lights[0], point_lights[1], point_lights[2], point_lights[3] }
};
pbr_uniforms.data = &pbr_bind_data;
- // encode_bind_shader_data(enc, 0, &pbr_uniforms);
+// encode_bind_shader_data(enc, 0, &pbr_uniforms);
- // Record draw call
- /* draw_mesh(&sphere, &model_affine, &cam); */
- #if 0
+// Record draw call
+/* draw_mesh(&sphere, &model_affine, &cam); */
+#if 0
encode_set_vertex_buffer(enc, cube.vertex_buffer);
encode_set_index_buffer(enc, cube.index_buffer);
encode_draw_indexed(enc, cube.geometry->indices->len);
- #endif
+#endif
for (u32 row = 0; row < num_rows; row++) {
f32 metallic = (float)row / (float)num_rows;
for (u32 col = 0; col < num_cols; col++) {
f32 roughness = (float)col / (float)num_cols;
- if (roughness == 0.0) { roughness += 0.05; };
- if (roughness == 1.0) { roughness -= 0.05; };
+ if (roughness == 0.0) {
+ roughness += 0.05;
+ };
+ if (roughness == 1.0) {
+ roughness -= 0.05;
+ };
pbr_bind_data.material.metallic = metallic;
pbr_bind_data.material.roughness = roughness;
f32 x = (col - ((f32)num_cols / 2.)) * spacing;
f32 y = (row - ((f32)num_rows / 2.)) * spacing;
- mat4 model = mat4_translation(vec3(
- x,
- y,
- 0.0f
- ));
+ mat4 model = mat4_translation(vec3(x, y, 0.0f));
pbr_bind_data.mvp_matrices.model = model;
- encode_bind_shader_data(enc, 0, &pbr_uniforms);
+ encode_bind_shader_data(enc, 0, &pbr_uniforms);
encode_set_vertex_buffer(enc, sphere.vertex_buffer);
encode_set_index_buffer(enc, sphere.index_buffer);
encode_draw_indexed(enc, sphere.geometry->indices->len);
}
}
-
+
// End recording
gpu_cmd_encoder_end_render(enc);
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;