This extension exposes one new constant, which can be used in the gl.getVertexAttrib()
method:
ext.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE
Returns a GLint
describing the frequency divisor used for instanced rendering when used in the gl.getVertexAttrib()
as the pname
parameter.
This extension exposes three new methods.
ext.drawArraysInstancedANGLE()
Behaves identically to gl.drawArrays()
except that multiple instances of the range of elements are executed, and the instance advances for each iteration.
ext.drawElementsInstancedANGLE()
Behaves identically to gl.drawElements()
except that multiple instances of the set of elements are executed and the instance advances between each set.
ext.vertexAttribDivisorANGLE()
Modifies the rate at which generic vertex attributes advance when rendering multiple instances of primitives with ext.drawArraysInstancedANGLE()
and ext.drawElementsInstancedANGLE()
.
The following example shows how to draw a given geometry multiple times with a single draw call.
Warning: The following is educational, not production level code. It should generally be avoided to construct data / buffers within the rendering loop or right before use.
// enable the extension
const ext = gl.getExtension("ANGLE_instanced_arrays");
// binding the geometry buffer as usual
gl.bindBuffer(gl.ARRAY_BUFFER, geometryVertexBuffer);
gl.enableVertexAttribArray(vertexPositionAttributeLocation);
gl.vertexAttribPointer(
vertexPositionAttributeLocation,
3,
gl.FLOAT,
false,
0,
0,
);
// build position buffer
const instancePositions = [];
for (const instance of instances) {
instancePositions.push(
instance.position.x,
instance.position.y,
instance.position.z,
);
}
const instancePositionBuffer = createWebGLBufferFromData(instancePositions);
// binding the instance position buffer as you would with any attribute
gl.bindBuffer(gl.ARRAY_BUFFER, instancePositionBuffer);
gl.enableVertexAttribArray(instancePositionAttributeLocation);
gl.vertexAttribPointer(
instancePositionAttributeLocation,
3,
gl.FLOAT,
false,
0,
0,
);
// mark the attribute as instanced and advance it every single(1) instance rather than every vertex
ext.vertexAttribDivisorANGLE(instancePositionAttributeLocation, 1);
// draw geometry for each instance
ext.drawArraysInstancedANGLE(
gl.TRIANGLES,
0,
numGeometryVertices,
instances.length,
);
Specifications Browser compatibility
Loadingâ¦
See alsoWebGLRenderingContext.getExtension()
WebGL2RenderingContext.drawArraysInstanced()
WebGL2RenderingContext.drawElementsInstanced()
WebGL2RenderingContext.vertexAttribDivisor()
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.5