TODO - texture support has been broken out into separate Texture classes, but documentation is not yet up to date. For now, please refer directly to src/webgl/texture.js
This method is used to either bind/unbind an existing texture or also
to create a new texture form an Image element or
to create an empty texture with specified dimensions.
Also, for all properties set to a texture, these properties are
remembered so they’re optional for later calls.
program.setTexture(name[, options]);
gl.bindTexture with. Default’s gl.TEXTURE_2D.gl.pixelStorei calls.
Default’s [{ name: gl.UNPACK_FLIP_Y_WEBGL, value: true }].gl.texParameteri.
Default’s [{ name: gl.TEXTURE_MAG_FILTER, value: gl.NEAREST }, { name: gl.TEXTURE_MIN_FILTER, value: gl.NEAREST }].gl.texImage2D calls. Default’s gl.RGBA.Image object then this image will be used to fill the texture. Default’s false. If no image is set then we might want to set the width and height of the texture.Setting a texture for a box. Adapted from [lesson 6]http://uber.github.io/luma.gl/examples/lessons/6/).
var img = new Image();
img.onload = function() {
program.setTexture('nearest', {
data: {
value: img
}
});
};
img.src = 'path/to/image.png';For each key, value of the object passed in it executes setTexture(key, value).
program.setTextures(object);
Set multiple type of textures from the same image. Taken from [lesson 6]http://uber.github.io/luma.gl/examples/lessons/6/).
//load textures from image
var img = new Image();
img.onload = function() {
program.setTextures({
'nearest': {
data: {
value: img
}
},
'linear': {
data: {
value: img
},
parameters: [{
name: gl.TEXTURE_MAG_FILTER,
value: gl.LINEAR
}, {
name: gl.TEXTURE_MIN_FILTER,
value: gl.LINEAR
}]
},
'mipmap': {
data: {
value: img
},
parameters: [{
name: gl.TEXTURE_MAG_FILTER,
value: gl.LINEAR
}, {
name: gl.TEXTURE_MIN_FILTER,
value: gl.LINEAR_MIPMAP_NEAREST,
generateMipmap: true
}]
}
});
};
img.src = 'path/to/image.png';