33 for (uint16_t passIndex = 0; passIndex < numberOfPasses; passIndex++)
46 if (this->
GetOutputs().colorBuffers.empty() && !this->GetOutputs().depthBuffer.has_value())
49 fmt::format(
"RenderPass {}: No outputs defined for render pass, cannot execute.", this->
GetName()));
56 renderPass.setPipeline(shader.GetPipeline());
58 for (
auto &[index, name] : this->
GetInputs())
62 renderPass.setBindGroup(index, bindGroup.
GetBindGroup(), 0,
nullptr);
70 wgpu::CommandBufferDescriptor cmdBufferDescriptor(
wgpu::Default);
71 std::string cmdBufferDescriptorLabel = fmt::format(
"CreateRenderPass::{}::CommandBuffer", this->
GetName());
76 context.
queue.value().submit(1, &commandBuffer);
77 commandBuffer.release();
85 auto &device = context.
GetDevice().value();
88 std::string encoderDescLabel = fmt::format(
"CreateRenderPass::{}::CommandEncoder", this->
GetName());
93 "CreateRenderPass::{}::Command encoder is not created, cannot draw sprite.", this->
GetName()));
96 std::string renderPassDescLabel = fmt::format(
"CreateRenderPass::{}::RenderPass", this->
GetName());
99 std::vector<wgpu::RenderPassColorAttachment> colorAttachments;
100 colorAttachments.reserve(this->
GetOutputs().colorBuffers.size());
102 for (
const auto &colorTextureName : this->
GetOutputs().colorBuffers)
104 const auto &colorTexture = colorTextureName.second;
105 wgpu::RenderPassColorAttachment colorAttachment(
wgpu::Default);
107 entt::hashed_string textureId = colorTexture.textureId;
111 colorAttachment.view = textureView;
112 if (colorTexture.textureResolveTargetName.has_value())
114 std::string resolveTargetName = colorTexture.textureResolveTargetName.value();
116 .Get(entt::hashed_string{resolveTargetName.c_str()})
119 colorAttachment.resolveTarget = resolveTextureView;
121 colorAttachment.storeOp = colorTexture.storeOp;
122 glm::vec4 clearColor(0.0f);
123 if (colorTexture.getClearColorCallback(core, clearColor))
125 colorAttachment.clearValue =
wgpu::Color{clearColor.r, clearColor.g, clearColor.b, clearColor.a};
126 colorAttachment.loadOp = wgpu::LoadOp::Clear;
130 colorAttachment.loadOp = wgpu::LoadOp::Load;
132 colorAttachments.push_back(colorAttachment);
135 renderPassDesc.colorAttachmentCount =
static_cast<uint32_t
>(colorAttachments.size());
136 renderPassDesc.colorAttachments = colorAttachments.data();
138 wgpu::RenderPassDepthStencilAttachment depthAttachment(
wgpu::Default);
139 if (this->
GetOutputs().depthBuffer.has_value())
141 const auto &depthTexture = this->
GetOutputs().depthBuffer.value();
143 wgpu::TextureView depthView;
144 if (depthTexture.depthTextureViewId.has_value())
147 .Get(depthTexture.depthTextureViewId.value())
152 entt::hashed_string textureId = depthTexture.textureId;
157 depthAttachment.view = depthView;
158 depthAttachment.depthStoreOp = depthTexture.storeOp;
159 float clearDepth = 1.0f;
160 if (depthTexture.getClearDepthCallback(core, clearDepth))
162 depthAttachment.depthClearValue = clearDepth;
163 depthAttachment.depthLoadOp = wgpu::LoadOp::Clear;
167 depthAttachment.depthLoadOp = wgpu::LoadOp::Load;
169 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:83
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:175
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
DeviceContext deviceContext
Definition Context.hpp:43
std::optional< wgpu::Queue > queue
Definition Context.hpp:44
Definition AGPUBuffer.hpp:6
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:13