18 if (this->
GetOutputs().colorBuffers.empty() && !this->GetOutputs().depthBuffer.has_value())
21 fmt::format(
"RenderPass {}: No outputs defined for render pass, cannot execute.", this->
GetName()));
27 renderPass.setPipeline(shader.GetPipeline());
29 for (
auto &[index, name] : this->
GetInputs())
33 renderPass.setBindGroup(index, bindGroup.
GetBindGroup(), 0,
nullptr);
41 wgpu::CommandBufferDescriptor cmdBufferDescriptor(
wgpu::Default);
42 std::string cmdBufferDescriptorLabel = fmt::format(
"CreateRenderPass::{}::CommandBuffer", this->
GetName());
47 context.
queue.value().submit(1, &commandBuffer);
48 commandBuffer.release();
56 auto &device = context.
GetDevice().value();
59 std::string encoderDescLabel = fmt::format(
"CreateRenderPass::{}::CommandEncoder", this->
GetName());
64 "CreateRenderPass::{}::Command encoder is not created, cannot draw sprite.", this->
GetName()));
67 std::string renderPassDescLabel = fmt::format(
"CreateRenderPass::{}::RenderPass", this->
GetName());
70 std::vector<wgpu::RenderPassColorAttachment> colorAttachments;
71 colorAttachments.reserve(this->
GetOutputs().colorBuffers.size());
73 for (
const auto &colorTextureName : this->
GetOutputs().colorBuffers)
75 const auto &colorTexture = colorTextureName.second;
76 wgpu::RenderPassColorAttachment colorAttachment(
wgpu::Default);
78 entt::hashed_string textureId = colorTexture.textureId;
82 colorAttachment.view = textureView;
83 if (colorTexture.textureResolveTargetName.has_value())
85 std::string resolveTargetName = colorTexture.textureResolveTargetName.value();
87 .Get(entt::hashed_string{resolveTargetName.c_str()})
90 colorAttachment.resolveTarget = resolveTextureView;
92 colorAttachment.storeOp = colorTexture.storeOp;
93 glm::vec4 clearColor(0.0f);
94 if (colorTexture.getClearColorCallback(core, clearColor))
96 colorAttachment.clearValue =
wgpu::Color{clearColor.r, clearColor.g, clearColor.b, clearColor.a};
97 colorAttachment.loadOp = wgpu::LoadOp::Clear;
101 colorAttachment.loadOp = wgpu::LoadOp::Load;
103 colorAttachments.push_back(colorAttachment);
106 renderPassDesc.colorAttachmentCount =
static_cast<uint32_t
>(colorAttachments.size());
107 renderPassDesc.colorAttachments = colorAttachments.data();
109 wgpu::RenderPassDepthStencilAttachment depthAttachment(
wgpu::Default);
110 if (this->
GetOutputs().depthBuffer.has_value())
112 const auto &depthTexture = this->
GetOutputs().depthBuffer.value();
114 wgpu::TextureView depthView;
115 if (depthTexture.depthTextureViewId.has_value())
117 const auto &textureViewId = depthTexture.depthTextureViewId.value();
122 entt::hashed_string textureId = depthTexture.textureId;
127 depthAttachment.view = depthView;
128 depthAttachment.depthStoreOp = depthTexture.storeOp;
129 float clearDepth = 1.0f;
130 if (depthTexture.getClearDepthCallback(core, clearDepth))
132 depthAttachment.depthClearValue = clearDepth;
133 depthAttachment.depthLoadOp = wgpu::LoadOp::Clear;
137 depthAttachment.depthLoadOp = wgpu::LoadOp::Load;
139 renderPassDesc.depthStencilAttachment = &depthAttachment;