Coder Social home page Coder Social logo

typedefinition / mkr_glsl_include Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 1.7 MB

Single header-only C++ helper class to reduce code duplication in GLSL by supporting file including.

License: MIT License

CMake 10.68% C++ 78.98% GLSL 3.39% JavaScript 6.96%
cpp glsl opengl

mkr_glsl_include's Introduction

GLSL Include

This single header-only C++ helper class adds support for including files in GLSL.

Natively, GLSL does not support the #include directive. However, as the number of shaders in a project grow, there is a high chance that much of the shader code are similar, leading to DRY being broken as multiple shaders having the same code copy-pasted.

While the ARB_shading_language_include extension exists, it is also troublesome to set up.

This is my attempt to solve that issue in a simple and elegant way.

Bug Reporting

If there are any bugs or suggestions, feel free to create a GitHub Issue, or even a Pull Request if you would like to add anything. ๐Ÿ˜„

How to Use

Sample Code:

#include "glsl_include.h"

using namespace mkr;

// Note that I do not know how to deal with multi-line comments, so avoid putting the #include in one.
int main() {
    string main = "#include <foo.frag>\n" // Each `#include` MUST be on a new line on its own.
                  "#include <boo.frag>\n"
                  "void main() {}";

    string foo = "#include <kee.frag>\n" 
                 "void foo() {}";

    string boo = "#include <kee.frag>\n"
                 "void boo() {}";

    string kee = "void kee() {}";

    glsl_include include;
    include.add("main.frag", main); 
    include.add("foo.frag", foo); // The first argument must match the name between the arrow brackets <>.
    include.add("boo.frag", boo);
    include.add("kee.frag", kee);

    string merged = shaders.merge();
    cout << merged << endl;

    return 0;
}

Console Output:

void kee() {}
void foo() {}
void boo() {}
void main() {}

mkr_glsl_include's People

Contributors

typedefinition avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.