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