33 for (uint16_t passIndex = 0; passIndex < numberOfPasses; passIndex++)
47 if (this->
GetOutputs().colorBuffers.empty() && !this->GetOutputs().depthBuffer.has_value())
50 fmt::format(
"RenderPass {}: No outputs defined for render pass, cannot execute.", this->
GetName()));
54 wgpu::RenderPassEncoder renderPass = this->
_CreateRenderPass(deviceContext, core);
57 renderPass.setPipeline(shader.GetPipeline());
59 for (
auto &[index, name] : this->
GetInputs())
63 renderPass.setBindGroup(index, bindGroup.
GetBindGroup(), 0,
nullptr);
71 wgpu::CommandBufferDescriptor cmdBufferDescriptor(
wgpu::Default);
72 std::string cmdBufferDescriptorLabel = fmt::format(
"CreateRenderPass::{}::CommandBuffer", this->
GetName());
77 queue->submit(1, &commandBuffer);
78 commandBuffer.release();
86 auto &device = context.
GetDevice().value();
89 std::string encoderDescLabel = fmt::format(
"CreateRenderPass::{}::CommandEncoder", this->
GetName());
94 "CreateRenderPass::{}::Command encoder is not created, cannot draw sprite.", this->
GetName()));
97 std::string renderPassDescLabel = fmt::format(
"CreateRenderPass::{}::RenderPass", this->
GetName());
100 std::vector<wgpu::RenderPassColorAttachment> colorAttachments;
101 colorAttachments.reserve(this->
GetOutputs().colorBuffers.size());
103 for (
const auto &colorTextureName : this->
GetOutputs().colorBuffers)
105 const auto &colorTexture = colorTextureName.second;
106 wgpu::RenderPassColorAttachment colorAttachment(
wgpu::Default);
108 entt::hashed_string textureId = colorTexture.textureId;
112 colorAttachment.view = textureView;
113 if (colorTexture.textureResolveTargetName.has_value())
115 std::string resolveTargetName = colorTexture.textureResolveTargetName.value();
117 .Get(entt::hashed_string{resolveTargetName.c_str()})
120 colorAttachment.resolveTarget = resolveTextureView;
122 colorAttachment.storeOp = colorTexture.storeOp;
123 glm::vec4 clearColor(0.0f);
124 if (colorTexture.getClearColorCallback(core, clearColor))
126 colorAttachment.clearValue =
wgpu::Color{clearColor.r, clearColor.g, clearColor.b, clearColor.a};
127 colorAttachment.loadOp = wgpu::LoadOp::Clear;
131 colorAttachment.loadOp = wgpu::LoadOp::Load;
133 colorAttachments.push_back(colorAttachment);
136 renderPassDesc.colorAttachmentCount =
static_cast<uint32_t
>(colorAttachments.size());
137 renderPassDesc.colorAttachments = colorAttachments.data();
139 wgpu::RenderPassDepthStencilAttachment depthAttachment(
wgpu::Default);
140 if (this->
GetOutputs().depthBuffer.has_value())
142 const auto &depthTexture = this->
GetOutputs().depthBuffer.value();
144 wgpu::TextureView depthView;
145 if (depthTexture.depthTextureViewId.has_value())
148 .Get(depthTexture.depthTextureViewId.value())
153 entt::hashed_string textureId = depthTexture.textureId;
158 depthAttachment.view = depthView;
159 depthAttachment.depthStoreOp = depthTexture.storeOp;
160 float clearDepth = 1.0f;
161 if (depthTexture.getClearDepthCallback(core, clearDepth))
163 depthAttachment.depthClearValue = clearDepth;
164 depthAttachment.depthLoadOp = wgpu::LoadOp::Clear;
168 depthAttachment.depthLoadOp = wgpu::LoadOp::Load;
170 renderPassDesc.depthStencilAttachment = &depthAttachment;
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
TResource & GetResource()
Get a reference of a resource.
Definition Core.ipp:14
Definition FailToCreateCommandEncoderError.hpp:7
AMultipleExecutionRenderPass(std::string_view name)
Definition AMultipleExecutionRenderPass.hpp:12
wgpu::RenderPassEncoder _CreateRenderPass(Resource::DeviceContext &context, Engine::Core &core)
Definition AMultipleExecutionRenderPass.hpp:84
virtual void UniqueRenderCallback(wgpu::RenderPassEncoder &renderPass, Engine::Core &core)=0
void ExecuteSinglePass(Engine::Core &core)
Definition AMultipleExecutionRenderPass.hpp:42
virtual void postMultiplePass(Engine::Core &core)
Definition AMultipleExecutionRenderPass.hpp:19
virtual void perPass(uint16_t passIndex, Engine::Core &core)
Definition AMultipleExecutionRenderPass.hpp:22
virtual void postPass(uint16_t passIndex, Engine::Core &core)
Definition AMultipleExecutionRenderPass.hpp:25
void Execute(Engine::Core &core) override
Definition AMultipleExecutionRenderPass.hpp:29
wgpu::CommandEncoder _commandEncoder
Definition AMultipleExecutionRenderPass.hpp:176
virtual uint16_t GetNumberOfPasses(Engine::Core &core)=0
virtual void preMultiplePass(Engine::Core &core)
Definition AMultipleExecutionRenderPass.hpp:16
const auto & GetInputs(void) const
Definition ARenderPass.hpp:146
const auto & GetName(void) const
Definition ARenderPass.hpp:147
ARenderPass(std::string_view name)
Definition ARenderPass.hpp:56
const auto & GetBoundShader(void) const
Definition ARenderPass.hpp:145
const auto & GetOutputs(void) const
Definition ARenderPass.hpp:148
Definition BindGroup.hpp:17
const wgpu::BindGroup & GetBindGroup() const
Definition BindGroup.hpp:54
Object::Resource::ResourceManager< Resource::TextureView > TextureViewContainer
Definition TextureViewContainer.hpp:9
Object::Resource::ResourceManager< Shader > ShaderContainer
ShaderContainer is a resource that stores Shader resources.
Definition ShaderContainer.hpp:17
Object::Resource::ResourceManager< BindGroup > BindGroupManager
BindGroupManager is a resource that stores BindGroup resources.
Definition BindGroupManager.hpp:17
Object::Resource::ResourceManager< Texture > TextureContainer
TextureContainer is a resource that stores Texture resources.
Definition TextureContainer.hpp:17
void Error(const T &msg) noexcept(false)
Definition Logger.hpp:34
constexpr DefaultFlag Default
Definition webgpu.hpp:78
Color(double r, double g, double b, double a)
Definition webgpu.hpp:636
StringView(const std::string_view &cpp)
Definition webgpu.hpp:618
Definition DeviceContext.hpp:7
auto & GetDevice()
Definition DeviceContext.hpp:19