MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
VertexLayout.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "NDData.hpp"
4
5namespace MayaFlux::Kakshya {
6
7/**
8 * @struct VertexAttributeLayout
9 * @brief Semantic description of a single vertex attribute
10 *
11 * Describes one component of vertex data without exposing Vulkan types.
12 * The modality encodes everything needed (3D position, 2D texture coords, etc.)
13 */
15 /**
16 * Semantic type of this attribute
17 * e.g., VERTEX_POSITIONS_3D → vec3, TEXTURE_COORDS_2D → vec2
18 */
20
21 /**
22 * Byte offset of this attribute within one vertex
23 * e.g., position at 0, normal at 12, color at 24
24 */
25 uint32_t offset_in_vertex = 0;
26
27 /**
28 * Optional name for debugging/introspection
29 * e.g., "position", "normal", "texCoord"
30 */
31 std::string name;
32};
33
34/**
35 * @struct VertexLayout
36 * @brief Complete description of vertex data layout in a buffer
37 *
38 * Fully semantic and backend-agnostic. Portal layer translates to Vulkan.
39 * Derived from buffer's modality and dimensions.
40 */
42 /**
43 * Total number of vertices in this buffer
44 */
45 uint32_t vertex_count = 0;
46
47 /**
48 * Total bytes per vertex (stride in Vulkan terms)
49 * e.g., 3 floats (position) + 3 floats (normal) = 24 bytes
50 */
51 uint32_t stride_bytes = 0;
52
53 /**
54 * All attributes that make up one vertex
55 * Ordered by shader location (0, 1, 2, ...)
56 */
57 std::vector<VertexAttributeLayout> attributes;
58
59 /**
60 * @brief Helper: compute stride from attributes if not explicitly set
61 */
63 {
64 if (stride_bytes == 0 && !attributes.empty()) {
65 uint32_t max_offset = 0;
66 uint32_t last_size = 0;
67
68 for (const auto& attr : attributes) {
69 uint32_t attr_size = modality_size_bytes(attr.component_modality);
70 max_offset = std::max(max_offset, attr.offset_in_vertex);
71 if (attr.offset_in_vertex == max_offset) {
72 last_size = attr_size;
73 }
74 }
75
76 stride_bytes = max_offset + last_size;
77 }
78 }
79
80 /**
81 * @brief Factory: Create layout for point primitives (position, color, size)
82 * @return VertexLayout configured for PointVertex
83 */
84 static VertexLayout for_points(uint32_t stride = 28)
85 {
86 VertexLayout layout;
87 layout.stride_bytes = stride;
88
89 layout.attributes.push_back(VertexAttributeLayout {
91 .offset_in_vertex = 0,
92 .name = "position" });
93
94 layout.attributes.push_back(VertexAttributeLayout {
96 .offset_in_vertex = 12,
97 .name = "color" });
98
99 layout.attributes.push_back(VertexAttributeLayout {
101 .offset_in_vertex = 24,
102 .name = "size" });
103
104 return layout;
105 }
106
107 /**
108 * @brief Factory: Create layout for line primitives (position, color, thickness)
109 * @return VertexLayout configured for LineVertex
110 */
111 static VertexLayout for_lines(uint32_t stride = 36)
112 {
113 VertexLayout layout;
114 layout.stride_bytes = stride;
115
116 layout.attributes.push_back(VertexAttributeLayout {
118 .offset_in_vertex = 0,
119 .name = "position" });
120
121 layout.attributes.push_back(VertexAttributeLayout {
123 .offset_in_vertex = 12,
124 .name = "color" });
125
126 layout.attributes.push_back(VertexAttributeLayout {
128 .offset_in_vertex = 24,
129 .name = "thickness" });
130
131 layout.attributes.push_back(VertexAttributeLayout {
133 .offset_in_vertex = 28,
134 .name = "uv" });
135 return layout;
136 }
137
138 /**
139 * @brief Factory: Create layout for textured quad primitives (position, texcoord).
140 * @param vertex_count Number of vertices in the buffer (default: 4).
141 * @return VertexLayout configured for Nodes::TextureQuadVertex.
142 */
144 {
145 VertexLayout layout;
146 layout.vertex_count = vertex_count;
147 layout.stride_bytes = static_cast<uint32_t>(sizeof(glm::vec3) + sizeof(glm::vec2)); // 20
148
149 layout.attributes.push_back(VertexAttributeLayout {
151 .offset_in_vertex = 0,
152 .name = "position" });
153
154 layout.attributes.push_back(VertexAttributeLayout {
156 .offset_in_vertex = static_cast<uint32_t>(sizeof(glm::vec3)),
157 .name = "texcoord" });
158
159 return layout;
160 }
161
162private:
163 /**
164 * Get size in bytes for a given modality
165 * Mirrors VKBuffer::get_format() logic
166 */
168 {
169 switch (mod) {
174 return sizeof(glm::vec3);
175
177 return sizeof(glm::vec2);
178
180 return sizeof(glm::vec4);
181
184 return sizeof(double);
185
186 default:
187 return 4; // Conservative default
188 }
189 }
190};
191
192} // namespace MayaFlux::Buffers
DataModality
Data modality types for cross-modal analysis.
Definition NDData.hpp:78
@ AUDIO_MULTICHANNEL
Multi-channel audio.
@ SCALAR_F32
Single-channel float data.
std::string name
Optional name for debugging/introspection e.g., "position", "normal", "texCoord".
uint32_t offset_in_vertex
Byte offset of this attribute within one vertex e.g., position at 0, normal at 12,...
DataModality component_modality
Semantic type of this attribute e.g., VERTEX_POSITIONS_3D → vec3, TEXTURE_COORDS_2D → vec2.
Semantic description of a single vertex attribute.
uint32_t stride_bytes
Total bytes per vertex (stride in Vulkan terms) e.g., 3 floats (position) + 3 floats (normal) = 24 by...
uint32_t vertex_count
Total number of vertices in this buffer.
static VertexLayout for_textured_quad(uint32_t vertex_count=4)
Factory: Create layout for textured quad primitives (position, texcoord).
static uint32_t modality_size_bytes(DataModality mod)
Get size in bytes for a given modality Mirrors VKBuffer::get_format() logic.
void compute_stride()
Helper: compute stride from attributes if not explicitly set.
static VertexLayout for_points(uint32_t stride=28)
Factory: Create layout for point primitives (position, color, size)
std::vector< VertexAttributeLayout > attributes
All attributes that make up one vertex Ordered by shader location (0, 1, 2, ...)
static VertexLayout for_lines(uint32_t stride=36)
Factory: Create layout for line primitives (position, color, thickness)
Complete description of vertex data layout in a buffer.