| 334 | } |
| 335 | |
| 336 | inline void prepare_meshlets(std::vector<Meshlet> &meshlets, std::unique_ptr<vkb::sg::SubMesh> &submesh, std::vector<unsigned char> &index_data) |
| 337 | { |
| 338 | Meshlet meshlet; |
| 339 | meshlet.vertex_count = 0; |
| 340 | meshlet.index_count = 0; |
| 341 | |
| 342 | std::set<uint32_t> vertices; // set for unique vertices |
| 343 | uint32_t triangle_check = 0; // each meshlet needs to contain full primitives |
| 344 | |
| 345 | for (uint32_t i = 0; i < submesh->vertex_indices; i++) |
| 346 | { |
| 347 | // index_data is unsigned char type, casting to uint32_t* will give proper value |
| 348 | meshlet.indices[meshlet.index_count] = *(reinterpret_cast<uint32_t *>(index_data.data()) + i); |
| 349 | |
| 350 | if (vertices.insert(meshlet.indices[meshlet.index_count]).second) |
| 351 | { |
| 352 | ++meshlet.vertex_count; |
| 353 | } |
| 354 | |
| 355 | meshlet.index_count++; |
| 356 | triangle_check = triangle_check < 3 ? ++triangle_check : 1; |
| 357 | |
| 358 | // 96 because for each traingle we draw a line in a mesh shader sample, 32 triangles/lines per meshlet = 64 vertices on output |
| 359 | if (meshlet.vertex_count == 64 || meshlet.index_count == 96 || i == submesh->vertex_indices - 1) |
| 360 | { |
| 361 | if (i == submesh->vertex_indices - 1) |
| 362 | { |
| 363 | assert(triangle_check == 3); |
| 364 | } |
| 365 | |
| 366 | uint32_t counter = 0; |
| 367 | for (auto v : vertices) |
| 368 | { |
| 369 | meshlet.vertices[counter++] = v; |
| 370 | } |
| 371 | if (triangle_check != 3) |
| 372 | { |
| 373 | meshlet.index_count -= triangle_check; |
| 374 | i -= triangle_check; |
| 375 | triangle_check = 0; |
| 376 | } |
| 377 | |
| 378 | meshlets.push_back(meshlet); |
| 379 | meshlet.vertex_count = 0; |
| 380 | meshlet.index_count = 0; |
| 381 | vertices.clear(); |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | static inline bool texture_needs_srgb_colorspace(const std::string &name) |
| 387 | { |
no test coverage detected