Class Texture_EX

Hierarchy

  • Texture
    • Texture_EX

Constructors

  • Create a new Texture instance.

    Example

    // Create a 8x8x24-bit texture
    var texture = new pc.Texture(graphicsDevice, {
    width: 8,
    height: 8,
    format: pc.PIXELFORMAT_R8_G8_B8
    });

    // Fill the texture with a gradient
    var pixels = texture.lock();
    var count = 0;
    for (var i = 0; i < 8; i++) {
    for (var j = 0; j < 8; j++) {
    pixels[count++] = i * 32;
    pixels[count++] = j * 32;
    pixels[count++] = 255;
    }
    }
    texture.unlock();

    Parameters

    • graphicsDevice: GraphicsDevice

      The graphics device used to manage this texture.

    • Optional options: { addressU?: number; addressV?: number; addressW?: number; anisotropy?: number; compareFunc?: number; compareOnRead?: boolean; cubemap?: boolean; depth?: number; fixCubemapSeams?: boolean; flipY?: boolean; format?: number; height?: number; levels?: Uint8Array[]; magFilter?: number; minFilter?: number; mipmaps?: boolean; name?: string; premultiplyAlpha?: boolean; projection?: string; type?: string; volume?: boolean; width?: number }

      Object for passing optional arguments.

      • Optional addressU?: number

        The repeat mode to use in the U direction. Defaults to ADDRESS_REPEAT.

      • Optional addressV?: number

        The repeat mode to use in the V direction. Defaults to ADDRESS_REPEAT.

      • Optional addressW?: number

        The repeat mode to use in the W direction. Defaults to ADDRESS_REPEAT.

      • Optional anisotropy?: number

        The level of anisotropic filtering to use. Defaults to 1.

      • Optional compareFunc?: number

        Comparison function when compareOnRead is enabled (WebGL2 only). Can be:

        • FUNC_LESS
        • FUNC_LESSEQUAL
        • FUNC_GREATER
        • FUNC_GREATEREQUAL
        • FUNC_EQUAL
        • FUNC_NOTEQUAL

        Defaults to FUNC_LESS.

      • Optional compareOnRead?: boolean

        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 (WebGL2 only). Defaults to false.

      • Optional cubemap?: boolean

        Specifies whether the texture is to be a cubemap. Defaults to false.

      • Optional depth?: number

        The number of depth slices in a 3D texture (WebGL2 only). Defaults to 1 (single 2D image).

      • Optional fixCubemapSeams?: boolean

        Specifies whether this cubemap texture requires special seam fixing shader code to look right. Defaults to false.

      • Optional flipY?: boolean

        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.

      • Optional format?: number

        The pixel format of the texture. Can be:

        • PIXELFORMAT_A8
        • PIXELFORMAT_L8
        • PIXELFORMAT_L8_A8
        • PIXELFORMAT_R5_G6_B5
        • PIXELFORMAT_R5_G5_B5_A1
        • PIXELFORMAT_R4_G4_B4_A4
        • PIXELFORMAT_R8_G8_B8
        • PIXELFORMAT_R8_G8_B8_A8
        • PIXELFORMAT_DXT1
        • PIXELFORMAT_DXT3
        • PIXELFORMAT_DXT5
        • PIXELFORMAT_RGB16F
        • PIXELFORMAT_RGBA16F
        • PIXELFORMAT_RGB32F
        • PIXELFORMAT_RGBA32F
        • PIXELFORMAT_ETC1
        • PIXELFORMAT_PVRTC_2BPP_RGB_1
        • PIXELFORMAT_PVRTC_2BPP_RGBA_1
        • PIXELFORMAT_PVRTC_4BPP_RGB_1
        • PIXELFORMAT_PVRTC_4BPP_RGBA_1
        • PIXELFORMAT_111110F
        • PIXELFORMAT_ASTC_4x4>/li>
        • PIXELFORMAT_ATC_RGB
        • PIXELFORMAT_ATC_RGBA

        Defaults to PIXELFORMAT_R8_G8_B8_A8.

      • Optional height?: number

        The height of the texture in pixels. Defaults to 4.

      • Optional levels?: Uint8Array[]

        Array of Uint8Array.

      • Optional magFilter?: number

        The magnification filter type to use. Defaults to FILTER_LINEAR.

      • Optional minFilter?: number

        The minification filter type to use. Defaults to FILTER_LINEAR_MIPMAP_LINEAR.

      • Optional mipmaps?: boolean

        When enabled try to generate or use mipmaps for this texture. Default is true.

      • Optional name?: string

        The name of the texture.

      • Optional premultiplyAlpha?: boolean

        If true, the alpha channel of the texture (if present) is multiplied into the color channels. Defaults to false.

      • Optional projection?: string

        The projection type of the texture, used when the texture represents an environment. Can be:

        • TEXTUREPROJECTION_NONE
        • TEXTUREPROJECTION_CUBE
        • TEXTUREPROJECTION_EQUIRECT
        • TEXTUREPROJECTION_OCTAHEDRAL

        Defaults to TEXTUREPROJECTION_CUBE if options.cubemap is specified, otherwise TEXTUREPROJECTION_NONE.

      • Optional type?: string

        Specifies the image type, see TEXTURETYPE_DEFAULT.

      • Optional volume?: boolean

        Specifies whether the texture is to be a 3D volume (WebGL2 only). Defaults to false.

      • Optional width?: number

        The width of the texture in pixels. Defaults to 4.

    Returns Texture_EX

Properties

_addressU: number
_addressV: number
_addressW: number
_anisotropy: number
_compareFunc: any
_compareOnRead: boolean
_compressed: boolean
_cubemap: boolean
_depth: number
_flipY: boolean
_format: number
_gpuSize: number
_height: number
_invalid: boolean
_isRenderTarget: boolean
_levels: Uint8Array[] | any[][]
_levelsUpdated: boolean[] | boolean[][]
_lockedLevel: number
_magFilter: number
_minFilter: number
_mipmaps: any
_mipmapsUploaded: boolean
_needsMipmapsUpload: any
_needsUpload: boolean
_parameterFlags: number
_pixelData: Uint8ClampedArray
_premultiplyAlpha: boolean
_volume: boolean
_width: number
device: GraphicsDevice
fixCubemapSeams: boolean
id: number
impl: any
name: string

The name of the texture. Defaults to null.

profilerHint: any
projection: string
type: string

Accessors

  • get addressU(): number
  • Returns number

  • set addressU(arg: number): void
  • The addressing mode to be applied to the texture horizontally. Can be:

    • ADDRESS_REPEAT
    • ADDRESS_CLAMP_TO_EDGE
    • ADDRESS_MIRRORED_REPEAT

    Parameters

    • arg: number

    Returns void

  • get addressV(): number
  • Returns number

  • set addressV(arg: number): void
  • The addressing mode to be applied to the texture vertically. Can be:

    • ADDRESS_REPEAT
    • ADDRESS_CLAMP_TO_EDGE
    • ADDRESS_MIRRORED_REPEAT

    Parameters

    • arg: number

    Returns void

  • get addressW(): number
  • Returns number

  • set addressW(arg: number): void
  • The addressing mode to be applied to the 3D texture depth (WebGL2 only). Can be:

    • ADDRESS_REPEAT
    • ADDRESS_CLAMP_TO_EDGE
    • ADDRESS_MIRRORED_REPEAT

    Parameters

    • arg: number

    Returns void

  • get anisotropy(): number
  • Returns number

  • set anisotropy(arg: number): void
  • Integer value specifying the level of anisotropic to apply to the texture ranging from 1 (no anisotropic filtering) to the GraphicsDevice property maxAnisotropy.

    Parameters

    • arg: number

    Returns void

  • get autoMipmap(): any
  • Returns any

  • get compareFunc(): any
  • Returns any

  • set compareFunc(arg: any): void
  • Comparison function when compareOnRead is enabled (WebGL2 only). Possible values:

    • FUNC_LESS
    • FUNC_LESSEQUAL
    • FUNC_GREATER
    • FUNC_GREATEREQUAL
    • FUNC_EQUAL
    • FUNC_NOTEQUAL

    Parameters

    • arg: any

    Returns void

  • get compareOnRead(): boolean
  • Returns boolean

  • set compareOnRead(arg: 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 (WebGL2 only).

    Parameters

    • arg: 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 (WebGL2 only).

    Returns number

  • get encoding(): "srgb" | "linear" | "rgbm" | "rgbe" | "rgbp"
  • Returns "srgb" | "linear" | "rgbm" | "rgbe" | "rgbp"

  • get flipY(): boolean
  • Returns boolean

  • set flipY(arg: boolean): void
  • 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 true.

    Parameters

    • arg: boolean

    Returns void

  • get format(): number
  • The pixel format of the texture. Can be:

    • PIXELFORMAT_A8
    • PIXELFORMAT_L8
    • PIXELFORMAT_L8_A8
    • PIXELFORMAT_R5_G6_B5
    • PIXELFORMAT_R5_G5_B5_A1
    • PIXELFORMAT_R4_G4_B4_A4
    • PIXELFORMAT_R8_G8_B8
    • PIXELFORMAT_R8_G8_B8_A8
    • PIXELFORMAT_DXT1
    • PIXELFORMAT_DXT3
    • PIXELFORMAT_DXT5
    • PIXELFORMAT_RGB16F
    • PIXELFORMAT_RGBA16F
    • PIXELFORMAT_RGB32F
    • PIXELFORMAT_RGBA32F
    • PIXELFORMAT_ETC1
    • PIXELFORMAT_PVRTC_2BPP_RGB_1
    • PIXELFORMAT_PVRTC_2BPP_RGBA_1
    • PIXELFORMAT_PVRTC_4BPP_RGB_1
    • PIXELFORMAT_PVRTC_4BPP_RGBA_1
    • PIXELFORMAT_111110F
    • PIXELFORMAT_ASTC_4x4>/li>
    • PIXELFORMAT_ATC_RGB
    • PIXELFORMAT_ATC_RGBA

    Returns number

  • get gpuSize(): number
  • Returns number

  • get height(): number
  • The height of the texture in pixels.

    Returns number

  • get magFilter(): number
  • Returns number

  • set magFilter(arg: number): void
  • The magnification filter to be applied to the texture. Can be:

    • FILTER_NEAREST
    • FILTER_LINEAR

    Parameters

    • arg: number

    Returns void

  • get minFilter(): number
  • Returns number

  • set minFilter(arg: number): void
  • The minification filter to be applied to the texture. Can be:

    • FILTER_NEAREST
    • FILTER_LINEAR
    • FILTER_NEAREST_MIPMAP_NEAREST
    • FILTER_NEAREST_MIPMAP_LINEAR
    • FILTER_LINEAR_MIPMAP_NEAREST
    • FILTER_LINEAR_MIPMAP_LINEAR

    Parameters

    • arg: number

    Returns void

  • get mipmaps(): any
  • Returns any

  • set mipmaps(arg: any): void
  • Defines if texture should generate/upload mipmaps if possible.

    Parameters

    • arg: any

    Returns void

  • get pot(): boolean
  • Returns true if all dimensions of the texture are power of two, and false otherwise.

    Returns boolean

  • get premultiplyAlpha(): boolean
  • Returns boolean

  • set premultiplyAlpha(arg: boolean): void
  • Parameters

    • arg: boolean

    Returns void

  • 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

  • Returns void

  • 获得该贴图的像素数据

    Returns

    贴图的像素数据

    Returns Uint8ClampedArray

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

    Returns

    The source image of this texture. Can be null if source not assigned for specific image level.

    Parameters

    • Optional mipLevel: number

      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

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

    Returns

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

    Parameters

    • Optional options: { face?: number; level?: number; mode?: number }

      Optional options object. Valid properties are as follows:

      • Optional face?: number

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

      • Optional level?: number

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

      • Optional mode?: number

        The lock mode. Can be:

        • TEXTURELOCK_READ
        • TEXTURELOCK_WRITE Defaults to TEXTURELOCK_WRITE.

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

    Parameters

    • source: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement | HTMLCanvasElement[] | HTMLImageElement[] | HTMLVideoElement[]

      A canvas, image or video element, or an array of 6 canvas, image or video elements.

    • Optional mipLevel: number

      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 void

  • 根据uv读取贴图的颜色值

    Returns

    Parameters

    • uv: { x: number; y: number }

      uv值

      • x: number
      • y: number
    • Optional color: Color

      颜色值(不传则创建新的颜色)

    Returns Color

  • 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