diff options
Diffstat (limited to 'src/gpu/effect.cc')
| -rw-r--r-- | src/gpu/effect.cc | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc index 81d5952..fdc604c 100644 --- a/src/gpu/effect.cc +++ b/src/gpu/effect.cc @@ -111,14 +111,24 @@ void MainSequence::create_framebuffers(int width, int height) { framebuffer_view_a_ = wgpuTextureCreateView(framebuffer_a_, &view_desc); framebuffer_view_b_ = wgpuTextureCreateView(framebuffer_b_, &view_desc); -} -void MainSequence::init_test(WGPUDevice d, WGPUQueue q, WGPUTextureFormat f) { - device = d; - queue = q; - format = f; - // No framebuffers or passthrough effect created in test mode. - // Test effects should not rely on these being real. + // Depth Buffer + WGPUTextureDescriptor depth_desc = {}; + depth_desc.usage = WGPUTextureUsage_RenderAttachment; + depth_desc.dimension = WGPUTextureDimension_2D; + depth_desc.size = {(uint32_t)width, (uint32_t)height, 1}; + depth_desc.format = WGPUTextureFormat_Depth24Plus; + depth_desc.mipLevelCount = 1; + depth_desc.sampleCount = 1; + depth_texture_ = wgpuDeviceCreateTexture(device, &depth_desc); + + WGPUTextureViewDescriptor depth_view_desc = {}; + depth_view_desc.format = WGPUTextureFormat_Depth24Plus; + depth_view_desc.dimension = WGPUTextureViewDimension_2D; + depth_view_desc.aspect = WGPUTextureAspect_DepthOnly; + depth_view_desc.mipLevelCount = 1; + depth_view_desc.arrayLayerCount = 1; + depth_view_ = wgpuTextureCreateView(depth_texture_, &depth_view_desc); } void MainSequence::init(WGPUDevice d, WGPUQueue q, WGPUTextureFormat f, @@ -139,6 +149,10 @@ void MainSequence::init(WGPUDevice d, WGPUQueue q, WGPUTextureFormat f, void MainSequence::add_sequence(std::shared_ptr<Sequence> seq, float start_time, int priority) { sequences_.push_back({seq, start_time, priority}); + // If MainSequence is already initialized, init the new sequence immediately + if (device) { + seq->init(this); + } std::sort(sequences_.begin(), sequences_.end(), [](const ActiveSequence& a, const ActiveSequence& b) { return a.priority < b.priority; @@ -183,8 +197,16 @@ void MainSequence::render_frame(float global_time, float beat, float peak, #if !defined(DEMO_CROSS_COMPILE_WIN32) scene_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED; #endif /* !defined(DEMO_CROSS_COMPILE_WIN32) */ + + WGPURenderPassDepthStencilAttachment depth_attachment = {}; + depth_attachment.view = depth_view_; + depth_attachment.depthLoadOp = WGPULoadOp_Clear; + depth_attachment.depthStoreOp = WGPUStoreOp_Store; + depth_attachment.depthClearValue = 1.0f; + WGPURenderPassDescriptor scene_desc = {.colorAttachmentCount = 1, - .colorAttachments = &scene_attachment}; + .colorAttachments = &scene_attachment, + .depthStencilAttachment = &depth_attachment}; WGPURenderPassEncoder scene_pass = wgpuCommandEncoderBeginRenderPass(encoder, &scene_desc); for (const SequenceItem* item : scene_effects) { @@ -200,7 +222,10 @@ void MainSequence::render_frame(float global_time, float beat, float peak, if (post_effects.empty()) { wgpuSurfaceGetCurrentTexture(surface, &st); final_view = wgpuTextureCreateView(st.texture, nullptr); - passthrough_effect_->update_bind_group(framebuffer_view_a_); + + // Safely cast to PostProcessEffect to call update_bind_group + PostProcessEffect* pp_effect = (PostProcessEffect*)passthrough_effect_.get(); + pp_effect->update_bind_group(framebuffer_view_a_); WGPURenderPassColorAttachment final_attachment = {}; final_attachment.view = final_view; @@ -274,6 +299,10 @@ void MainSequence::shutdown() { wgpuTextureViewRelease(framebuffer_view_b_); if (framebuffer_b_) wgpuTextureRelease(framebuffer_b_); + if (depth_view_) + wgpuTextureViewRelease(depth_view_); + if (depth_texture_) + wgpuTextureRelease(depth_texture_); for (ActiveSequence& entry : sequences_) { entry.seq->reset(); } |
