From 52381d5afa11b43a43e8ee35c85889c0b3593872 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 20 Jul 2024 15:36:30 +0300 Subject: [PATCH] feat: preprocessing glsl header files --- src/coders/GLSLExtension.cpp | 13 ++++++++++--- src/coders/GLSLExtension.hpp | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/coders/GLSLExtension.cpp b/src/coders/GLSLExtension.cpp index 1e25c934..cce84e8c 100644 --- a/src/coders/GLSLExtension.cpp +++ b/src/coders/GLSLExtension.cpp @@ -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(); } diff --git a/src/coders/GLSLExtension.hpp b/src/coders/GLSLExtension.hpp index 98884c28..1c51eec3 100644 --- a/src/coders/GLSLExtension.hpp +++ b/src/coders/GLSLExtension.hpp @@ -31,7 +31,8 @@ public: std::string process( const std::filesystem::path& file, - const std::string& source + const std::string& source, + bool header=false ); };