Create a new Texture instance.
The graphics device used to manage this texture.
Optional
options: { Object for passing optional arguments.
The repeat mode to use in the U direction. Defaults to ADDRESS_REPEAT.
The repeat mode to use in the V direction. Defaults to ADDRESS_REPEAT.
The repeat mode to use in the W direction. Defaults to ADDRESS_REPEAT.
The level of anisotropic filtering to use. Defaults to 1.
Specifies whether the texture is to be a 2D texture array. When passed in as undefined or < 1, this is not an array texture. If >= 1, this is an array texture. (not supported by WebGL1). Defaults to undefined.
Comparison function when compareOnRead is enabled (not supported by WebGL1). Can be:
Defaults to FUNC_LESS.
When enabled, and if texture format is PIXELFORMAT_DEPTH or PIXELFORMAT_DEPTHSTENCIL, hardware PCF is enabled for this texture, and you can get filtered results of comparison using texture() in your shader (not supported by WebGL1). Defaults to false.
Specifies whether the texture is to be a cubemap. Defaults to false.
The number of depth slices in a 3D texture (not supported by WebGl1).
Specifies whether this cubemap texture requires special seam fixing shader code to look right. Defaults to false.
Specifies whether the texture should be flipped in the Y-direction. Only affects textures with a source that is an image, canvas or video element. Does not affect cubemaps, compressed textures or textures set from raw pixel data. Defaults to false.
The pixel format of the texture. Can be:
Defaults to PIXELFORMAT_RGBA8.
The height of the texture in pixels. Defaults to 4.
Array of Uint8Array or other supported browser interface; or a two-dimensional array of Uint8Array if options.arrayLength is defined and greater than zero.
The magnification filter type to use. Defaults to FILTER_LINEAR.
The minification filter type to use. Defaults to FILTER_LINEAR_MIPMAP_LINEAR.
When enabled try to generate or use mipmaps for this texture. Default is true.
The name of the texture. Defaults to null.
If true, the alpha channel of the texture (if present) is multiplied into the color channels. Defaults to false.
The projection type of the texture, used when the texture represents an environment. Can be:
Defaults to TEXTUREPROJECTION_CUBE if options.cubemap is true, otherwise TEXTUREPROJECTION_NONE.
Defines if texture can be used as a storage texture by a compute shader. Defaults to false.
Specifies the texture type. Can be:
Defaults to TEXTURETYPE_DEFAULT.
Specifies whether the texture is to be a 3D volume (not supported by WebGL1). Defaults to false.
The width of the texture in pixels. Defaults to 4.
// Create a 8x8x24-bit texture
const texture = new pc.Texture(graphicsDevice, {
width: 8,
height: 8,
format: pc.PIXELFORMAT_RGB8
});
// Fill the texture with a gradient
const pixels = texture.lock();
const count = 0;
for (let i = 0; i < 8; i++) {
for (let j = 0; j < 8; j++) {
pixels[count++] = i * 32;
pixels[count++] = j * 32;
pixels[count++] = 255;
}
}
texture.unlock();
Protected
_invalidProtected
_lockedProtected
_lockedProtected
_storageProtected
idThe name of the texture.
Gets the addressing mode to be applied to the texture horizontally.
Sets the addressing mode to be applied to the texture horizontally. Can be:
Gets the addressing mode to be applied to the texture vertically.
Sets the addressing mode to be applied to the texture vertically. Can be:
Gets the addressing mode to be applied to the 3D texture depth.
Sets the addressing mode to be applied to the 3D texture depth. Can be:
Gets the integer value specifying the level of anisotropy to apply to the texture.
Sets the integer value specifying the level of anisotropy to apply to the texture ranging from 1 (no anisotropic filtering) to the GraphicsDevice property maxAnisotropy.
Returns true if this texture is a 2D texture array and false otherwise.
Returns the number of textures inside this texture if this is a 2D array texture or 0 otherwise.
Sets the comparison function when compareOnRead is enabled.
Sets the comparison function when compareOnRead is enabled. Possible values:
Gets whether you can get filtered results of comparison using texture() in your shader.
When enabled, and if texture format is PIXELFORMAT_DEPTH or PIXELFORMAT_DEPTHSTENCIL, hardware PCF is enabled for this texture, and you can get filtered results of comparison using texture() in your shader (not supported on WebGL1).
Returns true if this texture is a cube map and false otherwise.
The number of depth slices in a 3D texture.
Gets whether the texture should be flipped in the Y-direction.
Sets whether the texture should be flipped in the Y-direction. Only affects textures with a source that is an image, canvas or video element. Does not affect cubemaps, compressed textures or textures set from raw pixel data. Defaults to true.
The pixel format of the texture. Can be:
The height of the texture in pixels.
Gets the magnification filter to be applied to the texture.
Sets the magnification filter to be applied to the texture. Can be:
Gets the minification filter to be applied to the texture.
Sets the minification filter to be applied to the texture. Can be:
Gets whether the texture should generate/upload mipmaps.
Sets whether the texture should generate/upload mipmaps.
Returns true if all dimensions of the texture are power of two, and false otherwise.
Defines if texture can be used as a storage texture by a compute shader.
Returns true if this texture is a 3D volume and false otherwise.
The width of the texture in pixels.
Get the pixel data of the texture. If this is a cubemap then an array of 6 images will be returned otherwise a single image.
Optional
mipLevel: number = 0A non-negative integer specifying the image level of detail. Defaults to 0, which represents the base image source. A level value of N, that is greater than 0, represents the image source for the Nth mipmap reduction level.
The source image of this texture. Can be null if source not assigned for specific image level.
Locks a miplevel of the texture, returning a typed array to be filled with pixel data.
Optional
options: { Optional options object. Valid properties are as follows:
If the texture is a cubemap, this is the index of the face to lock.
The mip level to lock with 0 being the top level. Defaults to 0.
The lock mode. Can be:
A typed array containing the pixel data of the locked mip level.
Set the pixel data of the texture from a canvas, image, video DOM element. If the texture is a cubemap, the supplied source must be an array of 6 canvases, images or videos.
A canvas, image or video element, or an array of 6 canvas, image or video elements.
Optional
mipLevel: number = 0A non-negative integer specifying the image level of detail. Defaults to 0, which represents the base image source. A level value of N, that is greater than 0, represents the image source for the Nth mipmap reduction level.
Forces a reupload of the textures pixel data to graphics memory. Ordinarily, this function is called by internally by Texture#setSource and Texture#unlock. However, it still needs to be called explicitly in the case where an HTMLVideoElement is set as the source of the texture. Normally, this is done once every frame before video textured geometry is rendered.
A texture is a container for texel data that can be utilized in a fragment shader. Typically, the texel data represents an image that is mapped over geometry.