Skip to content

WebGraphicLibrary-buffer is a lightweight and efficient WebGL buffer wrapper. This library provides an easy-to-use interface for creating and managing WebGL buffers, making it convenient to handle vertex data, element indices, and more in your WebGL applications

License

Notifications You must be signed in to change notification settings

ahmerhh/WebGraphicLibrary-buffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@ahmerhh/WebGraphicLibrary-buffer

WebGL buffer wrapper.

Installation

$ npm install --save @ahmerhh/WebGraphicLibrary-buffer

Usage

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

API

buffer = new Buffer(gl, type, data, usage)

Create a new buffer, where:

  • gl is the WebGraphicLibrary context.
  • type is the buffer type. Default is gl.ARRAY_BUFFER.
  • data is a typed array representing the data.
  • usage is the buffer usage type. Default is gl.STATIC_DRAW.

buffer.bind()

Make the buffer the active one.

buffer.dispose()

Delete instance. Calls gl.deleteBuffer().

License

MIT, see LICENSE.md for more details.

Credits

Thanks to the amazing stackgl for the inspiration.

About

WebGraphicLibrary-buffer is a lightweight and efficient WebGL buffer wrapper. This library provides an easy-to-use interface for creating and managing WebGL buffers, making it convenient to handle vertex data, element indices, and more in your WebGL applications

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published