CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
GPURenderPass.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Common.hpp"
11#include "Forward.hpp"
12
13#include "GPUFormat.hpp"
14#include "GPUImage.hpp"
15
18
23
25
26#include <functional>
27
28namespace CeresEngine {
29
36
39 Load,
40
43 Clear,
44 };
45
54
56 Store,
57 };
58
65 Format format = Format::Undefined;
66
69 UInt32 samples = 1;
70
78
85
90 GPUImageLayout initialLayout = GPUImageLayout::DontCare;
91
96 GPUImageLayout finalLayout = GPUImageLayout::ShaderAccess;
97
98 public: // Reflection
101 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
102 CE_REFL_DATA(format);
103 CE_REFL_DATA(samples);
104 CE_REFL_DATA(loadOp);
105 CE_REFL_DATA(storeOp);
106 CE_REFL_DATA(initialLayout);
107 CE_REFL_DATA(finalLayout);
108 }
109 };
110
117
125
133
137 String name;
138
141 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
142 CE_REFL_DATA(colorAttachments);
143 CE_REFL_DATA(depthAttachment);
144 CE_REFL_DATA(stencilAttachment);
145 CE_REFL_DATA(name);
146 }
147 };
148
149 class CE_SCRIPT_EXPORT() GPURenderPass : public TDeviceObject<GPURenderPassDescriptor> {
150 public:
152 using TDeviceObject::TDeviceObject;
153
155 GPURenderPass(const GPURenderPass&) = delete;
157
161
162 public:
164 virtual void begin(GPUCommandBuffer& commandBuffer, GPURenderTarget& renderTarget, const Color& clearColor = Color(0.0, 0.0, 0.0, 0.0)) = 0;
165
167 virtual void end(GPUCommandBuffer& commandBuffer, GPURenderTarget& renderTarget) = 0;
168
170 class Scope {
171 private:
173 GPUCommandBuffer* mCommandBuffer = nullptr;
174
176 GPURenderPass* mRenderPass = nullptr;
177
180 GPURenderTarget* mRenderTarget = nullptr;
181
182 public:
186 template<typename... Args>
187 explicit Scope(GPUCommandBuffer& commandBuffer, GPURenderPass& renderPass, GPURenderTarget& renderTarget, Args&&... args)
188 : mCommandBuffer(&commandBuffer), mRenderPass(&renderPass), mRenderTarget(&renderTarget) {
189 mRenderPass->begin(*mCommandBuffer, renderTarget, std::forward<Args>(args)...);
190 }
191
193 template<typename... Args>
194 explicit Scope(const GPUCommandBufferPtr& commandBuffer, GPURenderPass& renderPass, GPURenderTarget& renderTarget, Args&&... args)
195 : Scope(*commandBuffer, renderPass, renderTarget, std::forward<Args>(args)...) {}
196
198 template<typename... Args>
199 explicit Scope(const GPUCommandBufferPtr& commandBuffer, const GPURenderPassPtr& renderPass, GPURenderTarget& renderTarget, Args&&... args)
200 : Scope(*commandBuffer, *renderPass, renderTarget, std::forward<Args>(args)...) {}
201
203 template<typename... Args>
204 explicit Scope(const GPUCommandBufferPtr& commandBuffer, GPURenderPass& renderPass, const GPURenderTargetPtr& renderTarget, Args&&... args)
205 : Scope(*commandBuffer, renderPass, *renderTarget, std::forward<Args>(args)...) {}
206
208 template<typename... Args>
209 explicit Scope(GPUCommandBuffer& commandBuffer, const GPURenderPassPtr& renderPass, GPURenderTarget& renderTarget, Args&&... args)
210 : Scope(commandBuffer, *renderPass, renderTarget, std::forward<Args>(args)...) {}
211
213 template<typename... Args>
214 explicit Scope(GPUCommandBuffer& commandBuffer, const GPURenderPassPtr& renderPass, const GPURenderTargetPtr& renderTarget, Args&&... args)
215 : Scope(commandBuffer, *renderPass, *renderTarget, std::forward<Args>(args)...) {}
216
218 template<typename... Args>
219 explicit Scope(GPUCommandBuffer& commandBuffer, GPURenderPass& renderPass, const GPURenderTargetPtr& renderTarget, Args&&... args)
220 : Scope(commandBuffer, renderPass, *renderTarget, std::forward<Args>(args)...) {}
221
223 template<typename... Args>
224 explicit Scope(const GPUCommandBufferPtr& commandBuffer, const GPURenderPassPtr& renderPass, const GPURenderTargetPtr& renderTarget, Args&&... args)
225 : Scope(*commandBuffer, *renderPass, *renderTarget, std::forward<Args>(args)...) {}
226
228 ~Scope() noexcept { reset(); }
229
230 public:
232 void reset() {
233 if(mRenderPass != nullptr) {
234 mRenderPass->end(*mCommandBuffer, *mRenderTarget);
235 mRenderPass = nullptr;
236 mRenderTarget = nullptr;
237 mCommandBuffer = nullptr;
238 }
239 }
240 };
241
250 template<typename Func, typename... Args>
251 decltype(auto) with(GPUCommandBuffer& commandBuffer, GPURenderTarget& renderTarget, Func&& block, Args&&... args) {
252 const Scope scope(commandBuffer, *this, renderTarget, std::forward<Args>(args)...);
253 return block();
254 }
255 };
256
257} // namespace CeresEngine
258
261
#define CE_REFLECT_HASH(T)
Definition Hash.hpp:89
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Definition GPUCommandBuffer.hpp:77
A helper class that begins a scoped render target binding.
Definition GPURenderPass.hpp:170
Scope(GPUCommandBuffer &commandBuffer, const GPURenderPassPtr &renderPass, GPURenderTarget &renderTarget, Args &&... args)
Definition GPURenderPass.hpp:209
Scope(GPUCommandBuffer &commandBuffer, GPURenderPass &renderPass, const GPURenderTargetPtr &renderTarget, Args &&... args)
Definition GPURenderPass.hpp:219
Scope(GPUCommandBuffer &commandBuffer, const GPURenderPassPtr &renderPass, const GPURenderTargetPtr &renderTarget, Args &&... args)
Definition GPURenderPass.hpp:214
Scope(const GPUCommandBufferPtr &commandBuffer, const GPURenderPassPtr &renderPass, GPURenderTarget &renderTarget, Args &&... args)
Definition GPURenderPass.hpp:199
Scope(const GPUCommandBufferPtr &commandBuffer, GPURenderPass &renderPass, GPURenderTarget &renderTarget, Args &&... args)
Definition GPURenderPass.hpp:194
~Scope() noexcept
Unbound the pipeline from the command buffer.
Definition GPURenderPass.hpp:228
Scope(const GPUCommandBufferPtr &commandBuffer, GPURenderPass &renderPass, const GPURenderTargetPtr &renderTarget, Args &&... args)
Definition GPURenderPass.hpp:204
Scope(GPUCommandBuffer &commandBuffer, GPURenderPass &renderPass, GPURenderTarget &renderTarget, Args &&... args)
Creates a new scope and calls begin() on the pipeline.
Definition GPURenderPass.hpp:187
void reset()
Unbound the pipeline from the command buffer.
Definition GPURenderPass.hpp:232
Scope(const GPUCommandBufferPtr &commandBuffer, const GPURenderPassPtr &renderPass, const GPURenderTargetPtr &renderTarget, Args &&... args)
Definition GPURenderPass.hpp:224
Definition GPURenderPass.hpp:149
GPURenderPass(const GPURenderPass &)=delete
Deleted copy constructor.
virtual void begin(GPUCommandBuffer &commandBuffer, GPURenderTarget &renderTarget, const Color &clearColor=Color(0.0, 0.0, 0.0, 0.0))=0
Prepares the render pass for execution.
GPURenderPass(GPURenderPass &&)=delete
Deleted move constructor.
virtual void end(GPUCommandBuffer &commandBuffer, GPURenderTarget &renderTarget)=0
Finishes the render pass execution.
decltype(auto) with(GPUCommandBuffer &commandBuffer, GPURenderTarget &renderTarget, Func &&block, Args &&... args)
Prepares the render pass for execution.
Definition GPURenderPass.hpp:251
GPURenderPass & operator=(GPURenderPass &&)=delete
GPURenderPass & operator=(const GPURenderPass &)=delete
Definition GPURenderTarget.hpp:105
Definition Common.hpp:62
Definition Application.hpp:19
GPUAttachmentLoadOp
Enumeration for render pass attachment load operations.
Definition GPURenderPass.hpp:32
@ Undefined
We don't care about the previous content of the respective render target attachment.
@ Load
Loads the previous content of the respective render target attachment.
GPUImageLayout
Definition GPUImage.hpp:65
GPUAttachmentStoreOp
Enumeration for render pass attachment store operations.
Definition GPURenderPass.hpp:48
@ Store
Stores the outcome in the respective render target attachment.
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
Format
Definition TextureFormat.hpp:54
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
@ Clear
Resulting operation: 0.
Definition Span.hpp:668
Render target attachment descriptor structure.
Definition GPURenderPass.hpp:63
Render pass descriptor structure.
Definition GPURenderPass.hpp:112
Vector< GPUAttachmentFormatDescriptor > colorAttachments
Specifies the color attachments used within the render pass.
Definition GPURenderPass.hpp:116