Asset Manager restructure #123
|
@ -183,8 +183,8 @@ namespace SHADE
|
|||
|
||||
worldRenderer->SetCameraDirector(cameraSystem->CreateDirector());
|
||||
|
||||
auto cubeVS = shaderModuleLibrary.GetShaderModule("TestCubeVs.glsl");
|
||||
auto cubeFS = shaderModuleLibrary.GetShaderModule("TestCubeFs.glsl");
|
||||
auto cubeVS = shaderModuleLibrary.GetBuiltInShaderModule("TestCubeVs.glsl");
|
||||
auto cubeFS = shaderModuleLibrary.GetBuiltInShaderModule("TestCubeFs.glsl");
|
||||
|
||||
defaultMaterial = AddMaterial(cubeVS, cubeFS, gBufferWriteSubpass);
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "SHPch.h"
|
||||
#include "SHShaderModuleLibrary.h"
|
||||
#include "Graphics/Devices/SHVkLogicalDevice.h"
|
||||
#include "Assets/Asset Types/SHShaderAsset.h"
|
||||
#include "Assets/SHAssetManager.h"
|
||||
|
||||
namespace SHADE
|
||||
|
@ -68,45 +67,61 @@ namespace SHADE
|
|||
// return {};
|
||||
//}
|
||||
|
||||
void SHShaderModuleLibrary::ImportBuiltInShaderSource(Handle<SHVkLogicalDevice>& logicalDeviceHdl) noexcept
|
||||
vk::ShaderStageFlagBits SHShaderModuleLibrary::GetVkShaderFlag(SH_SHADER_TYPE type) noexcept
|
||||
{
|
||||
uint32_t idCounter{ 0 };
|
||||
const AssetID DEFAULT_VS_ID{ 69 };
|
||||
const AssetID DEFAULT_FS_ID{ 420 };
|
||||
vk::ShaderStageFlagBits shaderType{};
|
||||
switch (type)
|
||||
{
|
||||
case SH_SHADER_TYPE::VERTEX:
|
||||
shaderType = vk::ShaderStageFlagBits::eVertex;
|
||||
break;
|
||||
case SH_SHADER_TYPE::FRAGMENT:
|
||||
shaderType = vk::ShaderStageFlagBits::eFragment;
|
||||
break;
|
||||
case SH_SHADER_TYPE::COMPUTE:
|
||||
shaderType = vk::ShaderStageFlagBits::eCompute;
|
||||
break;
|
||||
default:
|
||||
shaderType = vk::ShaderStageFlagBits::eVertex;
|
||||
break;
|
||||
}
|
||||
|
||||
auto vsData{ SHAssetManager::GetData<SHShaderAsset>(DEFAULT_VS_ID) };
|
||||
Handle<SHVkShaderModule> newShaderModule = logicalDeviceHdl->CreateShaderModule(vsData->spirvBinary, "main", shaderType, vsData->name);
|
||||
shaderModules.emplace(idCounter++, newShaderModule);
|
||||
return shaderType;
|
||||
}
|
||||
|
||||
Handle<SHVkShaderModule> SHShaderModuleLibrary::GetBuiltInShaderModule(std::string shaderName) const noexcept
|
||||
{
|
||||
if (builtInShaderModules.contains(shaderName))
|
||||
return shaderModules.at(builtInShaderModules.at(shaderName));
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
void SHShaderModuleLibrary::ImportAllShaderSource(Handle<SHVkLogicalDevice>& logicalDeviceHdl) noexcept
|
||||
{
|
||||
uint32_t idCounter{ 0 };
|
||||
|
||||
auto data = SHAssetManager::GetAllDataOfType(AssetType::SHADER);
|
||||
auto const data = SHAssetManager::GetAllDataOfType(AssetType::SHADER);
|
||||
for (auto const& dataPtr : data)
|
||||
{
|
||||
auto shader = dynamic_cast<SHShaderAsset const*>(dataPtr);
|
||||
vk::ShaderStageFlagBits shaderType{};
|
||||
switch (shader->shaderType)
|
||||
{
|
||||
case SH_SHADER_TYPE::VERTEX:
|
||||
shaderType = vk::ShaderStageFlagBits::eVertex;
|
||||
break;
|
||||
case SH_SHADER_TYPE::FRAGMENT:
|
||||
shaderType = vk::ShaderStageFlagBits::eFragment;
|
||||
break;
|
||||
case SH_SHADER_TYPE::COMPUTE:
|
||||
shaderType = vk::ShaderStageFlagBits::eCompute;
|
||||
break;
|
||||
default:
|
||||
shaderType = vk::ShaderStageFlagBits::eVertex;
|
||||
break;
|
||||
}
|
||||
auto const shader = dynamic_cast<SHShaderAsset const*>(dataPtr);
|
||||
|
||||
Handle<SHVkShaderModule> newShaderModule =
|
||||
logicalDeviceHdl->CreateShaderModule(shader->spirvBinary, "main", GetVkShaderFlag(shader->shaderType), shader->name);
|
||||
|
||||
Handle<SHVkShaderModule> newShaderModule = logicalDeviceHdl->CreateShaderModule(shader->spirvBinary, "main", shaderType, shader->name);
|
||||
shaderModules.emplace(idCounter++, newShaderModule);
|
||||
}
|
||||
|
||||
auto const builtIn = SHAssetManager::GetAllDataOfType(AssetType::SHADER_BUILT_IN);
|
||||
for (auto const& dataPtr : builtIn)
|
||||
{
|
||||
auto const shader = dynamic_cast<SHShaderAsset const*>(dataPtr);
|
||||
|
||||
Handle<SHVkShaderModule> newShaderModule =
|
||||
logicalDeviceHdl->CreateShaderModule(shader->spirvBinary, "main", GetVkShaderFlag(shader->shaderType), shader->name);
|
||||
|
||||
builtInShaderModules.emplace(shader->name, newShaderModule);
|
||||
}
|
||||
}
|
||||
|
||||
void SHShaderModuleLibrary::ReflectAllShaderModules() noexcept
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define SH_SHADER_MODULE_LIBRARY_H
|
||||
|
||||
#include "Graphics/Shaders/SHVkShaderModule.h"
|
||||
#include <map>
|
||||
#include "Assets/Asset Types/SHShaderAsset.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -23,6 +23,8 @@ namespace SHADE
|
|||
std::unordered_map<uint32_t, Handle<SHVkShaderModule>> shaderModules;
|
||||
std::unordered_map<std::string, Handle<SHVkShaderModule>> builtInShaderModules;
|
||||
|
||||
inline vk::ShaderStageFlagBits GetVkShaderFlag(SH_SHADER_TYPE type) noexcept;
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* PUBLIC MEMBER FUNCTIONS */
|
||||
|
@ -32,9 +34,8 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* SETTERS AND GETTERS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
//Handle<SHVkShaderModule> GetShaderModule(std::string shaderName) const noexcept;
|
||||
Handle<SHVkShaderModule> GetBuiltInShaderModule(std::string shaderName) const noexcept;
|
||||
|
||||
void ImportBuiltInShaderSource(Handle<SHVkLogicalDevice>& logicalDeviceHdl) noexcept;
|
||||
void ImportAllShaderSource(Handle<SHVkLogicalDevice>& logicalDeviceHdl) noexcept;
|
||||
void ReflectAllShaderModules() noexcept;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue