9 constexpr size_t k_vertex_bytes = 68;
13 constexpr std::array<std::pair<size_t, size_t>, 6> k_channel_layout { {
34 return std::visit([](
const auto& vec) -> ChannelView {
35 using V =
typename std::decay_t<
decltype(vec)>::value_type;
37 return { .ptr =
nullptr, .count = 0, .element_bytes =
sizeof(
V) };
39 reinterpret_cast<const uint8_t*
>(vec.data()),
47 void assemble_vertices(
48 std::span<const DataVariant>
channels,
50 const VertexAccessConfig& cfg,
54 const glm::vec4 default_tangent(cfg.default_tangent, 1.0F);
55 const void* defaults[6] = {
64 for (
size_t i = 0; i <
count; ++i) {
65 std::byte* v =
dst + i * k_vertex_bytes;
66 for (
size_t s = 0; s < 6; ++s) {
67 auto [dst_off, dst_sz] = k_channel_layout[s];
71 const size_t copy_sz = std::min(cv.element_bytes, dst_sz);
72 std::memcpy(v + dst_off, cv.ptr + i * cv.element_bytes, copy_sz);
73 if (copy_sz < dst_sz) {
74 std::memset(v + dst_off + copy_sz, 0, dst_sz - copy_sz);
75 if ((s == 1 || s == 5) && copy_sz ==
sizeof(glm::vec3)) {
76 const float opaque = 1.0F;
77 std::memcpy(v + dst_off + copy_sz, &opaque,
sizeof(
float));
81 std::memcpy(v + dst_off, defaults[s], dst_sz);
90 std::span<const DataVariant>
channels,
97 std::span<const DataVariant>
channels,
102 "as_point_vertex_access: no channels supplied");
108 if (
const auto*
b = std::get_if<std::vector<uint8_t>>(&
channels[0])) {
109 if (
b->size() % k_vertex_bytes != 0) {
111 "as_point_vertex_access: uint8_t byte count {} not a multiple of 68",
115 const auto count =
static_cast<uint32_t
>(
b->size() / k_vertex_bytes);
117 layout.vertex_count =
count;
125 "as_point_vertex_access: position channel (slot 0) is empty or unsupported");
141 std::span<const DataVariant>
channels,
146 "as_line_vertex_access: no channels supplied");
151 if (
const auto*
b = std::get_if<std::vector<uint8_t>>(&
channels[0])) {
152 if (
b->size() % k_vertex_bytes != 0) {
154 "as_line_vertex_access: uint8_t byte count {} not a multiple of 68",
158 const auto count =
static_cast<uint32_t
>(
b->size() / k_vertex_bytes);
160 layout.vertex_count =
count;
168 "as_line_vertex_access: position channel (slot 0) is empty or unsupported");
184 std::span<const DataVariant>
channels,
189 "as_mesh_vertex_access: no channels supplied");
194 if (
const auto*
b = std::get_if<std::vector<uint8_t>>(&
channels[0])) {
195 if (
b->size() % k_vertex_bytes != 0) {
197 "as_mesh_vertex_access: uint8_t byte count {} not a multiple of 68",
201 const auto count =
static_cast<uint32_t
>(
b->size() / k_vertex_bytes);
203 layout.vertex_count =
count;
211 "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 68-byte vertices.
uint32_t vertex_count
Total number of vertices in this buffer.
static VertexLayout for_points(uint32_t stride=68)
Factory: layout for PointVertex (position, color, size, uv, normal, tangent)
static VertexLayout for_meshes(uint32_t stride=68)
Factory: layout for MeshVertex (position, color, weight, uv, normal, tangent)
static VertexLayout for_lines(uint32_t stride=68)
Factory: layout for LineVertex (position, color, thickness, uv, normal, tangent)