From d52654dfdbe16345023fed4c61261dc4c66b96fe Mon Sep 17 00:00:00 2001 From: Omniscient Date: Sat, 15 Jun 2024 22:20:15 +1000 Subject: trying to figure out uniform structs.. --- src/renderer/backends/opengl/backend_opengl.c | 16 ++++++++++++++-- src/renderer/builtin_materials.h | 18 +++++++++++++++++- src/renderer/render.c | 4 ++-- 3 files changed, 33 insertions(+), 5 deletions(-) (limited to 'src/renderer') diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c index 478ba0c..eb9ad83 100644 --- a/src/renderer/backends/opengl/backend_opengl.c +++ b/src/renderer/backends/opengl/backend_opengl.c @@ -1,6 +1,8 @@ #include #include +#include "builtin_materials.h" #include "colours.h" +#include "maths.h" #include "opengl_helpers.h" #include "ral_types.h" #define CEL_REND_BACKEND_OPENGL @@ -67,6 +69,7 @@ void gpu_device_destroy() { /* No-op in OpenGL */ } // --- Render Pipeline gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc description) { + static u32 ubo_count = 0; gpu_pipeline* pipeline = pipeline_pool_alloc(&context.gpu_pools.pipelines, NULL); // Create shader program @@ -182,16 +185,25 @@ 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); 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); glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo); - glBufferSubData(GL_UNIFORM_BUFFER, 0, ubo_buf->size, data->data); + if (i == 2) { + vec3* v = binding.data.bytes.data; + print_vec3(*v); + (*v).x = 0.0; + (*v).y = 0.0; + (*v).z = 1.0; + } + + 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 740ab3d..8d84e53 100644 --- a/src/renderer/builtin_materials.h +++ b/src/renderer/builtin_materials.h @@ -10,8 +10,10 @@ */ #pragma once +#include #include "colours.h" #include "defines.h" +#include "maths.h" #include "ral.h" #include "ral_types.h" @@ -51,7 +53,7 @@ typedef struct pbr_point_light { typedef struct pbr_params_light_uniforms { vec3 viewPos; - pbr_point_light pointLights[4]; + /* pbr_point_light pointLights[4]; */ } pbr_params_light_uniforms; typedef struct pbr_params_bindgroup { @@ -79,7 +81,21 @@ 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) { + 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); + } + return (shader_data_layout){ .name = "pbr_params", .bindings = { b1, b2, b3 }, .bindings_count = 3 }; } + +static void* shader_layout_get_binding(shader_data_layout* layout, u32 nth_binding) { + assert(nth_binding < layout->bindings_count); + return &layout->bindings[nth_binding].data; +} diff --git a/src/renderer/render.c b/src/renderer/render.c index 351a7e0..1c98b0b 100644 --- a/src/renderer/render.c +++ b/src/renderer/render.c @@ -62,7 +62,7 @@ bool renderer_init(renderer* ren) { resource_pools_init(&pool_arena, ren->resource_pools); // Create default rendering pipeline - default_pipelines_init(ren); + /* default_pipelines_init(ren); */ return true; } @@ -284,4 +284,4 @@ material pbr_material_load(char* albedo_path, char* normal_path, bool metal_roug m.mat_data.pbr.metallic_map = texture_data_upload(tex_data, true); return m; -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2