Texture

DataTexture

Creates a texture directly from raw data, width and height.

Constructor

DataTexture(data : TypedArray, width : Integer, height : Integer, format : Constant, type : Constant, mapping : Constant, wrapS : Constant, wrapT : Constant, magFilter : Constant, minFilter : Constant, anisotropy : Integer, encoding : Constant)

The data argument must be a TypedArray. Further parameters correspond to the properties inherited from Texture, where both magFilter and minFilter default to v3d.NearestFilter.

The interpretation of the data depends on type and format: If the type is v3d.UnsignedByteType, a Uint8Array will be useful for addressing the texel data. If the format is v3d.RGBAFormat, data needs four values for one texel; Red, Green, Blue and Alpha (typically the opacity).
For the packed types, v3d.UnsignedShort4444Type and v3d.UnsignedShort5551Type all color components of one texel can be addressed as bitfields within an integer element of a Uint16Array.
In order to use the types v3d.FloatType and v3d.HalfFloatType, the WebGL implementation must support the respective extensions OES_texture_float and OES_texture_half_float. In order to use v3d.LinearFilter for component-wise, bilinear interpolation of the texels based on these types, the WebGL extensions OES_texture_float_linear or OES_texture_half_float_linear must also be present.

Code Example

// create a buffer with color data const width = 512; const height = 512; const size = width * height; const data = new Uint8Array(4 * size); const color = new v3d.Color(0xffffff); const r = Math.floor(color.r * 255); const g = Math.floor(color.g * 255); const b = Math.floor(color.b * 255); for (let i = 0; i < size; i++) { const stride = i * 4; data[stride] = r; data[stride + 1] = g; data[stride + 2] = b; data[stride + 3] = 255; } // used the buffer to create a DataTexture const texture = new v3d.DataTexture(data, width, height); texture.needsUpdate = true;

Properties

See the base Texture class for common properties.

.flipY : Boolean

If set to true, the texture is flipped along the vertical axis when uploaded to the GPU. Default is false.

.generateMipmaps : Boolean

Whether to generate mipmaps (if possible) for a texture. False by default.

.image : Image

Overridden with a record type holding data, width and height.

.isDataTexture : Boolean

Read-only flag to check if a given object is of type DataTexture.

.unpackAlignment : Integer

1 by default. Specifies the alignment requirements for the start of each pixel row in memory. The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), 4 (word-alignment), and 8 (rows start on double-word boundaries). See glPixelStorei for more information.

Methods

See the base Texture class for common methods.

Source

For more info on how to obtain the source code of this module see this page.