-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShaderGenerator.cpp
More file actions
42 lines (37 loc) · 1.06 KB
/
Copy pathShaderGenerator.cpp
File metadata and controls
42 lines (37 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "ShaderGenerator.h"
#include "Core/FileSystem.h"
#include <cctype>
namespace sh::render
{
auto ShaderGenerator::ReplaceSpaceString(const std::string& str) -> std::string
{
std::string result;
result.reserve(str.size());
for (char c : str)
{
if (std::isalnum(static_cast<unsigned char>(c)))
result.push_back(c);
else
result.push_back('_');
}
return result;
}
SH_RENDER_API auto ShaderGenerator::GenerateShaderFile(
const std::string& shaderName,
const ShaderAST::PassNode& passNode,
const std::filesystem::path& path) -> std::vector<std::filesystem::path>
{
std::vector<std::filesystem::path> results;
for (auto& stage : passNode.stages)
{
std::string fileName{ ReplaceSpaceString(shaderName + "_" + passNode.name) };
if (stage.type == ShaderAST::StageType::Vertex)
fileName += ".vert";
else if (stage.type == ShaderAST::StageType::Fragment)
fileName += ".frag";
if (core::FileSystem::SaveText(stage.code, path / fileName))
results.push_back(path / fileName);
}
return results;
}
}//namespace