Skip to content

Commit

Permalink
work on loading sponza
Browse files Browse the repository at this point in the history
  • Loading branch information
WinteryFox committed Jan 25, 2024
1 parent ae1afc9 commit 1ead02e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
25 changes: 17 additions & 8 deletions src/engine/vk/VkImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,16 @@ namespace Vixen::Vk {
FreeImage_Initialise();

const auto& format = FreeImage_GetFileType(path.c_str(), static_cast<int>(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);
}
Expand All @@ -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<BYTE*>(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);
}

Expand Down
27 changes: 17 additions & 10 deletions src/engine/vk/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#endif

#include <cstdlib>
#include <filesystem>
#include <string>
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
Expand Down Expand Up @@ -76,9 +77,11 @@ int main() {

auto renderer = std::make_unique<Vixen::Vk::VkRenderer>(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");

Expand Down Expand Up @@ -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<Vixen::Vk::VkImage> image;
if (texture->mHeight != 0) {
// TODO: Not implemented
throw std::runtime_error("Not implemented");
if (texture == nullptr) {
image = std::make_shared<Vixen::Vk::VkImage>(
Vixen::Vk::VkImage::from(
vixen.getDevice(),
path + imagePath.C_Str()
)
);
}
else {
image = std::make_shared<Vixen::Vk::VkImage>(
Expand Down

0 comments on commit 1ead02e

Please sign in to comment.