Class WebGLContextWrapper

A wrapper class for WebGL context that provides enhanced functionality and state management. This class handles WebGL state optimization, extension management, and provides convenience methods for common WebGL operations while maintaining compatibility with both WebGL1 and WebGL2.

Constructors

Properties

__extensions: Map<EnumIO, WebGLObject> = ...
__gl: WebGL2RenderingContext
__webglVersion: number = 1
_isWebXRMode: boolean = false
canvas: HTMLCanvasElement
height: number = 0
webgl1ExtBM?: EXT_blend_minmax
webgl1ExtCBF?: WEBGL_color_buffer_float
webgl1ExtCTAstc?: WEBGL_compressed_texture_astc
webgl1ExtCTAtc?: WEBGL_compressed_texture_atc
webgl1ExtCTBptc?: WEBGL_compressed_texture_bptc
webgl1ExtCTEtc?: WEBGL_compressed_texture_etc
webgl1ExtCTEtc1?: WEBGL_compressed_texture_etc1
webgl1ExtCTPvrtc?: WEBKIT_WEBGL_compressed_texture_pvrtc
webgl1ExtCTS3tc?: WEBGL_compressed_texture_s3tc
webgl1ExtDB?: WEBGL_draw_buffers
webgl1ExtDRV?: OES_standard_derivatives
webgl1ExtEIUI?: OES_element_index_uint
webgl1ExtIA?: ANGLE_instanced_arrays
webgl1ExtSTL?: EXT_shader_texture_lod
webgl1ExtTF?: OES_texture_float
webgl1ExtTFA?: EXT_texture_filter_anisotropic
webgl1ExtTFL?: OES_texture_float_linear
webgl1ExtTHF?: OES_texture_half_float
webgl1ExtTHFL?: OES_texture_half_float_linear
webgl1ExtVAO?: OES_vertex_array_object
webgl2ExtCBF?: EXT_color_buffer_float
webgl2ExtCBHF?: EXT_color_buffer_half_float
webgl2ExtCTAstc?: WEBGL_compressed_texture_astc
webgl2ExtCTAtc?: WEBGL_compressed_texture_atc
webgl2ExtCTBptc?: WEBGL_compressed_texture_bptc
webgl2ExtCTEtc?: WEBGL_compressed_texture_etc
webgl2ExtCTEtc1?: WEBGL_compressed_texture_etc1
webgl2ExtCTPvrtc?: WEBKIT_WEBGL_compressed_texture_pvrtc
webgl2ExtCTS3tc?: WEBGL_compressed_texture_s3tc
webgl2ExtClipCtrl?: any
webgl2ExtGmanWM?: any
webgl2ExtMLTVIEW?: WEBGL_multiview
webgl2ExtTFA?: EXT_texture_filter_anisotropic
webgl2ExtTFL?: OES_texture_float_linear
webgl2ExtTHFL?: OES_texture_half_float_linear
width: number = 0

Accessors

Methods

  • Binds a 2D texture to a specific texture unit. Optimized to avoid redundant state changes.

    Parameters

    • activeTextureIndex: number

      The texture unit index

    • texture: WebGLTexture

      The 2D texture to bind

    Returns void

  • Binds a 2D array texture to a specific texture unit. Optimized to avoid redundant state changes.

    Parameters

    • activeTextureIndex: number

      The texture unit index

    • texture: WebGLTexture

      The 2D array texture to bind

    Returns void

  • Binds a cube map texture to a specific texture unit. Optimized to avoid redundant state changes.

    Parameters

    • activeTextureIndex: number

      The texture unit index

    • texture: WebGLTexture

      The cube map texture to bind

    Returns void

  • Binds a sampler object to a specific texture unit. Optimized to avoid redundant state changes.

    Parameters

    • activeTextureIndex: number

      The texture unit index

    • sampler: WebGLSampler

      The sampler object to bind

    Returns void

  • Binds a vertex array object.

    Parameters

    • vao: null | WebGLVertexArrayObjectOES

      The vertex array object to bind, or null to unbind

    Returns void

  • Gets the color attachment constant for a given index.

    Parameters

    • index: number

      The attachment index

    Returns number

    The WebGL color attachment constant

  • Creates a new vertex array object.

    Returns null | WebGLVertexArrayObject

    A new WebGL vertex array object

  • Deletes a vertex array object.

    Parameters

    • vertexArray: WebGLVertexArrayObjectOES | WebGLVertexArrayObject

      The vertex array object to delete

    Returns void

  • Draws arrays with instancing support.

    Parameters

    • primitiveMode: number

      The primitive mode (GL_TRIANGLES, etc.)

    • first: number

      The starting index in the enabled arrays

    • count: number

      The number of vertices to draw

    • instanceCount: number

      The number of instances to draw

    Returns void

  • Draws elements with instancing support.

    Parameters

    • primitiveMode: number

      The primitive mode (GL_TRIANGLES, etc.)

    • indexCount: number

      The number of indices to draw

    • type: number

      The type of the index values

    • offset: number

      The offset in the index buffer

    • instanceCount: number

      The number of instances to draw

    Returns void

  • Gets the maximum uniform block size aligned to the required offset alignment.

    Returns number

    The aligned maximum uniform block size in bytes

  • Type guard to check if the context is WebGL2.

    Parameters

    • gl: WebGLRenderingContext | WebGL2RenderingContext

      The WebGL context to check

    Returns gl is WebGL2RenderingContext

    True if the context is WebGL2, false otherwise

  • Gets the maximum number of uniform blocks that can be used in both vertex and fragment shaders.

    Returns number

    The minimum of vertex and fragment shader uniform block limits

  • Gets the maximum number of uniform vectors available in fragment shaders.

    Returns number

    The maximum fragment uniform vectors

  • Gets the maximum number of uniform vectors available in vertex shaders.

    Returns number

    The maximum vertex uniform vectors

  • Gets the raw WebGL rendering context.

    Returns WebGLRenderingContext | WebGL2RenderingContext

    The underlying WebGL context (WebGL1 or WebGL2)

  • Gets the raw WebGL context cast as WebGL1.

    Returns WebGLRenderingContext

    The underlying WebGL context as WebGL1 type

  • Gets the raw WebGL context cast as WebGL2.

    Returns WebGL2RenderingContext

    The underlying WebGL context as WebGL2 type

  • Gets WebGL memory usage information if the GMAN_WEBGL_MEMORY extension is available.

    Returns any

    Memory information object or undefined if extension is not available

  • Checks if multiview rendering is supported and enabled.

    Returns boolean

    True if multiview is available and enabled for WebVR

  • Checks if a WebGL1 extension is not supported.

    Parameters

    • webGLExtension: EnumIO

      The WebGL extension to check

    Returns boolean

    True if the extension is not supported, false otherwise

  • Checks if a WebGL1 extension is supported.

    Parameters

    • webGLExtension: EnumIO

      The WebGL extension to check

    Returns boolean

    True if the extension is supported, false otherwise

  • Sets the viewport with optimization to avoid redundant state changes.

    Parameters

    • left: number

      Left coordinate of the viewport

    • top: number

      Top coordinate of the viewport

    • width: number

      Width of the viewport

    • height: number

      Height of the viewport

    Returns void

  • Sets the viewport using a Vector4 with optimization to avoid redundant state changes.

    Parameters

    • viewport: Vector4

      Vector4 containing left, top, width, and height

    Returns void

  • Unbinds a 2D texture from a specific texture unit.

    Parameters

    • activeTextureIndex: number

      The texture unit index

    Returns void

  • Unbinds a 2D array texture from a specific texture unit.

    Parameters

    • activeTextureIndex: number

      The texture unit index

    Returns void

  • Unbinds a cube map texture from a specific texture unit.

    Parameters

    • activeTextureIndex: number

      The texture unit index

    Returns void

  • Unbinds all currently bound textures from all texture units. This is useful for cleanup operations.

    Returns void

  • Sets the divisor for instanced rendering for a vertex attribute.

    Parameters

    • index: number

      The index of the vertex attribute

    • divisor: number

      The divisor value (0 for per-vertex, 1+ for per-instance)

    Returns void