Initial commit
This commit is contained in:
97
renderer/render_pass.jai
Normal file
97
renderer/render_pass.jai
Normal file
@@ -0,0 +1,97 @@
|
||||
DEPTH_STENCIL_SLOT :: 42;
|
||||
|
||||
// The slots used by the render pass render targets
|
||||
// Slots 10-17 are reserved for the passes
|
||||
Render_Target_Shader_Slots :: enum {
|
||||
SLOT0 :: 10;
|
||||
SLOT1 :: 11;
|
||||
SLOT2 :: 12;
|
||||
SLOT3 :: 13;
|
||||
SLOT4 :: 14;
|
||||
SLOT5 :: 15;
|
||||
SLOT6 :: 16;
|
||||
SLOT7 :: 17;
|
||||
}
|
||||
|
||||
Render_Target_Info :: struct {
|
||||
format: Format;
|
||||
width: u32;
|
||||
height: u32;
|
||||
|
||||
clear_color: Color;
|
||||
}
|
||||
|
||||
Depth_Stencil_Info :: struct {
|
||||
enabled: bool;
|
||||
format: Format;
|
||||
width: u32;
|
||||
height: u32;
|
||||
}
|
||||
|
||||
Render_Pass_Input_Info :: struct {
|
||||
pass_handle: Render_Pass_Handle;
|
||||
rt_index: u32; // the index into the render pass
|
||||
}
|
||||
|
||||
Render_Pass :: struct {
|
||||
name: string;
|
||||
|
||||
inputs: [..] Render_Pass_Input_Info;
|
||||
|
||||
uses_backbuffer: bool;
|
||||
render_targets: [..] Render_Target_Handle;
|
||||
clear_colors: [..] Color;
|
||||
depth_stencil: Depth_Stencil_Buffer_Handle;
|
||||
has_depth_stencil: bool;
|
||||
|
||||
width: u32;
|
||||
height: u32;
|
||||
|
||||
callback: (pass: Render_Pass);
|
||||
}
|
||||
|
||||
create_render_pass :: (graph: *Render_Graph, name: string, callback: (Render_Pass), render_target_infos: [] Render_Target_Info = .[], depth_stencil_info : Depth_Stencil_Info = .{}, uses_backbuffer: bool = false) -> Render_Pass_Handle {
|
||||
render_pass : Render_Pass;
|
||||
render_pass.name = copy_string(name);
|
||||
render_pass.uses_backbuffer = uses_backbuffer;
|
||||
render_pass.callback = callback;
|
||||
|
||||
if depth_stencil_info.enabled {
|
||||
render_pass.has_depth_stencil = true;
|
||||
render_pass.depth_stencil = create_depth_stencil_buffer(depth_stencil_info.width, depth_stencil_info.height, 0);
|
||||
render_pass.width = depth_stencil_info.width;
|
||||
render_pass.height = depth_stencil_info.height;
|
||||
}
|
||||
|
||||
array_reserve(*render_pass.render_targets, render_target_infos.count);
|
||||
array_reserve(*render_pass.clear_colors, render_target_infos.count);
|
||||
|
||||
for render_target_infos {
|
||||
array_add(*render_pass.render_targets, create_render_target(it.width, it.height, it.format));
|
||||
array_add(*render_pass.clear_colors, it.clear_color);
|
||||
render_pass.width = it.width;
|
||||
render_pass.height = it.height;
|
||||
}
|
||||
|
||||
return parray_add(*graph.render_passes, render_pass);
|
||||
}
|
||||
|
||||
add_render_pass_input :: (graph: *Render_Graph, to_pass: Render_Pass_Handle, from_pass: Render_Pass_Handle, rt_index: u32) {
|
||||
info : Render_Pass_Input_Info;
|
||||
info.pass_handle = from_pass;
|
||||
info.rt_index = rt_index;
|
||||
|
||||
pass := parray_get(*graph.render_passes, to_pass);
|
||||
array_add(*pass.inputs, info);
|
||||
}
|
||||
|
||||
get_texture_from_pass :: (name: string) -> Texture_Handle {
|
||||
for renderer.render_graph.render_passes {
|
||||
if it.name == name {
|
||||
rt := parray_get(renderer.render_targets, it.render_targets[0]);
|
||||
return rt.texture;
|
||||
}
|
||||
}
|
||||
|
||||
return xx 0;
|
||||
}
|
||||
Reference in New Issue
Block a user