WebGL buffer wrapper.
$ npm install --save @ahmerhh/WebGraphicLibrary-buffer
import Buffer from '@ahmerhh/WebGraphicLibrary-buffer';
// setup canvas, gl, program, etc.
const vertices = new Float32Array([
-1.0, -1.0, 0.0,
1.0, -1.0, 0.0,
1.0, 1.0, 0.0,
-1.0, 1.0, 0.0
]);
const faces = new Uint16Array([
0, 1, 2,
0, 2, 3
]);
const verticesBuffer = new Buffer(gl, gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
const facesBuffer = new Buffer(gl, gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW);
program.bind();
verticesBuffer.bind();
program.setAttributePointer('aPos');
facesBuffer.bind();
// draw elements
Create a new buffer, where:
gl
is the WebGraphicLibrary context.type
is the buffer type. Default isgl.ARRAY_BUFFER
.data
is a typed array representing the data.usage
is the buffer usage type. Default isgl.STATIC_DRAW
.
Make the buffer the active one.
Delete instance. Calls gl.deleteBuffer()
.
MIT, see LICENSE.md for more details.
Thanks to the amazing stackgl for the inspiration.