feat: Add Camera component / Add cooked model and texture loading

This commit is contained in:
2026-10-13 00:29:17 +02:00
parent fa98bf08e8
commit ce55f75ac3
26 changed files with 930 additions and 194 deletions
+47 -1
View File
@@ -11,7 +11,14 @@
#include "spdlog/spdlog.h"
#include <destrum/Assets/TextureFile.h>
ImageData::~ImageData()
{
freePixels();
}
void ImageData::freePixels()
{
if (shouldSTBFree) {
if (pixels) stbi_image_free(pixels);
@@ -22,6 +29,12 @@ ImageData::~ImageData()
if (hdrPixels) free(hdrPixels);
spdlog::debug("Freed TinyEXR image memory");
}
cookedPixels.clear();
pixels = nullptr;
hdrPixels = nullptr;
shouldSTBFree = false;
shouldEXRFree = false;
}
namespace util
@@ -33,13 +46,46 @@ namespace util
return ext == ".exr";
}
static bool isCookedTextureExt(const std::filesystem::path& p)
{
auto ext = p.extension().string();
for (auto& c : ext) c = char(::tolower(c));
return ext == TextureFile::Extension;
}
static VkFormat toVkFormat(TextureFile::PixelFormat format)
{
switch (format) {
case TextureFile::PixelFormat::RGBA16Float: return VK_FORMAT_R16G16B16A16_SFLOAT;
}
return VK_FORMAT_UNDEFINED;
}
ImageData loadImage(const std::filesystem::path& p, TextureIntent intent)
{
ImageData data;
// ---------- EXR ----------
if (isCookedTextureExt(p)) {
try {
TextureFile::Texture texture = TextureFile::ReadFromFile(p);
data.cookedPixels = std::move(texture.pixels);
data.pixels = data.cookedPixels.data();
data.width = static_cast<int>(texture.width);
data.height = static_cast<int>(texture.height);
data.channels = 4;
data.vkFormat = toVkFormat(texture.format);
data.byteSize = data.cookedPixels.size();
} catch (const std::exception& exception) {
spdlog::error("Failed to read cooked texture '{}': {}", p.string(), exception.what());
return {};
}
return data;
}
if (isExrExt(p)) {
float* out = nullptr;
int w = 0, h = 0;