17 if (this->
GetOutputs().colorBuffers.empty() && !this->GetOutputs().depthBuffer.has_value())
20 fmt::format(
"RenderPass {}: No outputs defined for render pass, cannot execute.", this->
GetName()));
26 renderPass.setPipeline(shader.GetPipeline());
28 for (
auto &[index, name] : this->
GetInputs())
32 renderPass.setBindGroup(index, bindGroup.
GetBindGroup(), 0,
nullptr);
40 wgpu::CommandBufferDescriptor cmdBufferDescriptor(
wgpu::Default);
41 std::string cmdBufferDescriptorLabel = fmt::format(
"CreateRenderPass::{}::CommandBuffer", this->
GetName());
46 context.
queue.value().submit(1, &commandBuffer);
47 commandBuffer.release();
55 auto &device = context.
GetDevice().value();
58 std::string encoderDescLabel = fmt::format(
"CreateRenderPass::{}::CommandEncoder", this->
GetName());
63 "CreateRenderPass::{}::Command encoder is not created, cannot draw sprite.", this->
GetName()));
66 std::string renderPassDescLabel = fmt::format(
"CreateRenderPass::{}::RenderPass", this->
GetName());
69 std::vector<wgpu::RenderPassColorAttachment> colorAttachments;
70 colorAttachments.reserve(this->
GetOutputs().colorBuffers.size());
72 for (
const auto &colorTextureName : this->
GetOutputs().colorBuffers)
74 const auto &colorTexture = colorTextureName.second;
75 wgpu::RenderPassColorAttachment colorAttachment(
wgpu::Default);
77 entt::hashed_string textureId = colorTexture.textureId;
80 colorAttachment.view = textureView;
81 if (colorTexture.textureResolveTargetName.has_value())
83 std::string resolveTargetName = colorTexture.textureResolveTargetName.value();
85 .Get(entt::hashed_string{resolveTargetName.c_str()})
87 colorAttachment.resolveTarget = resolveTextureView;
89 colorAttachment.storeOp = colorTexture.storeOp;
90 glm::vec4 clearColor(0.0f);
91 if (colorTexture.getClearColorCallback(core, clearColor))
93 colorAttachment.clearValue =
wgpu::Color{clearColor.r, clearColor.g, clearColor.b, clearColor.a};
94 colorAttachment.loadOp = wgpu::LoadOp::Clear;
98 colorAttachment.loadOp = wgpu::LoadOp::Load;
100 colorAttachments.push_back(colorAttachment);
103 renderPassDesc.colorAttachmentCount =
static_cast<uint32_t
>(colorAttachments.size());
104 renderPassDesc.colorAttachments = colorAttachments.data();
106 wgpu::RenderPassDepthStencilAttachment depthAttachment(
wgpu::Default);
107 if (this->
GetOutputs().depthBuffer.has_value())
109 const auto &depthTexture = this->
GetOutputs().depthBuffer.value();
111 wgpu::TextureView depthView;
112 if (depthTexture.depthTextureView.has_value())
114 depthView = depthTexture.depthTextureView.value();
118 entt::hashed_string textureId = depthTexture.textureId;
122 depthAttachment.view = depthView;
123 depthAttachment.depthStoreOp = depthTexture.storeOp;
124 float clearDepth = 1.0f;
125 if (depthTexture.getClearDepthCallback(core, clearDepth))
127 depthAttachment.depthClearValue = clearDepth;
128 depthAttachment.depthLoadOp = wgpu::LoadOp::Clear;
132 depthAttachment.depthLoadOp = wgpu::LoadOp::Load;
134 renderPassDesc.depthStencilAttachment = &depthAttachment;