diff --git a/components/shader/shadermanager.cpp b/components/shader/shadermanager.cpp index ea971586a..59c81f40a 100644 --- a/components/shader/shadermanager.cpp +++ b/components/shader/shadermanager.cpp @@ -123,8 +123,22 @@ namespace Shader std::string content = source.substr(contentStart, contentEnd - contentStart); size_t overallEnd = contentEnd + std::string("$endforeach").length(); - // This will be wrong if there are other #line directives, so that needs fixing - int lineNumber = std::count(source.begin(), source.begin() + overallEnd, '\n') + 2; + + size_t lineDirectivePosition = source.rfind("#line", overallEnd); + int lineNumber; + if (lineDirectivePosition != std::string::npos) + { + size_t lineNumberStart = lineDirectivePosition + std::string("#line ").length(); + size_t lineNumberEnd = source.find_first_not_of("0123456789", lineNumberStart); + std::string lineNumberString = source.substr(lineNumberStart, lineNumberEnd - lineNumberStart); + lineNumber = std::stoi(lineNumberString); + } + else + { + lineDirectivePosition = 0; + lineNumber = 2; + } + lineNumber += std::count(source.begin() + lineDirectivePosition, source.begin() + overallEnd, '\n'); std::string replacement = ""; for (std::vector::const_iterator element = listElements.cbegin(); element != listElements.cend(); element++) diff --git a/files/shaders/water_fragment.glsl b/files/shaders/water_fragment.glsl index ca09aa94b..fddd81eff 100644 --- a/files/shaders/water_fragment.glsl +++ b/files/shaders/water_fragment.glsl @@ -1,7 +1,5 @@ #version 120 -//DUMPME - #define REFRACTION @refraction_enabled #define SHADOWS @shadows_enabled