CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
GPUVertexFormat.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Common.hpp"
11
12#include "GPUFormat.hpp"
13
16
20
22
23#include <tuple>
24
25namespace CeresEngine {
26
32
38 UInt32 offset = 0;
39
40 public:
45 friend bool operator==(const GPUVertexAttribute& lhs, const GPUVertexAttribute& rhs);
46
51 friend bool operator!=(const GPUVertexAttribute& lhs, const GPUVertexAttribute& rhs);
52
53 public: // Reflection
56 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
57 CE_REFL_DATA(element);
58 CE_REFL_DATA(offset);
59 }
60 };
61
76
80
84 UInt32 stride = 0;
85
93 UInt32 inputSlot = 0;
94
98
100 GPUVertexFormat() noexcept = default;
101
104 GPUVertexFormat& operator=(const GPUVertexFormat&) = default;
105
109 GPUVertexFormat(std::initializer_list<GPUVertexAttribute>&& aAttributesList, const UInt32 inputSlot = 0) noexcept
110 : GPUVertexFormat(aAttributesList.begin(), aAttributesList.end(), inputSlot) {}
111
115 template<typename BeginIterator, typename EndIterator>
116 explicit GPUVertexFormat(const BeginIterator& begin, const EndIterator& end, const UInt32 inputSlot = 0) noexcept
117 : attributes(begin, end), inputSlot(inputSlot) {
118 UInt32 offsetSoFar = 0;
119 for(GPUVertexAttribute& attribute : attributes) {
120 if(attribute.offset == 0) {
121 attribute.offset = offsetSoFar;
122 }
123 offsetSoFar = attribute.offset + UInt32(attribute.element.getSize());
124 }
125 }
126
127 public:
132 friend bool operator==(const GPUVertexFormat& lhs, const GPUVertexFormat& rhs);
133
138 friend bool operator!=(const GPUVertexFormat& lhs, const GPUVertexFormat& rhs);
139
140 public: // Reflection
143 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
144 CE_REFL_DATA(attributes);
145 CE_REFL_DATA(stride);
146 CE_REFL_DATA(inputSlot);
147 CE_REFL_DATA(inputRate);
148 }
149 };
150
151} // namespace CeresEngine
152
155
157template<> struct std::hash<CeresEngine::GPUVertexInputRate> {
158 inline size_t operator()(const CeresEngine::GPUVertexInputRate object) const noexcept { return CeresEngine::hash(object.raw); }
159};
160
#define CE_REFLECT_HASH(T)
Definition Hash.hpp:89
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
#define CE_STRUCT_ENUM_DECL(T)
Definition StructEnum.hpp:49
Definition StructEnum.hpp:18
UInt32 UnderlyingType
Definition StructEnum.hpp:20
Determines how a single element should be a vertex.
Definition VertexDeclaration.hpp:153
Definition Application.hpp:19
sfl::small_vector< T, N, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > SmallVector
SmallVector is a sequence container similar to Vector.
Definition SmallVector.hpp:31
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Span.hpp:668
A vertex attribute represents a pair of points that can be stored inside a vertex buffer.
Definition GPUVertexFormat.hpp:29
VertexElement element
The vertex element that this vertex attribute represents.
Definition GPUVertexFormat.hpp:31
Definition GPUVertexFormat.hpp:77
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition GPUVertexFormat.hpp:143
friend bool operator!=(const GPUVertexFormat &lhs, const GPUVertexFormat &rhs)
Compares two VertexFormat instances for inequality.
friend bool operator==(const GPUVertexFormat &lhs, const GPUVertexFormat &rhs)
Compares two VertexFormat instances for equality.
GPUVertexFormat(const BeginIterator &begin, const EndIterator &end, const UInt32 inputSlot=0) noexcept
Create a new VertexFormat from a vector of attributes.
Definition GPUVertexFormat.hpp:116
SmallVector< GPUVertexAttribute, 6 > attributes
Specifies the list of vertex attributes.
Definition GPUVertexFormat.hpp:79
Specify rate at which vertex attributes are pulled from buffers.
Definition GPUVertexFormat.hpp:63
@ Instance
Specifies that vertex attribute addressing is a function of the instance index.
Definition GPUVertexFormat.hpp:72
@ Vertex
Specifies that vertex attribute addressing is a function of the vertex index.
Definition GPUVertexFormat.hpp:68
enum CeresEngine::GPUVertexInputRate::@32 raw
The underlying raw value of VertexElementSemantic.
A basic vertex type.
Definition Mesh.hpp:51