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

Thread: Questions about and glVertexAttribPointer and the fixed function pipeline

  1. #11
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    Re: glVertexAttrib calls, there may or may not also be some historical inertia from the time the ARB were saying "Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls".

    More seriously, they serve different use cases. Uniforms are expected to stay the same for all invocations of a given shader; attribs may change per-vertex; and the driver may optimize storage differently for each. In the GLSL model uniforms are part of per-program state whereas attribs are global state. In the old days (and possible on some modern mobile hardware) changing a uniform meant recompiling a shader. There are fewer attrib slots available for use than there are uniform slots.

    The upshot of all of this is that you get to choose the most appropriate type depending on your own use case, and just because you may not have a use case that suits having both available as options, it doesn't mean that nobody else does.
    Last edited by mhagain; 01-26-2018 at 06:43 AM.

  2. #12
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,008
    Quote Originally Posted by mhagain View Post
    Re: glVertexAttrib calls, there may or may not also be some historical inertia from the time the ARB were saying "Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls".

    More seriously, they serve different use cases. Uniforms are expected to stay the same for all invocations of a given shader; attribs may change per-vertex; and the driver may optimize storage differently for each. In the GLSL model uniforms are part of per-program state whereas attribs are global state. In the old days (and possible on some modern mobile hardware) changing a uniform meant recompiling a shader. There are fewer attrib slots available for use than there are uniform slots.

    The upshot of all of this is that you get to choose the most appropriate type depending on your own use case, and just because you may not have a use case that suits having both available as options, it doesn't mean that nobody else does.
    Of course, all of that assumes that the underlying hardware mirrors OpenGL's interface. If it doesn't, if it's set up so that attributes are always arrayed, then the OpenGL implementation effectively has to recompile the shader to turn the non-arrayed attribute into a uniform, set the uniform's value from global state, and then render with this slightly modified program. And it has to do this every time you use that uniform-throug-attribute thing.

  3. #13
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    I've trivially emulated standalone glVertexAttrib calls in D3D by setting a stride of 0, which in D3D means "actually 0" rather than "tightly packed". There was no technical or other requirement for this; I just did it (1) for the sheer hell of it, and (2) to see if it could be done.

    I only mention this because it's another approach that hardware might use behind-the-scenes (and avoids the uniform round-tripping thing you mention).

  4. #14
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,828
    Quote Originally Posted by Alfonse Reinheart View Post
    Of course, all of that assumes that the underlying hardware mirrors OpenGL's interface. If it doesn't, if it's set up so that attributes are always arrayed, then the OpenGL implementation effectively has to recompile the shader to turn the non-arrayed attribute into a uniform, set the uniform's value from global state, and then render with this slightly modified program. And it has to do this every time you use that uniform-throug-attribute thing.
    Well, if you have instancing, you can get the same effect by using glVertexAttribPointer() with a single-element array and glVertexAttribDivisor() with a sufficiently large divisor.

  5. #15
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    Quote Originally Posted by GClements View Post
    Well, if you have instancing, you can get the same effect by using glVertexAttribPointer() with a single-element array and glVertexAttribDivisor() with a sufficiently large divisor.
    That's another sensible way of doing it yeah. So for a given implementation, if the option is between a totally brain-dead way that makes it impossible to reliably answer several glGets vs a sensible way, which of those would a betting man choose?

  6. #16
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,828
    Quote Originally Posted by mhagain View Post
    impossible to reliably answer several glGets
    glGet() is for retrieving implementation details at initialisation. Anything else should be tracked by the client. Or maybe treating indirect rendering as the default has become too ingrained ;)

    Beyond that, glVertexAttrib() still makes sense if you can't rely upon 3.3+ (instancing) or need to retrofit shaders to immediate-mode code.

Posting Permissions

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