Skip to content

Commit

Permalink
Fixed|GL: Handling the shader version number
Browse files Browse the repository at this point in the history
The version number must be specified on the first line.
  • Loading branch information
skyjake committed Feb 10, 2020
1 parent 361ce6d commit 424fb3e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
11 changes: 11 additions & 0 deletions doomsday/libs/gui/src/graphics/glshader.cpp
Expand Up @@ -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.
Expand Down
32 changes: 16 additions & 16 deletions doomsday/libs/gui/src/graphics/glshaderbank.cpp
Expand Up @@ -202,7 +202,7 @@ DE_PIMPL(GLShaderBank)
.toLatin1();
}
predefs += "#line 1\n";
sourceText = predefs + sourceText;
sourceText = GLShader::prefixToSource(sourceText, predefs);
}
return sourceText;
}
Expand Down Expand Up @@ -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<File const>(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<ArrayValue>().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);
}

Expand Down

0 comments on commit 424fb3e

Please sign in to comment.