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

Method parse_image

framework/gltf_loader.cpp:1456–1497  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1454 return material;
1455}
1456
1457std::unique_ptr<sg::Image> GLTFLoader::parse_image(tinygltf::Image &gltf_image) const
1458{
1459 std::unique_ptr<sg::Image> image{nullptr};
1460
1461 if (gltf_image.name.empty())
1462 {
1463 gltf_image.name = gltf_image.uri;
1464 }
1465
1466 if (!gltf_image.image.empty())
1467 {
1468 // Image embedded in gltf file
1469 auto mipmap = sg::Mipmap{
1470 /* .level = */ 0,
1471 /* .offset = */ 0,
1472 /* .extent = */ {/* .width = */ static_cast<uint32_t>(gltf_image.width),
1473 /* .height = */ static_cast<uint32_t>(gltf_image.height),
1474 /* .depth = */ 1u}};
1475 std::vector<sg::Mipmap> mipmaps{mipmap};
1476 image = std::make_unique<sg::Image>(gltf_image.name, std::move(gltf_image.image), std::move(mipmaps));
1477 }
1478 else
1479 {
1480 // Load image from uri
1481 auto image_uri = model_path + "/" + gltf_image.uri;
1482 image = sg::Image::load(gltf_image.name, image_uri, vkb::sg::Image::Unknown);
1483 }
1484
1485 // Check whether the format is supported by the GPU
1486 if (sg::is_astc(image->get_format()))
1487 {
1488 if (!device.is_image_format_supported(image->get_format()))
1489 {
1490 image = std::make_unique<sg::Astc>(*image);
1491 image->generate_mipmaps();
1492 }
1493 }
1494
1495 image->create_vk_image(device);
1496
1497 return image;
1498}
1499
1500std::unique_ptr<vkb::scene_graph::components::SamplerC> GLTFLoader::parse_sampler(const tinygltf::Sampler &gltf_sampler) const

Callers

nothing calls this directly

Calls 6

emptyMethod · 0.80
is_astcFunction · 0.50
get_formatMethod · 0.45
generate_mipmapsMethod · 0.45
create_vk_imageMethod · 0.45

Tested by

no test coverage detected