the current WebGL renderer session
additional settings to initialize this batcher (see WebGLBatcher#init)
an array of vertex attribute properties
the shader currently used by this batcher
the default shader created by this batcher
the name of the projection matrix uniform in the shader
the renderer this batcher is bound to
the stride of a single vertex in bytes (will automatically be calculated as attributes definitions are added)
whether this batcher uses indexed drawing
the vertex data buffer used by this batcher
the size of a single vertex in floats (will automatically be calculated as attributes definitions are added)
Primitive type to render, as a GL enum (gl.TRIANGLES, gl.LINES, …).
Assignable from either vocabulary — batcher.mode = "line-list" and
batcher.mode = gl.LINES are equivalent — but always reads back as the
GL enum, so existing comparisons keep working. Read
WebGLBatcher#topology for the portable name.
a topology name or a GL primitive mode
How this batcher assembles vertices into primitives, in the backend-neutral vocabulary.
"line-loop" and "triangle-fan" are engine extensions with no
equivalent in modern GPU APIs — prefer the others for anything that must
survive a backend change.
a topology name or a GL primitive mode
Add a vertex attribute to this batcher's layout.
Accepts either vocabulary. The backend-neutral form names the component type and count in one token, which is what a non-WebGL backend can consume directly and what lets a layout be written without a live rendering context:
batcher.addAttribute({ name: "aColor", format: "unorm8x4", offset: 20 });
batcher.addAttribute("aColor", "unorm8x4", 20);
The GL form is supported indefinitely and behaves exactly as before:
batcher.addAttribute("aColor", 4, gl.UNSIGNED_BYTE, true, 20);
Records keep both spellings, so existing readers of size / type /
normalized are unaffected. A GL combination with no portable name —
three-component 8- and 16-bit types, which the neutral vocabulary does
not define — is stored with format: undefined rather than an invented
name that a backend could not honour.
The layout is frozen once init() has built the vertex state, and each
record is frozen on insertion: a batcher rebuilds its vertex state from
these records after a context loss, so a later mutation would take
effect at restore time rather than where it was written.
attribute name, or a descriptor object
Optionalsize: number | VertexFormat
component count (GL form), or the format (neutral form)
Optionaltype: number
component type (GL form), or the byte offset (neutral form)
Optionalnormalized: boolean
whether integers are scaled into [0, 1] / [-1, 1] (GL form only)
Optionaloffset: number
byte offset of the attribute within a vertex (GL form)
Add index values to the index buffer (only for indexed batchers). Indices are rebased relative to the current vertex count.
array of index values to add
called by the WebGL renderer when a batcher becomes the current one
Flush batched vertex data to the GPU
Optionalmode: number = ...
the GL drawing mode
Initialize the batcher (called by the constructor)
the current WebGL renderer session
additional settings to initialize this batcher
an array of attributes definition
Optionalindexed?: booleanwhether this batcher uses an index buffer for indexed drawing (drawElements)
OptionalmaxVertices?: numberthe maximum number of vertices this batcher can hold
OptionalprojectionUniform?: stringthe name of the projection matrix uniform in the shader
shader definition
a string containing the GLSL source code to set
a string containing the GLSL source code to set
set/change the current projection matrix
the new projection matrix
called by the WebGL renderer when this batcher is being replaced by
another. Attribute state no longer needs disabling — it lives in this
batcher's vertex-state object and the incoming batcher's bind()
replaces the binding wholesale. Kept as a lifecycle hook: subclasses
override it to restore mode-specific GL state (see MeshBatcher's
blend/depth restore).
Select the shader to use for compositing
a reference to a GLShader instance
The base WebGL Batcher — manages shader programs, vertex attribute definitions, and vertex buffer batching for efficient GPU draw calls, realizing the backend-neutral Batcher lifecycle on GL state. Custom WebGL batchers extend this class.