From 210283562967053b5763d90edcdcd8fb39a222a1 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Thu, 27 Oct 2022 14:24:03 +0800 Subject: [PATCH] Added function to manually compile shaders by path --- SHADE_Engine/src/Assets/SHAssetManager.cpp | 24 +++++++++++++++++++++- SHADE_Engine/src/Assets/SHAssetManager.h | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index f6760ec0..228f3fdc 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -246,7 +246,29 @@ namespace SHADE return result; } - bool SHAssetManager::IsRecognised(char const* ext) noexcept + AssetID SHAssetManager::CompileAsset(AssetPath path) noexcept + { + SHAsset newAsset + { + .name = path.stem().string(), + .location = 0 + }; + + auto const ext{ path.extension().string() }; + if (ext == GLSL_EXTENSION.data()) + { + newAsset.path = SHShaderSourceCompiler::LoadAndCompileShader(path).value(); + newAsset.id = GenerateAssetID(AssetType::SHADER_BUILT_IN); + newAsset.type = AssetType::SHADER_BUILT_IN; + } + + assetCollection.push_back(newAsset); + SHAssetMetaHandler::WriteMetaData(newAsset); + + return newAsset.id; + } + + bool SHAssetManager::IsRecognised(char const* ext) noexcept { for (auto const& e : EXTENSIONS) { diff --git a/SHADE_Engine/src/Assets/SHAssetManager.h b/SHADE_Engine/src/Assets/SHAssetManager.h index 6e5abfd1..bc6f8878 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.h +++ b/SHADE_Engine/src/Assets/SHAssetManager.h @@ -82,6 +82,8 @@ namespace SHADE static std::vector GetAllDataOfType(AssetType type) noexcept; static std::vector GetAllRecordOfType(AssetType type) noexcept; + + static AssetID CompileAsset(AssetPath path) noexcept; private: