Engine API Reference
    Preparing search index...

    Class Texture

    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.

    Note on HDR texture format support:

    1. As textures:

    2. As renderable textures that can be used as color buffers in a RenderTarget:

    Index

    Constructors

    • Create a new Texture instance.

      Parameters

      Returns Texture

      // 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();

    Properties

    _invalid: boolean = false
    _lockedLevel: number = -1
    _lockedMode: number = TEXTURELOCK_NONE
    _numLevels: number = 0
    _numLevelsRequested: undefined | number
    _storage: boolean = false
    id: number = ...
    name: string

    The name of the texture.

    Accessors

    • get addressU(): number

      Gets the addressing mode to be applied to the texture horizontally.

      Returns number

    • set addressU(v: number): void

      Sets the addressing mode to be applied to the texture horizontally. Can be:

      Parameters

      • v: number

      Returns void

    • get addressV(): number

      Gets the addressing mode to be applied to the texture vertically.

      Returns number

    • set addressV(v: number): void

      Sets the addressing mode to be applied to the texture vertically. Can be:

      Parameters

      • v: number

      Returns void

    • get addressW(): number

      Gets the addressing mode to be applied to the 3D texture depth.

      Returns number

    • set addressW(addressW: number): void

      Sets the addressing mode to be applied to the 3D texture depth. Can be:

      Parameters

      • addressW: number

      Returns void

    • get anisotropy(): number

      Gets the integer value specifying the level of anisotropy to apply to the texture.

      Returns number

    • set anisotropy(v: number): void

      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.

      Parameters

      • v: number

      Returns void

    • get array(): boolean

      Returns true if this texture is a 2D texture array and false otherwise.

      Returns boolean

    • get arrayLength(): number

      Returns the number of textures inside this texture if this is a 2D array texture or 0 otherwise.

      Returns number

    • get compareOnRead(): boolean

      Gets whether you can get filtered results of comparison using texture() in your shader.

      Returns boolean

    • set compareOnRead(v: boolean): void

      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.

      Parameters

      • v: boolean

      Returns void

    • get cubemap(): boolean

      Returns true if this texture is a cube map and false otherwise.

      Returns boolean

    • get depth(): number

      The number of depth slices in a 3D texture.

      Returns number

    • get flipY(): boolean

      Gets whether the texture should be flipped in the Y-direction.

      Returns boolean

    • set flipY(flipY: boolean): void

      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.

      Parameters

      • flipY: boolean

      Returns void

    • get height(): number

      The height of the texture in pixels.

      Returns number

    • get magFilter(): number

      Gets the magnification filter to be applied to the texture.

      Returns number

    • set magFilter(v: number): void

      Sets the magnification filter to be applied to the texture. Can be:

      Parameters

      • v: number

      Returns void

    • get mipmaps(): boolean

      Gets whether the texture should generate/upload mipmaps.

      Returns boolean

    • set mipmaps(v: boolean): void

      Sets whether the texture should generate/upload mipmaps.

      Parameters

      • v: boolean

      Returns void

    • get numLevels(): number

      Gets the number of mip levels.

      Returns number

    • get pot(): boolean

      Returns true if all dimensions of the texture are power of two, and false otherwise.

      Returns boolean

    • get srgb(): boolean

      Returns true if the texture is stored in an sRGB format, meaning it will be converted to linear space when sampled. Returns false if the texture is stored in a linear format.

      Returns boolean

    • get storage(): boolean

      Defines if texture can be used as a storage texture by a compute shader.

      Returns boolean

    • get volume(): boolean

      Returns true if this texture is a 3D volume and false otherwise.

      Returns boolean

    • get width(): number

      The width of the texture in pixels.

      Returns number

    Methods

    • Frees resources associated with this texture.

      Returns 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.

      Parameters

      • OptionalmipLevel: number = 0

        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.

    • Locks a miplevel of the texture, returning a typed array to be filled with pixel data.

      Parameters

      • Optionaloptions: { face?: number; level?: number; mode?: number } = {}

        Optional options object. Valid properties are as follows:

        • Optionalface?: number

          If the texture is a cubemap, this is the index of the face to lock.

        • Optionallevel?: number

          The mip level to lock with 0 being the top level. Defaults to 0.

        • Optionalmode?: number

          The lock mode. Can be:

      Returns
          | Uint8Array<ArrayBufferLike>
          | Uint16Array<ArrayBufferLike>
          | Uint32Array<ArrayBufferLike>
          | Float32Array<ArrayBufferLike>

      A typed array containing the pixel data of the locked mip level.

    • Unlocks the currently locked mip level and uploads it to VRAM.

      Returns void

    • 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.

      Returns void