Cogs.Core
VertexFormat.h
1#pragma once
2
3#include "Common.h"
4#include "DataFormat.h"
5
6#include <vector>
7
8namespace Cogs
9{
13 enum class ElementSemantic : uint16_t
14 {
15 Position,
16 Normal,
17 Color,
19 Tangent,
22 Semantic_Size // Provided for size comparisons.
23 };
24
28 enum class InputType : uint16_t
29 {
30 VertexData = 0,
32 };
33
38 {
39 uint16_t offset;
40 DataFormat format;
42 uint16_t semanticIndex;
44 uint16_t instanceStep;
45 };
46
48 {
49 DataFormat format;
51 uint16_t semanticIndex;
53 uint16_t instanceStep;
54 };
55
60 {
62 std::vector<VertexElement> elements;
63
65 size_t hash = 0;
66
68 uint32_t size = 0;
69 };
70
71 struct COGSRENDERING_DLL_API VertexFormats
72 {
73 static VertexFormatHandle createVertexFormat(const VertexElement * elements, size_t count);
74 static VertexFormatHandle createVertexFormat(const PackedVertexElement * elements, size_t count);
75 static inline VertexFormatHandle createVertexFormat(const VertexElement & element) { return createVertexFormat(&element, 1); }
76
77 static const VertexFormat * getVertexFormat(VertexFormatHandle handle);
78 };
79
80 StringView COGSRENDERING_DLL_API getElementSemanticName(ElementSemantic semantic);
81
82 inline uint32_t COGSRENDERING_DLL_API getSize(const Cogs::VertexFormat & vertexFormat)
83 {
84 return vertexFormat.size;
85 }
86 inline uint32_t COGSRENDERING_DLL_API getSize(VertexFormatHandle vertexFormatHandle)
87 {
88 return getSize(*VertexFormats::getVertexFormat(vertexFormatHandle));
89 }
90 inline size_t COGSRENDERING_DLL_API getHash(const Cogs::VertexFormat & vertexFormat)
91 {
92 return vertexFormat.hash;
93 }
94 inline size_t COGSRENDERING_DLL_API getHash(VertexFormatHandle vertexFormatHandle)
95 {
96 return getHash(*VertexFormats::getVertexFormat(vertexFormatHandle));
97 }
98
100 inline size_t hash(const VertexElement& element, size_t hashValue = Cogs::hash()) {
101 hashValue = Cogs::hash(element.offset, hashValue);
102 hashValue = Cogs::hash(static_cast<uint16_t>(element.format), hashValue);
103 hashValue = Cogs::hash(static_cast<uint16_t>(element.semantic), hashValue);
104 hashValue = Cogs::hash(element.semanticIndex, hashValue);
105 hashValue = Cogs::hash(static_cast<uint16_t>(element.inputType), hashValue);
106 hashValue = Cogs::hash(element.instanceStep, hashValue);
107
108 return hashValue;
109 }
110
112 inline size_t hash(const Cogs::VertexFormat& format, size_t hashValue = Cogs::hash()) {
113 for (const VertexElement& element : format.elements) {
114 hashValue = Cogs::hash(element, hashValue);
115 }
116 return hashValue;
117 }
118}
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
Definition: HashFunctions.h:62
InputType
Input types for the input assembler.
Definition: VertexFormat.h:29
@ InstanceData
Per instance data.
@ VertexData
Per vertex data.
ElementSemantic
Element semantics used to map data to the shader stage.
Definition: VertexFormat.h:14
@ Position
Position semantic.
@ Tangent
Tangent semantic.
@ Normal
Normal semantic.
@ InstanceMatrix
Instance matrix semantic.
@ InstanceVector
Instance vector semantic.
@ Color
Color semantic.
@ TextureCoordinate
Texture coordinate semantic.
InputType inputType
Input type of the element, vertex or instance data.
Definition: VertexFormat.h:52
uint16_t instanceStep
Instance step factor.
Definition: VertexFormat.h:53
ElementSemantic semantic
Semantic mapping of the element (position, normal, etc...).
Definition: VertexFormat.h:50
uint16_t semanticIndex
Index for the semantic mapping.
Definition: VertexFormat.h:51
DataFormat format
Format of the element.
Definition: VertexFormat.h:49
Vertex element structure used to describe a single data element in a vertex for the input assembler.
Definition: VertexFormat.h:38
InputType inputType
Input type of the element, vertex or instance data.
Definition: VertexFormat.h:43
DataFormat format
Format of the element.
Definition: VertexFormat.h:40
uint16_t offset
Offset in bytes from the vertex position in memory.
Definition: VertexFormat.h:39
uint16_t semanticIndex
Index for the semantic mapping.
Definition: VertexFormat.h:42
ElementSemantic semantic
Semantic mapping of the element (position, normal, etc...).
Definition: VertexFormat.h:41
uint16_t instanceStep
Instance step factor.
Definition: VertexFormat.h:44
Vertex format structure used to describe a single vertex for the input assembler.
Definition: VertexFormat.h:60
uint32_t size
Calculated size of the vertex format.
Definition: VertexFormat.h:68
size_t hash
Hash code of the vertex format.
Definition: VertexFormat.h:65
std::vector< VertexElement > elements
Vector containing all vertex elements of this format.
Definition: VertexFormat.h:62