Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
VertexLayout.h
Go to the documentation of this file.
1/**
2 * @file VertexLayout.h
3 * @ingroup mnd_graphics
4 * @brief Describes the memory layout of a single vertex in a VBO.
5 *
6 * A VertexLayout is a list of VertexElements — each element maps one
7 * interleaved field (position, UV, normal …) to a numbered shader attribute.
8 *
9 * The layout is created by Builder factory methods together with the vertex
10 * data and is then stored inside Mesh. When Mesh::Bind() is called,
11 * GraphicsAPI reads the layout to issue the matching glVertexAttribPointer
12 * calls, connecting the raw buffer bytes to the GLSL attribute slots.
13 *
14 * Example interleaved vertex (pos + normal + UV) looks like:
15 * @code
16 * | x y z | nx ny nz | u v | ← one vertex, stride = 8 floats
17 * ^--- offset 0 ---^--- offset 12 ---^--- offset 24
18 * @endcode
19 *
20 * @see Builder, Mesh, GraphicsAPI::BindMesh
21 */
22
23#pragma once
24
25#include <cstdint>
26#include <vector>
27
28#include "graphics/GLForward.h"
29
30namespace mnd
31{
32
33/**
34 * @brief Describes one interleaved vertex attribute within a VBO.
35 *
36 * Maps directly to a glVertexAttribPointer call:
37 * - `index` → attrib location in the vertex shader.
38 * - `size` → component count (1–4).
39 * - `type` → GL data type (typically GL_FLOAT).
40 * - `offset` → byte offset from the start of the vertex struct.
41 */
43{
44 GLuint index; ///< Shader attribute location (layout(location = N)).
45 GLuint size; ///< Number of components (e.g. 3 for a vec3 position).
46 GLuint type; ///< GL data type constant (e.g. GL_FLOAT).
47 uint32_t offset; ///< Byte offset from the start of one vertex.
48
49 /// @brief Canonical attribute slot indices — must match the GLSL layout locations.
50 /// @{
51 static constexpr int PositionIndex = 0; ///< layout(location = 0) vec3 aPosition
52 static constexpr int ColorIndex = 1; ///< layout(location = 1) vec3 aColor
53 static constexpr int UVIndex = 2; ///< layout(location = 2) vec2 aUV
54 static constexpr int NormalIndex = 3; ///< layout(location = 3) vec3 aNormal
55 static constexpr int BoneIndicesIndex = 4; ///< layout(location = 4) ivec4 aBoneIndices
56 static constexpr int BoneWeightsIndex = 5; ///< layout(location = 5) vec4 aBoneWeights
57 /// @}
58};
59
60/**
61 * @brief Complete description of how vertex data is packed in a VBO.
62 *
63 * Holds all VertexElements for one mesh type plus the total stride (bytes
64 * between the start of consecutive vertices). Created by Builder factory
65 * functions and stored inside Mesh until the mesh is destroyed.
66 */
68{
69 std::vector<VertexElement> elements; ///< Ordered list of vertex attributes.
70 uint32_t stride = 0; ///< Total byte size of one vertex.
71};
72
73} // namespace mnd
unsigned int GLuint
Definition GLForward.h:11
Describes one interleaved vertex attribute within a VBO.
GLuint index
Shader attribute location (layout(location = N)).
static constexpr int NormalIndex
layout(location = 3) vec3 aNormal
uint32_t offset
Byte offset from the start of one vertex.
GLuint type
GL data type constant (e.g. GL_FLOAT).
static constexpr int BoneWeightsIndex
layout(location = 5) vec4 aBoneWeights
static constexpr int BoneIndicesIndex
layout(location = 4) ivec4 aBoneIndices
static constexpr int ColorIndex
layout(location = 1) vec3 aColor
static constexpr int UVIndex
layout(location = 2) vec2 aUV
GLuint size
Number of components (e.g. 3 for a vec3 position).
static constexpr int PositionIndex
Canonical attribute slot indices — must match the GLSL layout locations.
Complete description of how vertex data is packed in a VBO.
std::vector< VertexElement > elements
Ordered list of vertex attributes.
uint32_t stride
Total byte size of one vertex.