MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ mill_on_host()

MAYAFLUX_API Kakshya::VertexLayout MayaFlux::Portal::Graphics::mill_on_host ( std::span< const uint8_t > src,
const Kakshya::VertexLayout & layout,
std::span< const DrawRun > runs,
const MillSpec & spec,
const MillView & view,
std::vector< uint8_t > & dst,
std::span< const uint32_t > indices = {} )

Host equivalent of PrimitiveMill::mill, over raw bytes.

Parameters
srcSource vertex bytes. Must be four byte aligned.
layoutDescribes src. The result carries the same attributes.
runsSpans to mill, in output order.
specShaping parameters, as for the device path.
viewViewpoint, as for the device path.
dstResized to hold the result.
indicesWhen non-empty, triangle spans address these indices instead of vertices.
Returns
Layout describing dst, which is layout with a new vertex_count.

Gives the kernel a reference to be tested against, and a route for a caller with no compute queue available. It builds the unjoined ribbon form only (no miter, no width averaging across shared positions), so use it to check span indexing and vertex counts rather than ribbon geometry. Not a general geometry utility, and not intended for per-frame use at scale.

Definition at line 965 of file PrimitiveMill.cpp.

973{
974 const auto vertex_at = [&indices](uint32_t k) {
975 return indices.empty() ? k : indices[k];
976 };
977
978 auto result = layout;
979 result.vertex_count = 0;
980 dst.clear();
981
982 MillOffsets off;
983 if (!offsets_from(layout, off)) {
984 return result;
985 }
986
987 std::vector<uint32_t> prefix;
988 build_prefix(runs, prefix);
989 const uint32_t total = prefix.empty() ? 0U : prefix.back();
990 if (total == 0) {
991 return result;
992 }
993
994 dst.assign(static_cast<size_t>(total) * layout.stride_bytes, 0);
995 result.vertex_count = total;
996
997 const HostRecords rec {
998 .src = reinterpret_cast<const uint32_t*>(src.data()),
999 .dst = reinterpret_cast<uint32_t*>(dst.data()),
1000 .stride_words = off.stride_words
1001 };
1002
1003 const bool world_plane = spec.ribbon == MillSpec::Ribbon::WorldPlane;
1004 const bool billboard = spec.billboard_instances && !world_plane && off.tangent != ABSENT;
1005 const uint32_t scalar_offset = spec.use_vertex_extent ? off.scalar : ABSENT;
1006
1007 for (size_t r = 0; r < runs.size(); ++r) {
1008 const auto& run = runs[r];
1009 const uint32_t emitted = prefix[r + 1] - prefix[r];
1010 const uint32_t base = prefix[r];
1011 const uint32_t voff = run.vertex_offset;
1012
1013 for (uint32_t local = 0; local < emitted; ++local) {
1014 const uint32_t out = base + local;
1015
1016 const bool is_tri = is_triangle_topology(run.topology);
1017 const bool as_point = run.topology == PrimitiveTopology::POINT_LIST
1018 || (run.fill == PolygonMode::POINT
1019 && (is_tri || run.topology == PrimitiveTopology::LINE_LIST
1020 || run.topology == PrimitiveTopology::LINE_STRIP));
1021 const bool wire = is_tri && run.fill == PolygonMode::LINE;
1022 const auto wire_uv = [](uint32_t c) {
1023 return glm::vec2(c == 0U ? 21.0F : 20.0F, c == 1U ? 1.0F : 0.0F);
1024 };
1025
1026 if (run.topology == PrimitiveTopology::TRIANGLE_LIST && !as_point) {
1027 rec.copy_vertex(out, vertex_at(voff + local));
1028 if (wire) {
1029 rec.write_uv(out, off.uv, wire_uv(local % 3U));
1030 }
1031 continue;
1032 }
1033
1034 if ((run.topology == PrimitiveTopology::TRIANGLE_STRIP
1035 || run.topology == PrimitiveTopology::TRIANGLE_FAN)
1036 && !as_point) {
1037 const uint32_t tri = local / 3U;
1038 const uint32_t c = local - tri * 3U;
1039 uint32_t a = 0;
1040 uint32_t b1 = tri + 1U;
1041 uint32_t b2 = tri + 2U;
1042 if (run.topology == PrimitiveTopology::TRIANGLE_STRIP) {
1043 a = tri;
1044 if ((tri & 1U) == 1U) {
1045 std::swap(a, b1);
1046 }
1047 }
1048 const uint32_t pick = c == 0U ? a : (c == 1U ? b1 : b2);
1049 rec.copy_vertex(out, vertex_at(voff + pick));
1050 if (wire) {
1051 rec.write_uv(out, off.uv, wire_uv(c));
1052 }
1053 continue;
1054 }
1055
1056 const uint32_t corner = local % 6U;
1057 const uint32_t quad = local / 6U;
1058
1059 if (as_point) {
1060 const uint32_t s = run.topology == PrimitiveTopology::POINT_LIST
1061 ? voff + quad
1062 : vertex_at(voff + quad);
1063 const glm::vec3 p = rec.read_pos(s, off.position);
1064 const float h = rec.read_extent(s, scalar_offset, spec.fallback_extent)
1065 * spec.point_scale * 0.5F;
1066
1067 glm::vec3 rx;
1068 glm::vec3 ry;
1069 if (world_plane) {
1070 rx = glm::vec3(h, 0.0F, 0.0F);
1071 ry = glm::vec3(0.0F, h, 0.0F);
1072 } else {
1073 const glm::vec3 n = host_view_normal(p, view.eye);
1074 const glm::vec3 up = std::abs(n.y) < 0.99F
1075 ? glm::vec3(0.0F, 1.0F, 0.0F)
1076 : glm::vec3(1.0F, 0.0F, 0.0F);
1077 rx = glm::normalize(glm::cross(up, n)) * h;
1078 ry = glm::normalize(glm::cross(n, rx)) * h;
1079 }
1080
1081 glm::vec3 o;
1082 glm::vec2 uv;
1083 switch (corner) {
1084 case 1:
1085 o = rx - ry;
1086 uv = { 1.0F, 0.0F };
1087 break;
1088 case 2:
1089 case 4:
1090 o = rx + ry;
1091 uv = { 1.0F, 1.0F };
1092 break;
1093 case 5:
1094 o = -rx + ry;
1095 uv = { 0.0F, 1.0F };
1096 break;
1097 default:
1098 o = -rx - ry;
1099 uv = { 0.0F, 0.0F };
1100 break;
1101 }
1102
1103 rec.copy_vertex(out, s);
1104 if (billboard) {
1105 rec.write_pos(out, off.position, p);
1106 rec.write_tangent(out, off.tangent,
1107 glm::vec4((uv * 2.0F - glm::vec2(1.0F)) * h, 0.0F, 0.0F));
1108 } else {
1109 rec.write_pos(out, off.position, p + o);
1110 }
1111 if (spec.synthesize_uv) {
1112 rec.write_uv(out, off.uv, uv + glm::vec2(10.0F));
1113 }
1114 continue;
1115 }
1116
1117 const uint32_t s0 = run.topology == PrimitiveTopology::LINE_LIST
1118 ? voff + quad * 2U
1119 : voff + quad;
1120 const uint32_t s1 = s0 + 1U;
1121
1122 const glm::vec3 p0 = rec.read_pos(s0, off.position);
1123 const glm::vec3 p1 = rec.read_pos(s1, off.position);
1124 const glm::vec3 d = p1 - p0;
1125
1126 if (glm::length(d) < 1e-6F) {
1127 rec.write_pos(out, off.position, p0);
1128 if (billboard) {
1129 rec.write_tangent(out, off.tangent, glm::vec4(0.0F));
1130 }
1131 continue;
1132 }
1133
1134 const float h0 = rec.read_extent(s0, scalar_offset, spec.fallback_extent)
1135 * spec.width_scale * 0.5F;
1136 const float h1 = rec.read_extent(s1, scalar_offset, spec.fallback_extent)
1137 * spec.width_scale * 0.5F;
1138
1139 const glm::vec3 e0 = host_side_at(
1140 p0, d, view.eye, h0, world_plane);
1141 const glm::vec3 e1 = host_side_at(
1142 p1, d, view.eye, h1, world_plane);
1143
1144 glm::vec3 pos;
1145 uint32_t pick = s0;
1146 glm::vec2 uv;
1147 switch (corner) {
1148 case 1:
1149 pos = p0 + e0;
1150 uv = { 0.0F, 0.0F };
1151 break;
1152 case 2:
1153 case 4:
1154 pos = p1 + e1;
1155 pick = s1;
1156 uv = { 1.0F, 0.0F };
1157 break;
1158 case 5:
1159 pos = p1 - e1;
1160 pick = s1;
1161 uv = { 1.0F, 1.0F };
1162 break;
1163 default:
1164 pos = p0 - e0;
1165 uv = { 0.0F, 1.0F };
1166 break;
1167 }
1168
1169 rec.copy_vertex(out, pick);
1170 if (billboard) {
1171 const float sign = (corner == 0U || corner == 3U || corner == 5U) ? -1.0F : 1.0F;
1172 const float half_w = (corner == 0U || corner == 1U || corner == 3U) ? h0 : h1;
1173 rec.write_pos(out, off.position, pick == s0 ? p0 : p1);
1174 rec.write_tangent(out, off.tangent,
1175 glm::vec4(d / glm::length(d), sign * half_w));
1176 } else {
1177 rec.write_pos(out, off.position, pos);
1178 }
1179 if (run.fill == PolygonMode::LINE) {
1180 rec.write_uv(out, off.uv, wire_uv(corner % 3U));
1181 } else if (spec.synthesize_uv) {
1182 rec.write_uv(out, off.uv, uv);
1183 }
1184 }
1185 }
1186
1187 return result;
1188}
void run()
Definition main.cpp:21
void pick(std::string title, std::vector< std::string > labels, PickCallback callback)
Open a window of clickable rows, one per label, and report the choice.
Definition Picker.cpp:49
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.
@ WorldPlane
Held in the XY plane, viewpoint ignored.
bool synthesize_uv
Write 0..1 UVs across each ribbon and quad instead of copying the source.
float fallback_extent
Extent used when the layout carries no scalar attribute.
float width_scale
World units of total ribbon width per unit of a vertex's scalar.
bool billboard_instances
Keep point quads and ribbons unexpanded for an instanced draw.
bool use_vertex_extent
Take ribbon width and point size from each vertex's own scalar (LineVertex::thickness,...
float point_scale
World units per unit of a vertex's own size, on point spans.

References MayaFlux::Portal::Graphics::MillSpec::billboard_instances, MayaFlux::Portal::Graphics::MillView::eye, MayaFlux::Portal::Graphics::MillSpec::fallback_extent, LINE, LINE_LIST, LINE_STRIP, POINT, POINT_LIST, MayaFlux::Portal::Graphics::MillSpec::point_scale, MayaFlux::Portal::Graphics::MillSpec::ribbon, run(), MayaFlux::Kakshya::VertexLayout::stride_bytes, MayaFlux::Portal::Graphics::MillSpec::synthesize_uv, TRIANGLE_FAN, TRIANGLE_LIST, TRIANGLE_STRIP, MayaFlux::Portal::Graphics::MillSpec::use_vertex_extent, MayaFlux::Kakshya::VertexLayout::vertex_count, MayaFlux::Portal::Graphics::MillSpec::width_scale, and MayaFlux::Portal::Graphics::MillSpec::WorldPlane.

Here is the call graph for this function: