11 constexpr std::array<std::pair<size_t, size_t>, 6> k_channel_layout { {
32 return std::visit([](
const auto& vec) -> ChannelView {
33 using V =
typename std::decay_t<
decltype(vec)>::value_type;
35 return { .ptr =
nullptr, .count = 0, .element_bytes =
sizeof(
V) };
37 reinterpret_cast<const uint8_t*
>(vec.data()),
45 void assemble_vertices(
46 std::span<const DataVariant> channels,
48 const VertexAccessConfig& cfg,
52 const void* defaults[6] = {
61 for (
size_t i = 0; i <
count; ++i) {
62 std::byte* v = dst + i * 60;
63 for (
size_t s = 0; s < 6; ++s) {
64 auto [dst_off, dst_sz] = k_channel_layout[s];
65 if (s < channels.size()) {
66 auto cv = channel_view(channels[s]);
68 const size_t copy_sz = std::min(cv.element_bytes, dst_sz);
69 std::memcpy(v + dst_off, cv.ptr + i * cv.element_bytes, copy_sz);
70 if (copy_sz < dst_sz) {
71 std::memset(v + dst_off + copy_sz, 0, dst_sz - copy_sz);
74 std::memcpy(v + dst_off, defaults[s], dst_sz);
83 std::span<const DataVariant> channels,
90 std::span<const DataVariant> channels,
93 if (channels.empty()) {
95 "as_point_vertex_access: no channels supplied");
100 if (channels.size() == 1) {
101 if (
const auto*
b = std::get_if<std::vector<uint8_t>>(&channels[0])) {
102 if (
b->size() % 60 != 0) {
104 "as_point_vertex_access: uint8_t byte count {} not a multiple of 60",
108 const auto count =
static_cast<uint32_t
>(
b->size() / 60);
110 layout.vertex_count =
count;
115 const size_t count = channel_view(channels[0]).count;
118 "as_point_vertex_access: position channel (slot 0) is empty or unsupported");
134 std::span<const DataVariant> channels,
137 if (channels.empty()) {
139 "as_line_vertex_access: no channels supplied");
143 if (channels.size() == 1) {
144 if (
const auto*
b = std::get_if<std::vector<uint8_t>>(&channels[0])) {
145 if (
b->size() % 60 != 0) {
147 "as_line_vertex_access: uint8_t byte count {} not a multiple of 60",
151 const auto count =
static_cast<uint32_t
>(
b->size() / 60);
153 layout.vertex_count =
count;
158 const size_t count = channel_view(channels[0]).count;
161 "as_line_vertex_access: position channel (slot 0) is empty or unsupported");
177 std::span<const DataVariant> channels,
180 if (channels.empty()) {
182 "as_mesh_vertex_access: no channels supplied");
186 if (channels.size() == 1) {
187 if (
const auto*
b = std::get_if<std::vector<uint8_t>>(&channels[0])) {
188 if (
b->size() % 60 != 0) {
190 "as_mesh_vertex_access: uint8_t byte count {} not a multiple of 60",
194 const auto count =
static_cast<uint32_t
>(
b->size() / 60);
196 layout.vertex_count =
count;
201 const size_t count = channel_view(channels[0]).count;
204 "as_mesh_vertex_access: position channel (slot 0) is empty or unsupported");
#define MF_ERROR(comp, ctx,...)
@ Runtime
General runtime operations (default fallback)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
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::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
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.
Memory-compatible view of channel data assembled into full 60-byte vertices.
uint32_t vertex_count
Total number of vertices in this buffer.
static VertexLayout for_lines(uint32_t stride=60)
Factory: layout for LineVertex (position, color, thickness, uv, normal, tangent)
static VertexLayout for_meshes(uint32_t stride=60)
Factory: layout for MeshVertex (position, color, weight, uv, normal, tangent)
static VertexLayout for_points(uint32_t stride=60)
Factory: layout for PointVertex (position, color, size, uv, normal, tangent)