Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support baseInstance/baseVertex draw and multidraw extension calls #198

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

micahscopes
Copy link

@micahscopes micahscopes commented Apr 21, 2022

This adds support for WEBGL_draw_instanced_base_vertex_base_instance and
WEBGL_multi_draw_instanced_base_vertex_base_instance via the DrawCall.drawRanges interface. It resolves #197.

This change lets you specify the first vertex and/or instance in your range on a per-draw basis, like this:

drawCall.drawRanges(
  [offset, numElements, numInstances, baseInstance, baseElement],
  ...
)

The multidraw+baseVertex+baseInstance extension calls will be used if they're available, since they cover the most use cases (and provide gl_DrawID). Then if baseVertices or baseInstances have been set the non-multidraw baseVertex+baseInstance extension calls will be used. If not, the existing draw call preference order (multidraw then non-multidraw) takes over.

I added an example at examples/multi-draw-base-instance.html:
image

let drawCall = app.createDrawCall(program, triangleArray)
  .drawRanges(
    [0, 3, 1, 2], // draw one instance starting at instance index 2
    [3, 6, 2, 1], // draw two instances starting at instance index 1
    [3, 6, 2], // draw two instances (implicitly starting at index 0) 
    [0, 3, 3], // draw three instances (implicitly starting at index 0)
  );

I tested this with the existing examples/multi-draw.html and examples/multi-draw-base-instance.html, and also spot checked the rest of the examples and didn't see anything broken. That said I didn't explicitly test the drawElementsInstancedBaseVertexBaseInstanceWEBGL and multiDrawElementsInstancedBaseVertexBaseInstanceWEBGL calls, instead I just made sure they conformed to the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

drawRanges but for selectively drawing instances?
1 participant