pass_frustum_debug.cpp

cross platform rendering playground

src/passes/debug/pass_frustum_debug.cpp

1.76 KB
#include "pass_frustum_debug.h"

#include "renderer.h"
#include "shaders/renderer_types.h"

void FrustumDebugPass::render() {
    FrameData &frame = ctx_->frame_data[ctx_->frame_index];

    rhi::AttachmentDesc colorAttachment{};
    colorAttachment.img = &ctx_->render_data->targets.main.default_view;
    colorAttachment.loadOp = rhi::LoadOp::LOAD;
    colorAttachment.storeOp = rhi::StoreOp::STORE;

    rhi::AttachmentDesc depthAttachment{};
    depthAttachment.img = &ctx_->render_data->targets.depth.default_view;
    depthAttachment.loadOp = rhi::LoadOp::LOAD;
    depthAttachment.storeOp = rhi::StoreOp::STORE;

    rhi::RenderingInfo ri{};
    ri.colorAttachments[0] = colorAttachment;
    ri.colorAttachmentCount = 1;
    ri.depthAttachment = depthAttachment;
    ri.width = ctx_->width;
    ri.height = ctx_->height;

    rhi::begin_rendering(ctx_->cmdbuf, ri);
    rhi::set_pipeline(ctx_->cmdbuf, pipeline);
    rhi::set_descriptor_set(ctx_->cmdbuf, pipeline, *ctx_->descriptor_set);

    rhi::Viewport viewport{};
    viewport.width = (f32)ctx_->width;
    viewport.height = (f32)ctx_->height;
    rhi::set_viewports(ctx_->cmdbuf, &viewport);

    rhi::Rect scissor{};
    scissor.width = ctx_->width;
    scissor.height = ctx_->height;
    rhi::set_scissors(ctx_->cmdbuf, &scissor);

    FrustumDebugPushConstants pc{};
    pc.frame_ubo_idx = frame.camera_view.shader_handle;
    pc.debug_view_proj = ctx_->scene->cameras.debug_camera()->view_proj;
    pc.debug_inv_view_proj = ctx_->scene->cameras.debug_camera()->inv_view_proj;
    rhi::set_constants(ctx_->cmdbuf, pipeline, rhi::ShaderStage::VERTEX, sizeof(pc), &pc);

    rhi::draw(ctx_->cmdbuf, 24, 1, 0, 0);
    rhi::end_rendering(ctx_->cmdbuf);
}

void FrustumDebugPass::resize() {
}

FrustumDebugPass::~FrustumDebugPass() {
}