feat: preprocessing glsl header files
This commit is contained in:
parent
9b8c421557
commit
52381d5afa
@ -23,7 +23,8 @@ void GLSLExtension::setPaths(const ResPaths* paths) {
|
|||||||
void GLSLExtension::loadHeader(const std::string& name) {
|
void GLSLExtension::loadHeader(const std::string& name) {
|
||||||
fs::path file = paths->find("shaders/lib/"+name+".glsl");
|
fs::path file = paths->find("shaders/lib/"+name+".glsl");
|
||||||
std::string source = files::read_string(file);
|
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) {
|
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";
|
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;
|
std::stringstream ss;
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
uint linenum = 1;
|
uint linenum = 1;
|
||||||
ss << "#version " << version << '\n';
|
if (!header) {
|
||||||
|
ss << "#version " << version << '\n';
|
||||||
|
}
|
||||||
for (auto& entry : defines) {
|
for (auto& entry : defines) {
|
||||||
ss << "#define " << entry.first << " " << entry.second << '\n';
|
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);
|
ss << source.substr(pos, endline+1-pos);
|
||||||
pos = endline+1;
|
pos = endline+1;
|
||||||
}
|
}
|
||||||
|
if (!header) {
|
||||||
|
std::cout << " ========================================================== " << file.u8string() << std::endl;
|
||||||
|
std::cout << ss.str() << std::endl;
|
||||||
|
}
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,8 @@ public:
|
|||||||
|
|
||||||
std::string process(
|
std::string process(
|
||||||
const std::filesystem::path& file,
|
const std::filesystem::path& file,
|
||||||
const std::string& source
|
const std::string& source,
|
||||||
|
bool header=false
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user