Results 1 to 4 of 4

Thread: Efficently set shader uniform parameter.

Hybrid View

  1. #1
    Newbie
    Join Date
    Jul 2013
    Posts
    1

    Efficently set shader uniform parameter.

    Hi Guys:
    I'm relative new to opengl ES 2.0, and just wondering if someone can give me an answer on this.
    From opengl es 2.0 specification, I've learned that for every glUseProgram call, it will clear out all uniform register ,which is an expensive operation, and in order to have the vertex shader working properly, I need to reset all view/projection matrices etc.

    My question is, for a render frame, the view/projection matrix might be almost identical across all draw calls, and everytime I change the shader, it have to reset those matrices and cost CPU/GPU time. Is there a way to avoid this like using constant register in directX or uniform buffer object for opengl es 3.0 ?

    Any help is really appreciated.

    P

  2. #2
    Member
    Join Date
    Jun 2012
    Location
    Texas
    Posts
    61
    Quote Originally Posted by PengPeng View Post
    Hi Guys:
    I'm relative new to opengl ES 2.0, and just wondering if someone can give me an answer on this.
    From opengl es 2.0 specification, I've learned that for every glUseProgram call, it will clear out all uniform register ,which is an expensive operation, and in order to have the vertex shader working properly, I need to reset all view/projection matrices etc.

    My question is, for a render frame, the view/projection matrix might be almost identical across all draw calls, and everytime I change the shader, it have to reset those matrices and cost CPU/GPU time. Is there a way to avoid this like using constant register in directX or uniform buffer object for opengl es 3.0 ?

    Any help is really appreciated.

    P

    "Expensive" is a relative term and OpenGL ES 2.0 is for embedded systems and not intended to match the performance of desktop OpenGL implementations.

    The approach I use is to only switch shaders when absolutely necessary. It can be better to have a larger shader with more uniform parameters than a lot of smaller shaders that must be switched frequently.

    Regards, Clay

  3. #3
    Which is exactly why developers will typically sort draw calls based on program first to avoid the expensive state transitions. Ideally, a program would only be selected once per frame.

  4. #4
    Newbie
    Join Date
    Aug 2013
    Posts
    6
    I haven't had the same experience. Some uniforms I set at initialization time and never change them, whereas other uniforms are changes every call. I switch programs a lot, too, because I don't have control of the display list. Have you tried not setting uniforms that do not change for a given program?

Posting Permissions

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