LiteFX 0.3.1.2022
Computer Graphics Engine
rendering_builders.hpp
1#pragma once
2
3#include "rendering_api.hpp"
4#include "rendering.hpp"
5
6#if defined(BUILD_DEFINE_BUILDERS)
7namespace LiteFX::Rendering {
8
15 template <typename TDerived, typename TShaderProgram> requires
16 rtti::implements<TShaderProgram, ShaderProgram<typename TShaderProgram::shader_module_type>>
17 class ShaderProgramBuilder : public Builder<TDerived, TShaderProgram, std::nullptr_t, SharedPtr<TShaderProgram>> {
18 public:
19 using Builder<TDerived, TShaderProgram, std::nullptr_t, SharedPtr<TShaderProgram>>::Builder;
20 using shader_program_type = TShaderProgram;
21 using shader_module_type = shader_program_type::shader_module_type;
22
23 public:
30 virtual TDerived& withShaderModule(const ShaderStage& type, const String& fileName, const String& entryPoint = "main") = 0;
31
39 virtual TDerived& withShaderModule(const ShaderStage& type, std::istream& stream, const String& name, const String& entryPoint = "main") = 0;
40
46 virtual TDerived& withVertexShaderModule(const String& fileName, const String& entryPoint = "main") = 0;
47
54 virtual TDerived& withVertexShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") = 0;
55
61 virtual TDerived& withTessellationControlShaderModule(const String& fileName, const String& entryPoint = "main") = 0;
62
69 virtual TDerived& withTessellationControlShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") = 0;
70
76 virtual TDerived& withTessellationEvaluationShaderModule(const String& fileName, const String& entryPoint = "main") = 0;
77
84 virtual TDerived& withTessellationEvaluationShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") = 0;
85
91 virtual TDerived& withGeometryShaderModule(const String& fileName, const String& entryPoint = "main") = 0;
92
99 virtual TDerived& withGeometryShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") = 0;
100
106 virtual TDerived& withFragmentShaderModule(const String& fileName, const String& entryPoint = "main") = 0;
107
114 virtual TDerived& withFragmentShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") = 0;
115
121 virtual TDerived& withComputeShaderModule(const String& fileName, const String& entryPoint = "main") = 0;
122
129 virtual TDerived& withComputeShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") = 0;
130 };
131
138 template <typename TDerived, typename TRasterizer> requires
139 rtti::implements<TRasterizer, IRasterizer>
140 class RasterizerBuilder : public Builder<TDerived, TRasterizer, std::nullptr_t, SharedPtr<TRasterizer>> {
141 public:
142 using Builder<TDerived, TRasterizer, std::nullptr_t, SharedPtr<TRasterizer>>::Builder;
143 using rasterizer_type = TRasterizer;
144
145 public:
150 virtual TDerived& polygonMode(const PolygonMode& mode) noexcept = 0;
151
156 virtual TDerived& cullMode(const CullMode& mode) noexcept = 0;
157
162 virtual TDerived& cullOrder(const CullOrder& order) noexcept = 0;
163
168 virtual TDerived& lineWidth(const Float& width) noexcept = 0;
169
174 virtual TDerived& depthBias(const DepthStencilState::DepthBias& depthBias) noexcept = 0;
175
180 virtual TDerived& depthState(const DepthStencilState::DepthState& depthState) noexcept = 0;
181
186 virtual TDerived& stencilState(const DepthStencilState::StencilState& stencilState) noexcept = 0;
187 };
188
195 template <typename TDerived, typename TVertexBufferLayout, typename TParent> requires
196 rtti::implements<TVertexBufferLayout, IVertexBufferLayout>
197 class VertexBufferLayoutBuilder : public Builder<TDerived, TVertexBufferLayout, TParent> {
198 public:
199 using Builder<TDerived, TVertexBufferLayout, TParent>::Builder;
200 using vertex_buffer_layout_type = TVertexBufferLayout;
201
202 public:
207 virtual TDerived& withAttribute(UniquePtr<BufferAttribute>&& attribute) = 0;
208 };
209
217 template <typename TDerived, typename TDescriptorSetLayout, typename TParent> requires
218 rtti::implements<TDescriptorSetLayout, DescriptorSetLayout<typename TDescriptorSetLayout::descriptor_layout_type, typename TDescriptorSetLayout::descriptor_set_type>>
219 class DescriptorSetLayoutBuilder : public Builder<TDerived, TDescriptorSetLayout, TParent> {
220 public:
221 using Builder<TDerived, TDescriptorSetLayout, TParent>::Builder;
222 using descriptor_set_layout_type = TDescriptorSetLayout;
223 using descriptor_layout_type = descriptor_set_layout_type::descriptor_layout_type;
224 using descriptor_set_type = descriptor_set_layout_type::descriptor_set_type;
225
226 public:
231 virtual TDerived& withDescriptor(UniquePtr<descriptor_layout_type>&& layout) = 0;
232
240 virtual TDerived& withDescriptor(const DescriptorType& type, const UInt32& binding, const UInt32& descriptorSize, const UInt32& descriptors = 1) = 0;
241
256 virtual TDerived& withStaticSampler(const UInt32& binding, const FilterMode& magFilter = FilterMode::Nearest, const FilterMode& minFilter = FilterMode::Nearest, const BorderMode& borderU = BorderMode::Repeat, const BorderMode& borderV = BorderMode::Repeat, const BorderMode& borderW = BorderMode::Repeat, const MipMapMode& mipMapMode = MipMapMode::Nearest, const Float& mipMapBias = 0.f, const Float& minLod = 0.f, const Float& maxLod = std::numeric_limits<Float>::max(), const Float& anisotropy = 0.f) = 0;
257
258 public:
265 virtual TDerived& withConstantBuffer(const UInt32& binding, const UInt32& descriptorSize, const UInt32& descriptors = 1) {
266 return this->withDescriptor(DescriptorType::ConstantBuffer, binding, descriptorSize, descriptors);
267 }
268
275 virtual TDerived& withBuffer(const UInt32& binding, const UInt32& descriptors = 1, const bool& writable = false) {
276 return this->withDescriptor(writable ? DescriptorType::RWBuffer : DescriptorType::Buffer, binding, 0, descriptors);
277 }
278
285 virtual TDerived& withStructuredBuffer(const UInt32& binding, const UInt32& descriptors = 1, const bool& writable = false) {
286 return this->withDescriptor(writable ? DescriptorType::RWStructuredBuffer : DescriptorType::StructuredBuffer, binding, 0, descriptors);
287 }
288
295 virtual TDerived& withByteAddressBuffer(const UInt32& binding, const UInt32& descriptors = 1, const bool& writable = false) {
296 return this->withDescriptor(writable ? DescriptorType::RWByteAddressBuffer : DescriptorType::ByteAddressBuffer, binding, 0, descriptors);
297 }
298
305 virtual TDerived& withTexture(const UInt32& binding, const UInt32& descriptors = 1, const bool& writable = false) {
306 return this->withDescriptor(writable ? DescriptorType::RWTexture : DescriptorType::Texture, binding, 0, descriptors);
307 }
308
313 virtual TDerived& withInputAttachment(const UInt32& binding) {
314 return this->withDescriptor(DescriptorType::InputAttachment, binding, 0);
315 }
316
322 virtual TDerived& withSampler(const UInt32& binding, const UInt32& descriptors = 1) {
323 return this->withDescriptor(DescriptorType::Sampler, binding, 0, descriptors);
324 }
325
331 virtual void use(UniquePtr<descriptor_layout_type>&& layout) {
332 this->withDescriptor(std::move(layout));
333 }
334 };
335
342 template <typename TDerived, typename TPushConstantsLayout, typename TParent> requires
343 rtti::implements<TPushConstantsLayout, PushConstantsLayout<typename TPushConstantsLayout::push_constants_range_type>>
344 class PushConstantsLayoutBuilder : public Builder<TDerived, TPushConstantsLayout, TParent> {
345 public:
346 using Builder<TDerived, TPushConstantsLayout, TParent>::Builder;
347 using push_constants_layout_type = TPushConstantsLayout;
348 using push_constants_range_type = push_constants_layout_type::push_constants_range_type;
349
350 public:
359 virtual TDerived& withRange(const ShaderStage& shaderStages, const UInt32& offset, const UInt32& size, const UInt32& space, const UInt32& binding) = 0;
360 };
361
368 template <typename TDerived, typename TPipelineLayout> requires
369 rtti::implements<TPipelineLayout, PipelineLayout<typename TPipelineLayout::descriptor_set_layout_type, typename TPipelineLayout::push_constants_layout_type>>
370 class PipelineLayoutBuilder : public Builder<TDerived, TPipelineLayout, std::nullptr_t, SharedPtr<TPipelineLayout>> {
371 public:
372 using Builder<TDerived, TPipelineLayout, std::nullptr_t, SharedPtr<TPipelineLayout>>::Builder;
373 using pipeline_layout_type = TPipelineLayout;
374 using descriptor_set_layout_type = pipeline_layout_type::descriptor_set_layout_type;
375 using push_constants_layout_type = pipeline_layout_type::push_constants_layout_type;
376
377 public:
383 virtual void use(UniquePtr<descriptor_set_layout_type>&& layout) = 0;
384
390 virtual void use(UniquePtr<push_constants_layout_type>&& layout) = 0;
391 };
392
399 template <typename TDerived, typename TInputAssembler> requires
400 rtti::implements<TInputAssembler, InputAssembler<typename TInputAssembler::vertex_buffer_layout_type, typename TInputAssembler::index_buffer_layout_type>>
401 class InputAssemblerBuilder : public Builder<TDerived, TInputAssembler, std::nullptr_t, SharedPtr<TInputAssembler>> {
402 public:
403 using Builder<TDerived, TInputAssembler, std::nullptr_t, SharedPtr<TInputAssembler>>::Builder;
404 using input_assembler_type = TInputAssembler;
405 using vertex_buffer_layout_type = input_assembler_type::vertex_buffer_layout_type;
406 using index_buffer_layout_type = input_assembler_type::index_buffer_layout_type;
407
408 public:
413 virtual TDerived& topology(const PrimitiveTopology& topology) = 0;
414
419 virtual void use(UniquePtr<vertex_buffer_layout_type>&& layout) = 0;
420
426 virtual void use(UniquePtr<index_buffer_layout_type>&& layout) = 0;
427 };
428
435 template <typename TDerived, typename TRenderPipeline> requires
436 rtti::implements<TRenderPipeline, RenderPipeline<typename TRenderPipeline::pipeline_layout_type, typename TRenderPipeline::shader_program_type, typename TRenderPipeline::input_assembler_type, typename TRenderPipeline::rasterizer_type>>
437 class RenderPipelineBuilder : public Builder<TDerived, TRenderPipeline> {
438 public:
439 using Builder<TDerived, TRenderPipeline>::Builder;
440 using render_pipeline_type = TRenderPipeline;
441 using pipeline_layout_type = render_pipeline_type::pipeline_layout_type;
442 using shader_program_type = render_pipeline_type::shader_program_type;
443 using input_assembler_type = render_pipeline_type::input_assembler_type;
444 using rasterizer_type = render_pipeline_type::rasterizer_type;
445
446 public:
455 virtual TDerived& shaderProgram(SharedPtr<shader_program_type> program) = 0;
456
461 virtual TDerived& layout(SharedPtr<pipeline_layout_type> layout) = 0;
462
467 virtual TDerived& rasterizer(SharedPtr<rasterizer_type> rasterizer) = 0;
468
473 virtual TDerived& inputAssembler(SharedPtr<input_assembler_type> inputAssembler) = 0;
474
479 virtual TDerived& viewport(SharedPtr<IViewport> viewport) = 0;
480
485 virtual TDerived& scissor(SharedPtr<IScissor> scissor) = 0;
486
494 virtual TDerived& enableAlphaToCoverage(const bool& enable = true) = 0;
495 };
496
503 template <typename TDerived, typename TComputePipeline> requires
504 rtti::implements<TComputePipeline, ComputePipeline<typename TComputePipeline::pipeline_layout_type, typename TComputePipeline::shader_program_type>>
505 class ComputePipelineBuilder : public Builder<TDerived, TComputePipeline> {
506 public:
507 using Builder<TDerived, TComputePipeline>::Builder;
508 using compute_pipeline_type = TComputePipeline;
509 using pipeline_layout_type = compute_pipeline_type::pipeline_layout_type;
510 using shader_program_type = compute_pipeline_type::shader_program_type;
511
512 public:
521 virtual TDerived& shaderProgram(SharedPtr<shader_program_type> program) = 0;
522
527 virtual TDerived& layout(SharedPtr<pipeline_layout_type> layout) = 0;
528 };
529
536 template <typename TDerived, typename TRenderPass> requires
537 rtti::implements<TRenderPass, RenderPass<typename TRenderPass::render_pipeline_type, typename TRenderPass::frame_buffer_type, typename TRenderPass::input_attachment_mapping_type>>
538 class RenderPassBuilder : public Builder<TDerived, TRenderPass> {
539 public:
540 using Builder<TDerived, TRenderPass>::Builder;
541 using render_pass_type = TRenderPass;
542 using input_attachment_mapping_type = render_pass_type::input_attachment_mapping_type;
543
544 public:
549 virtual TDerived& commandBuffers(const UInt32& count) = 0;
550
555 virtual TDerived& multiSamplingLevel(const MultiSamplingLevel& samples) = 0;
556
566 virtual TDerived& renderTarget(const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) = 0;
567
578 virtual TDerived& renderTarget(const String& name, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) = 0;
579
590 virtual TDerived& renderTarget(const UInt32& location, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) = 0;
591
603 virtual TDerived& renderTarget(const String& name, const UInt32& location, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) = 0;
604
615 virtual TDerived& renderTarget(input_attachment_mapping_type& output, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) = 0;
616
628 virtual TDerived& renderTarget(const String& name, input_attachment_mapping_type& output, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) = 0;
629
641 virtual TDerived& renderTarget(input_attachment_mapping_type& output, const UInt32& location, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) = 0;
642
655 virtual TDerived& renderTarget(const String& name, input_attachment_mapping_type& output, const UInt32& location, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) = 0;
656
661 virtual TDerived& inputAttachment(const input_attachment_mapping_type& inputAttachment) = 0;
662
669 virtual TDerived& inputAttachment(const UInt32& inputLocation, const render_pass_type& renderPass, const UInt32& outputLocation) = 0;
670
677 virtual TDerived& inputAttachment(const UInt32& inputLocation, const render_pass_type& renderPass, const RenderTarget& renderTarget) = 0;
678 };
679}
680#endif // defined(BUILD_DEFINE_BUILDERS)
Describes an generic builder type.
Definition: containers.hpp:509
Definition: math.hpp:349
Implements a render target.
Definition: rendering_api.hpp:1994
uint32_t UInt32
Definition: math.hpp:37
float_t Float
Definition: math.hpp:40
Definition: dx12.hpp:8
std::string String
Definition: string.hpp:19
std::shared_ptr< T > SharedPtr
Represents a shared pointer, that expresses non-exclusive ownership.
Definition: containers.hpp:94
std::unique_ptr< T, TDeleter > UniquePtr
Represents a unique pointer, that expresses exclusive ownership.
Definition: containers.hpp:87
Describes the rasterizer depth bias.
Definition: rendering_api.hpp:2100
Describes the rasterizer depth state.
Definition: rendering_api.hpp:2073
Describes the rasterizer stencil state.
Definition: rendering_api.hpp:2152