Cogs.Core
Common.h
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
134 ControlPoint1PatchList,
135 ControlPoint2PatchList,
136 ControlPoint3PatchList,
137 ControlPoint4PatchList,
138
139 // Provided for size comparisons.
140 PrimitiveType_Size,
141 };
142 };
143
148 {
150 {
152 Front = 0,
154 Back
155 };
156 };
157
159 {
160 enum EBlendFlags
161 {
162 None = 0,
163 AlphaToCoverage = 1 << 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
224 typedef Handle_t<struct RasterizerState> RasterizerStateHandle;
225 typedef Handle_t<struct DepthStencilState> DepthStencilStateHandle;
226 typedef Handle_t<struct BlendState> BlendStateHandle;
227
228 typedef Handle_t<InputLayoutTag> InputLayoutHandle;
229
230 typedef Handle_t<BufferTag> BufferHandle;
231 typedef Handle_t<BufferTag, BufferHandle> VertexBufferHandle;
232 typedef Handle_t<BufferTag, BufferHandle> IndexBufferHandle;
233
234 typedef Handle_t<VertexFormatTag> VertexFormatHandle;
235
236 typedef Handle_t<VertexArrayObjectTag> VertexArrayObjectHandle;
237
238 typedef intptr_t TextureNativeHandle;
239 typedef Handle_t<TextureTag> TextureHandle;
240 typedef Handle_t<SamplerTag> SamplerStateHandle;
241
242 typedef Handle_t<EffectTag> EffectHandle;
243 typedef Handle_t<ShaderTag> ShaderHandle;
244 typedef Handle_t<RenderPipelineTag> RenderPipelineHandle;
245 typedef Handle_t<ComputePipelineTag> ComputePipelineHandle;
246
247 typedef Handle_t<RenderTargetTag> RenderTargetHandle;
248 typedef Handle_t<DepthStencilTag> DepthStencilHandle;
249
250 typedef Handle_t<VariableBindingTag> EffectVariableHandle;
251 typedef Handle_t<ConstantBufferBindingTag> ConstantBufferBindingHandle;
252 typedef Handle_t<TextureBindingTag> TextureBindingHandle;
253 typedef Handle_t<SamplerStateBindingTag> SamplerStateBindingHandle;
254 typedef Handle_t<BufferBindingTag> BufferBindingHandle;
255
256 typedef Handle_t<TextureViewTag> TextureViewHandle;
257
258 typedef Handle_t<FenceTag> FenceHandle;
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}
bool HandleIsValid(const ResourceHandle_t< T > &handle)
Check if the given resource is valid, that is not equal to NoHandle or InvalidHandle.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
Axis
Axis definitions.
Definition: Common.h:188
STL namespace.
Framebuffers to select from when doing framebuffer operations.
Definition: Common.h:148
@ 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
@ LineStripAdjacency
Line strip with adjacency.
Definition: Common.h:132
@ LineList
List of lines.
Definition: Common.h:120
@ 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
@ TriangleStripAdjacency
Triangle strip with adjacency.
Definition: Common.h:128
@ LineListAdjacency
List of lines with adjacency.
Definition: Common.h:130
@ TriangleList
List of triangles.
Definition: Common.h:116