omega-game-engine
    Preparing search index...

    A class for managing the loading, creation, and binding of a cubemap texture for use in WebGL.

    • It handles six individual images (one for each face of the cube) and combines them into a single cubemap texture object.

    Hierarchy (View Summary)

    Indexable

    • [key: string]: any
    Index

    Constructors

    • Creates an instance of CubeMapTexture. *

      Parameters

      • Optionalgl: WebGL2RenderingContext

        The WebGL2 rendering context. *

      • OptionaltextureUris: string[]

        An array of six URIs for the cube map faces in the order: right, left, top, bottom, front, back.

      Returns CubemapTexture

    Properties

    _className: string = "CubemapTexture"
    _glTexture: null | WebGLTexture = null

    The WebGL texture object.

    _height: number = 0

    The height of the texture in pixels.

    _isBound: boolean = false

    A flag to indicate if the texture is currently in a bound state.

    _loadPromise: null | Promise<void> = null

    A promise that resolves when the texture is fully loaded.

    _serializationIgnoreKeys: string[]
    _uuid: string
    _width: number = 0

    The width of the texture in pixels.

    gl?: WebGL2RenderingContext

    The WebGL2 rendering context. *

    image: null | HTMLImageElement = null

    The HTML image element that contains the texture data.

    imagesData: HTMLImageElement[] = []

    An array to hold the HTML image elements for each of the six faces. * *

    isLoaded: boolean = false

    Indicates whether the image data has been loaded.

    isLoading: boolean = false

    Indicates whether the texture is currently in the process of loading.

    isWhiteCubemap: boolean = false

    Flag indicating if this texture is a procedurally generated white fallback cubemap.

    magFilter: TextureFilterMode = TextureFilterMode.LINEAR

    The magnification filter.

    minFilter: TextureFilterMode = TextureFilterMode.LINEAR_MIPMAP_LINEAR

    The minification filter.

    name: string = ''
    textureUri?: string

    The URI of the image to load.

    textureUris?: string[]

    An array of six URIs for the cube map faces in the order: right, left, top, bottom, front, back.

    wrapS: TextureWrapMode = TextureWrapMode.MIRRORED_REPEAT

    The texture wrap mode for the S (horizontal) axis.

    wrapT: TextureWrapMode = TextureWrapMode.MIRRORED_REPEAT

    The texture wrap mode for the T (vertical) axis.

    Accessors

    • get glTexture(): null | WebGLTexture

      Gets the WebGLTexture object.

      Returns null | WebGLTexture

    • get height(): number

      Gets the height of the texture.

      Returns number

    • get isImageLoaded(): boolean

      Checks if the image data has been successfully loaded into the HTMLImageElement.

      Returns boolean

    • get width(): number

      Gets the width of the texture.

      Returns number

    Methods

    • Protected

      Checks if all image fetch operations have completed, regardless of success. * *

      Returns boolean

      • True if all fetch attempts are done, otherwise false.
    • Protected

      Checks if all images have been successfully fetched and loaded. * *

      Returns boolean

      • True if all images are loaded, otherwise false.
    • Protected

      Creates the WebGLTexture object from the six loaded images. * * *

      Parameters

      • gl: WebGL2RenderingContext

        The WebGL2 rendering context. *

      Returns void

    • Reads the pixels from the texture and returns them as a Uint8Array. NOTE: This function requires the texture to be attached to a framebuffer object (FBO). A more complete implementation would handle FBO creation and binding.

      Parameters

      • width: number

        The width of the texture to read.

      • height: number

        The height of the texture to read.

      Returns null | Uint8Array<ArrayBufferLike>

      A Uint8Array containing the pixel data, or null if an error occurred.

    • Loads all six images from their respective URLs. * *

      Returns Promise<void>

      • A Promise that resolves when all images are loaded.
    • Re-uploads the texture data to the GPU. This is useful if the underlying image or data has changed.

      Returns void

    • Sets the WebGL2 rendering context for the texture.

      Parameters

      • gl: WebGL2RenderingContext

        The WebGL2 rendering context.

      Returns void

    • Updates the loading status of a single image and triggers the creation of the WebGL texture if all images are loaded. *

      Parameters

      • imageIndex: number

        The index of the image that has finished loading. *

      • wasLoaded: boolean

        A boolean indicating if the image loaded successfully. *

      Returns void

    • Sets a sub-region of the texture's pixels.

      Parameters

      • x: number

        The x-coordinate of the sub-region to update.

      • y: number

        The y-coordinate of the sub-region to update.

      • width: number

        The width of the sub-region.

      • height: number

        The height of the sub-region.

      • data: ArrayBufferView<ArrayBufferLike> | TexImageSource

        The pixel data to upload.

      Returns void

    • Sets the texture filtering and wrapping parameters for the texture. This method applies the values stored in the class properties to the GPU.

      Returns void

    • Sets the URIs for the six faces of the cubemap texture. *

      Parameters

      • uris: string[]

        An array of six URIs. *

      Returns void

    • Creates and returns a texture with a specified color and size. This is useful for creating fallback textures or solid colors.

      Parameters

      • gl: WebGL2RenderingContext

        The WebGL2 rendering context.

      • width: number

        The width of the texture.

      • height: number

        The height of the texture.

      • Optionalcolor: null | Uint8Array<ArrayBufferLike> = null

        An optional array of color data. If not provided, a single white pixel is used.

      Returns Texture

      A new Texture instance.

    • Creates a new texture specifically for depth information (e.g., for shadow mapping).

      Parameters

      • gl: WebGL2RenderingContext

        The WebGL2 rendering context.

      • width: number

        The width of the texture.

      • height: number

        The height of the texture.

      Returns Texture

      A new Texture instance configured as a depth texture.

    • Creates a 1x1 cubemap texture filled with white pixels for each face. This is useful as a default or fallback cubemap.

      Parameters

      • gl: WebGL2RenderingContext

        The WebGL2 rendering context.

      Returns CubemapTexture

      A new CubemapTexture instance containing the white pixels.