fix: restore backpack material import output
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <XCEngine/Core/Asset/ArtifactFormats.h>
|
||||
#include <XCEngine/Resources/BuiltinResources.h>
|
||||
#include <XCEngine/Core/Asset/ResourceManager.h>
|
||||
#include <XCEngine/Resources/Texture/TextureImportSettings.h>
|
||||
#include <stb_image.h>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
@@ -50,6 +51,25 @@ LoadResult CreateTextureResource(const Containers::String& path,
|
||||
return LoadResult(texture);
|
||||
}
|
||||
|
||||
TextureFormat ResolveDecodedTextureFormat(const ImportSettings* settings, bool isHdrTexture) {
|
||||
if (isHdrTexture) {
|
||||
return TextureFormat::RGBA32_FLOAT;
|
||||
}
|
||||
|
||||
const auto* textureSettings = dynamic_cast<const TextureImportSettings*>(settings);
|
||||
if (textureSettings == nullptr) {
|
||||
return TextureFormat::RGBA8_UNORM;
|
||||
}
|
||||
|
||||
if (textureSettings->GetTargetFormat() != TextureFormat::Unknown) {
|
||||
return textureSettings->GetTargetFormat();
|
||||
}
|
||||
|
||||
return textureSettings->GetSRGB()
|
||||
? TextureFormat::RGBA8_SRGB
|
||||
: TextureFormat::RGBA8_UNORM;
|
||||
}
|
||||
|
||||
LoadResult LoadTextureArtifact(const Containers::String& path) {
|
||||
std::filesystem::path resolvedPath(path.CStr());
|
||||
if (!resolvedPath.is_absolute() && !std::filesystem::exists(resolvedPath)) {
|
||||
@@ -124,8 +144,6 @@ bool TextureLoader::CanLoad(const Containers::String& path) const {
|
||||
}
|
||||
|
||||
LoadResult TextureLoader::Load(const Containers::String& path, const ImportSettings* settings) {
|
||||
(void)settings;
|
||||
|
||||
if (IsBuiltinTexturePath(path)) {
|
||||
return CreateBuiltinTextureResource(path);
|
||||
}
|
||||
@@ -149,10 +167,14 @@ LoadResult TextureLoader::Load(const Containers::String& path, const ImportSetti
|
||||
return LoadResult(Containers::String("Failed to read file: ") + path);
|
||||
}
|
||||
|
||||
return LoadFromMemory(path, fileData.Data(), fileData.Size());
|
||||
return LoadFromMemory(path, fileData.Data(), fileData.Size(), settings);
|
||||
}
|
||||
|
||||
LoadResult TextureLoader::LoadFromMemory(const Containers::String& path, const void* data, size_t dataSize) const {
|
||||
LoadResult TextureLoader::LoadFromMemory(
|
||||
const Containers::String& path,
|
||||
const void* data,
|
||||
size_t dataSize,
|
||||
const ImportSettings* settings) const {
|
||||
if (data == nullptr || dataSize == 0) {
|
||||
return LoadResult(Containers::String("Texture data is empty: ") + path);
|
||||
}
|
||||
@@ -180,7 +202,7 @@ LoadResult TextureLoader::LoadFromMemory(const Containers::String& path, const v
|
||||
4u *
|
||||
sizeof(float);
|
||||
LoadResult result = CreateTextureResource(path,
|
||||
TextureFormat::RGBA32_FLOAT,
|
||||
ResolveDecodedTextureFormat(settings, true),
|
||||
static_cast<Core::uint32>(width),
|
||||
static_cast<Core::uint32>(height),
|
||||
pixels,
|
||||
@@ -204,7 +226,7 @@ LoadResult TextureLoader::LoadFromMemory(const Containers::String& path, const v
|
||||
4u *
|
||||
sizeof(stbi_uc);
|
||||
LoadResult result = CreateTextureResource(path,
|
||||
TextureFormat::RGBA8_UNORM,
|
||||
ResolveDecodedTextureFormat(settings, false),
|
||||
static_cast<Core::uint32>(width),
|
||||
static_cast<Core::uint32>(height),
|
||||
pixels,
|
||||
|
||||
Reference in New Issue
Block a user