32 for (uint16_t passIndex = 0; passIndex < numberOfPasses; passIndex++)
45 if (this->
GetOutputs().colorBuffers.empty() && !this->GetOutputs().depthBuffer.has_value())
48 fmt::format(
"RenderPass {}: No outputs defined for render pass, cannot execute.", this->
GetName()));
55 renderPass.setPipeline(shader.GetPipeline());
57 for (
auto &[index, name] : this->
GetInputs())
61 renderPass.setBindGroup(index, bindGroup.
GetBindGroup(), 0,
nullptr);
69 wgpu::CommandBufferDescriptor cmdBufferDescriptor(
wgpu::Default);
70 std::string cmdBufferDescriptorLabel = fmt::format(
"CreateRenderPass::{}::CommandBuffer", this->
GetName());
75 context.
queue.value().submit(1, &commandBuffer);
76 commandBuffer.release();
84 auto &device = context.
GetDevice().value();
87 std::string encoderDescLabel = fmt::format(
"CreateRenderPass::{}::CommandEncoder", this->
GetName());
92 "CreateRenderPass::{}::Command encoder is not created, cannot draw sprite.", this->
GetName()));
95 std::string renderPassDescLabel = fmt::format(
"CreateRenderPass::{}::RenderPass", this->
GetName());
98 std::vector<wgpu::RenderPassColorAttachment> colorAttachments;
99 colorAttachments.reserve(this->
GetOutputs().colorBuffers.size());
101 for (
const auto &colorTextureName : this->
GetOutputs().colorBuffers)
103 const auto &colorTexture = colorTextureName.second;
104 wgpu::RenderPassColorAttachment colorAttachment(
wgpu::Default);
106 entt::hashed_string textureId = colorTexture.textureId;
109 colorAttachment.view = textureView;
110 if (colorTexture.textureResolveTargetName.has_value())
112 std::string resolveTargetName = colorTexture.textureResolveTargetName.value();
114 .Get(entt::hashed_string{resolveTargetName.c_str()})
116 colorAttachment.resolveTarget = resolveTextureView;
118 colorAttachment.storeOp = colorTexture.storeOp;
119 glm::vec4 clearColor(0.0f);
120 if (colorTexture.getClearColorCallback(core, clearColor))
122 colorAttachment.clearValue =
wgpu::Color{clearColor.r, clearColor.g, clearColor.b, clearColor.a};
123 colorAttachment.loadOp = wgpu::LoadOp::Clear;
127 colorAttachment.loadOp = wgpu::LoadOp::Load;
129 colorAttachments.push_back(colorAttachment);
132 renderPassDesc.colorAttachmentCount =
static_cast<uint32_t
>(colorAttachments.size());
133 renderPassDesc.colorAttachments = colorAttachments.data();
135 wgpu::RenderPassDepthStencilAttachment depthAttachment(
wgpu::Default);
136 if (this->
GetOutputs().depthBuffer.has_value())
138 const auto &depthTexture = this->
GetOutputs().depthBuffer.value();
140 wgpu::TextureView depthView;
141 if (depthTexture.depthTextureView.has_value())
143 depthView = depthTexture.depthTextureView.value();
147 entt::hashed_string textureId = depthTexture.textureId;
151 depthAttachment.view = depthView;
152 depthAttachment.depthStoreOp = depthTexture.storeOp;
153 float clearDepth = 1.0f;
154 if (depthTexture.getClearDepthCallback(core, clearDepth))
156 depthAttachment.depthClearValue = clearDepth;
157 depthAttachment.depthLoadOp = wgpu::LoadOp::Clear;
161 depthAttachment.depthLoadOp = wgpu::LoadOp::Load;
163 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.inl:14
Definition FailToCreateCommandEncoderError.hpp:7
AMultipleExecutionRenderPass(std::string_view name)
Definition AMultipleExecutionRenderPass.hpp:11
wgpu::RenderPassEncoder _CreateRenderPass(Resource::DeviceContext &context, Engine::Core &core)
Definition AMultipleExecutionRenderPass.hpp:82
virtual void UniqueRenderCallback(wgpu::RenderPassEncoder &renderPass, Engine::Core &core)=0
void ExecuteSinglePass(Engine::Core &core)
Definition AMultipleExecutionRenderPass.hpp:41
virtual void postMultiplePass(Engine::Core &core)
Definition AMultipleExecutionRenderPass.hpp:18
virtual void perPass(uint16_t passIndex, Engine::Core &core)
Definition AMultipleExecutionRenderPass.hpp:21
virtual void postPass(uint16_t passIndex, Engine::Core &core)
Definition AMultipleExecutionRenderPass.hpp:24
void Execute(Engine::Core &core) override
Definition AMultipleExecutionRenderPass.hpp:28
wgpu::CommandEncoder _commandEncoder
Definition AMultipleExecutionRenderPass.hpp:169
virtual uint16_t GetNumberOfPasses(Engine::Core &core)=0
virtual void preMultiplePass(Engine::Core &core)
Definition AMultipleExecutionRenderPass.hpp:15
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
DeviceContext deviceContext
Definition Context.hpp:43
std::optional< wgpu::Queue > queue
Definition Context.hpp:44
Definition AGPUBuffer.hpp:6
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
Definition Logger.hpp:51
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:13