Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Compile time shader stage information in GLSL

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    Apr 2010
    Posts
    68

    Compile time shader stage information in GLSL

    As far as I know there currently is no way to retrieve the stage for which the GLSL compiler is generating code.
    Such a feature could ease the development of GLSL libraries whose functions can be evaluated accross multiple stages.
    Here's an example of source code which could be included at any stage and is safe to use:
    Code :
    // check GLSL compiler version
    #if (__VERSION__ < 150)
    #error Unsupported GLSL version
    #endif
     
    // some function (shading function for example)
    vec3 shade(...) {
    #if (__STAGE__ == GL_vertex_stage)
        perform per-vertex operations
    #elif (__STAGE__ == GL_fragment_stage)
       per-fragment operations
    #else
    // either halt compilation...
       #error Invalid stage 
    // ... or return something
       return vec3(0);
    #endif
    }
    On the client side, one would simply use
    Code :
    const GLchar * files[] = {"library.glsl", "main_function.glsl"};
    GLuint shader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(shader, 2, load_strings(2, files), NULL);
    Granted, this can already be accomplished by including a string in glShaderSource, but having the compiler doing it would save some time and ease the development of safer and more portable GLSL libraries... What do you think ?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    It's already been discussed. In the future, you should look around a bit to see if something you want to proposed has already been proposed.

  3. #3
    Intern Contributor
    Join Date
    Apr 2010
    Posts
    68
    Quote Originally Posted by Alfonse Reinheart View Post
    It's already been discussed. In the future, you should look around a bit to see if something you want to proposed has already been proposed.
    I should have linked this in my post as it is indeed related to what I am asking for. I guess I am adding another argument in favour of this proposal: users can still use multiple strings, compile time stage improves shader library code portability. There already are some great GLSL libraries available which are easy to share since they do not use built-in functions whose behaviour vary depending on the shader stage (texture, dFdx, etc.). Adding such a feature could allow richer libraries to emerge without forcing users to print strings for each library they use.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •