SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
RenderPass.h
1#pragma once
2
3#include "spark/render/Export.h"
4#include "spark/render/FrameBuffer.h"
5#include "spark/render/InputAttachementMapping.h"
6#include "spark/render/RenderPipeilne.h"
7#include "spark/render/RenderTarget.h"
8#include "spark/render/StateResource.h"
9
10#include <span>
11
12namespace spark::render
13{
17 class SPARK_RENDER_EXPORT IRenderPass : public virtual IStateResource
18 {
19 public:
20 ~IRenderPass() noexcept override = default;
21
29 virtual void begin(unsigned int buffer) = 0;
30
37 virtual void end() const = 0;
38
45 [[nodiscard]] const IFrameBuffer& activeFrameBuffer() const { return genericActiveFrameBuffer(); }
46
51 [[nodiscard]] std::vector<const IFrameBuffer*> frameBuffers() const noexcept { return genericFrameBuffers(); }
52
57 virtual void resizeFrameBuffers(const math::Vector2<unsigned int>& new_render_area) = 0;
58
63 [[nodiscard]] std::vector<const IRenderPipeline*> pipelines() const noexcept { return genericPipelines(); }
64
70 [[nodiscard]] virtual const RenderTarget& renderTarget(unsigned int location) const = 0;
71
76 [[nodiscard]] virtual std::span<const RenderTarget> renderTargets() const noexcept = 0;
77
82 [[nodiscard]] virtual bool hasPresentRenderTarget() const noexcept = 0;
83
88 [[nodiscard]] virtual MultiSamplingLevel multiSamplingLevel() const noexcept = 0;
89
94 void updateAttachments(const IDescriptorSet& descriptor_set) const { genericUpdateAttachments(descriptor_set); }
95
96 private:
97 [[nodiscard]] virtual const IFrameBuffer& genericActiveFrameBuffer() const = 0;
98 [[nodiscard]] virtual std::vector<const IFrameBuffer*> genericFrameBuffers() const noexcept = 0;
99 [[nodiscard]] virtual std::vector<const IRenderPipeline*> genericPipelines() const noexcept = 0;
100 virtual void genericUpdateAttachments(const IDescriptorSet& descriptor_set) const = 0;
101 };
102
112 template <typename RenderPipelineType, typename FrameBufferType, typename InputAttachmentMappingType>
113 class RenderPass : public StateResource, public IRenderPass, public InputAttachmentMappingSource<FrameBufferType>
114 {
115 public:
116 using frame_buffer_type = FrameBufferType;
117 using render_pipeline_type = RenderPipelineType;
118 using input_attachment_mapping_type = InputAttachmentMappingType;
119 using pipeline_layout_type = typename render_pipeline_type::pipeline_layout_type;
120 using descriptor_set_layout_type = typename pipeline_layout_type::descriptor_set_layout_type;
121 using descriptor_set_type = typename descriptor_set_layout_type::descriptor_set_type;
122
123 public:
125 [[nodiscard]] virtual const frame_buffer_type& activeFrameBuffer() const = 0;
126
128 [[nodiscard]] virtual std::vector<const frame_buffer_type*> frameBuffers() const noexcept = 0;
129
131 [[nodiscard]] virtual std::vector<const render_pipeline_type*> pipelines() const noexcept = 0;
132
137 [[nodiscard]] virtual std::span<const input_attachment_mapping_type> inputAttachments() const noexcept = 0;
138
140 virtual void updateAttachments(const descriptor_set_type& descriptor_set) const = 0;
141
142 private:
143 [[nodiscard]] const IFrameBuffer& genericActiveFrameBuffer() const final { return activeFrameBuffer(); }
144
145 [[nodiscard]] std::vector<const IFrameBuffer*> genericFrameBuffers() const noexcept final
146 {
147 auto tmp = frameBuffers();
148 std::vector<const IFrameBuffer*> frame_buffers_vector;
149 frame_buffers_vector.reserve(tmp.size());
150 std::ranges::transform(tmp, std::back_inserter(frame_buffers_vector), [](const auto& frame_buffer) { return static_cast<const IFrameBuffer*>(frame_buffer); });
151 return frame_buffers_vector;
152 }
153
154 [[nodiscard]] std::vector<const IRenderPipeline*> genericPipelines() const noexcept final
155 {
156 auto tmp = pipelines();
157 std::vector<const IRenderPipeline*> pipelines_vector;
158 pipelines_vector.reserve(tmp.size());
159 std::ranges::transform(tmp, std::back_inserter(pipelines_vector), [](const auto& pipeline) { return static_cast<const IRenderPipeline*>(pipeline); });
160 return pipelines_vector;
161 }
162
163 void genericUpdateAttachments(const IDescriptorSet& descriptor_set) const final { updateAttachments(static_cast<const descriptor_set_type&>(descriptor_set)); }
164 };
165}
A vector with two components.
Definition Vector2.h:13
Interface for a descriptor set.
Definition DescriptorSet.h:103
Interface for a frame buffer.
Definition FrameBuffer.h:17
Interface for a render pass.
Definition RenderPass.h:18
virtual const RenderTarget & renderTarget(unsigned int location) const =0
Gets the render target at the specified location.
virtual void resizeFrameBuffers(const math::Vector2< unsigned int > &new_render_area)=0
Resets the frame buffers owned by the render pass.
virtual void begin(unsigned int buffer)=0
Begins the render pass.
virtual std::span< const RenderTarget > renderTargets() const noexcept=0
Gets all render targets the render pass is rendering to.
const IFrameBuffer & activeFrameBuffer() const
Gets the active frame buffer from the render pass.
Definition RenderPass.h:45
virtual void end() const =0
Ends the render pass.
std::vector< const IFrameBuffer * > frameBuffers() const noexcept
Gets all frame buffers owned by the render pass.
Definition RenderPass.h:51
std::vector< const IRenderPipeline * > pipelines() const noexcept
Gets all render pipelines owned by the render pass.
Definition RenderPass.h:63
Interface for a render pipeline.
Definition RenderPipeilne.h:16
Interface for a state resource.
Definition StateResource.h:14
Represents the source for an input attachment mapping.
Definition InputAttachementMapping.h:16
Represents a render pass.
Definition RenderPass.h:114
virtual std::vector< const frame_buffer_type * > frameBuffers() const noexcept=0
Gets all frame buffers owned by the render pass.
virtual const frame_buffer_type & activeFrameBuffer() const =0
Gets the active frame buffer from the render pass.
Implements a IRenderTarget.
Definition RenderTarget.h:201
Base class for a resource that can be identified by a name in a DeviceState.
Definition StateResource.h:29