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 4 of 4

Thread: Same shader on multiple objects w/ different uniforms

  1. #1
    Intern Newbie
    Join Date
    Jul 2004
    Location
    ISU VRAC
    Posts
    42

    Same shader on multiple objects w/ different uniforms

    This is a simple question, is it possible to render multiple objects with the same shader BUT modify the value of a uniform between objects? For example:

    myDisplay()
    {
    ...
    enbleShader("simple");
    shader("simple")->setUniform("color")= blue;
    drawQuad();
    shader("simple")->setUniform("color")= red;
    drawQuad();
    shader("simple")->setUniform("color")= green;
    drawQuad();
    disableShader("simple");
    ...
    }

    Obviously this isn't exact code but hopefully it is clear enough to explain my question. I'm having problems implementing something I thought was easy but it's not working so I want to eliminate the obvious before diving into full debug mode...
    thanks,
    biv

  2. #2
    Junior Member Regular Contributor Zulfiqar Malik's Avatar
    Join Date
    Jun 2004
    Location
    London, UK
    Posts
    247

    Re: Same shader on multiple objects w/ different uniforms

    Yes you can.
    Zulfiqar Inayat Malik.
    Senior Developer, The Foundry.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Feb 2001
    Posts
    136

    Re: Same shader on multiple objects w/ different uniforms

    Yes. Consider OpenGL like a state machine. You set a shader and all the remaining draw calls will use that shader. If you change the shader state at some point, all the remaining calls after that will use the new states. Hope you get the point.

  4. #4
    Intern Newbie
    Join Date
    Jul 2004
    Location
    ISU VRAC
    Posts
    42

    Re: Same shader on multiple objects w/ different uniforms

    thanks. that's what I thought but I wanted to be sure. I think this has something to do w/ the scene graph API I'm using so I'll post there. Thanks for the "re-assurance"

Posting Permissions

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