Merge pull request #57 from SHADE-DP/SP3-13-Assets-Manager
SP3-13 Assets Management Changed texture struct to contain pre processed information ready for buffer
This commit is contained in:
commit
4c23151a14
Binary file not shown.
File diff suppressed because one or more lines are too long
|
@ -78,7 +78,7 @@ namespace Sandbox
|
|||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHInputManagerSystem, SHADE::SHInputManagerSystem::InputManagerRoutine>();
|
||||
|
||||
//TODO: REMOVE AFTER PRESENTATION
|
||||
SHADE::SHAssetManager::LoadDataTemp("../../Assets/racoon.fbx");
|
||||
SHADE::SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf");
|
||||
SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonBag_Color_Ver4.dds");
|
||||
SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.dds");
|
||||
//TODO: REMOVE AFTER PRESENTATION
|
||||
|
|
|
@ -54,6 +54,9 @@ namespace Sandbox
|
|||
}
|
||||
graphicsSystem->BuildMeshBuffers();
|
||||
|
||||
//Test Textures
|
||||
auto textures{ SHADE::SHAssetManager::GetAllTextures() };
|
||||
|
||||
// Create Materials
|
||||
auto matInst = graphicsSystem->AddOrGetBaseMaterialInstance();
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "tinyddsloader.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
struct SHDDSAsset
|
||||
{
|
||||
tinyddsloader::DDSFile image;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include "tinyddsloader.h"
|
||||
|
||||
#include "Graphics/MiddleEnd/Textures/SHTextureLibrary.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
struct SHTextureAsset
|
||||
{
|
||||
uint32_t numBytes;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
SHTexture::TextureFormat format;
|
||||
std::vector<uint32_t> mipOffsets;
|
||||
SHTexture::PixelChannel const * pixelData;
|
||||
|
||||
SHTextureAsset()
|
||||
: numBytes{ 0 },
|
||||
width{ 0 },
|
||||
height{ 0 },
|
||||
format{ SHTexture::TextureFormat::eUndefined },
|
||||
pixelData{ nullptr }
|
||||
{}
|
||||
|
||||
SHTextureAsset(SHTextureAsset const& rhs)
|
||||
: numBytes{ rhs.numBytes },
|
||||
width{ rhs.width },
|
||||
height{ rhs.height },
|
||||
format{ rhs.format },
|
||||
mipOffsets{ rhs.mipOffsets },
|
||||
pixelData(rhs.pixelData)
|
||||
{}
|
||||
|
||||
//SHTextureAsset(SHTextureAsset&& rhs)
|
||||
// : numBytes{ rhs.numBytes },
|
||||
// width{ rhs.width },
|
||||
// height{ rhs.height },
|
||||
// format{ rhs.format },
|
||||
// mipOffsets{ rhs.mipOffsets },
|
||||
// pixelData(std::move(rhs.pixelData))
|
||||
//{}
|
||||
};
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHDDSLoader.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
std::string SHDDSLoader::TinyDDSResultToString(tinyddsloader::Result value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case tinyddsloader::Result::ErrorFileOpen:
|
||||
return "File open err";
|
||||
case tinyddsloader::Result::ErrorRead:
|
||||
return "File read err";
|
||||
case tinyddsloader::Result::ErrorMagicWord:
|
||||
return "File header magicword err";
|
||||
case tinyddsloader::Result::ErrorSize:
|
||||
return "File size err";
|
||||
case tinyddsloader::Result::ErrorVerify:
|
||||
return "Pixel format err";
|
||||
case tinyddsloader::Result::ErrorNotSupported:
|
||||
return "Unsupported format";
|
||||
case tinyddsloader::Result::ErrorInvalidData:
|
||||
return "Invalid data";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
void SHDDSLoader::LoadImageAsset(AssetPath path, SHDDSAsset& asset)
|
||||
{
|
||||
tinyddsloader::Result loadResult = tinyddsloader::Result::Success;
|
||||
loadResult = asset.image.Load(path.string().c_str());
|
||||
if (loadResult != tinyddsloader::Result::Success)
|
||||
{
|
||||
SHLOG_ERROR("Unable to load DDS file: {} at {}", TinyDDSResultToString(loadResult), path.string());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
#pragma once
|
||||
#define TINYDDSLOADER_IMPLEMENTATION
|
||||
|
||||
#include "../SHAssetMacros.h"
|
||||
#include "../Asset Types/SHDDSAsset.h"
|
||||
#include "tinyddsloader.h"
|
||||
#include <vector>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SHDDSLoader
|
||||
{
|
||||
private:
|
||||
static std::string TinyDDSResultToString(tinyddsloader::Result value);
|
||||
public:
|
||||
static void LoadImageAsset(AssetPath paths, SHDDSAsset& image);
|
||||
};
|
||||
}
|
|
@ -100,9 +100,7 @@ namespace SHADE
|
|||
| aiProcess_JoinIdenticalVertices
|
||||
// join identical vertices/ optimize indexing
|
||||
| aiProcess_RemoveRedundantMaterials // remove redundant materials
|
||||
| aiProcess_FindInvalidData
|
||||
// detect invalid model data, such as invalid normal vectors
|
||||
| aiProcess_PreTransformVertices // pre-transform all vertices
|
||||
| aiProcess_FindInvalidData// detect invalid model data, such as invalid normal vectors
|
||||
| aiProcess_FlipUVs // flip the V to match the Vulkans way of doing UVs
|
||||
);
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHMeshWriter.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
void SHADE::SHMeshWriter::WriteMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept
|
||||
{
|
||||
std::ofstream file{path, std::ios::out | std::ios::binary};
|
||||
if (!file.is_open())
|
||||
{
|
||||
SHLOG_ERROR("Unable to open file for writing mesh file: {}", path.string());
|
||||
}
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&(asset.header.vertexCount)),
|
||||
sizeof(uint32_t)
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<const char*>(&(asset.header.indexCount)),
|
||||
sizeof(uint32_t)
|
||||
);
|
||||
|
||||
auto const vertexVec3Byte {sizeof(SHVec3) * asset.header.vertexCount};
|
||||
auto const vertexVec2Byte {sizeof(SHVec2) * asset.header.vertexCount};
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.vertexPosition.data()),
|
||||
vertexVec3Byte
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.vertexTangent.data()),
|
||||
vertexVec3Byte
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.vertexNormal.data()),
|
||||
vertexVec3Byte
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.texCoords.data()),
|
||||
vertexVec2Byte
|
||||
);
|
||||
|
||||
file.close();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "../Asset Types/SHMeshAsset.h"
|
||||
#include "../SHAssetMacros.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SHMeshWriter
|
||||
{
|
||||
private:
|
||||
public:
|
||||
static void WriteMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHTextureLoader.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
std::string SHTextureLoader::TinyDDSResultToString(tinyddsloader::Result value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case tinyddsloader::Result::ErrorFileOpen:
|
||||
return "File open err";
|
||||
case tinyddsloader::Result::ErrorRead:
|
||||
return "File read err";
|
||||
case tinyddsloader::Result::ErrorMagicWord:
|
||||
return "File header magic word err";
|
||||
case tinyddsloader::Result::ErrorSize:
|
||||
return "File size err";
|
||||
case tinyddsloader::Result::ErrorVerify:
|
||||
return "Pixel format err";
|
||||
case tinyddsloader::Result::ErrorNotSupported:
|
||||
return "Unsupported format";
|
||||
case tinyddsloader::Result::ErrorInvalidData:
|
||||
return "Invalid data";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
vk::Format SHTextureLoader::ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eBc1RgbaUnormBlock : vk::Format::eBc1RgbaSrgbBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eBc2UnormBlock : vk::Format::eBc2SrgbBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eBc3UnormBlock : vk::Format::eBc3SrgbBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC5_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC5_SNorm:
|
||||
return isLinear ? vk::Format::eBc5UnormBlock : vk::Format::eBc5SnormBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eR8G8B8A8Unorm : vk::Format::eR8G8B8A8Srgb;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_SNorm:
|
||||
return vk::Format::eR8G8B8A8Snorm;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8A8Srgb;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::B8G8R8X8_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::B8G8R8X8_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8Srgb;
|
||||
default:
|
||||
throw std::runtime_error("Unsupported DDS format.");
|
||||
}
|
||||
}
|
||||
|
||||
void SHTextureLoader::LoadImageAsset(AssetPath path, SHTextureAsset& asset)
|
||||
{
|
||||
tinyddsloader::Result loadResult = tinyddsloader::Result::Success;
|
||||
tinyddsloader::DDSFile file;
|
||||
loadResult = file.Load(path.string().c_str());
|
||||
if (loadResult != tinyddsloader::Result::Success)
|
||||
{
|
||||
SHLOG_ERROR("Unable to load Texture file: {} at {}", TinyDDSResultToString(loadResult), path.string());
|
||||
}
|
||||
|
||||
size_t totalBytes{ 0 };
|
||||
|
||||
std::vector<uint32_t> mipOff(file.GetMipCount());
|
||||
|
||||
for (auto i{0}; i < file.GetMipCount(); ++i)
|
||||
{
|
||||
mipOff.push_back(totalBytes);
|
||||
totalBytes += file.GetImageData(i, 0)->m_memSlicePitch;
|
||||
}
|
||||
|
||||
SHTexture::PixelChannel* pixel = new SHTexture::PixelChannel[totalBytes];
|
||||
std::memcpy(pixel, file.GetDDSData(), totalBytes);
|
||||
//pixel = std::move(reinterpret_cast<SHTexture::PixelChannel const*>(file.GetDDSData()));
|
||||
|
||||
asset.numBytes = totalBytes;
|
||||
asset.width = file.GetWidth();
|
||||
asset.height = file.GetHeight();
|
||||
asset.format = ddsLoaderToVkFormat(file.GetFormat(), true);
|
||||
asset.mipOffsets = std::move(mipOff);
|
||||
asset.pixelData = std::move(pixel);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
#define TINYDDSLOADER_IMPLEMENTATION
|
||||
|
||||
#include "../SHAssetMacros.h"
|
||||
#include "../Asset Types/SHTextureAsset.h"
|
||||
#include "tinyddsloader.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SHTextureLoader
|
||||
{
|
||||
private:
|
||||
static std::string TinyDDSResultToString(tinyddsloader::Result value);
|
||||
static vk::Format ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear);
|
||||
|
||||
public:
|
||||
static void LoadImageAsset(AssetPath paths, SHTextureAsset& image);
|
||||
};
|
||||
}
|
|
@ -69,8 +69,10 @@ enum class AssetType : uint8_t
|
|||
#define SCENE_EXTENSION ".SHADE"
|
||||
#define PREFAB_EXTENSION ".SHPrefab"
|
||||
#define MATERIAL_EXTENSION ".SHMat"
|
||||
#define TEXTURE_EXTENSION ".dds"
|
||||
#define TEXTURE_EXTENSION ".shtex"
|
||||
#define DDS_EXTENSION ".dds"
|
||||
#define FBX_EXTENSION ".fbx"
|
||||
#define GLTF_EXTENSION ".gltf"
|
||||
#define MESH_EXTENSION ".shmesh"
|
||||
|
||||
std::string const EXTENSIONS[] = {
|
||||
|
@ -79,12 +81,14 @@ std::string const EXTENSIONS[] = {
|
|||
MATERIAL_EXTENSION,
|
||||
IMAGE_EXTENSION,
|
||||
TEXTURE_EXTENSION,
|
||||
DDS_EXTENSION,
|
||||
MESH_EXTENSION,
|
||||
SCRIPT_EXTENSION,
|
||||
SCENE_EXTENSION,
|
||||
PREFAB_EXTENSION,
|
||||
AUDIO_WAV_EXTENSION,
|
||||
FBX_EXTENSION
|
||||
FBX_EXTENSION,
|
||||
GLTF_EXTENSION
|
||||
};
|
||||
|
||||
// Error flags
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "Filesystem/SHFileSystem.h"
|
||||
|
||||
#include "Libraries/SHMeshLoader.h"
|
||||
#include "Libraries/SHDDSLoader.h"
|
||||
#include "Libraries/SHTextureLoader.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -26,7 +26,7 @@ namespace SHADE
|
|||
std::unordered_map<AssetID, SHAsset> SHAssetManager::assetRegistry;
|
||||
|
||||
std::unordered_map<AssetID, SHMeshAsset> SHAssetManager::meshCollection;
|
||||
std::unordered_map<AssetID, SHDDSAsset> SHAssetManager::ddsCollection;
|
||||
std::unordered_map<AssetID, SHTextureAsset> SHAssetManager::textureCollection;
|
||||
|
||||
/****************************************************************************
|
||||
* \brief Static function to generate asset ID.
|
||||
|
@ -199,7 +199,7 @@ namespace SHADE
|
|||
{
|
||||
AssetPath path{ p };
|
||||
|
||||
if (path.extension().string() == FBX_EXTENSION)
|
||||
if (path.extension().string() == GLTF_EXTENSION)
|
||||
{
|
||||
LoadGLTF(
|
||||
{
|
||||
|
@ -211,7 +211,7 @@ namespace SHADE
|
|||
}
|
||||
);
|
||||
}
|
||||
else if (path.extension().string() == TEXTURE_EXTENSION)
|
||||
else if (path.extension().string() == DDS_EXTENSION)
|
||||
{
|
||||
LoadDDS(
|
||||
{
|
||||
|
@ -236,10 +236,10 @@ namespace SHADE
|
|||
return result;
|
||||
}
|
||||
|
||||
std::vector<SHDDSAsset> SHAssetManager::GetAllDDS() noexcept
|
||||
std::vector<SHTextureAsset> SHAssetManager::GetAllTextures() noexcept
|
||||
{
|
||||
std::vector<SHDDSAsset> result;
|
||||
for (auto const& dds : ddsCollection)
|
||||
std::vector<SHTextureAsset> result;
|
||||
for (auto const& dds : textureCollection)
|
||||
{
|
||||
result.push_back(dds.second);
|
||||
}
|
||||
|
@ -305,11 +305,11 @@ namespace SHADE
|
|||
|
||||
void SHAssetManager::LoadDDS(SHAsset asset) noexcept
|
||||
{
|
||||
SHDDSAsset image;
|
||||
SHTextureAsset image;
|
||||
|
||||
SHDDSLoader::LoadImageAsset(asset.path, image);
|
||||
SHTextureLoader::LoadImageAsset(asset.path, image);
|
||||
|
||||
ddsCollection.emplace(GenerateAssetID(AssetType::DDS), image);
|
||||
textureCollection.emplace(GenerateAssetID(AssetType::DDS), image);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "SHAsset.h"
|
||||
|
||||
#include "Asset Types/SHMeshAsset.h"
|
||||
#include "Asset Types/SHDDSAsset.h"
|
||||
#include "Asset Types/SHTextureAsset.h"
|
||||
#include "SH_API.h"
|
||||
|
||||
namespace SHADE
|
||||
|
@ -73,7 +73,7 @@ namespace SHADE
|
|||
//TODO: TEMPORARY FOR TESTING GLTF & DDS
|
||||
static void LoadDataTemp(std::string path) noexcept;
|
||||
static std::vector<SHMeshAsset> GetAllMeshes() noexcept;
|
||||
static std::vector<SHDDSAsset> GetAllDDS() noexcept;
|
||||
static std::vector<SHTextureAsset> GetAllTextures() noexcept;
|
||||
|
||||
private:
|
||||
/****************************************************************************
|
||||
|
@ -128,6 +128,6 @@ namespace SHADE
|
|||
static std::unordered_map<AssetID, SHAsset> assetRegistry;
|
||||
|
||||
static std::unordered_map<AssetID, SHMeshAsset> meshCollection;
|
||||
static std::unordered_map<AssetID, SHDDSAsset> ddsCollection;
|
||||
static std::unordered_map<AssetID, SHTextureAsset> textureCollection;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue