WEBGL_multi_draw
WebGL working group (public_webgl 'at' khronos.org)
Contributors to the ANGLE_multi_draw specification
Members of the WebGL working group
Last modified date: September 08, 2023
Revision: 8
WebGL extension #40
Written against the WebGL API 1.0 specification.
This extension exposes the ANGLE_multi_draw functionality to WebGL.
The following WebGL-specific behavioral changes apply:
MultiDrawArraysANGLE
, MultiDrawElementsANGLE
, MultiDrawArraysInstancedANGLE
, and MultiDrawElementsInstancedANGLE
entrypoints as multiDrawArraysWEBGL
, multiDrawElementsWEBGL
, multiDrawArraysInstancedWEBGL
, and multiDrawElementsInstancedWEBGL
.
multiDrawArraysWEBGL
, multiDrawElementsWEBGL
, multiDrawArraysInstancedWEBGL
, and multiDrawElementsInstancedWEBGL
, similarly to how indices referenced by drawArrays
and drawElements
are validated according to section
Enabled Vertex Attributes and Range Checking of the
WebGL specification.
#extension GL_ANGLE_multi_draw
directive, as shown in the sample code, to use
the gl_DrawID
built-in in a shader.
Likewise the shading language preprocessor #define GL_ANGLE_multi_draw
, will be defined to 1 if the extension is supported.
*Offset
arguments for each array to choose the starting point into the respective typed array or sequence. This primarily avoids allocation of temporary typed array views.
Consult the above extension for documentation, issues and new functions and enumerants.
CAD vendors rendering large models comprised of many individual parts face scalability issues issuing large numbers of draw calls from WebGL. This extension reduces draw call overhead by allowing better batching.
When this extension is enabled:
multiDrawArraysWEBGL
, multiDrawElementsWEBGL
, multiDrawArraysInstancedWEBGL
, and multiDrawElementsInstancedWEBGL
entry points are added. These provide a counterpoint to instanced rendering and are more flexible for certain scenarios. They behave identically to multiple calls to drawArrays
, drawElements
, drawArraysInstanced
, and drawElementsInstanced
except they handle multiple lists of arguments in one call.gl_DrawID
builtin is added to the shading language. For any Multi* draw call variant, the index of the draw i
may be read by the vertex shader as gl_DrawID
. For non Multi* calls, the value of gl_DrawID is 0.GL_ANGLE_multi_draw
with an #extension
directive:int gl_DrawID
is a built-in input.
GL_ANGLE_multi_draw
is defined as 1
.
[Exposed=(Window,Worker), LegacyNoInterfaceObject] interface WEBGL_multi_draw { undefined multiDrawArraysWEBGL( GLenum mode, ([AllowShared] Int32Array or sequence<GLint>) firstsList, unsigned long long firstsOffset, ([AllowShared] Int32Array or sequence<GLsizei>) countsList, unsigned long long countsOffset, GLsizei drawcount); undefined multiDrawElementsWEBGL( GLenum mode, ([AllowShared] Int32Array or sequence<GLsizei>) countsList, unsigned long long countsOffset, GLenum type, ([AllowShared] Int32Array or sequence<GLsizei>) offsetsList, unsigned long long offsetsOffset, GLsizei drawcount); undefined multiDrawArraysInstancedWEBGL( GLenum mode, ([AllowShared] Int32Array or sequence<GLint>) firstsList, unsigned long long firstsOffset, ([AllowShared] Int32Array or sequence<GLsizei>) countsList, unsigned long long countsOffset, ([AllowShared] Int32Array or sequence<GLsizei>) instanceCountsList, unsigned long long instanceCountsOffset, GLsizei drawcount); undefined multiDrawElementsInstancedWEBGL( GLenum mode, ([AllowShared] Int32Array or sequence<GLsizei>) countsList, unsigned long long countsOffset, GLenum type, ([AllowShared] Int32Array or sequence<GLsizei>) offsetsList, unsigned long long offsetsOffset, ([AllowShared] Int32Array or sequence<GLsizei>) instanceCountsList, unsigned long long instanceCountsOffset, GLsizei drawcount); };
var ext = gl.getExtension("WEBGL_multi_draw"); { // multiDrawArrays variant. let firsts = new Int32Array(...); let counts = new Int32Array(...); ext.multiDrawArraysWEBGL(gl.TRIANGLES, firsts, 0, counts, 0, firsts.length); } { // multiDrawElements variant. let counts = new Int32Array(...); let offsets = new Int32Array(...); ext.multiDrawElementsWEBGL( gl.TRIANGLES, counts, 0, gl.UNSIGNED_INT, offsets, 0, counts.length); } { // multiDrawArraysInstanced variant. let firsts = new Int32Array(...); let counts = new Int32Array(...); let instanceCounts = new Int32Array(...); ext.multiDrawArraysInstancedWEBGL( gl.TRIANGLES, firsts, 0, counts, 0, instanceCounts, 0, firsts.length); } { // multiDrawElementsInstanced variant. let counts = new Int32Array(...); let offsets = new Int32Array(...); let instanceCounts = new Int32Array(...); ext.multiDrawElementsInstancedWEBGL( gl.POINTS, counts, 0, gl.UNSIGNED_SHORT, offsets, 0, instanceCounts, 0, counts.length); }
#extension GL_ANGLE_multi_draw : require void main() { gl_Position = vec4(gl_DrawID, 0, 0, 1); }
Revision 1, 2018/11/09
Revision 2, 2019/01/21
Revision 3, 2019/10/23
Revision 4, 2020/06/26
Revision 5, 2020/07/28
Revision 6, 2020/07/31
Revision 7, 2021/05/18
Revision 8, 2023/09/08