diff --git a/doomsday/libs/gui/src/graphics/glshader.cpp b/doomsday/libs/gui/src/graphics/glshader.cpp index 88544ba959..c858c3272c 100644 --- a/doomsday/libs/gui/src/graphics/glshader.cpp +++ b/doomsday/libs/gui/src/graphics/glshader.cpp @@ -139,6 +139,17 @@ void GLShader::compile(Type shaderType, const IByteArray &shaderSource) { preamble += DEFAULT_VERSION; } + else + { + // Move the #version line to the preamble. + const auto versionPos = source.indexOf("#version "); + const auto endPos = source.indexOf("\n", versionPos); + const auto len = endPos - versionPos + 1; + const String versionLine = source.substr(versionPos, len); + source.remove(versionPos, len); + preamble += versionLine; + } + preamble += PREFIX; // Keep a copy of the source for possible recompilation. diff --git a/doomsday/libs/gui/src/graphics/glshaderbank.cpp b/doomsday/libs/gui/src/graphics/glshaderbank.cpp index dd5dbf22a9..11aa5b6f90 100644 --- a/doomsday/libs/gui/src/graphics/glshaderbank.cpp +++ b/doomsday/libs/gui/src/graphics/glshaderbank.cpp @@ -202,7 +202,7 @@ DE_PIMPL(GLShaderBank) .toLatin1(); } predefs += "#line 1\n"; - sourceText = predefs + sourceText; + sourceText = GLShader::prefixToSource(sourceText, predefs); } return sourceText; } @@ -291,36 +291,36 @@ Bank::ISource *GLShaderBank::newSourceFromInfo(const String &id) for (int i = 0; i < 3; ++i) { if (def.has(typeTokens[i])) - { + { sources[i] = ShaderSource(def[typeTokens[i]], ShaderSource::ShaderSourceText); - } + } else if (def.has(pathTokens[i])) - { + { sources[i] = ShaderSource(absolutePathInContext(def, def[pathTokens[i]]), ShaderSource::FilePath); - } - else if (def.has("path")) - { + } + else if (def.has("path")) + { String spath = absolutePathInContext(def, def.gets("path") + fileExt[i]); if (i == GLShader::Geometry && !FS::tryLocate(spath)) - { + { continue; // Geometry shader not provided. - } + } sources[i] = ShaderSource(spath, ShaderSource::FilePath); - } + } - // Additional shaders to append to the main source. + // Additional shaders to append to the main source. if (def.has(includeTokens[i])) - { - // Including in reverse to retain order -- each one is prepended. + { + // Including in reverse to retain order -- each one is prepended. const auto &incs = def[includeTokens[i]].value().elements(); for (int j = incs.sizei() - 1; j >= 0; --j) - { + { sources[i].insertFromFile(absolutePathInContext(def, incs.at(j)->asText())); + } } - } - // Handle #include directives in the source. + // Handle #include directives in the source. sources[i].insertIncludes(*this, def); }