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

Thread: Using multiple shader programs per step

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    12

    Using multiple shader programs per step

    This may be answered somewhere, but I haven't found it. I'm wondering if it is possible to switch between different shader programs within a single rendering step. I'll explain what I mean with an example. I have a "ground" mesh and a "sky" mesh, and I want to use different shader code to render each one. One way to use the same code for both meshes is to pass in a value to a shader variable (for example: "ground = 1") to tell the shader program to use the part of the shader code for the ground. Then I can check this value in the shader code itself to determine whether to use the ground shader code or the sky shader code. But it's inefficiency to check this value per vertex (or per pixel).

    What I'd like to do instead is use glUseProgram (or something) to use a shader program just before drawing the ground mesh and then to use a different shader program just before drawing the sky mesh. I've been able to get the shader programs to work individually, but I don't know how to switch between them in a single step. Is this possible? If so, how do I do it? I hope you understand what I'm trying to ask.

    Thanks in advance for your help. (This forum has always been so very helpful to me.)
    Inventor

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    12
    Okay. I actually figured it out! It's very simple. You just use glUseProgram(program_id) switch between shaders during the run-time step. When I initially tried this, it didn't work, but that was because I had set some uniform variables without first calling glUseProgram. So, you have to make sure you call glUseProgram before defining the variables. Now it works!
    Inventor

Tags for this Thread

Posting Permissions

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