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: Uniforms inside a GLSL structure

  1. #1
    Intern Contributor
    Join Date
    Sep 2012
    Posts
    76

    Uniforms inside a GLSL structure

    Greetings:
    I would like to set up a light properties structure in the vertex shader - something like

    Code :
    struct Light
    {
       uniform vec4 ambientColors;
       etc.
    };

    and then specify a light in the shader

    Code :
    Light light0;

    Finally, I want to assign light properties from within the app program with

    Code :
    glGetUniformLocation(programId, "light0.ambientColors");
    etc.

    But this doesn't work. It seems the uniform declaration of a structure member isn't acceptable. Is this the case or am I missing something?

    Thanks,
    Sam

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Remember: a struct doesn't define variables; it is just a prototype.

    Code :
    struct Foo
    {
      int bar;
    };
     
    Foo stuff;

    Using C++ lingo `Foo::bar` is a non-static member of the class `Foo`. It therefore does not name a variable. However, `stuff.bar` is a variable. It's the use of a prototype that creates variables.

    Uniforms are first and foremost variables. Therefore, a uniform cannot be inside of a prototype definition.

    However, a uniform's type can be a struct:

    Code :
    struct Foo
    {
      int bar;
    };
     
    uniform Foo stuff;

    `stuff.bar` is now a uniform variable. It has a specific uniform location. See the OpenGL Wiki for further details.

  3. #3
    Intern Contributor
    Join Date
    Sep 2012
    Posts
    76
    Thank you, Alfonse. That clears it up totally.

Posting Permissions

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