diff --git a/Assets/Cube.003.shmesh.shmeta b/Assets/Cube.003.shmesh.shmeta deleted file mode 100644 index 207f3999..00000000 --- a/Assets/Cube.003.shmesh.shmeta +++ /dev/null @@ -1,3 +0,0 @@ -Name: Cube.003 -ID: 110152941 -Type: 6 diff --git a/Assets/Cube.012.shmesh.shmeta b/Assets/Cube.012.shmesh.shmeta deleted file mode 100644 index 3af04f93..00000000 --- a/Assets/Cube.012.shmesh.shmeta +++ /dev/null @@ -1,3 +0,0 @@ -Name: Cube.012 -ID: 107348815 -Type: 6 diff --git a/Assets/RaccoonPreTexturedVer1_Base9.shtex.shmeta b/Assets/RaccoonPreTexturedVer1_Base9.shtex.shmeta deleted file mode 100644 index 3905aa4f..00000000 --- a/Assets/RaccoonPreTexturedVer1_Base9.shtex.shmeta +++ /dev/null @@ -1,3 +0,0 @@ -Name: RaccoonPreTexturedVer1_Base9 -ID: 91918845 -Type: 4 diff --git a/TempShaderFolder/KirschCs.glsl b/Assets/Shaders/KirschCs.glsl similarity index 100% rename from TempShaderFolder/KirschCs.glsl rename to Assets/Shaders/KirschCs.glsl diff --git a/TempShaderFolder/PureCopyCs.glsl b/Assets/Shaders/PureCopyCs.glsl similarity index 100% rename from TempShaderFolder/PureCopyCs.glsl rename to Assets/Shaders/PureCopyCs.glsl diff --git a/TempShaderFolder/TestCubeFs.glsl b/Assets/Shaders/TestCubeFs.glsl similarity index 100% rename from TempShaderFolder/TestCubeFs.glsl rename to Assets/Shaders/TestCubeFs.glsl diff --git a/TempShaderFolder/TestCubeVs.glsl b/Assets/Shaders/TestCubeVs.glsl similarity index 100% rename from TempShaderFolder/TestCubeVs.glsl rename to Assets/Shaders/TestCubeVs.glsl diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index a06e68c2..de408cc9 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -53,7 +53,7 @@ namespace Sandbox if (asset.name == "Cube.012") handles.emplace_back(SHResourceManager::LoadOrGet(asset.id)); break; - case AssetType::IMAGE: + case AssetType::TEXTURE: texHandles.emplace_back(SHResourceManager::LoadOrGet(asset.id)); break; } diff --git a/SHADE_Engine/SHAnimationAsset.h b/SHADE_Engine/SHAnimationAsset.h deleted file mode 100644 index d8d0ffb1..00000000 --- a/SHADE_Engine/SHAnimationAsset.h +++ /dev/null @@ -1,30 +0,0 @@ -/*************************************************************************//** - * \file SHAnimationAsset.h - * \author Loh Xiao Qi - * \date October 2022 - * \brief - * - * Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or - * disclosure of this file or its contents without the prior written consent - * of DigiPen Institute of Technology is prohibited. - *****************************************************************************/ -#pragma once - -#include -#include -#include "SH_API.power h" - -namespace SHADE -{ - struct SH_API SHAnimationAsset - { - std::string name; - - std::vector nodeChannels; - std::vector meshChannels; - std::vector morphMeshChannels; - - double duration; - double ticksPerSecond; - }; -} \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Libraries/Compilers/SHAssimpLibrary.cpp b/SHADE_Engine/src/Assets/Libraries/Compilers/SHAssimpLibrary.cpp deleted file mode 100644 index f4be0b68..00000000 --- a/SHADE_Engine/src/Assets/Libraries/Compilers/SHAssimpLibrary.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/*************************************************************************//** - * \file SHAssimpLibrary.cpp - * \author Loh Xiao Qi - * \date October 2022 - * \brief - * - * Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or - * disclosure of this file or its contents without the prior written consent - * of DigiPen Institute of Technology is prohibited. - *****************************************************************************/ -#include "SHpch.h" -#include "SHAssimpLibrary.h" -#include - -namespace SHADE -{ - Assimp::Importer SHAssimpLibrary::aiImporter; - - void SHAssimpLibrary::ProcessNode(aiNode const& node, aiScene const& scene, MeshVectorRef meshes) noexcept - { - for (size_t i {0}; i < node.mNumMeshes; ++i) - { - aiMesh* mesh = scene.mMeshes[node.mMeshes[i]]; - meshes.push_back(ProcessMesh(*mesh)); - } - - for (size_t i{ 0 }; i < node.mNumChildren; ++i) - { - ProcessNode(*node.mChildren[i], scene, meshes); - } - } - - void SHAssimpLibrary::ExtractAnimations(aiScene const& scene, AnimVectorRef anims) noexcept - { - if (scene.HasAnimations()) - { - std::vector anims(scene.mNumAnimations); - for (auto i{0}; i < scene.mNumAnimations; ++i) - { - auto const& anim {*scene.mAnimations[i]}; - - anims[i].name = anim.mName.C_Str(); - - anims[i].duration = anim.mDuration; - anims[i].ticksPerSecond = anim.mTicksPerSecond; - - std::copy_n(anim.mChannels, anim.mNumChannels, anims[i].nodeChannels.data()); - std::copy_n(anim.mMeshChannels, anim.mNumMeshChannels, anims[i].meshChannels.data()); - std::copy_n(anim.mMorphMeshChannels, anim.mNumMorphMeshChannels, anims[i].morphMeshChannels.data()); - } - } - } - - SHMeshAsset* SHAssimpLibrary::ProcessMesh(aiMesh const& mesh) noexcept - { - SHMeshAsset* result = new SHMeshAsset(); - result->compiled = false; - result->changed = false; - - for (size_t i{0}; i < mesh.mNumVertices; ++i) - { - // Vertex position - SHVec3 vertex; - vertex.x = mesh.mVertices[i].x; - vertex.y = mesh.mVertices[i].y; - vertex.z = mesh.mVertices[i].z; - result->vertexPosition.push_back(vertex); - - // Tex coords - SHVec2 texCoord{0.f, 0.f}; - if (mesh.mTextureCoords[0]) - { - texCoord.x = mesh.mTextureCoords[0][i].x; - texCoord.y = mesh.mTextureCoords[0][i].y; - } - result->texCoords.push_back(texCoord); - - // Normals - SHVec3 normal{0.f, 0.f, 0.f}; - if (mesh.mNormals) - { - normal.x = mesh.mNormals[i].x; - normal.y = mesh.mNormals[i].y; - normal.z = mesh.mNormals[i].z; - } - result->vertexNormal.push_back(normal); - - // Tangent - SHVec3 tangent{0.f, 0.f, 0.f}; - if (mesh.mTangents) - { - tangent.x = mesh.mTangents[i].x; - tangent.y = mesh.mTangents[i].y; - tangent.z = mesh.mTangents[i].z; - } - result->vertexTangent.push_back(tangent); - } - - for (size_t i {0}; i < mesh.mNumFaces; ++i) - { - aiFace face = mesh.mFaces[i]; - for (size_t j{0}; j < face.mNumIndices; ++j) - { - result->indices.push_back(face.mIndices[j]); - } - } - - result->header.vertexCount = static_cast(result->vertexPosition.size()); - result->header.indexCount = static_cast(result->indices.size()); - result->header.name = mesh.mName.C_Str(); - - return result; - } - - void SHAssimpLibrary::LoadFromFile(AssetPath path, MeshVectorRef meshes, AnimVectorRef anims) noexcept - { - const aiScene* scene = aiImporter.ReadFile(path.string().c_str(), - aiProcess_Triangulate // Make sure we get triangles rather than nvert polygons - | aiProcess_GenUVCoords // Convert any type of mapping to uv mapping - | aiProcess_TransformUVCoords // preprocess UV transformations (scaling, translation ...) - | aiProcess_FindInstances // search for instanced meshes and remove them by references to one master - | aiProcess_CalcTangentSpace // calculate tangents and bitangents if possible - | aiProcess_JoinIdenticalVertices // join identical vertices/ optimize indexing - | aiProcess_RemoveRedundantMaterials // remove redundant materials - | aiProcess_FindInvalidData // detect invalid model data, such as invalid normal vectors - | aiProcess_FlipUVs // flip the V to match the Vulkans way of doing UVs - ); - - if (!scene || !scene->HasMeshes()) - { - SHLOG_ERROR("ERROR in GLTF::ASSIMP: {}\nFile: {}", aiImporter.GetErrorString(), path.string()); - return; - } - - ExtractAnimations(*scene, anims); - - ProcessNode(*scene->mRootNode, *scene, meshes); - - aiImporter.FreeScene(); - } -} diff --git a/SHADE_Engine/src/Assets/Libraries/Compilers/SHAssimpLibrary.h b/SHADE_Engine/src/Assets/Libraries/Compilers/SHAssimpLibrary.h deleted file mode 100644 index d5afde00..00000000 --- a/SHADE_Engine/src/Assets/Libraries/Compilers/SHAssimpLibrary.h +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************//** - * \file SHAssimpLibrary.h - * \author Loh Xiao Qi - * \date October 2022 - * \brief - * - * Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or - * disclosure of this file or its contents without the prior written consent - * of DigiPen Institute of Technology is prohibited. - *****************************************************************************/ - -#pragma once -#include -#include -#include -#include "Assets/SHAssetMacros.h" -#include "Assets/Asset Types/SHMeshAsset.h" -#include "Assets/Asset Types/SHAnimationAsset.h" - -namespace SHADE -{ - class SHAssimpLibrary - { - private: - using MeshVectorRef = std::vector&; - using AnimVectorRef = std::vector&; - - static Assimp::Importer aiImporter; - static void ProcessNode(aiNode const& node, aiScene const& scene,MeshVectorRef meshes) noexcept; - static void ExtractAnimations(aiScene const& scene, AnimVectorRef anims) noexcept; - static SHMeshAsset* ProcessMesh(aiMesh const& mesh) noexcept; - - public: - static void LoadFromFile(AssetPath path, MeshVectorRef meshes, AnimVectorRef anims) noexcept; - }; -} \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Libraries/Compilers/SHMeshCompiler.cpp b/SHADE_Engine/src/Assets/Libraries/Compilers/SHMeshCompiler.cpp index 335eb631..3962b851 100644 --- a/SHADE_Engine/src/Assets/Libraries/Compilers/SHMeshCompiler.cpp +++ b/SHADE_Engine/src/Assets/Libraries/Compilers/SHMeshCompiler.cpp @@ -13,59 +13,189 @@ #include "SHpch.h" #include "SHMeshCompiler.h" #include "Graphics/MiddleEnd/Meshes/SHMeshData.h" +#include #include -std::string SHADE::SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept +namespace SHADE { - std::string newPath{ path.parent_path().string() + '/'}; - newPath += asset.header.name + MESH_EXTENSION.data(); - std::ofstream file{ newPath, std::ios::out | std::ios::binary | std::ios::trunc }; - if (!file.is_open()) - { - SHLOG_ERROR("Unable to open file for writing mesh file: {}", path.string()); - } + Assimp::Importer SHMeshCompiler::aiImporter; - file.write( - reinterpret_cast(&(asset.header.vertexCount)), - sizeof(uint32_t) - ); + void SHMeshCompiler::ProcessNode(aiNode const& node, aiScene const& scene, MeshVectorRef meshes) noexcept + { + for (size_t i{ 0 }; i < node.mNumMeshes; ++i) + { + aiMesh* mesh = scene.mMeshes[node.mMeshes[i]]; + meshes.push_back(ProcessMesh(*mesh)); + } - file.write( - reinterpret_cast(&(asset.header.indexCount)), - sizeof(uint32_t) - ); + for (size_t i{ 0 }; i < node.mNumChildren; ++i) + { + ProcessNode(*node.mChildren[i], scene, meshes); + } + } - auto const vertexVec3Byte {sizeof(SHVec3) * asset.header.vertexCount}; - auto const vertexVec2Byte {sizeof(SHVec2) * asset.header.vertexCount}; + void SHMeshCompiler::ExtractAnimations(aiScene const& scene, AnimVectorRef anims) noexcept + { + if (scene.HasAnimations()) + { + std::vector anims(scene.mNumAnimations); + for (auto i{ 0 }; i < scene.mNumAnimations; ++i) + { + auto const& anim{ *scene.mAnimations[i] }; - file.write( - reinterpret_cast(asset.vertexPosition.data()), - vertexVec3Byte - ); - - file.write( - reinterpret_cast(asset.vertexTangent.data()), - vertexVec3Byte - ); - - file.write( - reinterpret_cast(asset.vertexNormal.data()), - vertexVec3Byte - ); - - file.write( - reinterpret_cast(asset.texCoords.data()), - vertexVec2Byte - ); + anims[i].name = anim.mName.C_Str(); - file.write( - reinterpret_cast(asset.indices.data()), - sizeof(uint32_t) * asset.header.indexCount - ); + anims[i].duration = anim.mDuration; + anims[i].ticksPerSecond = anim.mTicksPerSecond; - file.close(); + std::copy_n(anim.mChannels, anim.mNumChannels, anims[i].nodeChannels.data()); + std::copy_n(anim.mMeshChannels, anim.mNumMeshChannels, anims[i].meshChannels.data()); + std::copy_n(anim.mMorphMeshChannels, anim.mNumMorphMeshChannels, anims[i].morphMeshChannels.data()); + } + } + } - return newPath; + SHMeshAsset* SHMeshCompiler::ProcessMesh(aiMesh const& mesh) noexcept + { + SHMeshAsset* result = new SHMeshAsset(); + result->compiled = false; + result->changed = false; + + for (size_t i{ 0 }; i < mesh.mNumVertices; ++i) + { + // Vertex position + SHVec3 vertex; + vertex.x = mesh.mVertices[i].x; + vertex.y = mesh.mVertices[i].y; + vertex.z = mesh.mVertices[i].z; + result->vertexPosition.push_back(vertex); + + // Tex coords + SHVec2 texCoord{ 0.f, 0.f }; + if (mesh.mTextureCoords[0]) + { + texCoord.x = mesh.mTextureCoords[0][i].x; + texCoord.y = mesh.mTextureCoords[0][i].y; + } + result->texCoords.push_back(texCoord); + + // Normals + SHVec3 normal{ 0.f, 0.f, 0.f }; + if (mesh.mNormals) + { + normal.x = mesh.mNormals[i].x; + normal.y = mesh.mNormals[i].y; + normal.z = mesh.mNormals[i].z; + } + result->vertexNormal.push_back(normal); + + // Tangent + SHVec3 tangent{ 0.f, 0.f, 0.f }; + if (mesh.mTangents) + { + tangent.x = mesh.mTangents[i].x; + tangent.y = mesh.mTangents[i].y; + tangent.z = mesh.mTangents[i].z; + } + result->vertexTangent.push_back(tangent); + } + + for (size_t i{ 0 }; i < mesh.mNumFaces; ++i) + { + aiFace face = mesh.mFaces[i]; + for (size_t j{ 0 }; j < face.mNumIndices; ++j) + { + result->indices.push_back(face.mIndices[j]); + } + } + + result->header.vertexCount = static_cast(result->vertexPosition.size()); + result->header.indexCount = static_cast(result->indices.size()); + result->header.name = mesh.mName.C_Str(); + + return result; + } + + void SHMeshCompiler::LoadFromFile(AssetPath path, MeshVectorRef meshes, AnimVectorRef anims) noexcept + { + const aiScene* scene = aiImporter.ReadFile(path.string().c_str(), + aiProcess_Triangulate // Make sure we get triangles rather than nvert polygons + | aiProcess_GenUVCoords // Convert any type of mapping to uv mapping + | aiProcess_TransformUVCoords // preprocess UV transformations (scaling, translation ...) + | aiProcess_FindInstances // search for instanced meshes and remove them by references to one master + | aiProcess_CalcTangentSpace // calculate tangents and bitangents if possible + | aiProcess_JoinIdenticalVertices // join identical vertices/ optimize indexing + | aiProcess_RemoveRedundantMaterials // remove redundant materials + | aiProcess_FindInvalidData // detect invalid model data, such as invalid normal vectors + | aiProcess_FlipUVs // flip the V to match the Vulkans way of doing UVs + ); + + if (!scene || !scene->HasMeshes()) + { + SHLOG_ERROR("ERROR in GLTF::ASSIMP: {}\nFile: {}", aiImporter.GetErrorString(), path.string()); + return; + } + + ExtractAnimations(*scene, anims); + + ProcessNode(*scene->mRootNode, *scene, meshes); + + aiImporter.FreeScene(); + } + + std::string SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept + { + std::string newPath{ path.parent_path().string() + '/' }; + newPath += asset.header.name + MESH_EXTENSION.data(); + + std::ofstream file{ newPath, std::ios::out | std::ios::binary | std::ios::trunc }; + if (!file.is_open()) + { + SHLOG_ERROR("Unable to open file for writing mesh file: {}", path.string()); + } + + file.write( + reinterpret_cast(&(asset.header.vertexCount)), + sizeof(uint32_t) + ); + + file.write( + reinterpret_cast(&(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(asset.vertexPosition.data()), + vertexVec3Byte + ); + + file.write( + reinterpret_cast(asset.vertexTangent.data()), + vertexVec3Byte + ); + + file.write( + reinterpret_cast(asset.vertexNormal.data()), + vertexVec3Byte + ); + + file.write( + reinterpret_cast(asset.texCoords.data()), + vertexVec2Byte + ); + + file.write( + reinterpret_cast(asset.indices.data()), + sizeof(uint32_t) * asset.header.indexCount + ); + + file.close(); + + return newPath; + } } diff --git a/SHADE_Engine/src/Assets/Libraries/Compilers/SHMeshCompiler.h b/SHADE_Engine/src/Assets/Libraries/Compilers/SHMeshCompiler.h index 441c2297..0b873621 100644 --- a/SHADE_Engine/src/Assets/Libraries/Compilers/SHMeshCompiler.h +++ b/SHADE_Engine/src/Assets/Libraries/Compilers/SHMeshCompiler.h @@ -12,6 +12,11 @@ *****************************************************************************/ #pragma once +#include +#include +#include + +#include "Assets/Asset Types/SHAnimationAsset.h" #include "Assets/Asset Types/SHMeshAsset.h" #include "Assets/SHAssetMacros.h" @@ -19,7 +24,17 @@ namespace SHADE { class SHMeshCompiler { - public: - static std::string CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept; + + using MeshVectorRef = std::vector&; + using AnimVectorRef = std::vector&; + + static Assimp::Importer aiImporter; + static void ProcessNode(aiNode const& node, aiScene const& scene, MeshVectorRef meshes) noexcept; + static void ExtractAnimations(aiScene const& scene, AnimVectorRef anims) noexcept; + static SHMeshAsset* ProcessMesh(aiMesh const& mesh) noexcept; + + public: + static void LoadFromFile(AssetPath path, MeshVectorRef meshes, AnimVectorRef anims) noexcept; + static std::string CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Libraries/Compilers/SHShaderSourceCompiler.h b/SHADE_Engine/src/Assets/Libraries/Compilers/SHShaderSourceCompiler.h index 9fb93924..4872be59 100644 --- a/SHADE_Engine/src/Assets/Libraries/Compilers/SHShaderSourceCompiler.h +++ b/SHADE_Engine/src/Assets/Libraries/Compilers/SHShaderSourceCompiler.h @@ -17,6 +17,7 @@ namespace SHADE { class SHShaderSourceCompiler { + private: static std::string CompileShaderSourceToBinary(AssetPath path, SHShaderAsset const& data) noexcept; static SHShaderAsset const* CompileShaderSourceToMemory(std::string const& data, std::string const& name, SH_SHADER_TYPE type) noexcept; diff --git a/SHADE_Engine/src/Assets/Libraries/Compilers/SHTextureCompiler.cpp b/SHADE_Engine/src/Assets/Libraries/Compilers/SHTextureCompiler.cpp index 49de6b5c..9c65f5b2 100644 --- a/SHADE_Engine/src/Assets/Libraries/Compilers/SHTextureCompiler.cpp +++ b/SHADE_Engine/src/Assets/Libraries/Compilers/SHTextureCompiler.cpp @@ -17,6 +17,100 @@ namespace SHADE { + + std::string SHTextureCompiler::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 SHTextureCompiler::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 SHTextureCompiler::LoadTinyDDS(AssetPath path, SHTextureAsset& asset) noexcept + { + 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 mipOff(file.GetMipCount()); + + for (size_t i{ 0 }; i < file.GetMipCount(); ++i) + { + mipOff[i] = static_cast(totalBytes); + totalBytes += file.GetImageData(static_cast(i), 0)->m_memSlicePitch; + } + + SHTexture::PixelChannel* pixel = new SHTexture::PixelChannel[totalBytes]; + std::memcpy(pixel, file.GetImageData()->m_mem, totalBytes); + //pixel = std::move(reinterpret_cast(file.GetDDSData())); + + asset.name = path.stem().string(); + asset.compiled = false; + asset.numBytes = static_cast(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); + } + + void SHTextureCompiler::LoadImageAsset(AssetPath path, SHTextureAsset& image) + { + LoadTinyDDS(path, image); + } std::string SHTextureCompiler::CompileTextureBinary(SHTextureAsset const& asset, AssetPath path) { std::string newPath{ path.string() }; diff --git a/SHADE_Engine/src/Assets/Libraries/Compilers/SHTextureCompiler.h b/SHADE_Engine/src/Assets/Libraries/Compilers/SHTextureCompiler.h index 52980084..3a7e7db7 100644 --- a/SHADE_Engine/src/Assets/Libraries/Compilers/SHTextureCompiler.h +++ b/SHADE_Engine/src/Assets/Libraries/Compilers/SHTextureCompiler.h @@ -11,14 +11,22 @@ * of DigiPen Institute of Technology is prohibited. *****************************************************************************/ #pragma once +#define TINYDDSLOADER_IMPLEMENTATION #include "Assets/Asset Types/SHTextureAsset.h" #include "Assets/SHAssetMacros.h" +#include "tinyddsloader.h" namespace SHADE { - struct SHTextureCompiler + class SHTextureCompiler { + private: + static std::string TinyDDSResultToString(tinyddsloader::Result value); + static vk::Format ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear); + static void LoadTinyDDS(AssetPath path, SHTextureAsset& asset) noexcept; + public: + static void LoadImageAsset(AssetPath paths, SHTextureAsset& image); static std::string CompileTextureBinary(SHTextureAsset const& asset, AssetPath path); }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHShaderSourceLoader.h b/SHADE_Engine/src/Assets/Libraries/Loaders/SHShaderSourceLoader.h index befdade5..905eb223 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHShaderSourceLoader.h +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHShaderSourceLoader.h @@ -15,7 +15,7 @@ namespace SHADE { - struct SHShaderSourceLoader : SHAssetLoader + struct SHShaderSourceLoader final : SHAssetLoader { SHAssetData* Load(AssetPath path) override; }; diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextureLoader.cpp b/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextureLoader.cpp index 8b986524..74c08230 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextureLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextureLoader.cpp @@ -12,145 +12,47 @@ #include "SHpch.h" #include "SHTextureLoader.h" +#include + 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::LoadSHTexture(AssetPath path, SHTextureAsset& asset) noexcept + { + std::ifstream file{ path.string(), std::ios::in | std::ios::binary }; + if (!file.is_open()) + { + SHLOG_ERROR("Error opening SHTexture file: {}", path.string()); + } - void SHTextureLoader::LoadTinyDDS(AssetPath path, SHTextureAsset& asset) noexcept - { - 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()); - } + auto const intBytes{ sizeof(uint32_t) }; + uint32_t mipCount; - size_t totalBytes{ 0 }; + file.read(reinterpret_cast(&asset.numBytes), intBytes); + file.read(reinterpret_cast(&asset.width), intBytes); + file.read(reinterpret_cast(&asset.height), intBytes); + file.read(reinterpret_cast(&asset.format), sizeof(SHTexture::TextureFormat)); - std::vector mipOff(file.GetMipCount()); + file.read(reinterpret_cast(&mipCount), intBytes); + std::vector mips(mipCount); + file.read(reinterpret_cast(mips.data()), intBytes * mipCount); - for (size_t i{0}; i < file.GetMipCount(); ++i) - { - mipOff[i] = static_cast(totalBytes); - totalBytes += file.GetImageData(static_cast(i), 0)->m_memSlicePitch; - } + auto pixel = new SHTexture::PixelChannel[asset.numBytes]; + file.read(reinterpret_cast(pixel), asset.numBytes); - SHTexture::PixelChannel* pixel = new SHTexture::PixelChannel[totalBytes]; - std::memcpy(pixel, file.GetImageData()->m_mem, totalBytes); - //pixel = std::move(reinterpret_cast(file.GetDDSData())); + asset.mipOffsets = std::move(mips); + asset.pixelData = std::move(pixel); - asset.name = path.stem().string(); - asset.compiled = false; - asset.numBytes = static_cast(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); - } + asset.compiled = true; + file.close(); + } - void SHTextureLoader::LoadSHTexture(AssetPath path, SHTextureAsset& asset) noexcept - { - std::ifstream file{path.string(), std::ios::in | std::ios::binary}; - if (!file.is_open()) - { - SHLOG_ERROR("Error opening SHTexture file: {}", path.string()); - } + SHAssetData* SHTextureLoader::Load(AssetPath path) + { + auto result = new SHTextureAsset(); - auto const intBytes{ sizeof(uint32_t) }; - uint32_t mipCount; + LoadSHTexture(path, *result); - file.read(reinterpret_cast(&asset.numBytes), intBytes); - file.read(reinterpret_cast(&asset.width), intBytes); - file.read(reinterpret_cast(&asset.height), intBytes); - file.read(reinterpret_cast(&asset.format), sizeof(SHTexture::TextureFormat)); - - file.read(reinterpret_cast(&mipCount), intBytes); - std::vector mips(mipCount); - file.read(reinterpret_cast(mips.data()), intBytes * mipCount); - - auto pixel = new SHTexture::PixelChannel[asset.numBytes]; - file.read(reinterpret_cast(pixel), asset.numBytes); - - asset.mipOffsets = std::move(mips); - asset.pixelData = std::move( pixel ); - - asset.compiled = true; - file.close(); - } - - SHAssetData* SHTextureLoader::Load(AssetPath path) - { - auto result = new SHTextureAsset(); - - LoadImageAsset(path, *result); - - return result; - } - - void SHTextureLoader::LoadImageAsset(AssetPath path, SHTextureAsset& asset) - { - if (path.extension().string() == DDS_EXTENSION) - { - LoadTinyDDS(path, asset); - } - else if (path.extension().string() == TEXTURE_EXTENSION) - { - LoadSHTexture(path, asset); - } - } + return result; + } } diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextureLoader.h b/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextureLoader.h index 95dd7c9a..00b060ec 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextureLoader.h +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextureLoader.h @@ -10,24 +10,15 @@ * of DigiPen Institute of Technology is prohibited. *****************************************************************************/ #pragma once -#define TINYDDSLOADER_IMPLEMENTATION #include "Assets/SHAssetMacros.h" #include "Assets/Asset Types/SHTextureAsset.h" -#include "tinyddsloader.h" #include "SHAssetLoader.h" namespace SHADE { class SHTextureLoader : public SHAssetLoader { - private: - std::string TinyDDSResultToString(tinyddsloader::Result value); - vk::Format ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear); - - void LoadTinyDDS(AssetPath path, SHTextureAsset& asset) noexcept; - public: - void LoadImageAsset(AssetPath paths, SHTextureAsset& image); void LoadSHTexture(AssetPath path, SHTextureAsset& asset) noexcept; SHAssetData* Load(AssetPath path) override; }; diff --git a/SHADE_Engine/src/Assets/Libraries/SHShaderSourceLibrary.cpp b/SHADE_Engine/src/Assets/Libraries/SHShaderSourceLibrary.cpp deleted file mode 100644 index 8a5769d0..00000000 --- a/SHADE_Engine/src/Assets/Libraries/SHShaderSourceLibrary.cpp +++ /dev/null @@ -1,262 +0,0 @@ -#include "SHPch.h" -#include -#include -#include "SHShaderSourceLibrary.h" -#include "Tools/SHLogger.h" - -namespace SHADE -{ - - /***************************************************************************/ - /*! - - \brief - Private member function to compile a shader STRING source to binary and - returns a vector of 4 bytes. - - \param glslSource - The GLSL string source. - - \param type - Type of the shader: vertex, fragment, compute, etc. - - \param opLevel - Optimization level. - - \return - Returns a vector of the binary data. - - */ - /***************************************************************************/ - std::vector SHShaderSourceLibrary::CompileToBinary(std::string const& glslSource, char const* const spirvFilename, SH_SHADER_TYPE type, shaderc_optimization_level opLevel /*= shaderc_optimization_level_zero*/) - { - // shaderc compiler - shaderc::Compiler compiler; - shaderc::CompileOptions options; - - options.AddMacroDefinition("MY_DEFINE", "1"); - - // Set optimization levels - if (opLevel != shaderc_optimization_level_zero) - options.SetOptimizationLevel(opLevel); - - // Attempt to get the shaderc equivalent shader stage - shaderc_shader_kind shaderKind; - switch (type) - { - case SH_SHADER_TYPE::VERTEX: - shaderKind = shaderc_shader_kind::shaderc_glsl_vertex_shader; - break; - case SH_SHADER_TYPE::FRAGMENT: - shaderKind = shaderc_shader_kind::shaderc_glsl_fragment_shader; - break; - case SH_SHADER_TYPE::COMPUTE: - shaderKind = shaderc_shader_kind::shaderc_glsl_compute_shader; - break; - default: - shaderKind = shaderc_shader_kind::shaderc_glsl_vertex_shader; - break; - } - - // Compile the shader and get the result - shaderc::SpvCompilationResult compileResult = compiler.CompileGlslToSpv(glslSource, shaderKind, spirvFilename, options); - - if (compileResult.GetCompilationStatus() != shaderc_compilation_status_success) - { - SHLOG_ERROR("Shaderc failed to compile GLSL shader to binary | " + compileResult.GetErrorMessage()); - } - - return { compileResult.begin(), compileResult.end() }; - } - - /***************************************************************************/ - /*! - - \brief - TODO: Delete after file IO is implemented. Loads a shader from disk. - - \param filePath - file path to the shader in the asset directory. - - \return - Returns the data in the file in string form. - - */ - /***************************************************************************/ - std::string SHShaderSourceLibrary::GetStringFromFile(char const* filePath) noexcept - { - // Retrieve contents from filePath - // Ensure ifstream objects can throw exceptions - std::ifstream iFile; - iFile.exceptions(std::ifstream::failbit | std::ifstream::badbit); - std::string fileContent = ""; - - try - { - // Open file - // Read file's buffer contents into streams - iFile.open(filePath); - std::stringstream fileStream; - fileStream << iFile.rdbuf(); - - fileContent = fileStream.str(); - - // Close file handler - iFile.close(); - } - catch (std::ifstream::failure e) - { - std::cerr << "File was not successfully read" << filePath << std::endl; - } - - return fileContent; - - } - - /***************************************************************************/ - /*! - - \brief - Load a shader into the library. - - \param filePath - file path to the shader in the asset directory. - - */ - /***************************************************************************/ - bool SHShaderSourceLibrary::LoadShader (uint32_t id, std::string glslFile, SH_SHADER_TYPE type, bool checkSpirvOutdated/* = true*/, bool recompileAnyway /*= false*/) noexcept - { - if (path.extension() != ".glsl") - { - SHLOG_ERROR("Shader is not GLSL file, failed to load shader. "); - return false; - } - - std::string spirvFilepath = path.replace_extension("spv").string(); - - SHShaderAsset newShaderData{}; - newShaderData.shaderType = type; - - // spirv file - std::ifstream spirvFile(spirvFilepath, std::ios::ate | std::ios::binary); - - // If we disable spirv validation, file is not checked - if (!recompileAnyway && - spirvFile.is_open() && - (checkSpirvOutdated ? (std::filesystem::last_write_time(spirvFilepath) > std::filesystem::last_write_time(fullGLSLPath)) : true)) - { - // Get file size of binary - uint32_t fileSize = static_cast(spirvFile.tellg()); - - // resize container to store binary - newShaderData.spirvBinary.resize(fileSize / sizeof(uint32_t)); - - // Read data from binary file to container - spirvFile.seekg(0); - spirvFile.read(reinterpret_cast(newShaderData.spirvBinary.data()), fileSize); - - // close file - spirvFile.close(); - - } - else - { - // Use glslc to generate spirv file - newShaderData.spirvBinary = CompileToBinary(GetStringFromFile(fullGLSLPath.c_str()), spirvFilepath.c_str(), type); - - std::ofstream binaryFile(spirvFilepath, std::ios::binary); - - if (binaryFile.is_open()) - { - // write all data to binary file - binaryFile.write(reinterpret_cast(newShaderData.spirvBinary.data()), newShaderData.spirvBinary.size() * sizeof(uint32_t)); - } - else - { - SHLOG_ERROR("Failed to modify spirv file. "); - return false; - } - } - - newShaderData.name = glslFile; - newShaderData.id = id; - - sourceLibrary.emplace_back(std::move(newShaderData)); - return true; - } - - /***************************************************************************/ - /*! - - \brief - Move ctor for shader data. - - \param rhs - The other shader data - - */ - /***************************************************************************/ - SHShaderAsset::SHShaderAsset(SHShaderAsset&& rhs) noexcept - : spirvBinary{ std::move(rhs.spirvBinary) } - , shaderType{ std::move(rhs.shaderType) } - , name{ std::move(rhs.name) } - , id{ std::move(rhs.id) } - { - - } - - /***************************************************************************/ - /*! - - \brief - Default ctor for shader data. Does nothing. - - */ - /***************************************************************************/ - SHShaderAsset::SHShaderAsset(void) noexcept - : spirvBinary{} - , shaderType{ SH_SHADER_TYPE::VERTEX } - , name{ } - , id{ } - - { - - } - - SHShaderAsset::SHShaderAsset(SHShaderAsset const& rhs) noexcept - : spirvBinary{ rhs.spirvBinary } - , shaderType{ rhs.shaderType } - , name{ rhs.name } - , id{ rhs.id } - { - - } - - SHShaderAsset& SHShaderAsset::operator=(SHShaderAsset const& rhs) noexcept - { - if (this == &rhs) - return *this; - - spirvBinary = rhs.spirvBinary; - shaderType = rhs.shaderType; - name = rhs.name; - id = rhs.id; - - - return *this; - } - - SHShaderAsset& SHShaderAsset::operator=(SHShaderAsset&& rhs) noexcept - { - if (this == &rhs) - return *this; - - spirvBinary = std::move(rhs.spirvBinary); - shaderType = std::move (rhs.shaderType); - name = std::move (rhs.name); - id = std::move (rhs.id); - - return *this; - } - -} \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Libraries/SHShaderSourceLibrary.h b/SHADE_Engine/src/Assets/Libraries/SHShaderSourceLibrary.h deleted file mode 100644 index cb4a3453..00000000 --- a/SHADE_Engine/src/Assets/Libraries/SHShaderSourceLibrary.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SH_SHADER_SOURCE_LIBRARY_H -#define SH_SHADER_SOURCE_LIBRARY_H - -#include "Graphics/MiddleEnd/Shaders/SHShaderType.h" -#include "shaderc/shaderc.hpp" - -namespace SHADE -{ - class SHShaderSourceLibrary - { - private: - /*-----------------------------------------------------------------------*/ - /* PRIVATE MEMBER FUNCTIONS */ - /*-----------------------------------------------------------------------*/ - std::vector CompileToBinary(std::string const& glslSource, char const* const spirvFilename, SH_SHADER_TYPE type, shaderc_optimization_level opLevel = shaderc_optimization_level_zero); - - // TODO: Delete after file IO is implemented - std::string GetStringFromFile(char const* filePath) noexcept; - - public: - bool LoadShader (uint32_t id, std::string glslFile, SH_SHADER_TYPE type, bool checkSpirvOutdated = true, bool recompileAnyway = false) noexcept; - }; -} - -#endif diff --git a/SHADE_Engine/src/Assets/SHAssetMacros.h b/SHADE_Engine/src/Assets/SHAssetMacros.h index 3b352d4e..1df4e30b 100644 --- a/SHADE_Engine/src/Assets/SHAssetMacros.h +++ b/SHADE_Engine/src/Assets/SHAssetMacros.h @@ -42,19 +42,11 @@ constexpr std::string_view ASSET_META_VER { "1.0" }; // Asset type enum enum class AssetType : AssetTypeMeta { - INVALID = 0, - AUDIO = 1, + INVALID, SHADER, SHADER_BUILT_IN, - MATERIAL, - IMAGE, - TEXTURE, - MESH, - SCRIPT, - SCENE, - PREFAB, - AUDIO_WAV, - DDS, + TEXTURE, + MESH, MAX_COUNT }; constexpr size_t TYPE_COUNT{ static_cast(AssetType::MAX_COUNT) }; @@ -95,14 +87,12 @@ constexpr std::string_view EXTENSIONS[] = { // EXTERNAL EXTENSIONS constexpr std::string_view GLSL_EXTENSION{ ".glsl" }; -constexpr std::string_view IMAGE_EXTENSION{ ".png" }; constexpr std::string_view DDS_EXTENSION{ ".dds" }; constexpr std::string_view FBX_EXTENSION{ ".fbx" }; constexpr std::string_view GLTF_EXTENSION{ ".gltf" }; constexpr std::string_view EXTERNALS[] = { GLSL_EXTENSION, - IMAGE_EXTENSION, DDS_EXTENSION, FBX_EXTENSION, GLTF_EXTENSION diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 3cd4c33c..e7a7a1b7 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -18,10 +18,9 @@ #include "Libraries/Loaders/SHTextureLoader.h" #include "Libraries/Loaders/SHShaderSourceLoader.h" - -#include "Libraries/Compilers/SHAssimpLibrary.h" #include "Libraries/Compilers/SHMeshCompiler.h" #include "Libraries/Compilers/SHTextureCompiler.h" +#include "Libraries/Compilers/SHShaderSourceCompiler.h" namespace SHADE { @@ -112,17 +111,10 @@ namespace SHADE switch(type) { - case AssetType::SCENE: - folder = "scenes/"; - break; - - case AssetType::PREFAB: - folder = "prefabs/"; - break; - - case AssetType::MATERIAL: - folder = "materials/"; - break; + case AssetType::SHADER: + case AssetType::SHADER_BUILT_IN: + folder = "Shaders/"; + break; default: folder = "/"; @@ -280,19 +272,55 @@ namespace SHADE return result; } - void SHAssetManager::InitLoaders() noexcept + void SHAssetManager::CompileAll() noexcept + { + std::vector paths; + + for (auto const& dir : std::filesystem::recursive_directory_iterator{ ASSET_ROOT }) + { + if (dir.is_regular_file()) + { + for (auto const& ext : EXTERNALS) + { + if (dir.path().extension().string() == ext.data()) + { + paths.push_back(dir.path()); + } + } + } + } + + for (auto const& path : paths) + { + auto const ext{ path.extension().string() }; + if (ext == GLSL_EXTENSION.data()) + { + SHShaderSourceCompiler::LoadAndCompileShader(path); + } + else if (ext == DDS_EXTENSION.data()) + { + auto image = new SHTextureAsset(); + SHTextureCompiler::LoadImageAsset(path, *image); + } + else if (ext == GLTF_EXTENSION.data() || ext == FBX_EXTENSION.data()) + { + std::vector meshes; + std::vector anims; + SHMeshCompiler::LoadFromFile(path, meshes, anims); + for (auto const& mesh : meshes) + { + SHMeshCompiler::CompileMeshBinary(*mesh, path); + } + } + } + } + + void SHAssetManager::InitLoaders() noexcept { - loaders[static_cast(AssetType::AUDIO)] = nullptr; loaders[static_cast(AssetType::SHADER)] = dynamic_cast(new SHShaderSourceLoader()); loaders[static_cast(AssetType::SHADER_BUILT_IN)] = loaders[static_cast(AssetType::SHADER)]; - loaders[static_cast(AssetType::MATERIAL)] = nullptr; - loaders[static_cast(AssetType::TEXTURE)] = dynamic_cast(new SHTextureLoader()); - loaders[static_cast(AssetType::MESH)] = dynamic_cast(new SHMeshLoader()); - loaders[static_cast(AssetType::SCRIPT)] = nullptr; - loaders[static_cast(AssetType::SCENE)] = nullptr; - loaders[static_cast(AssetType::PREFAB)] = nullptr; - loaders[static_cast(AssetType::AUDIO_WAV)] = nullptr; - loaders[static_cast(AssetType::DDS)] = nullptr; + loaders[static_cast(AssetType::TEXTURE)] = dynamic_cast(new SHTextureLoader()); + loaders[static_cast(AssetType::MESH)] = dynamic_cast(new SHMeshLoader()); } /**************************************************************************** diff --git a/SHADE_Engine/src/Assets/SHAssetManager.h b/SHADE_Engine/src/Assets/SHAssetManager.h index 376467d8..6e5abfd1 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.h +++ b/SHADE_Engine/src/Assets/SHAssetManager.h @@ -84,20 +84,17 @@ namespace SHADE static std::vector GetAllRecordOfType(AssetType type) noexcept; private: - /**************************************************************************** - * \brief Load resource data into memory - ****************************************************************************/ + + static void InitLoaders() noexcept; static void LoadAllData() noexcept; - static SHAssetData* LoadData(SHAsset const& asset) noexcept; - inline static void BuildAssetCollection() noexcept; static bool IsRecognised(char const*) noexcept; static SHAsset CreateAssetFromPath(AssetPath path) noexcept; - static void InitLoaders() noexcept; + static void CompileAll() noexcept; static FMOD::System* audioSystem; static std::unordered_map* audioSoundList; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 2847f5f3..6c8baa36 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -118,24 +118,8 @@ namespace SHADE graphicsTexCmdBuffer = graphicsCmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); - // TODO: This is VERY temporarily here until a more solid resource management system is implemented - shaderSourceLibrary.Init("../../TempShaderFolder/"); - - shaderSourceLibrary.LoadShader(0, "TestCubeVs.glsl", SH_SHADER_TYPE::VERTEX, true); - shaderSourceLibrary.LoadShader(1, "TestCubeFs.glsl", SH_SHADER_TYPE::FRAGMENT, true); - - shaderSourceLibrary.LoadShader(2, "KirschCs.glsl", SH_SHADER_TYPE::COMPUTE, true); - shaderSourceLibrary.LoadShader(3, "PureCopyCs.glsl", SH_SHADER_TYPE::COMPUTE, true); - - shaderModuleLibrary.ImportFromSourceLibrary(device, shaderSourceLibrary); - auto cubeVS = shaderModuleLibrary.GetShaderModule("TestCubeVs.glsl"); - auto cubeFS = shaderModuleLibrary.GetShaderModule("TestCubeFs.glsl"); - auto greyscale = shaderModuleLibrary.GetShaderModule("KirschCs.glsl"); - auto pureCopy = shaderModuleLibrary.GetShaderModule("PureCopyCs.glsl"); - cubeVS->Reflect(); - cubeFS->Reflect(); - greyscale->Reflect(); - pureCopy->Reflect(); + shaderModuleLibrary.ImportAllShaderSource(device); + shaderModuleLibrary.ReflectAllShaderModules(); } void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept diff --git a/TempShaderFolder/KirschCs.spv b/TempShaderFolder/KirschCs.spv deleted file mode 100644 index 1ae5408b..00000000 Binary files a/TempShaderFolder/KirschCs.spv and /dev/null differ diff --git a/TempShaderFolder/PureCopyCs.spv b/TempShaderFolder/PureCopyCs.spv deleted file mode 100644 index bf967bbf..00000000 Binary files a/TempShaderFolder/PureCopyCs.spv and /dev/null differ diff --git a/TempShaderFolder/ShaderDescriptorDefinitions.glsl b/TempShaderFolder/ShaderDescriptorDefinitions.glsl deleted file mode 100644 index c70a9f5b..00000000 --- a/TempShaderFolder/ShaderDescriptorDefinitions.glsl +++ /dev/null @@ -1,11 +0,0 @@ -#define SET_STATIC_GLOBALS 0 -#define SET_DYNAMIC_GLOBALS 1 -#define SET_HIGH_FREQUENCY_GLOBALS 2 - -#define BINDING_GENERIC_DATA 0 -#define BINDING_IMAGE_AND_SAMPLERS_DATA 1 -#define BINDING_LIGHTS_DATA 0 -#define BINDING_CAMERA_DATA 0 -#define BINDING_BATCHED_PER_INST_DATA 0 - - diff --git a/TempShaderFolder/TestCubeFs.spv b/TempShaderFolder/TestCubeFs.spv deleted file mode 100644 index 9955abe5..00000000 Binary files a/TempShaderFolder/TestCubeFs.spv and /dev/null differ diff --git a/TempShaderFolder/TestCubeVs.spv b/TempShaderFolder/TestCubeVs.spv deleted file mode 100644 index 731e31d1..00000000 Binary files a/TempShaderFolder/TestCubeVs.spv and /dev/null differ