Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libgui|GLShaderBank: Shader definition macros
The "defines" key in the shader definition can define GLSL preprocessor
macros to be prepended to the shader sources. "defines" must have
a dictionary as value.
  • Loading branch information
skyjake committed Dec 10, 2015
1 parent 3e40f49 commit aac92f7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions doomsday/sdk/libgui/src/graphics/glshaderbank.cpp
Expand Up @@ -25,6 +25,7 @@
#include <de/ScriptedInfo>
#include <de/ArrayValue>
#include <de/ByteArrayFile>
#include <de/DictionaryValue>
#include <de/math.h>

#include <QMap>
Expand Down Expand Up @@ -66,6 +67,14 @@ DENG2_PIMPL(GLShaderBank)
Block(App::rootFolder().locate<File const>(path)));
source = String::fromLatin1(combo);
}

void insertDefinition(String const &macroName, String const &content)
{
convertToSourceText();
Block combo = GLShader::prefixToSource(source.toLatin1(),
Block(String("#define %1 %2\n").arg(macroName).arg(content).toLatin1()));
source = String::fromLatin1(combo);
}
};

GLShaderBank &bank;
Expand Down Expand Up @@ -263,6 +272,18 @@ Bank::ISource *GLShaderBank::newSourceFromInfo(String const &id)
}
}

if(def.has("defines"))
{
DictionaryValue const &dict = def.getdt("defines");
for(auto i : dict.elements())
{
String const macroName = i.first.value->asText();
String const content = i.second->asText();
vtx .insertDefinition(macroName, content);
frag.insertDefinition(macroName, content);
}
}

return new Source(*this, id, vtx, frag);
}

Expand Down

0 comments on commit aac92f7

Please sign in to comment.