Taos API Reference
    Preparing search index...

    Class Texture

    Owns a GPUTexture and a default GPUTextureView of the matching dimension.

    Callers must invoke destroy() to release the underlying GPU memory.

    Index

    Constructors

    Properties

    gpuTexture: GPUTexture

    Methods

    • Creates a 1x1 rgba8unorm texture filled with the given color.

      Parameters

      • device: GPUDevice

        The WebGPU device.

      • r: number

        Red component, 0-255.

      • g: number

        Green component, 0-255.

      • b: number

        Blue component, 0-255.

      • a: number = 255

        Alpha component, 0-255 (defaults to 255).

      Returns Texture

      A new Texture owning the 1x1 GPU texture.

    • Uploads an ImageBitmap as a 2D texture.

      Parameters

      • device: GPUDevice

        The WebGPU device.

      • bitmap: ImageBitmap

        Source image (typically from createImageBitmap).

      • options: { srgb?: boolean; usage?: number; mipLevelCount?: number } = {}

        srgb=true selects rgba8unorm-srgb so the GPU linearizes on sample; usage adds extra usage flags on top of the standard binding/copy/render set; mipLevelCount>1 allocates a mip chain and box-downsamples it on the GPU after upload.

      Returns Texture

      A new Texture owning the uploaded 2D image.

    • Uploads a pre-decoded (optionally block-compressed) 2D texture, one mip level at a time. Used for KTX2/Basis textures transcoded by transcodeKtx2: levels[0] is full resolution, each subsequent entry a half-size mip. Block-compressed formats compute bytesPerRow from the 4×4 block size; rgba8unorm[-srgb] uses the uncompressed width×4 stride.

      Parameters

      • device: GPUDevice

        The WebGPU device.

      • data: {
            format: GPUTextureFormat;
            width: number;
            height: number;
            levels: Uint8Array<ArrayBuffer>[];
        }

        format (GPU texture format), pixel width/height, and one byte array per mip level.

      Returns Texture

      A new Texture owning the uploaded image.

    • Fetches an image URL and uploads it as a 2D GPU texture.

      Use srgb=true for albedo/color maps; keep false for normal/ORM maps.

      Parameters

      • device: GPUDevice

        The WebGPU device.

      • url: string

        URL to fetch the image from.

      • options: {
            srgb?: boolean;
            resizeWidth?: number;
            resizeHeight?: number;
            usage?: number;
            generateMips?: boolean;
        } = {}

        srgb enables rgba8unorm-srgb; resizeWidth/resizeHeight resize the bitmap before upload; usage adds extra usage flags (e.g. COPY_SRC); generateMips allocates and box-downsamples a full mip chain (needed so the texture minifies cleanly instead of aliasing at distance).

      Returns Promise<Texture>

      A Texture containing the uploaded image.