Restructured passes

This commit is contained in:
2026-01-31 02:31:19 +01:00
parent bd4b81d434
commit b6a32ebe7f
6 changed files with 356 additions and 248 deletions

View File

@@ -2,93 +2,51 @@ package renderer
import "core:mem"
import "core:log"
import "core:fmt"
PIPELINE_MAX_SCENE_PASSES :: 8
PIPELINE_MAX_POST_PROCESSING_PASSES :: 8
PIPELINE_MAX_PASSES :: 8
Pipeline :: struct {
scene_passes: [PIPELINE_MAX_SCENE_PASSES]^Scene_Pass,
amount_of_scene_passes: u8,
post_processing_passes: [PIPELINE_MAX_POST_PROCESSING_PASSES]^Post_Processing_Pass,
amount_of_post_processing_passes: u8,
fullscreen_material: ^Material,
fullscreen_mesh: ^Mesh,
passes: [PIPELINE_MAX_PASSES]^Pass,
amount_of_passes: u8,
}
clear_pipeline :: proc(renderer: ^Renderer) {
assert(renderer != nil)
p := &renderer.pipeline
p.amount_of_scene_passes = 0;
mem.set(&p.scene_passes[0], 0, PIPELINE_MAX_SCENE_PASSES * size_of(^Scene_Pass))
p.amount_of_post_processing_passes = 0;
mem.set(&p.post_processing_passes[0], 0, PIPELINE_MAX_POST_PROCESSING_PASSES * size_of(^Post_Processing_Pass))
p.amount_of_passes = 0;
mem.set(&p.passes[0], 0, PIPELINE_MAX_PASSES * size_of(^Scene_Pass))
}
set_pipeline :: proc(
renderer: ^Renderer,
fullscreen_material: ^Material, fullscreen_mesh: ^Mesh,
scene_passes: []^Scene_Pass,
post_processing_passes: []^Post_Processing_Pass,
passes: []^Pass,
){
assert(renderer != nil)
clear_pipeline(renderer)
renderer.pipeline.fullscreen_material = fullscreen_material
renderer.pipeline.fullscreen_mesh = fullscreen_mesh
for p in scene_passes {
if !add_pass_to_pipeline(renderer, p) {
break
}
}
for p in post_processing_passes {
for p in passes {
if !add_pass_to_pipeline(renderer, p) {
break
}
}
}
add_pass_to_pipeline :: proc {
add_scene_pass_to_pipeline,
add_post_processing_pass_to_pipeline,
}
@(private="file") add_scene_pass_to_pipeline :: proc(renderer: ^Renderer, scene_pass: ^Scene_Pass) -> bool {
add_pass_to_pipeline :: proc(renderer: ^Renderer, pass: ^Pass) -> bool {
assert(renderer != nil)
assert(scene_pass != nil)
assert(pass != nil)
pipeline := &renderer.pipeline
if pipeline.amount_of_scene_passes == PIPELINE_MAX_SCENE_PASSES {
log.warnf("Failed to add scene-pass '%v' to renderer's pipeline; hit max capacity (%v).", scene_pass.name, PIPELINE_MAX_SCENE_PASSES)
if pipeline.amount_of_passes == PIPELINE_MAX_PASSES {
log.warnf("Failed to add scene-pass '%v' to renderer's pipeline; hit max capacity (%v).", pass.name, PIPELINE_MAX_PASSES)
return false
}
pipeline.scene_passes[pipeline.amount_of_scene_passes] = scene_pass
pipeline.amount_of_scene_passes += 1
return true
}
@(private="file") add_post_processing_pass_to_pipeline :: proc(renderer: ^Renderer, post_processing_pass: ^Post_Processing_Pass) -> bool {
assert(renderer != nil)
assert(post_processing_pass != nil)
pipeline := &renderer.pipeline
if pipeline.amount_of_post_processing_passes == PIPELINE_MAX_POST_PROCESSING_PASSES {
log.warnf("Failed to add post-processing pass '%v' to renderer's pipeline; hit max capacity (%v).", post_processing_pass.name, PIPELINE_MAX_POST_PROCESSING_PASSES)
return false
}
pipeline.post_processing_passes[pipeline.amount_of_post_processing_passes] = post_processing_pass
pipeline.amount_of_post_processing_passes += 1
pipeline.passes[pipeline.amount_of_passes] = pass
pipeline.amount_of_passes += 1
return true
}