diff --git a/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl.dei b/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl.dei index eda006e70c..3fad05a668 100644 --- a/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl.dei +++ b/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl.dei @@ -1,7 +1,5 @@ # Shader for the DGL drawing routines that emulate OpenGL 1.x behavior. shader dgl.draw { path.vertex = "dgl_draw.vsh" - - include.fragment <../include/fog.glsl> path.fragment = "dgl_draw.fsh" } diff --git a/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl_draw.fsh b/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl_draw.fsh index f51b309c42..431ef2bfe9 100644 --- a/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl_draw.fsh +++ b/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl_draw.fsh @@ -20,6 +20,8 @@ #version 330 +#include "../include/fog.glsl" + uniform int uTexEnabled; uniform int uTexMode; uniform vec4 uTexModeColor; diff --git a/doomsday/sdk/libgui/src/graphics/glshaderbank.cpp b/doomsday/sdk/libgui/src/graphics/glshaderbank.cpp index 0ba6a27627..849ea90daf 100644 --- a/doomsday/sdk/libgui/src/graphics/glshaderbank.cpp +++ b/doomsday/sdk/libgui/src/graphics/glshaderbank.cpp @@ -29,10 +29,31 @@ #include #include +#include #include namespace de { +static String processIncludes(String source, String const &sourceFolderPath) +{ + QRegularExpression const re("#include\\s+\"([^\"]+)\""); + forever + { + auto found = re.match(source); + if (!found.hasMatch()) break; // No more includes. + + String incFilePath = sourceFolderPath / found.captured(1); + String incSource = String::fromUtf8(Block(App::rootFolder().locate(incFilePath))); + incSource = processIncludes(incSource, incFilePath.fileNamePath()); + + Rangei const capRange(found.capturedStart(), found.capturedEnd()); + source = source.substr(0, capRange.start) + + incSource + + source.substr(capRange.end); + } + return source; +} + DENG2_PIMPL(GLShaderBank) { struct Source : public ISource @@ -76,6 +97,12 @@ DENG2_PIMPL(GLShaderBank) Block(String("#define %1 %2\n").arg(macroName).arg(content).toLatin1())); source = String::fromLatin1(combo); } + + void insertIncludes(GLShaderBank const &bank, Record const &def) + { + convertToSourceText(); + source = processIncludes(source, bank.absolutePathInContext(def, ".").fileNamePath()); + } }; GLShaderBank &bank; @@ -276,6 +303,10 @@ Bank::ISource *GLShaderBank::newSourceFromInfo(String const &id) } } + // Handle #include directives in the source. + vtx .insertIncludes(*this, def); + frag.insertIncludes(*this, def); + if (def.has("defines")) { DictionaryValue const &dict = def.getdt("defines");