Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Efficiency of multple glDrawElements commands

  1. #11
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    14

    Re: Efficiency of multple glDrawElements commands

    Ah, did not know about that. I was wondering why uniforms cannot be changed within a draw call. I'm assuming the OpenGL implementation takes care of that post-T&L buffer optimized triangle list itself, without exposing it to the user.

    I'm guessing glDrawElementsInstanced cannot take advantage of the post-T&L buffer, as it reads a different gl_InstanceID for each draw.

  2. #12
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,716

    Re: Efficiency of multple glDrawElements commands

    I was wondering why uniforms cannot be changed within a draw call.
    How could you change them within a draw call? The only functions that change uniforms are API functions. And a draw call is a single, atomic API call.

    And glBegin/glEnd expressly forbid calling most functions between them, glUniform included.

    I'm guessing glDrawElementsInstanced cannot take advantage of the post-T&L buffer, as it reads a different gl_InstanceID for each draw.
    It can't use it for vertices between instances. But it certainly can use it for vertices within an instance.

  3. #13
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    14

    Re: Efficiency of multple glDrawElements commands

    Quote Originally Posted by Alfonse Reinheart
    How could you change them within a draw call? The only functions that change uniforms are API functions. And a draw call is a single, atomic API call.
    I was wondering why shaders themselves could not modify the uniform values they read.

    Quote Originally Posted by Alfonse Reinheart
    It can't use it for vertices between instances. But it certainly can use it for vertices within an instance.
    Ah that makes a lot more sense than what how I thought glDrawElementsInstanced works.

  4. #14
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,716

    Re: Efficiency of multple glDrawElements commands

    I was wondering why shaders themselves could not modify the uniform values they read.
    Because then they wouldn't be uniform

  5. #15
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    892

    Re: Efficiency of multple glDrawElements commands

    I was wondering why shaders themselves could not modify the uniform values they read.
    A more pressing question is: Why would you want to modify values that are inherently constant across a primitive, across multiple objects, across the whole frame or over the whole runtime?

  6. #16
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    14

    Re: Efficiency of multple glDrawElements commands

    Thokra, I can't precisely remember the reason why I wanted such functionality. I think I wanted to emulate glDrawElementsInstaced's capabilities using glDrawElements (in case OpenGL 3.x is not available on the target system) and this involved me using uniforms as "loop counters". Looking back, this entire idea doesn't even make sense in my head, so it's probably best to forget about it.

    That said, I don't even know if shaders being able to modify uniforms is even needed for that.

  7. #17
    Junior Member Regular Contributor
    Join Date
    Dec 2009
    Posts
    178

    Re: Efficiency of multple glDrawElements commands

    You should read the pseudo instancing paper from NVidia: http://developer.download.nvidia.com...udo_instancing

  8. #18
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,716

    Re: Efficiency of multple glDrawElements commands

    It should be noted that this paper is from the pre-DX10 days, and it is not known how efficient this is for hardware that isn't a GeForce FX or GeForce 6xxx.

    Someone should get an OpenGL performance test suite together.

  9. #19
    Junior Member Regular Contributor
    Join Date
    Dec 2009
    Posts
    178

    Re: Efficiency of multple glDrawElements commands

    Hardware that is OpenGL 3 capable should use native instancing, so pseudo instancing is only a fallback for those old chips anyway.

    This is especially nice as a fallback for GL_ARB_instanced_arrays (pseudocode):
    Code :
    <bind non-instanced attribs>
    if( GL_ARB_instanced_arrays_available) {
      glEnableVertexAttribArray(<instanced attr>);
      glVertexAttribPointer(<instanced attr>, 4, GL_FLOAT, 0, 0, attribs);
      glVertexAttribDivisorARB(<instanced attr>, 1);
      glDrawElementsInstancedARB(GL_TRIANGLES, num_instances, ...);
    } else {
      glDisableVertexAttribArray(<instanced attr>);
      for(i = 0; i < num_instances; i++) {
        glVertexAttrib4fv(<instanced attr>, attribs[i]);
        glDrawElements(GL_TRIANGLES, ...)
      }
    }

    You application can use the identical shaders, VBOs etc.

    +1 for the performance test suite.

Posting Permissions

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