feat: preprocessing glsl header files

This commit is contained in:
MihailRis 2024-07-20 15:36:30 +03:00
parent 9b8c421557
commit 52381d5afa
2 changed files with 12 additions and 4 deletions

View File

@ -23,7 +23,8 @@ void GLSLExtension::setPaths(const ResPaths* paths) {
void GLSLExtension::loadHeader(const std::string& name) {
fs::path file = paths->find("shaders/lib/"+name+".glsl");
std::string source = files::read_string(file);
addHeader(name, source);
addHeader(name, "");
addHeader(name, process(file, source, true));
}
void GLSLExtension::addHeader(const std::string& name, std::string source) {
@ -84,11 +85,13 @@ inline void source_line(std::stringstream& ss, uint linenum) {
ss << "#line " << linenum << "\n";
}
std::string GLSLExtension::process(const fs::path& file, const std::string& source) {
std::string GLSLExtension::process(const fs::path& file, const std::string& source, bool header) {
std::stringstream ss;
size_t pos = 0;
uint linenum = 1;
ss << "#version " << version << '\n';
if (!header) {
ss << "#version " << version << '\n';
}
for (auto& entry : defines) {
ss << "#define " << entry.first << " " << entry.second << '\n';
}
@ -138,5 +141,9 @@ std::string GLSLExtension::process(const fs::path& file, const std::string& sour
ss << source.substr(pos, endline+1-pos);
pos = endline+1;
}
if (!header) {
std::cout << " ========================================================== " << file.u8string() << std::endl;
std::cout << ss.str() << std::endl;
}
return ss.str();
}

View File

@ -31,7 +31,8 @@ public:
std::string process(
const std::filesystem::path& file,
const std::string& source
const std::string& source,
bool header=false
);
};