WEBGL_draw_instanced_base_vertex_base_instance
WebGL working group (public_webgl 'at' khronos.org)
Contributors to the ANGLE_base_vertex_base_instance specification
Members of the WebGL working group
Last modified date: May 26, 2021
Revision: 3
WebGL extension #46
Written against the WebGL API 2.0 specification.
This extension exposes the ANGLE_base_vertex_base_instance functionality to WebGL.
The following WebGL-specific behavioral changes apply:
DrawArraysInstancedBaseInstanceANGLE
and
DrawElementsInstancedBaseVertexBaseInstanceANGLE
entrypoints as
drawArraysInstancedBaseInstanceWEBGL
and
drawElementsInstancedBaseVertexBaseInstanceWEBGL
.
gl_BaseVertex
and gl_BaseInstance
are not added.
drawArraysInstancedBaseInstanceWEBGL
and
drawElementsInstancedBaseVertexBaseInstanceWEBGL
, similarly to how indices
referenced by drawArrays
and drawElements
are validated according
to section
Enabled Vertex Attributes and Range Checking
and
Range Checking
of the WebGL specification.
Consult the above extension for documentation, issues and new functions and enumerants.
The baseVertex functionality could effectly help reduce CPU overhead with static batching and text rendering in game engine implementations.
The baseInstance functionality could make instanced arrays more useful as they could start instancing from a particular point in the buffer.
When this extension is enabled:
drawArraysInstancedBaseInstanceWEBGL
and drawElementsInstancedBaseVertexBaseInstanceWEBGL
entry points are added.
These provide a counterpoint to instanced rendering and are more flexible for certain
scenarios.
drawArraysInstancedBaseInstanceWEBGL
behaves identically to
drawArraysInstanced
except that the first element within those instanced
vertex attributes is specified in baseInstance
.
drawElementsInstancedBaseVertexBaseInstanceWEBGL
is equivalent to
drawElementsInstanced
except that the value of the base vertex passed into
driver is baseVertex
instead of zero, and that the first element within those
instanced vertex attributes is specified in baseInstance
.
[Exposed=(Window,Worker), LegacyNoInterfaceObject] interface WEBGL_draw_instanced_base_vertex_base_instance { undefined drawArraysInstancedBaseInstanceWEBGL( GLenum mode, GLint first, GLsizei count, GLsizei instanceCount, GLuint baseInstance); undefined drawElementsInstancedBaseVertexBaseInstanceWEBGL( GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei instanceCount, GLint baseVertex, GLuint baseInstance); };
var ext = gl.getExtension("WEBGL_draw_instanced_base_vertex_base_instance"); { // drawArraysInstancedBaseInstance variant. let first = 0; let count = 3; let instanceCount = 2; let baseInstance = 1; gl.uniform1i(u_BaseVertex_location, 0); gl.uniform1i(u_BaseInstance_location, baseInstance); ext.drawArraysInstancedBaseInstanceWEBGL( gl.TRIANGLES, first, count, instanceCount, baseInstance); } { // drawElementsInstancedBaseVertexBaseInstance variant. // Assumes that the indices which have been previously uploaded to the // ELEMENT_ARRAY_BUFFER are to be treated as UNSIGNED_SHORT. let count = 3; let offset = 0; let instanceCount = 2; let baseVertex = 3; let baseInstance = 1; gl.uniform1i(u_BaseVertex_location, baseVertex); gl.uniform1i(u_BaseInstance_location, baseInstance); ext.drawElementsInstancedBaseVertexBaseInstanceWEBGL( gl.TRIANGLES, count, gl.UNSIGHNED_SHORT, offset, instanceCount, baseVertex, baseInstance); }
#version 300 es uniform int u_BaseVertex; uniform int u_BaseInstance; void main() { gl_Position = vec4(u_BaseVertex, gl_InstanceID + u_BaseInstance, 0, 1); }
Revision 1, 2019/08/28
Revision 2, 2019/09/25
Revision 3, 2021/05/26