omega-game-engine
    Preparing search index...

    A class to manage the loading, creation, and binding of 2D textures for use in WebGL.

    Hierarchy (View Summary)

    Indexable

    • [key: string]: any
    Index

    Constructors

    Properties

    _className: string
    _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.

    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.

    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.

    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 isImageLoaded(): boolean

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

      Returns boolean

    Methods

    • Binds the texture to the TEXTURE_2D target if it is not already bound.

      Returns void

    • Protected

      Creates the WebGLTexture object from the loaded image data.

      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 an image from the provided URI and creates the WebGL texture.

      Returns Promise<void>

      A Promise that resolves when the image is fully loaded and the WebGL texture is created.

    • 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

    • 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

    • Unbinds the texture from the TEXTURE_2D target if it is currently bound.

      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.