-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMesh.hpp
More file actions
181 lines (172 loc) · 10.6 KB
/
Copy pathMesh.hpp
File metadata and controls
181 lines (172 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
Copyright (C) 2016-2021,2025,2026 Rodrigo Jose Hernandez Cordoba
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef AEONGAMES_MESH_H
#define AEONGAMES_MESH_H
#include <cstdint>
#include <string>
#include <memory>
#include <vector>
#include "aeongames/AABB.hpp"
#include "aeongames/CRC.hpp"
#include "aeongames/Resource.hpp"
namespace AeonGames
{
class MeshMsg;
/** @brief Represents a polygon mesh with vertex attributes and index data. */
class Mesh final : public Resource
{
public:
/** @brief Semantic meaning of a vertex attribute, identified by CRC32 of its name. */
enum AttributeSemantic : uint32_t
{
POSITION = "VertexPosition"_crc32, ///< Vertex position.
NORMAL = "VertexNormal"_crc32, ///< Vertex normal.
TANGENT = "VertexTangent"_crc32, ///< Vertex tangent.
BITANGENT = "VertexBitangent"_crc32, ///< Vertex bitangent.
TEXCOORD = "VertexUV"_crc32, ///< Texture coordinate.
WEIGHT_INDEX = "VertexWeightIndices"_crc32, ///< Bone weight indices.
WEIGHT_VALUE = "VertexWeights"_crc32, ///< Bone weight values.
COLOR = "VertexColor"_crc32, ///< Vertex color.
};
/** @brief Data type of a vertex attribute component. */
enum AttributeType : uint8_t
{
BYTE = 0, ///< Signed 8-bit integer.
UNSIGNED_BYTE = 1, ///< Unsigned 8-bit integer.
SHORT = 2, ///< Signed 16-bit integer.
UNSIGNED_SHORT = 3, ///< Unsigned 16-bit integer.
HALF_FLOAT = 4, ///< 16-bit floating point.
INT = 5, ///< Signed 32-bit integer.
UNSIGNED_INT = 6, ///< Unsigned 32-bit integer.
FLOAT = 7, ///< 32-bit floating point.
FIXED = 8, ///< Fixed-point.
DOUBLE = 9, ///< 64-bit floating point.
};
/** @brief Flags that modify how a vertex attribute is interpreted. */
enum AttributeFlag : uint8_t
{
NORMALIZED = 0b00000001, ///< Values are normalized to [0,1] or [-1,1].
INTEGER = 0b00000010, ///< Values are passed as integers (no conversion).
};
/** @brief Vertex stride of the compute-skinning output, in bytes.
*
* The skinning pass drops the per-vertex weight data, so its output is
* the compact position/normal/tangent/bitangent/uv layout rather than
* the weighted source stride. Both back-ends must bind the skinned
* buffer with this stride, not the source mesh's: getting it wrong
* misreads every vertex after the first. */
static constexpr size_t kSkinnedVertexStride = 56;
/** @brief CRC32-based binding location identifiers for descriptor sets. */
enum BindingLocations : uint32_t
{
MATRICES = "Matrices"_crc32, ///< Matrices binding.
MATERIAL = "Material"_crc32, ///< Material binding.
LIGHTS = "Lights"_crc32, ///< Per-frame lights binding.
SAMPLERS = "Samplers"_crc32, ///< Samplers binding.
CLUSTER_AABBS = "ClusterAABBs"_crc32, ///< Clustered shading: per-cluster view-space AABB list (SSBO).
LIGHT_INDEX_LIST = "LightIndexList"_crc32, ///< Clustered shading: flat light-index list per cluster (SSBO).
LIGHT_GRID = "LightGrid"_crc32, ///< Clustered shading: per-cluster (offset, count) into LightIndexList (SSBO).
LIGHT_INDEX_COUNTER = "LightIndexCounter"_crc32, ///< Clustered shading: global atomic allocator for the flat LightIndexList (SSBO, R1).
CLUSTER_ACTIVE = "ClusterActive"_crc32, ///< Clustered shading: per-cluster active flag set by the depth pre-pass mark stage (SSBO, R2).
CLUSTER_PARAMS = "ClusterParams"_crc32, ///< Clustered shading: tile/slice dimensions and depth-slicing constants (UBO).
SKINNING_MATRICES = "SkinningMatrices"_crc32, ///< Compute skinning: per-joint pose*inverse-bind matrices (SSBO, R4).
SOURCE_VERTICES = "SourceVertices"_crc32, ///< Compute skinning: rest-pose source vertex buffer (SSBO, R4).
SKINNED_VERTICES = "SkinnedVertices"_crc32, ///< Compute skinning: skinned output vertex buffer (SSBO, R4).
INSTANCE_MATRICES = "InstanceMatrices"_crc32, ///< Instanced rendering: per-instance model matrices indexed by instance id (SSBO).
INSTANCE_MATERIALS = "InstanceMaterials"_crc32, ///< GPU-driven rendering: per-instance bindless material index indexed by instance id (SSBO).
CULL_INSTANCES = "CullInstances"_crc32, ///< GPU-driven culling: per-candidate-instance model matrix, AABB and draw params, read by the cull compute (SSBO).
DRAW_COMMANDS = "DrawCommands"_crc32, ///< GPU-driven culling: compacted VkDrawIndexedIndirectCommand list written by the cull compute (SSBO).
DRAW_COUNT = "DrawCount"_crc32, ///< GPU-driven culling: visible-instance count written by the cull compute, read by vkCmdDrawIndexedIndirectCount (SSBO).
HI_Z = "HiZ"_crc32, ///< Hi-Z occlusion culling: max-reduced depth pyramid sampled by the cull compute (sampler2D).
SHADOW_PARAMS = "ShadowParams"_crc32, ///< Directional shadow mapping: light view-projection and filtering params (UBO).
SHADOW_MAP = "ShadowMap"_crc32, ///< Directional shadow mapping: depth shadow map sampled with comparison (sampler2DShadow).
SPOT_SHADOW_PARAMS = "SpotShadowParams"_crc32, ///< Spot shadow mapping: per-caster light view-projections, caster light indices and filtering params (UBO).
SPOT_SHADOW_MAP = "SpotShadowMap"_crc32, ///< Spot shadow mapping: depth shadow map array sampled with comparison (sampler2DArrayShadow).
POINT_SHADOW_PARAMS = "PointShadowParams"_crc32, ///< Point shadow mapping: per-caster six-face light view-projections, caster positions/radii and filtering params (UBO).
POINT_SHADOW_MAP = "PointShadowMap"_crc32, ///< Point shadow mapping: six-faces-per-caster depth array sampled with comparison (sampler2DArrayShadow).
GLOBALS = "Globals"_crc32, ///< Per-frame scene-wide shading globals (ambient fill, future frame-wide values) (UBO).
PREFILTERED_ENVIRONMENT = "PrefilteredEnvironment"_crc32, ///< Specular IBL: GGX-prefiltered environment equirect mip chain, window-owned global sampler (sampler2D).
BINDLESS = "Bindless"_crc32, ///< Bindless resources: global combined-image-sampler array (binding 0) + material storage buffer (binding 1), a renderer-owned set bound once per frame.
};
/** @brief Type alias for the number of components in a vertex attribute. */
using AttributeSize = uint8_t;
/** @brief Type alias for vertex attribute flag bits. */
using AttributeFlags = uint8_t;
/** @brief Tuple describing a single vertex attribute (semantic, component count, type, flags). */
using AttributeTuple = std::tuple<AttributeSemantic, AttributeSize, AttributeType, AttributeFlags, uint32_t>;
/** @brief Default constructor. */
DLL Mesh();
/** @brief Destructor. */
DLL ~Mesh() final;
/** @brief Load mesh data from a protobuf message.
* @param aMeshMsg The protobuf message to load from.
*/
DLL void LoadFromPBMsg ( const MeshMsg& aMeshMsg );
/** @brief Load mesh data from a raw memory buffer.
* @param aBuffer Pointer to the buffer.
* @param aBufferSize Size of the buffer in bytes.
*/
DLL void LoadFromMemory ( const void* aBuffer, size_t aBufferSize ) final;
/** @brief Unload mesh data and release resources. */
DLL void Unload() final;
/** @brief Get the list of vertex attributes.
* @return Const reference to the attribute tuple vector.
*/
DLL const std::vector<AttributeTuple>& GetAttributes() const;
/** @brief Get the byte offset of an attribute within one vertex. */
DLL uint32_t GetAttributeOffset ( const AttributeTuple& aAttribute ) const;
/** @brief Get the size in bytes of a single index.
* @return Index element size.
*/
DLL uint32_t GetIndexSize() const;
/** @brief Get the total number of indices.
* @return Index count.
*/
DLL uint32_t GetIndexCount() const;
/** @brief Get the total number of vertices.
* @return Vertex count.
*/
DLL uint32_t GetVertexCount() const;
/** @brief Get the raw vertex data buffer.
* @return Const reference to the vertex byte vector.
*/
DLL const std::vector<uint8_t>& GetVertexBuffer() const;
/** @brief Get the raw index data buffer.
* @return Const reference to the index byte vector.
*/
DLL const std::vector<uint8_t>& GetIndexBuffer() const;
/** @brief Get the axis-aligned bounding box of the mesh.
* @return Const reference to the AABB.
*/
DLL const AABB& GetAABB() const;
/** @brief Get the stride (bytes per vertex) for the vertex buffer.
* @return Stride in bytes.
*/
DLL size_t GetStride() const;
private:
AABB mAABB{};
std::vector<uint8_t> mVertexBuffer{};
std::vector<uint8_t> mIndexBuffer{};
std::vector<AttributeTuple> mAttributes{};
uint32_t mVertexCount{};
uint32_t mIndexSize{};
uint32_t mIndexCount{};
uint32_t mVertexStride{};
};
/** @brief Compute the total byte size of a single vertex attribute.
* @param aAttributeTuple Tuple describing the attribute.
* @return Size in bytes.
*/
DLL size_t GetAttributeTotalSize ( const Mesh::AttributeTuple& aAttributeTuple );
}
#endif