include recursive

v1
Brett 2023-11-13 14:27:51 -05:00
parent 32e2d48cd3
commit 19baf8b048
2 changed files with 4 additions and 4 deletions

View File

@ -18,7 +18,7 @@
namespace blt::fs { namespace blt::fs {
std::vector<std::string> getLinesFromFile(const std::string& path); std::vector<std::string> getLinesFromFile(const std::string& path);
std::vector<std::string> recursiveShaderInclude(const std::string& path); std::vector<std::string> recursiveShaderInclude(const std::string& path, const std::string& include_header = "#include");
static inline std::string loadShaderFile(const std::string& path) { static inline std::string loadShaderFile(const std::string& path) {
std::stringstream stringStream; std::stringstream stringStream;

View File

@ -32,7 +32,7 @@ std::vector<std::string> blt::fs::getLinesFromFile(const std::string& path) {
return string::split(shaderSource, "\n"); return string::split(shaderSource, "\n");
} }
std::vector<std::string> blt::fs::recursiveShaderInclude(const std::string& path) { std::vector<std::string> blt::fs::recursiveShaderInclude(const std::string& path, const std::string& include_header) {
std::string pathOnly = path.substr(0, path.find_last_of('/')); std::string pathOnly = path.substr(0, path.find_last_of('/'));
auto mainLines = getLinesFromFile(path); auto mainLines = getLinesFromFile(path);
@ -41,7 +41,7 @@ std::vector<std::string> blt::fs::recursiveShaderInclude(const std::string& path
for (unsigned int i = 0; i < mainLines.size(); i++) { for (unsigned int i = 0; i < mainLines.size(); i++) {
auto& line = mainLines[i]; auto& line = mainLines[i];
// if the line is an include statement then we want to add lines recursively. // if the line is an include statement then we want to add lines recursively.
if (string::starts_with(line, "#include")) { if (string::starts_with(line, include_header)) {
std::vector<std::string> include_statement = string::split(line, "<"); std::vector<std::string> include_statement = string::split(line, "<");
if (include_statement.size() <= 1) if (include_statement.size() <= 1)
@ -61,7 +61,7 @@ std::vector<std::string> blt::fs::recursiveShaderInclude(const std::string& path
BLT_TRACE("Recusing into %s/%s\n", pathOnly.c_str(), file.c_str()); BLT_TRACE("Recusing into %s/%s\n", pathOnly.c_str(), file.c_str());
includes.insert({i, recursiveShaderInclude((pathOnly + "/" + file))}); includes.insert({i, recursiveShaderInclude(pathOnly + "/" + file, include_header)});
} catch (std::exception& e) { } catch (std::exception& e) {
BLT_FATAL("Shader file contains an invalid #include statement. (Missing < or \")\n"); BLT_FATAL("Shader file contains an invalid #include statement. (Missing < or \")\n");
BLT_FATAL("Exception: %s", e.what()); BLT_FATAL("Exception: %s", e.what());