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

Method generate_quad

samples/api/texture_loading/texture_loading.cpp:483–515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

481}
482
483void TextureLoading::generate_quad()
484{
485 // Setup vertices for a single uv-mapped quad made from two triangles
486 std::vector<TextureLoadingVertexStructure> vertices =
487 {
488 {{1.0f, 1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f, 1.0f}},
489 {{-1.0f, 1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f, 1.0f}},
490 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}},
491 {{1.0f, -1.0f, 0.0f}, {1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}};
492
493 // Setup indices
494 std::vector<uint32_t> indices = {0, 1, 2, 2, 3, 0};
495 index_count = static_cast<uint32_t>(indices.size());
496
497 auto vertex_buffer_size = vkb::to_u32(vertices.size() * sizeof(TextureLoadingVertexStructure));
498 auto index_buffer_size = vkb::to_u32(indices.size() * sizeof(uint32_t));
499
500 // Create buffers
501 // For the sake of simplicity we won't stage the vertex data to the gpu memory
502 // Vertex buffer
503 vertex_buffer = std::make_unique<vkb::core::BufferC>(get_device(),
504 vertex_buffer_size,
505 VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
506 VMA_MEMORY_USAGE_CPU_TO_GPU);
507 vertex_buffer->update(vertices.data(), vertex_buffer_size);
508
509 index_buffer = std::make_unique<vkb::core::BufferC>(get_device(),
510 index_buffer_size,
511 VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
512 VMA_MEMORY_USAGE_CPU_TO_GPU);
513
514 index_buffer->update(indices.data(), index_buffer_size);
515}
516
517void TextureLoading::setup_descriptor_pool()
518{

Callers

nothing calls this directly

Calls 3

to_u32Function · 0.85
sizeMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected