mirror of
https://github.com/visgl/luma.gl.git
synced 2025-12-08 17:36:19 +00:00
2.4 KiB
2.4 KiB
Texture2DArray
For more background and details on parameters, see Textures and Samplers.
Usage
Program Method: setTexture
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.
Syntax:
program.setTexture(name[, options]);
Arguments:
- name - (string) The name (unique id) of the texture.
- options - (mixed) Can be a boolean or enum used to bind/unbind the texture (or set the enum as active texture) or an object with options/data described below:
Options:
- textureType - (enum, optional) The texture type used to call
gl.bindTexturewith. Default'sgl.TEXTURE_2D. - pixelStore - (array, optional) An array of objects with name, value options to be set with
gl.pixelStoreicalls. Default's[{ name: gl.UNPACK_FLIP_Y_WEBGL, value: true }]. - parameters - (array, optional) An array of objects with nane, value options to be set with
gl.texParameteri. Default's[{ name: gl.TEXTURE_MAG_FILTER, value: gl.NEAREST }, { name: gl.TEXTURE_MIN_FILTER, value: gl.NEAREST }]. - data - (object, optional) An object with properties described below:
- format - (enum, optional) The format used for
gl.texImage2Dcalls. Default'sgl.RGBA. - value - (object, optional) If set to an
Imageobject 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. - width - (number, optional) The width of the texture. Default's 0.
- height - (number, optional) The height of the texture. Default's 0.
- border - (number, optional) The border of the texture. Default's 0.
- format - (enum, optional) The format used for
Examples:
Setting a texture for a box. Adapted from [lesson 6]http://uber.github.io/luma.gl/examples/lessons/6/).
{% highlight js %} var img = new Image();
img.onload = function() { program.setTexture('nearest', { data: { value: img } }); };
img.src = 'path/to/image.png'; {% endhighlight %}
Program Method: setTextures
Sets a number of textures on the program.