summaryrefslogtreecommitdiff
path: root/src/renderer
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-16 01:21:12 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-16 01:21:12 +1000
commit60d1e086242940993432a40a934241dc40b7382c (patch)
tree1f7a16dd4ad527d3c9f201f616d3f1490445009b /src/renderer
parentd52654dfdbe16345023fed4c61261dc4c66b96fe (diff)
uniform blocks working. fix spec highlight bug tomorrow
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/backends/opengl/backend_opengl.c27
-rw-r--r--src/renderer/builtin_materials.h11
2 files changed, 26 insertions, 12 deletions
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c
index eb9ad83..18e7d2a 100644
--- a/src/renderer/backends/opengl/backend_opengl.c
+++ b/src/renderer/backends/opengl/backend_opengl.c
@@ -97,11 +97,11 @@ 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 {
- DEBUG("Retrived block index %d for %s", blockIndex, binding.label);
+ // DEBUG("Retrived block index %d for %s", blockIndex, binding.label);
}
u32 blocksize;
glGetActiveUniformBlockiv(pipeline->shader_id, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE,
@@ -111,7 +111,7 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip
glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo);
glBindBufferBase(GL_UNIFORM_BUFFER, binding_j, ubo_buf->id.ubo);
if (blockIndex != GL_INVALID_INDEX) {
- glUniformBlockBinding(pipeline->shader_id, blockIndex, 0);
+ glUniformBlockBinding(pipeline->shader_id, blockIndex, binding_j);
}
// Now we want to store a handle associated with the shader for this
@@ -185,25 +185,36 @@ void encode_bind_pipeline(gpu_cmd_encoder* encoder, pipeline_kind kind, gpu_pipe
}
void encode_bind_shader_data(gpu_cmd_encoder* encoder, u32 group, shader_data* data) {
shader_data_layout sdl = data->shader_data_get_layout(data->data);
- printf("Binding %s shader data\n", sdl.name);
+ // printf("Binding %s shader data\n", sdl.name);
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);
+
+ i32 blockIndex = glGetUniformBlockIndex(encoder->pipeline->shader_id, binding.label);
+ 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);
+ }
+
glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo);
+ glBindBufferBase(GL_UNIFORM_BUFFER, i, ubo_buf->id.ubo);
if (i == 2) {
- vec3* v = binding.data.bytes.data;
- print_vec3(*v);
+ pbr_params_light_uniforms* u = binding.data.bytes.data;
+ vec4* v = &u->viewPos;
(*v).x = 0.0;
(*v).y = 0.0;
(*v).z = 1.0;
+ // print_vec3(*v);
}
-
+ // glBindBufferBase(GL_UNIFORM_BUFFER, i, ubo_buf->id.ubo);
glBufferSubData(GL_UNIFORM_BUFFER, 0, ubo_buf->size, binding.data.bytes.data);
+
} else if (binding.type == SHADER_BINDING_TEXTURE) {
gpu_texture* tex = TEXTURE_GET(binding.data.texture.handle);
glActiveTexture(GL_TEXTURE0);
diff --git a/src/renderer/builtin_materials.h b/src/renderer/builtin_materials.h
index 8d84e53..7748599 100644
--- a/src/renderer/builtin_materials.h
+++ b/src/renderer/builtin_materials.h
@@ -44,16 +44,19 @@ typedef struct pbr_params_material_uniforms {
f32 metallic;
f32 roughness;
f32 ao;
+ f32 pad[2];
} pbr_params_material_uniforms;
typedef struct pbr_point_light {
vec3 pos;
+ f32 pad;
vec3 color;
+ f32 pad2;
} pbr_point_light;
typedef struct pbr_params_light_uniforms {
- vec3 viewPos;
- /* pbr_point_light pointLights[4]; */
+ pbr_point_light pointLights[4];
+ vec4 viewPos;
} pbr_params_light_uniforms;
typedef struct pbr_params_bindgroup {
@@ -81,13 +84,13 @@ static shader_data_layout pbr_params_shader_layout(void* data) {
.stores_data = has_data,
.data = { .bytes = { .size = sizeof(pbr_params_light_uniforms) } } };
- printf("Size %d \n", b3.data.bytes.size);
if (has_data) {
+ // printf("Size %d \n", b3.data.bytes.size);
b1.data.bytes.data = &d->mvp_matrices;
b2.data.bytes.data = &d->material;
/* d->lights.viewPos = vec3(0, 1, 0); */
b3.data.bytes.data = &d->lights;
- print_vec3(d->lights.viewPos);
+ // print_vec3(d->lights.viewPos);
}
return (shader_data_layout){ .name = "pbr_params", .bindings = { b1, b2, b3 }, .bindings_count = 3