diff options
Diffstat (limited to 'src/renderer')
-rw-r--r-- | src/renderer/backends/opengl/backend_opengl.c | 13 | ||||
-rw-r--r-- | src/renderer/backends/opengl/backend_opengl.h | 1 | ||||
-rw-r--r-- | src/renderer/builtin_materials.h | 81 | ||||
-rw-r--r-- | src/renderer/ral.c | 9 | ||||
-rw-r--r-- | src/renderer/render.h | 10 | ||||
-rw-r--r-- | src/renderer/render_types.h | 7 | ||||
-rw-r--r-- | src/renderer/static_pipeline.h | 4 |
7 files changed, 103 insertions, 22 deletions
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c index 5a11f39..478ba0c 100644 --- a/src/renderer/backends/opengl/backend_opengl.c +++ b/src/renderer/backends/opengl/backend_opengl.c @@ -55,7 +55,7 @@ bool gpu_backend_init(const char* window_name, struct GLFWwindow* window) { } glEnable(GL_DEPTH_TEST); - // glFrontFace(GL_CW); + glEnable(GL_CULL_FACE); return true; } @@ -93,8 +93,13 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip pipeline->uniform_bindings[binding_id] = ubo_handle; gpu_buffer* ubo_buf = BUFFER_GET(ubo_handle); - u32 blockIndex = glGetUniformBlockIndex(pipeline->shader_id, "Matrices"); - printf("Block index for Matrices: %d", blockIndex); + i32 blockIndex = glGetUniformBlockIndex(pipeline->shader_id, binding.label); + /* 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); + } u32 blocksize; glGetActiveUniformBlockiv(pipeline->shader_id, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, &blocksize); @@ -259,7 +264,7 @@ buffer_handle gpu_buffer_create(u64 size, gpu_buffer_type buf_type, gpu_buffer_f TRACE("Upload data (%d bytes) as part of buffer creation", size); glBufferData(gl_buf_type, buffer->size, data, gl_buf_usage); } else { - TRACE("Allocating the correct size anyway"); + TRACE("Allocating but not uploading (%d bytes)", size); glBufferData(gl_buf_type, buffer->size, NULL, gl_buf_usage); } diff --git a/src/renderer/backends/opengl/backend_opengl.h b/src/renderer/backends/opengl/backend_opengl.h index ccdb446..cde52a3 100644 --- a/src/renderer/backends/opengl/backend_opengl.h +++ b/src/renderer/backends/opengl/backend_opengl.h @@ -47,7 +47,6 @@ typedef struct gpu_texture { } gpu_texture; typedef struct opengl_support { - } opengl_support; u32 shader_create_separate(const char *vert_shader, const char *frag_shader); diff --git a/src/renderer/builtin_materials.h b/src/renderer/builtin_materials.h new file mode 100644 index 0000000..c284acc --- /dev/null +++ b/src/renderer/builtin_materials.h @@ -0,0 +1,81 @@ +/** + * @file builtin_materials.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2024-06-15 + * + * @copyright Copyright (c) 2024 + * + */ +#pragma once + +#include "colours.h" +#include "defines.h" +#include "ral.h" +#include "ral_types.h" + +// Currently supported materials +// - Blinn Phong (textured) +// - PBR (params) +// - PBR (textured) + +// Thoughts +// -------- +// +// A material and a shader are inextricably linked. The input data for a shader needs the material. +// However, a shader may require more than just a material? + +// --- Common uniform blocks + +/* In glsl code we call it 'MVP_Matrices' */ +typedef struct mvp_matrix_uniforms { + mat4 model; + mat4 view; + mat4 projection; +} mvp_matrix_uniforms; + +// --- PBR (params) + +typedef struct pbr_params_material_uniforms { + vec3 albedo; + f32 metallic; + f32 roughness; + f32 ao; +} pbr_params_material_uniforms; + +typedef struct pbr_params_light_uniforms { + vec3 viewPos; + // TODO: PointLights + +} pbr_params_light_uniforms; + +typedef struct pbr_params_bindgroup { + mvp_matrix_uniforms mvp_matrices; + pbr_params_material_uniforms material; + pbr_params_light_uniforms lights; +} pbr_params_bindgroup; + +static shader_data_layout pbr_params_shader_layout(void* data) { + pbr_params_bindgroup* d = (pbr_params_bindgroup*)data; + bool has_data = data != NULL; + + shader_binding b1 = { .label = "MVP_Matrices", + .type = SHADER_BINDING_BYTES, + .stores_data = has_data, + .data = { .bytes = { .size = sizeof(mvp_matrix_uniforms) } } }; + + shader_binding b2 = { .label = "PBR_Params", + .type = SHADER_BINDING_BYTES, + .stores_data = has_data, + .data = { .bytes = { .size = sizeof(pbr_params_material_uniforms) } } }; + + shader_binding b3 = { .label = "Scene_Lights", + .type = SHADER_BINDING_BYTES, + .stores_data = has_data, + .data = { .bytes = { .size = sizeof(pbr_params_light_uniforms) } } }; + + return (shader_data_layout){ .name = "pbr_params", .bindings = { b1, b2, b3 }, .bindings_count = 3 + + }; +} diff --git a/src/renderer/ral.c b/src/renderer/ral.c index 123c932..e73843b 100644 --- a/src/renderer/ral.c +++ b/src/renderer/ral.c @@ -42,10 +42,11 @@ void vertex_desc_add(vertex_description* builder, const char* name, vertex_attri } vertex_description static_3d_vertex_description() { - vertex_description builder = { .debug_label = "vertex" }; - vertex_desc_add(&builder, "position", ATTR_F32x3); - vertex_desc_add(&builder, "normal", ATTR_F32x3); - vertex_desc_add(&builder, "texCoords", ATTR_F32x2); + vertex_description builder = { .debug_label = "Standard static 3d vertex format" }; + vertex_desc_add(&builder, "inPosition", ATTR_F32x3); + vertex_desc_add(&builder, "inNormal", ATTR_F32x3); + vertex_desc_add(&builder, "inTexCoords", ATTR_F32x2); + builder.use_full_vertex_size = true; return builder; } diff --git a/src/renderer/render.h b/src/renderer/render.h index 35e2899..4e8035e 100644 --- a/src/renderer/render.h +++ b/src/renderer/render.h @@ -66,14 +66,8 @@ texture_data texture_data_load(const char* path, bool invert_y); texture_handle texture_data_upload(texture_data data, bool free_on_upload); /** @brief load all of the texture for a PBR material and returns an unnamed material */ -material pbr_material_load( - char* albedo_path, - char* normal_path, - bool metal_roughness_combined, - char* metallic_path, - char* roughness_map, - char* ao_map -); +material pbr_material_load(char* albedo_path, char* normal_path, bool metal_roughness_combined, + char* metallic_path, char* roughness_map, char* ao_map); buffer_handle buffer_create(const char* debug_name, u64 size); bool buffer_destroy(buffer_handle buffer); diff --git a/src/renderer/render_types.h b/src/renderer/render_types.h index 1485ae4..8588b87 100644 --- a/src/renderer/render_types.h +++ b/src/renderer/render_types.h @@ -10,10 +10,10 @@ */ #pragma once +#include "colours.h" #include "defines.h" #include "ral.h" #include "ral_types.h" -#include "colours.h" #if defined(CEL_PLATFORM_WINDOWS) // #include "backend_dx11.h" #endif @@ -66,10 +66,11 @@ typedef struct texture_data { typedef enum material_kind { MAT_BLINN_PHONG, MAT_PBR, - MAT_PBR_PARAMS, // uses float values to represent a surface uniformly + MAT_PBR_PARAMS, // uses float values to represent a surface uniformly MAT_COUNT } material_kind; -static const char* material_kind_names[] = { "Blinn Phong", "PBR (Textures)", "PBR (Params)", "Count (This should be an error)"}; +static const char* material_kind_names[] = { "Blinn Phong", "PBR (Textures)", "PBR (Params)", + "Count (This should be an error)" }; typedef struct blinn_phong_material { char name[256]; diff --git a/src/renderer/static_pipeline.h b/src/renderer/static_pipeline.h index 78f09f2..15e8842 100644 --- a/src/renderer/static_pipeline.h +++ b/src/renderer/static_pipeline.h @@ -1,6 +1,6 @@ #pragma once -#include "maths_types.h" #include "defines.h" +#include "maths_types.h" #include "ral.h" #include "ral_types.h" #include "render_types.h" @@ -26,5 +26,5 @@ static shader_data_layout mvp_uniforms_layout(void* data) { if (has_data) { b1.data.bytes.data = &d->mvp; } - return (shader_data_layout){ .name = "global_ubo", .bindings = { b1}, .bindings_count = 1 }; + return (shader_data_layout){ .name = "global_ubo", .bindings = { b1 }, .bindings_count = 1 }; } |