SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
Pipeline.h
1#pragma once
2
3#include "spark/render/DescriptorSet.h"
4#include "spark/render/Export.h"
5#include "spark/render/PushConstantsLayout.h"
6#include "spark/render/StateResource.h"
7
8namespace spark::render
9{
10 class IShaderProgram;
11
15 class SPARK_RENDER_EXPORT IPipelineLayout
16 {
17 public:
18 virtual ~IPipelineLayout() noexcept = default;
19
25 [[nodiscard]] virtual const IDescriptorSetLayout& descriptorSet(unsigned int space) const = 0;
26
31 [[nodiscard]] std::vector<const IDescriptorSetLayout*> descriptorSets() const noexcept { return genericDescriptorSets(); }
32
37 [[nodiscard]] virtual const IPushConstantsLayout* pushConstants() const noexcept = 0;
38
39 private:
41 [[nodiscard]] virtual std::vector<const IDescriptorSetLayout*> genericDescriptorSets() const noexcept = 0;
42 };
43
49 template <typename DescriptorSetLayoutType, typename PushConstantsLayoutType>
51 {
52 public:
53 using descriptor_set_layout_type = DescriptorSetLayoutType;
54 using push_constants_layout_type = PushConstantsLayoutType;
55
56 public:
58 [[nodiscard]] const descriptor_set_layout_type& descriptorSet(unsigned int space) const override = 0;
59
61 [[nodiscard]] virtual std::vector<const descriptor_set_layout_type*> descriptorSets() const noexcept = 0;
62
64 [[nodiscard]] const push_constants_layout_type* pushConstants() const noexcept override = 0;
65
66 private:
67 [[nodiscard]] std::vector<const IDescriptorSetLayout*> genericDescriptorSets() const noexcept override
68 {
69 std::vector<const IDescriptorSetLayout*> descriptor_sets_vector;
70 descriptor_sets_vector.reserve(descriptorSets().size());
71 std::ranges::transform(descriptorSets(),
72 std::back_inserter(descriptor_sets_vector),
73 [](const auto& descriptor_set) { return static_cast<const IDescriptorSetLayout*>(descriptor_set); });
74 return descriptor_sets_vector;
75 }
76 };
77
81 class SPARK_RENDER_EXPORT IPipeline : public virtual IStateResource
82 {
83 public:
84 ~IPipeline() noexcept override = default;
85
90 [[nodiscard]] std::shared_ptr<const IShaderProgram> program() const noexcept { return genericProgram(); }
91
96 [[nodiscard]] std::shared_ptr<IPipelineLayout> layout() const noexcept { return genericLayout(); }
97
98 private:
101 [[nodiscard]] virtual std::shared_ptr<const IShaderProgram> genericProgram() const noexcept = 0;
102 [[nodiscard]] virtual std::shared_ptr<IPipelineLayout> genericLayout() const noexcept = 0;
104 };
105
111 template <typename PipelineLayoutType, typename ShaderProgramType>
112 class Pipeline : virtual public IPipeline
113 {
114 public:
115 using shader_program_type = ShaderProgramType;
116 using pipeline_layout_type = PipelineLayoutType;
117
118 public:
120 [[nodiscard]] virtual std::shared_ptr<const shader_program_type> program() const noexcept = 0;
121
123 [[nodiscard]] virtual std::shared_ptr<pipeline_layout_type> layout() const noexcept = 0;
124
125 private:
126 [[nodiscard]] std::shared_ptr<IPipelineLayout> genericLayout() const noexcept final { return std::static_pointer_cast<IPipelineLayout>(layout()); }
127 [[nodiscard]] std::shared_ptr<const IShaderProgram> genericProgram() const noexcept final { return std::static_pointer_cast<const IShaderProgram>(program()); }
128 };
129}
Interface for a descriptor set layout.
Definition DescriptorSet.h:262
Interface for pipeline layouts.
Definition Pipeline.h:16
virtual const IDescriptorSetLayout & descriptorSet(unsigned int space) const =0
Gets the descriptor set layout bound to the given space.
std::vector< const IDescriptorSetLayout * > descriptorSets() const noexcept
Gets all descriptor set layouts the pipeline has been initialized with.
Definition Pipeline.h:31
virtual const IPushConstantsLayout * pushConstants() const noexcept=0
Gets the push constants layout, or nullptr, if the pipeline does not use any push constants.
Interface representing a pipeline.
Definition Pipeline.h:82
std::shared_ptr< IPipelineLayout > layout() const noexcept
Gets the pipeline layout.
Definition Pipeline.h:96
std::shared_ptr< const IShaderProgram > program() const noexcept
Gets the shader program used by the pipeline.
Definition Pipeline.h:90
Interface for a push constants layout.
Definition PushConstantsLayout.h:15
Interface for a state resource.
Definition StateResource.h:14
Represents a the layout of a RenderPipeline.
Definition Pipeline.h:51
virtual std::vector< const descriptor_set_layout_type * > descriptorSets() const noexcept=0
Gets all descriptor set layouts the pipeline has been initialized with.
const descriptor_set_layout_type & descriptorSet(unsigned int space) const override=0
Gets the descriptor set layout bound to the given space.
Represents a pipeline state.
Definition Pipeline.h:113
virtual std::shared_ptr< const shader_program_type > program() const noexcept=0
Gets the shader program used by the pipeline.