Cogs.Rendering
Loading...
Searching...
No Matches
Common.h
Go to the documentation of this file.
1#pragma once
2
3#include "Foundation/HashFunctions.h"
4
5// Use to ensure arrays used for mapping enumeration values are of correct size.
6#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.");
7
8namespace Cogs
9{
11
13 struct NoConversion {};
14
16
20 template<typename Type, typename Convertible = NoConversion>
21 struct Handle_t
22 {
24 typedef int64_t handle_type;
25
29 Handle_t() : handle(-1) {}
30
34 Handle_t(const Handle_t & other) : handle(other.handle) {}
35
41 explicit Handle_t(const handle_type& handle) : handle(handle) {}
42
48 Handle_t(const Convertible & other) : handle(other.handle) {}
49
53 Handle_t & operator=(const Handle_t & other) { this->handle = other.handle; return *this; }
54
61 [[nodiscard]] bool operator==(const Handle_t & other) const { return this->handle == other.handle; }
62
64 explicit operator bool() const { return handle != 0 && handle != -1; }
65
71 operator Convertible() { return Convertible(this->handle); };
72
74 handle_type handle;
75
77 const static Handle_t NoHandle;
78
80 const static Handle_t InvalidHandle;
81 };
82
83 template<typename T, typename U>
85
86 template<typename T, typename U>
88}
89
90namespace std
91{
95 template<typename T, typename U>
96 struct hash<Cogs::Handle_t<T, U>>
97 {
98 std::size_t operator()(const Cogs::Handle_t<T, U> & handle) const
99 {
100 return std::hash<typename Cogs::Handle_t<T, U>::handle_type>()(handle.handle);
101 }
102 };
103}
104
105namespace Cogs
106{
111 {
114 {
133
138
139 // Provided for size comparisons.
141 };
142 };
143
148 {
150 {
152 Front = 0,
154 Back
155 };
156 };
157
159 {
161 {
162 None = 0,
164 IndependentBlend = 1 << 1
165 };
166 };
167
172 {
175 {
177 None = 0,
181 NoSwap = 0x0001L,
182 };
183 };
184
188 enum class Axis {
189 PositiveX,
190 NegativeX,
191 PositiveY,
192 NegativeY,
193 PositiveZ,
194 NegativeZ,
195
196 Count,
197 Unknown = -1,
198 };
199
201
202 struct InputLayoutTag {};
203 struct BufferTag {};
204 struct TextureTag {};
205 struct SamplerTag {};
206 struct EffectTag {};
207 struct ShaderTag {};
208 struct RenderPipelineTag {};
209 struct ComputePipelineTag {};
210 struct RenderTargetTag {};
211 struct DepthStencilTag {};
212 struct ConstantBufferBindingTag {};
213 struct VariableBindingTag {};
214 struct TextureBindingTag {};
215 struct SamplerStateBindingTag {};
216 struct BufferBindingTag {};
217 struct TextureViewTag {};
218 struct VertexFormatTag {};
219 struct VertexArrayObjectTag {};
220 struct FenceTag {};
221
223
227
229
233
235
237
238 typedef intptr_t TextureNativeHandle;
241
246
249
255
257
259
260 template<typename T>
261 inline bool HandleIsValid(const Handle_t<T> handle)
262 {
263 return (handle != Handle_t<T>::NoHandle && handle != Handle_t<T>::InvalidHandle);
264 }
265
266 template<typename T, typename U>
267 inline bool HandleIsValid(const Handle_t<T, U> handle)
268 {
269 return (handle != Handle_t<T, U>::NoHandle && handle != Handle_t<T, U>::InvalidHandle);
270 }
271
272 inline bool isDebug()
273 {
274#ifdef _DEBUG
275 return true;
276#else
277 return false;
278#endif
279 }
280}
Definition: Base.h:24
@ Unknown
Unknown type of graphics device.
Handle_t< VertexFormatTag > VertexFormatHandle
Definition: Common.h:234
Handle_t< FenceTag > FenceHandle
Definition: Common.h:258
Axis
Axis definitions.
Definition: Common.h:188
Handle_t< ConstantBufferBindingTag > ConstantBufferBindingHandle
Definition: Common.h:251
Handle_t< BufferTag, BufferHandle > IndexBufferHandle
Definition: Common.h:232
Handle_t< struct RasterizerState > RasterizerStateHandle
Definition: Common.h:224
Handle_t< VariableBindingTag > EffectVariableHandle
Definition: Common.h:250
Handle_t< InputLayoutTag > InputLayoutHandle
Definition: Common.h:228
Handle_t< ComputePipelineTag > ComputePipelineHandle
Definition: Common.h:245
Handle_t< DepthStencilTag > DepthStencilHandle
Definition: Common.h:248
Handle_t< ShaderTag > ShaderHandle
Definition: Common.h:243
bool isDebug()
Definition: Common.h:272
Handle_t< SamplerStateBindingTag > SamplerStateBindingHandle
Definition: Common.h:253
Handle_t< SamplerTag > SamplerStateHandle
Definition: Common.h:240
Handle_t< BufferBindingTag > BufferBindingHandle
Definition: Common.h:254
Handle_t< TextureViewTag > TextureViewHandle
Definition: Common.h:256
Handle_t< VertexArrayObjectTag > VertexArrayObjectHandle
Definition: Common.h:236
intptr_t TextureNativeHandle
Definition: Common.h:238
Handle_t< RenderTargetTag > RenderTargetHandle
Definition: Common.h:247
Handle_t< struct BlendState > BlendStateHandle
Definition: Common.h:226
Handle_t< EffectTag > EffectHandle
Definition: Common.h:242
bool HandleIsValid(const Handle_t< T > handle)
Definition: Common.h:261
Handle_t< RenderPipelineTag > RenderPipelineHandle
Definition: Common.h:244
Handle_t< struct DepthStencilState > DepthStencilStateHandle
Definition: Common.h:225
Handle_t< BufferTag, BufferHandle > VertexBufferHandle
Definition: Common.h:231
Handle_t< BufferTag > BufferHandle
Definition: Common.h:230
Handle_t< TextureBindingTag > TextureBindingHandle
Definition: Common.h:252
Handle_t< TextureTag > TextureHandle
Definition: Common.h:239
STL namespace.
Definition: Common.h:159
EBlendFlags
Definition: Common.h:161
@ None
Definition: Common.h:162
@ AlphaToCoverage
Definition: Common.h:163
@ IndependentBlend
Definition: Common.h:164
Framebuffers to select from when doing framebuffer operations.
Definition: Common.h:148
EFrameBuffer
Definition: Common.h:150
@ Back
Back buffer.
Definition: Common.h:154
@ Front
Front buffer.
Definition: Common.h:152
Handle template class used to provide opaque, non-converting handles.
Definition: Common.h:22
static const Handle_t NoHandle
Represents a handle to nothing.
Definition: Common.h:77
Handle_t(const Handle_t &other)
Copy constructor.
Definition: Common.h:34
Handle_t(const handle_type &handle)
Construct a handle with an explicit internal resource handle.
Definition: Common.h:41
Handle_t(const Convertible &other)
Conversion constructor from Convertible type.
Definition: Common.h:48
handle_type handle
Internal resource handle.
Definition: Common.h:74
Handle_t()
Construct a handle.
Definition: Common.h:29
int64_t handle_type
Internal handle storage type.
Definition: Common.h:24
static const Handle_t InvalidHandle
Represents an invalid handle.
Definition: Common.h:80
bool operator==(const Handle_t &other) const
Equality operator.
Definition: Common.h:61
Handle_t & operator=(const Handle_t &other)
Assignment operator.
Definition: Common.h:53
Flags controlling presentation.
Definition: Common.h:172
EPresentFlags
Present flags enumeration.
Definition: Common.h:175
@ NoSwap
Disables frame buffer swapping. This will leave the currently presented buffer as is.
Definition: Common.h:181
@ Default
Default swap flags.
Definition: Common.h:179
@ None
No flags.
Definition: Common.h:177
Primitive types for interpreting vertex data sent to the graphics pipeline.
Definition: Common.h:111
EPrimitiveType
Primitive type enumeration.
Definition: Common.h:114
@ LineStrip
Line strip.
Definition: Common.h:122
@ ControlPoint4PatchList
Definition: Common.h:137
@ ControlPoint2PatchList
Definition: Common.h:135
@ LineStripAdjacency
Line strip with adjacency.
Definition: Common.h:132
@ LineList
List of lines.
Definition: Common.h:120
@ ControlPoint1PatchList
Definition: Common.h:134
@ TriangleStrip
Triangle strip.
Definition: Common.h:118
@ TriangleListAdjacency
List of triangles with adjacency.
Definition: Common.h:126
@ PointList
List of points.
Definition: Common.h:124
@ ControlPoint3PatchList
Definition: Common.h:136
@ TriangleStripAdjacency
Triangle strip with adjacency.
Definition: Common.h:128
@ LineListAdjacency
List of lines with adjacency.
Definition: Common.h:130
@ PrimitiveType_Size
Definition: Common.h:140
@ TriangleList
List of triangles.
Definition: Common.h:116
std::size_t operator()(const Cogs::Handle_t< T, U > &handle) const
Definition: Common.h:98