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: [OpenGL 3.2] glUseProgram: inside the mainloop ?

  1. #1
    Junior Member Newbie pixpaf's Avatar
    Join Date
    Nov 2012
    Posts
    3

    [OpenGL 3.2] glUseProgram: inside the mainloop ?

    Hello

    I wonder if i should put «glUseProgram» inside my render loop, or just calling it once after the GLSL program has been compiled and linked.

    I'm asking this, because i tried and put it outside the render loop, and it worked.
    But i read several tutorials which put it inside the render loop.


    Thank you

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Do you only ever intend to render with one program? In general, in any serious application, you will be using multiple programs. So yes, it "goes in the render loop."

  3. #3
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214
    Quote Originally Posted by pixpaf View Post
    I wonder if i should put «glUseProgram» inside my render loop, or just calling it once after the GLSL program has been compiled and linked.

    I'm asking this, because i tried and put it outside the render loop, and it worked.
    But i read several tutorials which put it inside the render loop.
    The OpenGL program is a global state, and only one program can be active. So if you have more than one program, then you need to enable each of them every time you use them.

    There is some overhead for switching programs. If you have two programs and switch MANY times between those for every frame, then it can be a good idea to sort the drawing. For example, draw all geometry with the first program, and then switch to the second program and draw the other things.

Posting Permissions

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