SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
Rasterizer.h
1#pragma once
2
3#include "spark/render/DepthStencilState.h"
4#include "spark/render/Export.h"
5
6#include <format>
7#include <memory>
8
9namespace spark::render
10{
15 enum class PolygonMode
16 {
18 Solid = 0x00000001,
19
21 WireFrame = 0x00000002,
22
24 Point = 0x00000004
25 };
26
30 enum class CullMode
31 {
33 FrontFaces = 0x00000001,
34
36 BackFaces = 0x00000002,
37
39 Both = 0x00000004,
40
42 Disabled = 0x0000000F
43 };
44
50 enum class CullOrder
51 {
53 ClockWise = 0x00000001,
54
56 CounterClockWise = 0x00000002
57 };
58
62 class SPARK_RENDER_EXPORT IRasterizer
63 {
64 public:
65 virtual ~IRasterizer() noexcept = default;
66
71 [[nodiscard]] virtual PolygonMode polygonMode() const noexcept = 0;
72
77 [[nodiscard]] virtual CullMode cullMode() const noexcept = 0;
78
83 [[nodiscard]] virtual CullOrder cullOrder() const noexcept = 0;
84
90 [[nodiscard]] virtual float lineWidth() const noexcept = 0;
91
96 [[nodiscard]] virtual const DepthStencilState& depthStencilState() const noexcept = 0;
97 };
98
102 class SPARK_RENDER_EXPORT Rasterizer : public IRasterizer
103 {
104 public:
113 explicit Rasterizer(PolygonMode polygon_mode, CullMode cull_mode, CullOrder cull_order, float line_width, const DepthStencilState& depth_stencil_state) noexcept;
114 ~Rasterizer() noexcept override;
115
116 Rasterizer(const Rasterizer& other);
117 Rasterizer(Rasterizer&& other) noexcept;
118 Rasterizer& operator=(const Rasterizer& other);
119 Rasterizer& operator=(Rasterizer&& other) noexcept;
120
122 [[nodiscard]] PolygonMode polygonMode() const noexcept override;
123
125 [[nodiscard]] CullMode cullMode() const noexcept override;
126
128 [[nodiscard]] CullOrder cullOrder() const noexcept override;
129
131 [[nodiscard]] float lineWidth() const noexcept override;
132
134 [[nodiscard]] const DepthStencilState& depthStencilState() const noexcept override;
135
136 protected:
138 [[nodiscard]] float& lineWidth() noexcept;
139
140 private:
141 struct Impl;
142 std::unique_ptr<Impl> m_impl;
143 };
144}
145
146template <>
147struct std::formatter<spark::render::PolygonMode> : std::formatter<std::string_view>
148{
149 static constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
150
151 static constexpr auto format(const spark::render::PolygonMode polygon_mode, auto& ctx)
152 {
153 switch (polygon_mode)
154 {
155 case spark::render::PolygonMode::Solid:
156 return std::format_to(ctx.out(), "Solid");
157 case spark::render::PolygonMode::WireFrame:
158 return std::format_to(ctx.out(), "WireFrame");
159 case spark::render::PolygonMode::Point:
160 return std::format_to(ctx.out(), "Point");
161 }
162
163 return std::format_to(ctx.out(), "Unknown");
164 }
165};
166
167template <>
168struct std::formatter<spark::render::CullMode> : std::formatter<std::string_view>
169{
170 static constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
171
172 static constexpr auto format(const spark::render::CullMode cull_mode, auto& ctx)
173 {
174 switch (cull_mode)
175 {
176 case spark::render::CullMode::FrontFaces:
177 return std::format_to(ctx.out(), "FrontFaces");
178 case spark::render::CullMode::BackFaces:
179 return std::format_to(ctx.out(), "BackFaces");
180 case spark::render::CullMode::Both:
181 return std::format_to(ctx.out(), "Both");
182 case spark::render::CullMode::Disabled:
183 return std::format_to(ctx.out(), "Disabled");
184 }
185
186 return std::format_to(ctx.out(), "Unknown");
187 }
188};
189
190template <>
191struct std::formatter<spark::render::CullOrder> : std::formatter<std::string_view>
192{
193 static constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
194
195 static constexpr auto format(const spark::render::CullOrder cull_order, auto& ctx)
196 {
197 switch (cull_order)
198 {
199 case spark::render::CullOrder::ClockWise:
200 return std::format_to(ctx.out(), "ClockWise");
201 case spark::render::CullOrder::CounterClockWise:
202 return std::format_to(ctx.out(), "CounterClockWise");
203 }
204
205 return std::format_to(ctx.out(), "Unknown");
206 }
207};
Stores the depth/stencil state of a see IRasterizer.
Definition DepthStencilState.h:75
Represents the rasterizer stage of the graphics pipeline.
Definition Rasterizer.h:63
virtual PolygonMode polygonMode() const noexcept=0
Gets the polygon mode of the rasterizer state.
Implements the IRasterizer interface.
Definition Rasterizer.h:103
Definition Rasterizer.cpp:6