summaryrefslogtreecommitdiff
path: root/src/new_render
diff options
context:
space:
mode:
Diffstat (limited to 'src/new_render')
-rw-r--r--src/new_render/immdraw.c5
-rw-r--r--src/new_render/pbr.c34
-rw-r--r--src/new_render/shadows.c12
-rw-r--r--src/new_render/skybox.c9
4 files changed, 33 insertions, 27 deletions
diff --git a/src/new_render/immdraw.c b/src/new_render/immdraw.c
index c79afa0..c711b0c 100644
--- a/src/new_render/immdraw.c
+++ b/src/new_render/immdraw.c
@@ -14,14 +14,15 @@ void Immdraw_Init(Immdraw_Storage* storage) {
// storage->sphere = Mesh_Create(&sphere_geo, false);
// pipeline / material
- ShaderData camera_data = { .get_layout = &Binding_Camera_GetLayout };
+ ShaderDataLayout camera_data = Binding_Camera_GetLayout(NULL);
GraphicsPipelineDesc pipeline_desc = {
.debug_name = "Immediate Draw Pipeline",
.data_layouts = { camera_data },
.data_layouts_count = 1,
};
- // storage->colour_pipeline = GPU_GraphicsPipeline_Create(pipeline_desc, GPU_GetDefaultRenderpass());
+ // storage->colour_pipeline = GPU_GraphicsPipeline_Create(pipeline_desc,
+ // GPU_GetDefaultRenderpass());
}
void Immdraw_Sphere(Transform tf, f32 size, Vec4 colour, bool wireframe) {} \ No newline at end of file
diff --git a/src/new_render/pbr.c b/src/new_render/pbr.c
index 0581f4a..1e94e81 100644
--- a/src/new_render/pbr.c
+++ b/src/new_render/pbr.c
@@ -39,10 +39,10 @@ GPU_Pipeline* PBR_PipelineCreate(GPU_Renderpass* rpass) {
char* vert_shader = string_from_file(vert_path);
char* frag_shader = string_from_file(frag_path);
- ShaderData camera_data = { .get_layout = &Binding_Camera_GetLayout };
- ShaderData model_data = { .get_layout = &Binding_Model_GetLayout };
- ShaderData material_data = { .get_layout = &PBRMaterial_GetLayout };
- ShaderData lights_data = { .get_layout = &Binding_Lights_GetLayout };
+ ShaderDataLayout camera_data = Binding_Camera_GetLayout(NULL);
+ ShaderDataLayout model_data = Binding_Model_GetLayout(NULL);
+ ShaderDataLayout material_data = PBRMaterial_GetLayout(NULL);
+ ShaderDataLayout lights_data = Binding_Lights_GetLayout(NULL);
GraphicsPipelineDesc desc = {
.debug_name = "PBR Pipeline",
@@ -86,8 +86,7 @@ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_te
.projection = proj,
.viewPos = vec4(camera.position.x, camera.position.y,
camera.position.z, 1.0) };
- GPU_EncodeBindShaderData(
- enc, 0, (ShaderData){ .data = &camera_data, .get_layout = &Binding_Camera_GetLayout });
+ GPU_EncodeBindShaderData(enc, 0, Binding_Camera_GetLayout(&camera_data));
Vec3 light_color = vec3(300.0, 300.0, 300.0);
Binding_Lights
@@ -99,8 +98,7 @@ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_te
(pbr_point_light){ .pos = vec3(10, -10, 10), .color = light_color },
(pbr_point_light){ .pos = vec3(-10, -10, 10), .color = light_color },
} };
- GPU_EncodeBindShaderData(
- enc, 3, (ShaderData){ .data = &lights_data, .get_layout = &Binding_Lights_GetLayout });
+ GPU_EncodeBindShaderData(enc, 3, Binding_Lights_GetLayout(&lights_data));
// TODO: Add shadowmap texture to uniforms
Mesh_pool* mesh_pool = Render_GetMeshPool();
@@ -113,13 +111,11 @@ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_te
// upload material data
PBRMaterialUniforms material_data = { .mat = *mat };
- GPU_EncodeBindShaderData(
- enc, 2, (ShaderData){ .data = &material_data, .get_layout = PBRMaterial_GetLayout });
+ GPU_EncodeBindShaderData(enc, 2, PBRMaterial_GetLayout(&material_data));
// upload model transform
Binding_Model model_data = { .model = renderable.affine };
- GPU_EncodeBindShaderData(
- enc, 1, (ShaderData){ .data = &model_data, .get_layout = &Binding_Model_GetLayout });
+ GPU_EncodeBindShaderData(enc, 1, Binding_Model_GetLayout(&model_data));
// set buffers
GPU_EncodeSetVertexBuffer(enc, mesh->vertex_buffer);
@@ -131,6 +127,20 @@ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_te
GPU_CmdEncoder_EndRender(enc);
}
+void PBRMaterial_BindData(ShaderDataLayout* layout, const void* data) {
+ PBRMaterialUniforms* d = (PBRMaterialUniforms*)data;
+ CASSERT(data);
+ CASSERT(layout->binding_count == 5);
+
+ TextureHandle white1x1 = Render_GetWhiteTexture();
+ if (d->mat.albedo_map.raw != INVALID_TEX_HANDLE.raw) {
+ layout->bindings[0].data.texture.handle = d->mat.albedo_map;
+ } else {
+ layout->bindings[0].data.texture.handle = white1x1;
+ }
+ // TODO .. the rest
+}
+
ShaderDataLayout PBRMaterial_GetLayout(void* data) {
PBRMaterialUniforms* d = (PBRMaterialUniforms*)data;
bool has_data = data != NULL;
diff --git a/src/new_render/shadows.c b/src/new_render/shadows.c
index 92fce81..1ca9119 100644
--- a/src/new_render/shadows.c
+++ b/src/new_render/shadows.c
@@ -79,7 +79,7 @@ void Shadow_Init(Shadow_Storage* storage, u32 shadowmap_width, u32 shadowmap_hei
ERROR_EXIT("Failed to load shaders from disk");
}
- ShaderData uniforms = { .data = NULL, .get_layout = &ShadowUniforms_GetLayout };
+ ShaderDataLayout uniforms = ShadowUniforms_GetLayout(NULL);
GraphicsPipelineDesc pipeline_desc = {
.debug_name = "Shadows Pipeline",
@@ -109,7 +109,7 @@ void Shadow_Init(Shadow_Storage* storage, u32 shadowmap_width, u32 shadowmap_hei
ERROR_EXIT("Failed to load shaders from disk");
}
- ShaderData debugquad_uniforms = { .data = NULL, .get_layout = &ShadowDebugQuad_GetLayout };
+ ShaderDataLayout debugquad_uniforms = ShadowDebugQuad_GetLayout(NULL);
GraphicsPipelineDesc debugquad_pipeline_desc = {
.debug_name = "Shadows debug quad Pipeline",
@@ -164,8 +164,7 @@ void Shadow_DrawDebugQuad() {
GPU_CmdEncoder_BeginRender(enc, shadow_storage->debugquad_pass);
GPU_EncodeBindPipeline(enc, shadow_storage->debugquad_pipeline);
- ShaderData quad_data = { .data = &shadow_storage->depth_texture,
- .get_layout = ShadowDebugQuad_GetLayout };
+ ShaderDataLayout quad_data = ShadowDebugQuad_GetLayout(&shadow_storage->depth_texture);
GPU_EncodeBindShaderData(enc, 0, quad_data);
GPU_EncodeSetVertexBuffer(enc, shadow_storage->quad.vertex_buffer);
GPU_EncodeSetIndexBuffer(enc, shadow_storage->quad.index_buffer);
@@ -190,10 +189,7 @@ void Shadow_ShadowmapExecute(Shadow_Storage* storage, Mat4 light_space_transform
.light_space = light_space_transform,
.model = mat4_ident() // this will be overwritten for each Model
};
- ShaderData shader_data = {
- .data = &uniforms,
- .get_layout = &ShadowUniforms_GetLayout,
- };
+ ShaderDataLayout shader_data = ShadowUniforms_GetLayout(&uniforms);
for (size_t ent_i = 0; ent_i < entity_count; ent_i++) {
RenderEnt renderable = entities[ent_i];
diff --git a/src/new_render/skybox.c b/src/new_render/skybox.c
index 5456401..cc5797f 100644
--- a/src/new_render/skybox.c
+++ b/src/new_render/skybox.c
@@ -95,8 +95,8 @@ Skybox Skybox_Create(const char** face_paths, int n) {
// VertexDesc_AddAttr(&pos_only, "inPos", ATTR_F32x3);
// pos_only.use_full_vertex_size = true;
- ShaderData camera_data = { .data = NULL, .get_layout = &Binding_Camera_GetLayout };
- ShaderData shader_data = { .data = NULL, .get_layout = &Skybox_GetLayout };
+ ShaderDataLayout camera_data = Binding_Camera_GetLayout(NULL);
+ ShaderDataLayout shader_data = Skybox_GetLayout(NULL);
VertexDescription builder = { .debug_label = "pos only" };
VertexDesc_AddAttr(&builder, "inPosition", ATTR_F32x3);
@@ -151,11 +151,10 @@ void Skybox_Draw(Skybox* skybox, Camera camera) {
.projection = proj,
.viewPos = vec4(camera.position.x, camera.position.y,
camera.position.z, 1.0) };
- GPU_EncodeBindShaderData(
- enc, 0, (ShaderData){ .data = &camera_data, .get_layout = &Binding_Camera_GetLayout });
+ GPU_EncodeBindShaderData(enc, 0, Binding_Camera_GetLayout(&camera_data));
SkyboxUniforms uniforms = { .cubemap = skybox->texture };
- ShaderData skybox_data = { .data = &uniforms, .get_layout = &Skybox_GetLayout };
+ ShaderDataLayout skybox_data = Skybox_GetLayout(&uniforms);
GPU_EncodeBindShaderData(enc, 0, skybox_data);
GPU_EncodeSetVertexBuffer(enc, skybox->cube.vertex_buffer);