Cogs.Rendering
Loading...
Searching...
No Matches
Common.h
Go to the documentation of this file.
1#pragma once
2
3#include "Flags.h"
4#include "Foundation/HashFunctions.h"
5
6// Use to ensure arrays used for mapping enumeration values are of correct size.
7#define STATIC_ASSERT_MAPPING(mappingArray, sourceEnum) static_assert(sizeof(mappingArray) / sizeof(mappingArray[0]) == (int)sourceEnum, "Array size of " #mappingArray " must match number of enumerations in mapping array.");
8
9namespace Cogs
10{
12
14 struct NoConversion {};
15
17
21 template<typename Type, typename Convertible = NoConversion>
22 struct Handle_t
23 {
25 typedef int64_t handle_type;
26
30 Handle_t() : handle(-1) {}
31
35 Handle_t(const Handle_t & other) : handle(other.handle) {}
36
42 explicit Handle_t(const handle_type& handle) : handle(handle) {}
43
49 Handle_t(const Convertible & other) : handle(other.handle) {}
50
54 Handle_t & operator=(const Handle_t & other) { this->handle = other.handle; return *this; }
55
62 [[nodiscard]] bool operator==(const Handle_t & other) const { return this->handle == other.handle; }
63
65 explicit operator bool() const { return handle != 0 && handle != -1; }
66
72 operator Convertible() { return Convertible(this->handle); };
73
75 handle_type handle;
76
78 const static Handle_t NoHandle;
79
81 const static Handle_t InvalidHandle;
82 };
83
84 template<typename T, typename U>
86
87 template<typename T, typename U>
89}
90
91namespace std
92{
96 template<typename T, typename U>
97 struct hash<Cogs::Handle_t<T, U>>
98 {
99 std::size_t operator()(const Cogs::Handle_t<T, U> & handle) const
100 {
101 return std::hash<typename Cogs::Handle_t<T, U>::handle_type>()(handle.handle);
102 }
103 };
104}
105
106namespace Cogs
107{
111 enum class PrimitiveType
112 {
114 TriangleList = 0,
118 LineList,
120 LineStrip,
122 PointList,
131
136
137 // Provided for size comparisons.
139
140 None = -1,
141 };
142
146 enum class Framebuffer
147 {
149 Front = 0,
151 Back
152 };
153
154 enum class BlendFlags
155 {
156 None = 0,
157 AlphaToCoverage = 1 << 0,
158 IndependentBlend = 1 << 1
159 };
161
165 enum class PresentFlags
166 {
168 None = 0,
170 Default = None,
172 NoSwap = 0x0001L,
173 };
175
179 enum class Axis {
180 PositiveX,
181 NegativeX,
182 PositiveY,
183 NegativeY,
184 PositiveZ,
185 NegativeZ,
186
187 Count,
188 Unknown = -1,
189 };
190
192
193 struct InputLayoutTag {};
194 struct BufferTag {};
195 struct TextureTag {};
196 struct SamplerTag {};
197 struct EffectTag {};
198 struct ShaderTag {};
199 struct RenderPipelineTag {};
200 struct ComputePipelineTag {};
201 struct RenderTargetTag {};
202 struct DepthStencilTag {};
203 struct ConstantBufferBindingTag {};
204 struct VariableBindingTag {};
205 struct TextureBindingTag {};
206 struct SamplerStateBindingTag {};
207 struct BufferBindingTag {};
208 struct TextureViewTag {};
209 struct VertexFormatTag {};
210 struct VertexArrayObjectTag {};
211 struct FenceTag {};
212
214
218
220
224
226
228
229 typedef intptr_t TextureNativeHandle;
232
237
240
246
248
250
251 template<typename T>
252 inline bool HandleIsValid(const Handle_t<T> handle)
253 {
254 return (handle != Handle_t<T>::NoHandle && handle != Handle_t<T>::InvalidHandle);
255 }
256
257 template<typename T, typename U>
258 inline bool HandleIsValid(const Handle_t<T, U> handle)
259 {
260 return (handle != Handle_t<T, U>::NoHandle && handle != Handle_t<T, U>::InvalidHandle);
261 }
262
263 inline bool isDebug()
264 {
265#ifdef _DEBUG
266 return true;
267#else
268 return false;
269#endif
270 }
271}
#define COGS_RENDERING_ENABLE_ENUM_FLAGS(EnumType)
Definition: Flags.h:8
Definition: Base.h:24
@ Default
Default type of graphics device, same as unknown.
@ Unknown
Unknown type of graphics device.
Handle_t< VertexFormatTag > VertexFormatHandle
Definition: Common.h:225
Handle_t< FenceTag > FenceHandle
Definition: Common.h:249
Axis
Axis definitions.
Definition: Common.h:179
Framebuffer
Framebuffers to select from when doing framebuffer operations.
Definition: Common.h:147
@ Back
Back buffer.
@ Front
Front buffer.
Handle_t< ConstantBufferBindingTag > ConstantBufferBindingHandle
Definition: Common.h:242
Handle_t< BufferTag, BufferHandle > IndexBufferHandle
Definition: Common.h:223
Handle_t< struct RasterizerState > RasterizerStateHandle
Definition: Common.h:215
Handle_t< VariableBindingTag > EffectVariableHandle
Definition: Common.h:241
Handle_t< InputLayoutTag > InputLayoutHandle
Definition: Common.h:219
Handle_t< ComputePipelineTag > ComputePipelineHandle
Definition: Common.h:236
Handle_t< DepthStencilTag > DepthStencilHandle
Definition: Common.h:239
PresentFlags
Flags controlling presentation.
Definition: Common.h:166
@ NoSwap
Disables frame buffer swapping. This will leave the currently presented buffer as is.
Handle_t< ShaderTag > ShaderHandle
Definition: Common.h:234
PrimitiveType
Primitive types for interpreting vertex data sent to the graphics pipeline.
Definition: Common.h:112
@ PointList
List of points.
@ TriangleStrip
Triangle strip.
@ LineList
List of lines.
@ TriangleStripAdjacency
Triangle strip with adjacency.
@ LineStripAdjacency
Line strip with adjacency.
@ LineListAdjacency
List of lines with adjacency.
@ TriangleListAdjacency
List of triangles with adjacency.
@ LineStrip
Line strip.
@ TriangleList
List of triangles.
@ None
Default flags.
Definition: IGraphicsDevice.h:30
bool isDebug()
Definition: Common.h:263
Handle_t< SamplerStateBindingTag > SamplerStateBindingHandle
Definition: Common.h:244
Handle_t< SamplerTag > SamplerStateHandle
Definition: Common.h:231
Handle_t< BufferBindingTag > BufferBindingHandle
Definition: Common.h:245
Handle_t< TextureViewTag > TextureViewHandle
Definition: Common.h:247
Handle_t< VertexArrayObjectTag > VertexArrayObjectHandle
Definition: Common.h:227
intptr_t TextureNativeHandle
Definition: Common.h:229
Handle_t< RenderTargetTag > RenderTargetHandle
Definition: Common.h:238
Handle_t< struct BlendState > BlendStateHandle
Definition: Common.h:217
Handle_t< EffectTag > EffectHandle
Definition: Common.h:233
bool HandleIsValid(const Handle_t< T > handle)
Definition: Common.h:252
Handle_t< RenderPipelineTag > RenderPipelineHandle
Definition: Common.h:235
Handle_t< struct DepthStencilState > DepthStencilStateHandle
Definition: Common.h:216
Handle_t< BufferTag, BufferHandle > VertexBufferHandle
Definition: Common.h:222
Handle_t< BufferTag > BufferHandle
Definition: Common.h:221
BlendFlags
Definition: Common.h:155
Handle_t< TextureBindingTag > TextureBindingHandle
Definition: Common.h:243
Handle_t< TextureTag > TextureHandle
Definition: Common.h:230
STL namespace.
Handle template class used to provide opaque, non-converting handles.
Definition: Common.h:23
static const Handle_t NoHandle
Represents a handle to nothing.
Definition: Common.h:78
Handle_t(const Handle_t &other)
Copy constructor.
Definition: Common.h:35
Handle_t(const handle_type &handle)
Construct a handle with an explicit internal resource handle.
Definition: Common.h:42
Handle_t(const Convertible &other)
Conversion constructor from Convertible type.
Definition: Common.h:49
handle_type handle
Internal resource handle.
Definition: Common.h:75
Handle_t()
Construct a handle.
Definition: Common.h:30
int64_t handle_type
Internal handle storage type.
Definition: Common.h:25
static const Handle_t InvalidHandle
Represents an invalid handle.
Definition: Common.h:81
bool operator==(const Handle_t &other) const
Equality operator.
Definition: Common.h:62
Handle_t & operator=(const Handle_t &other)
Assignment operator.
Definition: Common.h:54
std::size_t operator()(const Cogs::Handle_t< T, U > &handle) const
Definition: Common.h:99