MayaFlux 0.1.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 * 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
80private:
81 /**
82 * Get size in bytes for a given modality
83 * Mirrors VKBuffer::get_format() logic
84 */
85 static uint32_t modality_size_bytes(DataModality mod)
86 {
87 switch (mod) {
92 return sizeof(glm::vec3);
93
95 return sizeof(glm::vec2);
96
98 return sizeof(glm::vec4);
99
102 return sizeof(double);
103
104 default:
105 return 4; // Conservative default
106 }
107 }
108};
109
110} // namespace MayaFlux::Buffers
DataModality
Data modality types for cross-modal analysis.
Definition NDData.hpp:78
@ AUDIO_MULTICHANNEL
Multi-channel audio.
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 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.
std::vector< VertexAttributeLayout > attributes
All attributes that make up one vertex Ordered by shader location (0, 1, 2, ...)
Complete description of vertex data layout in a buffer.