/** * 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. * * @category Graphics */ export class Texture { /** * Create a new Texture instance. * * @param {import('./graphics-device.js').GraphicsDevice} graphicsDevice - The graphics device * used to manage this texture. * @param {object} [options] - Object for passing optional arguments. * @param {string} [options.name] - The name of the texture. Defaults to null. * @param {number} [options.width] - The width of the texture in pixels. Defaults to 4. * @param {number} [options.height] - The height of the texture in pixels. Defaults to 4. * @param {number} [options.depth] - The number of depth slices in a 3D texture (not supported by WebGl1). * @param {number} [options.format] - The pixel format of the texture. Can be: * * - {@link PIXELFORMAT_A8} * - {@link PIXELFORMAT_L8} * - {@link PIXELFORMAT_LA8} * - {@link PIXELFORMAT_RGB565} * - {@link PIXELFORMAT_RGBA5551} * - {@link PIXELFORMAT_RGBA4} * - {@link PIXELFORMAT_RGB8} * - {@link PIXELFORMAT_RGBA8} * - {@link PIXELFORMAT_DXT1} * - {@link PIXELFORMAT_DXT3} * - {@link PIXELFORMAT_DXT5} * - {@link PIXELFORMAT_RGB16F} * - {@link PIXELFORMAT_RGBA16F} * - {@link PIXELFORMAT_RGB32F} * - {@link PIXELFORMAT_RGBA32F} * - {@link PIXELFORMAT_ETC1} * - {@link PIXELFORMAT_PVRTC_2BPP_RGB_1} * - {@link PIXELFORMAT_PVRTC_2BPP_RGBA_1} * - {@link PIXELFORMAT_PVRTC_4BPP_RGB_1} * - {@link PIXELFORMAT_PVRTC_4BPP_RGBA_1} * - {@link PIXELFORMAT_111110F} * - {@link PIXELFORMAT_ASTC_4x4} * - {@link PIXELFORMAT_ATC_RGB} * - {@link PIXELFORMAT_ATC_RGBA} * * Defaults to {@link PIXELFORMAT_RGBA8}. * @param {string} [options.projection] - The projection type of the texture, used when the * texture represents an environment. Can be: * * - {@link TEXTUREPROJECTION_NONE} * - {@link TEXTUREPROJECTION_CUBE} * - {@link TEXTUREPROJECTION_EQUIRECT} * - {@link TEXTUREPROJECTION_OCTAHEDRAL} * * Defaults to {@link TEXTUREPROJECTION_CUBE} if options.cubemap is true, otherwise * {@link TEXTUREPROJECTION_NONE}. * @param {number} [options.minFilter] - The minification filter type to use. Defaults to * {@link FILTER_LINEAR_MIPMAP_LINEAR}. * @param {number} [options.magFilter] - The magnification filter type to use. Defaults to * {@link FILTER_LINEAR}. * @param {number} [options.anisotropy] - The level of anisotropic filtering to use. Defaults * to 1. * @param {number} [options.addressU] - The repeat mode to use in the U direction. Defaults to * {@link ADDRESS_REPEAT}. * @param {number} [options.addressV] - The repeat mode to use in the V direction. Defaults to * {@link ADDRESS_REPEAT}. * @param {number} [options.addressW] - The repeat mode to use in the W direction. Defaults to * {@link ADDRESS_REPEAT}. * @param {boolean} [options.mipmaps] - When enabled try to generate or use mipmaps for this * texture. Default is true. * @param {boolean} [options.cubemap] - Specifies whether the texture is to be a cubemap. * Defaults to false. * @param {number} [options.arrayLength] - 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. * @param {boolean} [options.volume] - Specifies whether the texture is to be a 3D volume * (not supported by WebGL1). Defaults to false. * @param {string} [options.type] - Specifies the texture type. Can be: * * - {@link TEXTURETYPE_DEFAULT} * - {@link TEXTURETYPE_RGBM} * - {@link TEXTURETYPE_RGBE} * - {@link TEXTURETYPE_RGBP} * - {@link TEXTURETYPE_SWIZZLEGGGR} * * Defaults to {@link TEXTURETYPE_DEFAULT}. * @param {boolean} [options.fixCubemapSeams] - Specifies whether this cubemap texture requires * special seam fixing shader code to look right. Defaults to false. * @param {boolean} [options.flipY] - 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. * @param {boolean} [options.premultiplyAlpha] - If true, the alpha channel of the texture (if * present) is multiplied into the color channels. Defaults to false. * @param {boolean} [options.compareOnRead] - When enabled, and if texture format is * {@link PIXELFORMAT_DEPTH} or {@link 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. * @param {number} [options.compareFunc] - Comparison function when compareOnRead is enabled * (not supported by WebGL1). Can be: * * - {@link FUNC_LESS} * - {@link FUNC_LESSEQUAL} * - {@link FUNC_GREATER} * - {@link FUNC_GREATEREQUAL} * - {@link FUNC_EQUAL} * - {@link FUNC_NOTEQUAL} * * Defaults to {@link FUNC_LESS}. * @param {Uint8Array[]|Uint16Array[]|Uint32Array[]|Float32Array[]|HTMLCanvasElement[]|HTMLImageElement[]|HTMLVideoElement[]|Uint8Array[][]} [options.levels] * - Array of Uint8Array or other supported browser interface; or a two-dimensional array * of Uint8Array if options.arrayLength is defined and greater than zero. * @param {boolean} [options.storage] - Defines if texture can be used as a storage texture by * a compute shader. Defaults to false. * @example * // 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(); */ constructor(graphicsDevice: import("./graphics-device.js").GraphicsDevice, options?: { name?: string; width?: number; height?: number; depth?: number; format?: number; projection?: string; minFilter?: number; magFilter?: number; anisotropy?: number; addressU?: number; addressV?: number; addressW?: number; mipmaps?: boolean; cubemap?: boolean; arrayLength?: number; volume?: boolean; type?: string; fixCubemapSeams?: boolean; flipY?: boolean; premultiplyAlpha?: boolean; compareOnRead?: boolean; compareFunc?: number; levels?: Uint8Array[] | Uint16Array[] | Uint32Array[] | Float32Array[] | HTMLCanvasElement[] | HTMLImageElement[] | HTMLVideoElement[] | Uint8Array[][]; storage?: boolean; }); /** * The name of the texture. * * @type {string} */ name: string; /** @ignore */ _gpuSize: number; /** @protected */ protected id: number; /** @protected */ protected _invalid: boolean; /** @protected */ protected _lockedLevel: number; /** @protected */ protected _lockedMode: number; /** * A render version used to track the last time the texture properties requiring bind group * to be updated were changed. * * @type {number} * @ignore */ renderVersionDirty: number; /** @protected */ protected _storage: boolean; device: import("./graphics-device.js").GraphicsDevice; _width: number; _height: number; _format: number; _compressed: boolean; _integerFormat: boolean; _volume: boolean; _depth: number; _arrayLength: number; _cubemap: boolean; fixCubemapSeams: boolean; _flipY: boolean; _premultiplyAlpha: boolean; _mipmaps: any; _minFilter: number; _magFilter: number; _anisotropy: number; _addressU: number; _addressV: number; _addressW: number; _compareOnRead: boolean; _compareFunc: number; type: string; projection: string; impl: any; profilerHint: any; _levels: Uint8Array[] | Uint16Array[] | Uint32Array[] | Float32Array[] | HTMLCanvasElement[] | HTMLImageElement[] | HTMLVideoElement[] | Uint8Array[][]; /** * Frees resources associated with this texture. */ destroy(): void; /** * Resizes the texture. Only supported for render target textures, as it does not resize the * existing content of the texture, but only the allocated buffer for rendering into. * * @param {number} width - The new width of the texture. * @param {number} height - The new height of the texture. * @param {number} [depth] - The new depth of the texture. Defaults to 1. * @ignore */ resize(width: number, height: number, depth?: number): void; /** * Called when the rendering context was lost. It releases all context related resources. * * @ignore */ loseContext(): void; /** * Updates vram size tracking for the texture, size can be positive to add or negative to subtract * * @ignore */ adjustVramSizeTracking(vram: any, size: any): void; propertyChanged(flag: any): void; /** * Returns number of required mip levels for the texture based on its dimensions and parameters. * * @ignore * @type {number} */ get requiredMipLevels(): number; /** * Returns the current lock mode. One of: * * - {@link TEXTURELOCK_NONE} * - {@link TEXTURELOCK_READ} * - {@link TEXTURELOCK_WRITE} * * @ignore * @type {number} */ get lockedMode(): number; /** * Sets the minification filter to be applied to the texture. Can be: * * - {@link FILTER_NEAREST} * - {@link FILTER_LINEAR} * - {@link FILTER_NEAREST_MIPMAP_NEAREST} * - {@link FILTER_NEAREST_MIPMAP_LINEAR} * - {@link FILTER_LINEAR_MIPMAP_NEAREST} * - {@link FILTER_LINEAR_MIPMAP_LINEAR} * * @type {number} */ set minFilter(v: number); /** * Gets the minification filter to be applied to the texture. * * @type {number} */ get minFilter(): number; /** * Sets the magnification filter to be applied to the texture. Can be: * * - {@link FILTER_NEAREST} * - {@link FILTER_LINEAR} * * @type {number} */ set magFilter(v: number); /** * Gets the magnification filter to be applied to the texture. * * @type {number} */ get magFilter(): number; /** * Sets the addressing mode to be applied to the texture horizontally. Can be: * * - {@link ADDRESS_REPEAT} * - {@link ADDRESS_CLAMP_TO_EDGE} * - {@link ADDRESS_MIRRORED_REPEAT} * * @type {number} */ set addressU(v: number); /** * Gets the addressing mode to be applied to the texture horizontally. * * @type {number} */ get addressU(): number; /** * Sets the addressing mode to be applied to the texture vertically. Can be: * * - {@link ADDRESS_REPEAT} * - {@link ADDRESS_CLAMP_TO_EDGE} * - {@link ADDRESS_MIRRORED_REPEAT} * * @type {number} */ set addressV(v: number); /** * Gets the addressing mode to be applied to the texture vertically. * * @type {number} */ get addressV(): number; /** * Sets the addressing mode to be applied to the 3D texture depth. Can be: * * - {@link ADDRESS_REPEAT} * - {@link ADDRESS_CLAMP_TO_EDGE} * - {@link ADDRESS_MIRRORED_REPEAT} * * @type {number} */ set addressW(addressW: number); /** * Gets the addressing mode to be applied to the 3D texture depth. * * @type {number} */ get addressW(): number; /** * When enabled, and if texture format is {@link PIXELFORMAT_DEPTH} or * {@link 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). * * @type {boolean} */ set compareOnRead(v: boolean); /** * Gets whether you can get filtered results of comparison using texture() in your shader. * * @type {boolean} */ get compareOnRead(): boolean; /** * Sets the comparison function when compareOnRead is enabled. Possible values: * * - {@link FUNC_LESS} * - {@link FUNC_LESSEQUAL} * - {@link FUNC_GREATER} * - {@link FUNC_GREATEREQUAL} * - {@link FUNC_EQUAL} * - {@link FUNC_NOTEQUAL} * * @type {number} */ set compareFunc(v: number); /** * Sets the comparison function when compareOnRead is enabled. * * @type {number} */ get compareFunc(): number; /** * Sets the integer value specifying the level of anisotropy to apply to the texture ranging * from 1 (no anisotropic filtering) to the {@link GraphicsDevice} property maxAnisotropy. * * @type {number} */ set anisotropy(v: number); /** * Gets the integer value specifying the level of anisotropy to apply to the texture. * * @type {number} */ get anisotropy(): number; /** * Sets whether the texture should generate/upload mipmaps. * * @type {boolean} */ set mipmaps(v: boolean); /** * Gets whether the texture should generate/upload mipmaps. * * @type {boolean} */ get mipmaps(): boolean; _needsMipmapsUpload: any; /** * Defines if texture can be used as a storage texture by a compute shader. * * @type {boolean} */ get storage(): boolean; /** * The width of the texture in pixels. * * @type {number} */ get width(): number; /** * The height of the texture in pixels. * * @type {number} */ get height(): number; /** * The number of depth slices in a 3D texture. * * @type {number} */ get depth(): number; /** * The pixel format of the texture. Can be: * * - {@link PIXELFORMAT_A8} * - {@link PIXELFORMAT_L8} * - {@link PIXELFORMAT_LA8} * - {@link PIXELFORMAT_RGB565} * - {@link PIXELFORMAT_RGBA5551} * - {@link PIXELFORMAT_RGBA4} * - {@link PIXELFORMAT_RGB8} * - {@link PIXELFORMAT_RGBA8} * - {@link PIXELFORMAT_DXT1} * - {@link PIXELFORMAT_DXT3} * - {@link PIXELFORMAT_DXT5} * - {@link PIXELFORMAT_RGB16F} * - {@link PIXELFORMAT_RGBA16F} * - {@link PIXELFORMAT_RGB32F} * - {@link PIXELFORMAT_RGBA32F} * - {@link PIXELFORMAT_ETC1} * - {@link PIXELFORMAT_PVRTC_2BPP_RGB_1} * - {@link PIXELFORMAT_PVRTC_2BPP_RGBA_1} * - {@link PIXELFORMAT_PVRTC_4BPP_RGB_1} * - {@link PIXELFORMAT_PVRTC_4BPP_RGBA_1} * - {@link PIXELFORMAT_111110F} * - {@link PIXELFORMAT_ASTC_4x4}>/li> * - {@link PIXELFORMAT_ATC_RGB} * - {@link PIXELFORMAT_ATC_RGBA} * * @type {number} */ get format(): number; /** * Returns true if this texture is a cube map and false otherwise. * * @type {boolean} */ get cubemap(): boolean; get gpuSize(): number; /** * Returns true if this texture is a 2D texture array and false otherwise. * * @type {boolean} */ get array(): boolean; /** * Returns the number of textures inside this texture if this is a 2D array texture or 0 otherwise. * * @type {number} */ get arrayLength(): number; /** * Returns true if this texture is a 3D volume and false otherwise. * * @type {boolean} */ get volume(): boolean; /** * 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. * * @type {boolean} */ set flipY(flipY: boolean); /** * Gets whether the texture should be flipped in the Y-direction. * * @type {boolean} */ get flipY(): boolean; _needsUpload: boolean; set premultiplyAlpha(premultiplyAlpha: boolean); get premultiplyAlpha(): boolean; /** * Returns true if all dimensions of the texture are power of two, and false otherwise. * * @type {boolean} */ get pot(): boolean; get encoding(): "srgb" | "linear" | "rgbm" | "rgbe" | "rgbp"; dirtyAll(): void; _levelsUpdated: boolean[] | boolean[][]; _mipmapsUploaded: boolean; /** * Locks a miplevel of the texture, returning a typed array to be filled with pixel data. * * @param {object} [options] - Optional options object. Valid properties are as follows: * @param {number} [options.level] - The mip level to lock with 0 being the top level. Defaults * to 0. * @param {number} [options.face] - If the texture is a cubemap, this is the index of the face * to lock. * @param {number} [options.mode] - The lock mode. Can be: * - {@link TEXTURELOCK_READ} * - {@link TEXTURELOCK_WRITE} * Defaults to {@link TEXTURELOCK_WRITE}. * @returns {Uint8Array|Uint16Array|Uint32Array|Float32Array} A typed array containing the pixel data of * the locked mip level. */ lock(options?: { level?: number; face?: number; mode?: number; }): Uint8Array | Uint16Array | Uint32Array | Float32Array; /** * 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. * * @param {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement|HTMLCanvasElement[]|HTMLImageElement[]|HTMLVideoElement[]} source - A * canvas, image or video element, or an array of 6 canvas, image or video elements. * @param {number} [mipLevel] - A 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. */ setSource(source: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement | HTMLCanvasElement[] | HTMLImageElement[] | HTMLVideoElement[], mipLevel?: number): void; /** * 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. * * @param {number} [mipLevel] - A 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. * @returns {HTMLImageElement} The source image of this texture. Can be null if source not * assigned for specific image level. */ getSource(mipLevel?: number): HTMLImageElement; /** * Unlocks the currently locked mip level and uploads it to VRAM. */ unlock(): void; /** * Forces a reupload of the textures pixel data to graphics memory. Ordinarily, this function * is called by internally by {@link Texture#setSource} and {@link 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. */ upload(): void; /** * Download texture's top level data from graphics memory to local memory. * * @ignore */ downloadAsync(): Promise; }