diff --git a/src/engine/vk/VkImage.cpp b/src/engine/vk/VkImage.cpp index 80e9453..35a4163 100644 --- a/src/engine/vk/VkImage.cpp +++ b/src/engine/vk/VkImage.cpp @@ -112,12 +112,16 @@ namespace Vixen::Vk { FreeImage_Initialise(); const auto& format = FreeImage_GetFileType(path.c_str(), static_cast(path.length())); - if (format == FIF_UNKNOWN) - error("Failed to determine image format, possibly unsupported format?"); + if (format == FIF_UNKNOWN) { + error(R"(Failed to determine image format for file "{}", is the relative path correct? Possibly unsupported format?)", path); + throw std::runtime_error("Failed to determine image format for file"); + } const auto& bitmap = FreeImage_Load(format, path.c_str(), 0); - if (!bitmap) - error("Failed to load image from file \"{}\"", path); + if (!bitmap) { + spdlog::error("Failed to load image from file \"{}\"", path); + throw std::runtime_error("Failed to load image from file"); + } return from(device, bitmap); } @@ -126,13 +130,18 @@ namespace Vixen::Vk { const uint32_t size) { // TODO: Add some way to detect the format const auto& memory = FreeImage_OpenMemory(reinterpret_cast(data), size); - if (!memory) - error("Failed to open image from memory"); + if (!memory) { + spdlog::error("Failed to open memory for image"); + throw std::runtime_error("Failed to open memory for image"); + } const auto& bitmap = FreeImage_LoadFromMemory(FreeImage_GetFIFFromFormat(format.c_str()), memory, 0); - if (!bitmap) - throw std::runtime_error("Failed to load image from memory"); + if (!bitmap) { + spdlog::error("Failed to load bitmap from memory"); + throw std::runtime_error("Failed to load bitmap from memory"); + } + // TODO: FreeImage_CloseMemory(memory); return from(device, bitmap); } diff --git a/src/engine/vk/test/main.cpp b/src/engine/vk/test/main.cpp index e5c5a2b..a95bb94 100644 --- a/src/engine/vk/test/main.cpp +++ b/src/engine/vk/test/main.cpp @@ -5,6 +5,7 @@ #endif #include +#include #include #include #include @@ -76,9 +77,11 @@ int main() { auto renderer = std::make_unique(pipeline, vixen.getSwapchain()); + const std::string& file = "../../src/engine/vk/test/vikingroom.glb"; + const std::string& path = std::filesystem::path(file).remove_filename().string(); + Assimp::Importer importer; - const auto& scene = importer.ReadFile("../../src/engine/vk/test/vikingroom.glb", - aiProcessPreset_TargetRealtime_Fast); + const auto& scene = importer.ReadFile(file, aiProcessPreset_TargetRealtime_Fast); if (!scene) throw std::runtime_error("Failed to load model from file"); @@ -113,16 +116,20 @@ int main() { indices[i * 3 + 2] = face.mIndices[2]; } - aiString path; - scene->mMaterials[aiMesh->mMaterialIndex]->GetTexture(aiTextureType_DIFFUSE, 0, &path); - - const auto& texture = scene->GetEmbeddedTexture(path.C_Str()); - assert(texture != nullptr && "Texture is nullptr"); + aiString imagePath; + const auto& material = scene->mMaterials[aiMesh->mMaterialIndex]; + assert(material != nullptr && "Material is nullptr"); + material->GetTexture(aiTextureType_DIFFUSE, 0, &imagePath); + const auto& texture = scene->GetEmbeddedTexture(imagePath.C_Str()); std::shared_ptr image; - if (texture->mHeight != 0) { - // TODO: Not implemented - throw std::runtime_error("Not implemented"); + if (texture == nullptr) { + image = std::make_shared( + Vixen::Vk::VkImage::from( + vixen.getDevice(), + path + imagePath.C_Str() + ) + ); } else { image = std::make_shared(