mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
feat: preprocessing glsl header files
This commit is contained in:
parent
9b8c421557
commit
52381d5afa
2 changed files with 12 additions and 4 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue