MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / generate_cubes

Method generate_cubes

samples/tooling/profiles/profiles.cpp:306–395  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304}
305
306void Profiles::generate_cubes()
307{
308 // Generate cubes with randomized per-face texture indices (as base for descriptor indexing)
309 std::vector<VertexStructure> vertices;
310 std::vector<uint32_t> indices;
311
312 // Generate random per-face texture indices
313 std::default_random_engine rndEngine(lock_simulation_speed ? 0u : std::random_device{}());
314 std::uniform_int_distribution<int32_t> rndDist(0, static_cast<uint32_t>(textures.size()) - 1);
315
316 // Generate cubes with random per-face texture indices
317 const uint32_t count = 6;
318 for (uint32_t i = 0; i < count; i++)
319 {
320 // Get a random texture index that the shader will sample from via the vertex attribute
321 const auto texture_index = [&rndDist, &rndEngine]() {
322 return rndDist(rndEngine);
323 };
324
325 // Push vertices to buffer
326 float pos = 2.5f * i - (count * 2.5f / 2.0f);
327
328 const std::vector<VertexStructure> cube = {
329 {{-1.0f + pos, -1.0f, 1.0f}, {0.0f, 0.0f}, texture_index()},
330 {{1.0f + pos, -1.0f, 1.0f}, {1.0f, 0.0f}, texture_index()},
331 {{1.0f + pos, 1.0f, 1.0f}, {1.0f, 1.0f}, texture_index()},
332 {{-1.0f + pos, 1.0f, 1.0f}, {0.0f, 1.0f}, texture_index()},
333
334 {{1.0f + pos, 1.0f, 1.0f}, {0.0f, 0.0f}, texture_index()},
335 {{1.0f + pos, 1.0f, -1.0f}, {1.0f, 0.0f}, texture_index()},
336 {{1.0f + pos, -1.0f, -1.0f}, {1.0f, 1.0f}, texture_index()},
337 {{1.0f + pos, -1.0f, 1.0f}, {0.0f, 1.0f}, texture_index()},
338
339 {{-1.0f + pos, -1.0f, -1.0f}, {0.0f, 0.0f}, texture_index()},
340 {{1.0f + pos, -1.0f, -1.0f}, {1.0f, 0.0f}, texture_index()},
341 {{1.0f + pos, 1.0f, -1.0f}, {1.0f, 1.0f}, texture_index()},
342 {{-1.0f + pos, 1.0f, -1.0f}, {0.0f, 1.0f}, texture_index()},
343
344 {{-1.0f + pos, -1.0f, -1.0f}, {0.0f, 0.0f}, texture_index()},
345 {{-1.0f + pos, -1.0f, 1.0f}, {1.0f, 0.0f}, texture_index()},
346 {{-1.0f + pos, 1.0f, 1.0f}, {1.0f, 1.0f}, texture_index()},
347 {{-1.0f + pos, 1.0f, -1.0f}, {0.0f, 1.0f}, texture_index()},
348
349 {{1.0f + pos, 1.0f, 1.0f}, {0.0f, 0.0f}, texture_index()},
350 {{-1.0f + pos, 1.0f, 1.0f}, {1.0f, 0.0f}, texture_index()},
351 {{-1.0f + pos, 1.0f, -1.0f}, {1.0f, 1.0f}, texture_index()},
352 {{1.0f + pos, 1.0f, -1.0f}, {0.0f, 1.0f}, texture_index()},
353
354 {{-1.0f + pos, -1.0f, -1.0f}, {0.0f, 0.0f}, texture_index()},
355 {{1.0f + pos, -1.0f, -1.0f}, {1.0f, 0.0f}, texture_index()},
356 {{1.0f + pos, -1.0f, 1.0f}, {1.0f, 1.0f}, texture_index()},
357 {{-1.0f + pos, -1.0f, 1.0f}, {0.0f, 1.0f}, texture_index()},
358 };
359 for (auto &vertex : cube)
360 {
361 vertices.push_back(vertex);
362 }
363 // Push indices to buffer

Callers

nothing calls this directly

Calls 3

to_u32Function · 0.85
sizeMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected