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:

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: number
_storage: boolean = false
id: number = ...
name: string

The name of the texture.

Accessors

  • 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

  • set srgb(value: boolean): void

    Sets the texture's internal format to an sRGB or linear equivalent of its current format. When set to true, the texture is stored in sRGB format and automatically converted to linear space when sampled. When set to false, the texture remains in a linear format. Changing this property recreates the texture on the GPU, which is an expensive operation, so it is preferable to create the texture with the correct format from the start. If the texture format has no sRGB variant, this operation is ignored.

    Parameters

    • value: boolean

    Returns void

Methods

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

  • 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