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

Thread: Multiple objects: single or multiple shaders?

  1. #11
    Intern Contributor
    Join Date
    Sep 2012
    Posts
    76
    I am just learning to code shaders so performance is not an issue for me at this time. So, it's simply a coding question: if uniforms are different for a bunch of objects can they be packed into a multi-draw call (which would be hugely convenient obviously as no conditionals/subroutines would then be needed)?

    Sorry if I am a bit slow picking up shaders but pre-shader OpenGL is all I'd learned till now.

  2. #12
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,129
    if uniforms are different for a bunch of objects can they be packed into a multi-draw call[..]?
    They can. You could add another generic attribute which is used as an index into a uniform array or uniform buffer (or any other indexable data store for that matter). Unfortunately, there is no gl_DrawCallID or something - actually I don't know why. There is gl_InstanceID but as the name suggests, it will only non-zero values if used with instanced draw calls.

    I agree with Alfonse that unless you're having performance issues due to draw call overhead, you can simply do two separate draw calls and set your uniform stuff accordingly.

  3. #13
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    There is gl_InstanceID but as the name suggests, it will only non-zero values if used with instanced draw calls.
    Not entirely. You can always use base instance rendering calls to specify the instance ID directly.

  4. #14
    Intern Contributor
    Join Date
    Sep 2012
    Posts
    76
    Thanks, Thokra.
    From the point of view of easy-to-understand code, my main concern now, I guess separate buffers/uniforms for separate objects is the best. I can see why though if you're after performance packing as much as possible into the least number of buffers makes sense.

  5. #15
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,129
    Quote Originally Posted by Alfonse
    Not entirely. You can always use base instance rendering calls to specify the instance ID directly.
    True. Completely missed that.

Posting Permissions

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