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

Method load

framework/scene_graph/components/hpp_image.cpp:49–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49std::unique_ptr<vkb::scene_graph::components::HPPImage> HPPImage::load(const std::string &name, const std::string &uri,
50 ContentType content_type)
51{
52 std::unique_ptr<vkb::scene_graph::components::HPPImage> image{nullptr};
53
54 auto data = fs::read_asset(uri);
55
56 // Get extension
57 auto extension = get_extension(uri);
58
59 // the derived classes Stb, Astc, and Ktx are not transcoded (yet), so we need some more complex casting here...
60 if (extension == "png" || extension == "jpg")
61 {
62 image = std::unique_ptr<vkb::scene_graph::components::HPPImage>(reinterpret_cast<vkb::scene_graph::components::HPPImage *>(
63 std::make_unique<vkb::sg::Stb>(name, data, static_cast<vkb::sg::Image::ContentType>(content_type)).release()));
64 }
65 else if (extension == "astc")
66 {
67 image = std::unique_ptr<vkb::scene_graph::components::HPPImage>(
68 reinterpret_cast<vkb::scene_graph::components::HPPImage *>(std::make_unique<vkb::sg::Astc>(name, data).release()));
69 }
70 else if ((extension == "ktx") || (extension == "ktx2"))
71 {
72 image = std::unique_ptr<vkb::scene_graph::components::HPPImage>(reinterpret_cast<vkb::scene_graph::components::HPPImage *>(
73 std::make_unique<vkb::sg::Ktx>(name, data, static_cast<vkb::sg::Image::ContentType>(content_type)).release()));
74 }
75
76 return image;
77}
78
79std::type_index HPPImage::get_type()
80{

Callers

nothing calls this directly

Calls 2

read_assetFunction · 0.85
get_extensionFunction · 0.85

Tested by

no test coverage detected