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.

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

The name of the texture.

Accessors

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