SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
RenderTarget.h
1#pragma once
2
3#include "spark/render/Export.h"
4#include "spark/render/Format.h"
5
6#include "spark/base/Macros.h"
7#include "spark/math/Vector4.h"
8
9#include <memory>
10#include <string>
11
12namespace spark::render
13{
17 enum class RenderTargetType
18 {
20 Color = 0x00000001,
21
23 DepthStencil = 0x00000002,
24
27 Present = 0x00000004
28 };
29
33 enum class BlendFactor
34 {
35 Zero = 0,
36 One = 1,
37 SourceColor = 2,
38 OneMinusSourceColor = 3,
39 DestinationColor = 4,
40 OneMinusDestinationColor = 5,
41 SourceAlpha = 6,
42 OneMinusSourceAlpha = 7,
43 DestinationAlpha = 8,
44 OneMinusDestinationAlpha = 9,
45 ConstantColor = 10,
46 OneMinusConstantColor = 11,
47 ConstantAlpha = 12,
48 OneMinusConstantAlpha = 13,
49 SourceAlphaSaturate = 14,
50 Source1Color = 15,
51 OneMinusSource1Color = 16,
52 Source1Alpha = 17,
53 OneMinusSource1Alpha = 18
54 };
55
59 enum class WriteMask
60 {
62 R = 0x01,
63
65 G = 0x02,
66
68 B = 0x04,
69
71 A = 0x08
72 };
73
74 SPARK_DEFINE_ENUM_FLAGS(WriteMask)
75
76
79 enum class BlendOperation
80 {
81 Add = 0x01,
82 Subtract = 0x02,
83 ReverseSubtract = 0x03,
84 Minimum = 0x04,
85 Maximum = 0x05
86 };
87
93 class SPARK_RENDER_EXPORT IRenderTarget
94 {
95 public:
96 virtual ~IRenderTarget() noexcept = default;
97
102 {
103 public:
105 bool enable = false;
106
108 BlendFactor sourceColor {BlendFactor::One};
109
111 BlendFactor destinationColor {BlendFactor::Zero};
112
114 BlendFactor sourceAlpha {BlendFactor::One};
115
117 BlendFactor destinationAlpha {BlendFactor::Zero};
118
120 BlendOperation colorOperation {BlendOperation::Add};
121
123 BlendOperation alphaOperation {BlendOperation::Add};
124
126 WriteMask writeMask {WriteMask::R | WriteMask::G | WriteMask::B | WriteMask::A};
127 };
128
133 [[nodiscard]] virtual std::string name() const noexcept = 0;
134
142 [[nodiscard]] virtual unsigned int location() const noexcept = 0;
143
148 [[nodiscard]] virtual RenderTargetType type() const noexcept = 0;
149
154 [[nodiscard]] virtual Format format() const noexcept = 0;
155
161 virtual bool clearBuffer() const noexcept = 0;
162
168 virtual bool clearStencil() const noexcept = 0;
169
177 [[nodiscard]] virtual math::Vector4<float> clearValues() const noexcept = 0;
178
188 [[nodiscard]] virtual bool isVolatile() const noexcept = 0;
189
194 [[nodiscard]] virtual BlendState blendState() const noexcept = 0;
195 };
196
200 class SPARK_RENDER_EXPORT RenderTarget final : public IRenderTarget
201 {
202 public:
206 explicit RenderTarget() noexcept;
207
219 explicit RenderTarget(unsigned int location,
220 RenderTargetType type,
221 Format format,
222 bool clear_buffer,
223 const math::Vector4<float>& clear_values = {0.f, 0.f, 0.f, 0.f},
224 bool clear_stencil = true,
225 bool is_volatile = false,
226 const BlendState& blend_state = {});
227
240 explicit RenderTarget(const std::string& name,
241 unsigned int location,
242 RenderTargetType type,
243 Format format,
244 bool clear_buffer,
245 const math::Vector4<float>& clear_values = {0.f, 0.f, 0.f, 0.f},
246 bool clear_stencil = true,
247 bool is_volatile = false,
248 const BlendState& blend_state = {});
249 ~RenderTarget() noexcept override;
250
251 RenderTarget(const RenderTarget& other);
252 RenderTarget(RenderTarget&& other) noexcept;
253 RenderTarget& operator=(const RenderTarget& other);
254 RenderTarget& operator=(RenderTarget&& other) noexcept;
255
257 [[nodiscard]] std::string name() const noexcept override;
258
260 [[nodiscard]] unsigned location() const noexcept override;
261
263 [[nodiscard]] RenderTargetType type() const noexcept override;
264
266 [[nodiscard]] Format format() const noexcept override;
267
269 bool clearBuffer() const noexcept override;
270
272 bool clearStencil() const noexcept override;
273
275 [[nodiscard]] math::Vector4<float> clearValues() const noexcept override;
276
278 [[nodiscard]] bool isVolatile() const noexcept override;
279
281 [[nodiscard]] BlendState blendState() const noexcept override;
282
283 private:
284 struct Impl;
285 std::unique_ptr<Impl> m_impl;
286 };
287}
A vector with four components.
Definition Vector4.h:13
Represents a render target, which is an abstract view of the output of a RenderPass....
Definition RenderTarget.h:94
virtual std::string name() const noexcept=0
Gets the name of the render target.
Implements a IRenderTarget.
Definition RenderTarget.h:201
RenderTarget(const std::string &name, unsigned int location, RenderTargetType type, Format format, bool clear_buffer, const math::Vector4< float > &clear_values={0.f, 0.f, 0.f, 0.f}, bool clear_stencil=true, bool is_volatile=false, const BlendState &blend_state={})
Initializes the RenderTarget.
RenderTarget() noexcept
Initializes a default RenderTarget.
Describes the blend state of a render target.
Definition RenderTarget.h:102