WebGL texture wrapper.
WebGraphicLibrary texture is a WebGL texture wrapper that simplifies the creation and management of textures for use in WebGL applications
$ npm install --save @ahmerhh/WebGraphicLibrary-texture
import Texture from '@ahmerhh/WebGraphicLibrary-texture';
const texture = new Texture(gl, gl.TEXTURE_2D);
const img = document.createElement('img');
img.onload = () => {
texture.bind(1);
texture.setData(img);
}
img.src = '';
program.bind();
program.setUniform('uTexture', texture.bind(1));
Create a new texture, if no data
is provided, the texture is empty.
gl
is the WebGL context.type
is the texture type. Default isgl.TEXTURE_2D
.data
can be an image, video or canvas.
Set the texture data. The texture must be bound first.
texture.bind(1);
texture.setData(image);
Bind the texture to the given unit, and returns it. Default is 0
.
This allows to set a program uniform at the same time.
program.setUniform('uTextureA', textureA.bind(0));
program.setUniform('uTextureB', textureA.bind(1));
Delete instance. Calls gl.deleteTexture()
.
MIT, see LICENSE.md for more details.
Thanks to the amazing stackgl for the inspiration.