summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOmniscient <omniscient.oce@gmail.com>2024-06-15 22:20:15 +1000
committerOmniscient <omniscient.oce@gmail.com>2024-06-15 22:20:15 +1000
commitd52654dfdbe16345023fed4c61261dc4c66b96fe (patch)
tree49b9dc298ec8d01533c13c909d827f96192551a1 /src
parentb3b19f081231c7c13322c7b0d577afb6084d48df (diff)
trying to figure out uniform structs..
Diffstat (limited to 'src')
-rw-r--r--src/maths/primitives.c5
-rw-r--r--src/renderer/backends/opengl/backend_opengl.c16
-rw-r--r--src/renderer/builtin_materials.h18
-rw-r--r--src/renderer/render.c4
4 files changed, 38 insertions, 5 deletions
diff --git a/src/maths/primitives.c b/src/maths/primitives.c
index 86f9261..86855db 100644
--- a/src/maths/primitives.c
+++ b/src/maths/primitives.c
@@ -234,6 +234,11 @@ geometry_data geo_create_uvsphere(f32 radius, u32 north_south_lines, u32 east_we
}
}
+ for (int i = 0; i < vertices->len; i++) {
+
+ print_vec3(vertices->data[i].static_3d.normal);
+ }
+
geometry_data geo = {
.format = VERTEX_STATIC_3D,
.vertices = vertices,
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 <stddef.h>
#include <stdio.h>
+#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 <assert.h>
#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
+}