MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
VertexAccess.hpp
Go to the documentation of this file.
1#pragma once
2#include "VertexLayout.hpp"
3
4namespace MayaFlux::Kakshya {
5
6/**
7 * @struct VertexAccessConfig
8 * @brief Default attribute values for shader-compatible vertex conversion.
9 *
10 * Applied when DataVariant contains only positional data and the target
11 * layout requires additional attributes (color, size, thickness, uv).
12 */
13struct MAYAFLUX_API VertexAccessConfig {
14 glm::vec3 default_color { 1.0F, 1.0F, 1.0F };
15 float default_size { 3.0F };
16 float default_thickness { 1.0F };
17 float default_weight { 0.0F };
18 glm::vec2 default_uv { 0.0F, 0.0F };
19 glm::vec3 default_normal { 0.0F, 0.0F, 1.0F };
20 glm::vec3 default_tangent { 1.0F, 0.0F, 0.0F };
21};
22/**
23 * @struct VertexAccess
24 * @brief Memory-compatible view of channel data assembled into full 60-byte vertices.
25 *
26 * Mirrors TextureAccess: describes what the data IS in memory terms —
27 * pointer, byte count, and a VertexLayout — with no knowledge of Vulkan,
28 * Portal, or concrete vertex structs (PointVertex, LineVertex, MeshVertex).
29 *
30 * A vertex is always the canonical 60-byte record:
31 * position (vec3, 12) | color (vec3, 12) | scalar (float, 4) |
32 * uv (vec2, 8) | normal (vec3, 12) | tangent (vec3, 12)
33 *
34 * Zero-copy path: single vector<uint8_t> channel of N*60 bytes. data_ptr
35 * points directly into variant storage; conversion_buffer is empty.
36 *
37 * Assembly path: one or more typed channels supplied in canonical field order.
38 * Slot 0 = position (vec3), slot 1 = color (vec3), slot 2 = scalar (float),
39 * slot 3 = uv (vec2), slot 4 = normal (vec3), slot 5 = tangent (vec3).
40 * Missing trailing slots are filled from VertexAccessConfig defaults.
41 * Assembled bytes are held in conversion_buffer; data_ptr points into it.
42 *
43 * Source element size is taken from the supplied variant type. A vec4 color
44 * channel (16 bytes) copies 12 bytes into the color field; the alpha is
45 * discarded. A float scalar channel (4 bytes) maps exactly. Oversized
46 * elements are truncated; undersized elements are zero-padded within the field.
47 */
48struct MAYAFLUX_API VertexAccess {
49 const void* data_ptr = nullptr;
50 size_t byte_count = 0;
52
53 /**
54 * @brief True when data_ptr points into conversion_buffer rather than
55 * the original variant storage.
56 */
57 [[nodiscard]] bool was_converted() const noexcept
58 {
59 return !conversion_buffer.empty();
60 }
61
62 /**
63 * @brief Conversion buffer. Non-empty only when a type conversion was
64 * performed (scalar waveform → vec3, complex → vec3, etc.).
65 * Keeps converted data alive for the lifetime of this struct.
66 */
67 std::vector<std::byte> conversion_buffer;
68};
69
70/**
71 * @brief Extract a VertexAccess from a DataVariant.
72 *
73 * Inspects the active variant type and produces a VertexAccess whose
74 * layout describes the resulting vertex data. Scalar and complex types
75 * are converted to a positional vec3 waveform representation. GLM vector
76 * types are passed through without copying.
77 *
78 * @param variant Source data.
79 * @return Populated VertexAccess, or std::nullopt on incompatible type.
80 */
81[[nodiscard]] MAYAFLUX_API std::optional<VertexAccess>
82as_vertex_access(std::span<const DataVariant> channels,
83 const VertexAccessConfig& config = {});
84
85/**
86 * @brief Assemble point-vertex-compatible bytes from one or more data channels.
87 *
88 * channels[0] must supply position data (vec3 or uint8_t interleaved).
89 * channels[1..5] optionally supply color, scalar, uv, normal, tangent in
90 * canonical field order. Missing trailing channels are filled from config.
91 * A single uint8_t channel of N*60 bytes is passed through zero-copy.
92 *
93 * @param channels Source channels in canonical field order.
94 * @param config Default attribute values for absent channels.
95 * @return Populated VertexAccess, or std::nullopt on empty or incompatible input.
96 */
97[[nodiscard]] MAYAFLUX_API std::optional<VertexAccess>
98as_point_vertex_access(std::span<const DataVariant> channels,
99 const VertexAccessConfig& config = {});
100
101/**
102 * @brief Assemble line-vertex-compatible bytes from one or more data channels.
103 *
104 * channels[0] must supply position data (vec3 or uint8_t interleaved).
105 * channels[1..5] optionally supply color, thickness, uv, normal, tangent in
106 * canonical field order. Missing trailing channels are filled from config;
107 * slot 2 defaults to config.default_thickness.
108 * A single uint8_t channel of N*60 bytes is passed through zero-copy.
109 *
110 * @param channels Source channels in canonical field order.
111 * @param config Default attribute values for absent channels.
112 * @return Populated VertexAccess, or std::nullopt on empty or incompatible input.
113 */
114[[nodiscard]] MAYAFLUX_API std::optional<VertexAccess>
115as_line_vertex_access(std::span<const DataVariant> channels,
116 const VertexAccessConfig& config = {});
117
118/**
119 * @brief Assemble mesh-vertex-compatible bytes from one or more data channels.
120 *
121 * channels[0] must supply position data (vec3 or uint8_t interleaved).
122 * channels[1..5] optionally supply color, weight, uv, normal, tangent in
123 * canonical field order. Missing trailing channels are filled from config;
124 * slot 2 defaults to config.default_weight.
125 * A single uint8_t channel of N*60 bytes is passed through zero-copy.
126 *
127 * @param channels Source channels in canonical field order.
128 * @param config Default attribute values for absent channels.
129 * @return Populated VertexAccess, or std::nullopt on empty or incompatible input.
130 */
131[[nodiscard]] MAYAFLUX_API std::optional<VertexAccess>
132as_mesh_vertex_access(std::span<const DataVariant> channels,
133 const VertexAccessConfig& config = {});
134
135} // namespace MayaFlux::Kakshya
std::optional< VertexAccess > as_line_vertex_access(std::span< const DataVariant > channels, const VertexAccessConfig &config)
Assemble line-vertex-compatible bytes from one or more data channels.
std::optional< VertexAccess > as_point_vertex_access(std::span< const DataVariant > channels, const VertexAccessConfig &config)
Assemble point-vertex-compatible bytes from one or more data channels.
std::optional< VertexAccess > as_mesh_vertex_access(std::span< const DataVariant > channels, const VertexAccessConfig &config)
Assemble mesh-vertex-compatible bytes from one or more data channels.
std::optional< VertexAccess > as_vertex_access(std::span< const DataVariant > channels, const VertexAccessConfig &config)
Extract a VertexAccess from a DataVariant.
Default attribute values for shader-compatible vertex conversion.
std::vector< std::byte > conversion_buffer
Conversion buffer.
bool was_converted() const noexcept
True when data_ptr points into conversion_buffer rather than the original variant storage.
Memory-compatible view of channel data assembled into full 60-byte vertices.
Complete description of vertex data layout in a buffer.