SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
Image.h
1#pragma once
2
3#include "spark/render/DeviceMemory.h"
4#include "spark/render/Export.h"
5#include "spark/render/StateResource.h"
6#include "spark/render/Format.h"
7
8#include "spark/math/Vector3.h"
9
10namespace spark::render
11{
15 enum class ImageDimensions
16 {
18 DIM_1 = 0x01,
19
21 DIM_2 = 0x02,
22
24 DIM_3 = 0x03,
25
27 CUBE = 0x04
28 };
29
33 enum class ImageLayout
34 {
39 Common = 0x00000001,
40
45 ShaderResource = 0x00000002,
46
51 ReadWrite = 0x00000003,
52
57 CopySource = 0x00000010,
58
63 CopyDestination = 0x00000011,
64
69 RenderTarget = 0x00000020,
70
75 DepthRead = 0x00000021,
76
81 DepthWrite = 0x00000022,
82
89 Present = 0x00000023,
90
95 ResolveSource = 0x00000024,
96
101 ResolveDestination = 0x00000025,
102
109 Undefined = 0x7FFFFFFF
110 };
111
116 enum class MultiSamplingLevel
117 {
121 X1 = 0x00000001,
122 X2 = 0x00000002,
123 X4 = 0x00000004,
124 X8 = 0x00000008,
125 X16 = 0x00000010,
126 X32 = 0x00000020,
127 X64 = 0x00000040
128 };
129
130 class SPARK_RENDER_EXPORT IImage : public virtual IStateResource, public virtual IDeviceMemory
131 {
132 public:
133 ~IImage() noexcept override = default;
134
135 // Needed to make clang happy, else it complains about a hidden overloaded virtual function (but it is not hidden)
136 using IDeviceMemory::size;
137
144 [[nodiscard]] virtual std::size_t size(unsigned int level) const = 0;
145
153 [[nodiscard]] virtual math::Vector3<unsigned> extent(unsigned level = 0) const noexcept = 0;
154
159 [[nodiscard]] virtual Format format() const noexcept = 0;
160
167 [[nodiscard]] virtual ImageDimensions dimensions() const noexcept = 0;
168
173 [[nodiscard]] virtual unsigned int levels() const noexcept = 0;
174
179 [[nodiscard]] virtual unsigned int layers() const noexcept = 0;
180
187 [[nodiscard]] virtual unsigned int planes() const noexcept = 0;
188
193 [[nodiscard]] virtual MultiSamplingLevel samples() const noexcept = 0;
194
200 [[nodiscard]] virtual ImageLayout layout(unsigned int sub_resource = 0) const = 0;
201
209 [[nodiscard]] virtual unsigned int subResourceId(unsigned& level, unsigned& layer, unsigned& plane) const noexcept
210 {
211 return level + layer * levels() + plane * levels() * layers();
212 }
213
219 [[nodiscard]] std::tuple<unsigned, unsigned, unsigned> resolveSubresource(const unsigned subresource) const noexcept
220 {
221 const unsigned level = levels();
222 const unsigned resources_per_plane = level * layers();
223 return std::make_tuple<unsigned, unsigned, unsigned>(subresource / resources_per_plane, subresource % resources_per_plane / level, subresource % level);
224 }
225 };
226}
227
228template <>
229struct std::formatter<spark::render::MultiSamplingLevel> : std::formatter<std::string_view>
230{
231 static constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
232
233 static constexpr auto format(const spark::render::MultiSamplingLevel level, auto& ctx)
234 {
235 switch (level) // NOLINT(clang-diagnostic-switch-enum): X1 is handled after the switch statement.
236 {
237 case spark::render::MultiSamplingLevel::X2:
238 return std::format_to(ctx.out(), "X2");
239 case spark::render::MultiSamplingLevel::X4:
240 return std::format_to(ctx.out(), "X4");
241 case spark::render::MultiSamplingLevel::X8:
242 return std::format_to(ctx.out(), "X8");
243 case spark::render::MultiSamplingLevel::X16:
244 return std::format_to(ctx.out(), "X16");
245 case spark::render::MultiSamplingLevel::X32:
246 return std::format_to(ctx.out(), "X32");
247 case spark::render::MultiSamplingLevel::X64:
248 return std::format_to(ctx.out(), "X64");
249 default:
250 break;
251 }
252 return std::format_to(ctx.out(), "X1");
253 }
254};
A vector with three components.
Definition Vector3.h:13
Describes a chunk of memory on the GPU.
Definition DeviceMemory.h:13
Definition Image.h:131
virtual std::size_t size(unsigned int level) const =0
Get the size of the image (in bytes) at the specified mip-map level.
std::tuple< unsigned, unsigned, unsigned > resolveSubresource(const unsigned subresource) const noexcept
Returns the sub-resource ID for a combination of mip-map level, array layer and plane.
Definition Image.h:219
virtual math::Vector3< unsigned > extent(unsigned level=0) const noexcept=0
Get the extent of the image at the specified mip-map level.
Interface for a state resource.
Definition StateResource.h:14