SpiecsEngine
 
Loading...
Searching...
No Matches

◆ Load()

bool Spices::ShaderLoader::Load ( const std::string & fileName,
ShaderStage stage,
Shader * outShader )
static

Public called API, it is entrance.

Parameters
[in]fileNameShader name.
[in]stageShaderStage.
[in,out]outShaderShader pointer, only pass this to it. Feel free for using row pointer here, it's very safe, for this API only called during Shader.
Returns
Returns true if load data successfully.

Read file as bytes.

Compile to spv.

Create shader module.

Read file as bytes.

Compile to spv.

Create shader module.

Definition at line 24 of file ShaderLoader.cpp.

25 {
27
28 bool isFind = false;
29 std::string filePath;
30 for (auto& it : ResourceSystem::GetSearchFolder())
31 {
32 filePath = it + defaultShaderPath + "Shader." + fileName + "." + ShaderHelper::ToString(stage);
33 if (FileLibrary::FileLibrary_Exists(filePath.c_str()))
34 {
35 isFind = true;
36 break;
37 }
38 }
39 if (!isFind)
40 {
41 std::stringstream ss;
42 ss << "Shader: " << fileName << "file is not found";
43
44 SPICES_CORE_WARN(ss.str());
45
46 return false;
47 }
48
52 std::ifstream stream(filePath);
53 std::stringstream strStream;
54 strStream << stream.rdbuf();
55
59 std::vector<uint8_t> spirv;
60 ShaderCompiler::CompileToSPV(strStream.str(), stage, fileName, spirv);
61
65 outShader->m_ShaderModule = std::make_shared<VulkanShaderModule>(VulkanRenderBackend::GetState(), fileName, stage, spirv, filePath);
66
67 return true;
68 }
#define SPICES_PROFILE_ZONE
static bool FileLibrary_Exists(const char *path)
Determine whether the given string is existing a file.
static void CompileToSPV(const std::string &data, const ShaderStage &stage, const std::string &name, std::vector< uint8_t > &spirv)
Compile glsl to spv.
static std::string ToString(ShaderStage stage)
Convert ShaderStage to String.
static VulkanState & GetState()
Get VulkanState in use.
const std::string defaultShaderPath
Const variable: Original Shader File Path.

Referenced by Spices::Shader::Deserialize().