Class Context

A WebGL2 rendering context.

Hierarchy (View Summary)

Constructors

  • Create a wrapper for a WebGL2 rendering context.

    Parameters

    • gl: WebGL2RenderingContext

      The rendering context.

    Returns Context

    DuplicateContextError if a Context already exists for gl.

  • Create a WebGL2 rendering context.

    Parameters

    • canvas: HTMLCanvasElement | OffscreenCanvas

      The canvas of the rendering context.

    • Optionaloptions: WebGLContextAttributes

      The options to create the rendering context with if necessary.

    • OptionaldoPrefillCache: boolean

      Whether or not cached values should be prefilled with their default values. It is recommended that this is set to true unless the rendering context may have been modified prior to the creation of this object.

    Returns Context

    UnsupportedOperationError if a WebGL2 context cannot be created.

    DuplicateContextError if a Context already exists for canvas.

Properties

canvas: HTMLCanvasElement | OffscreenCanvas

The canvas of this rendering context.

Accessors

  • get doRasterizerDiscard(): boolean
  • Whether or not primitives are discarded immediately before the rasterization stage.

    Returns boolean

  • set doRasterizerDiscard(value: boolean): void
  • Parameters

    • value: boolean

    Returns void

  • get doScissorTest(): boolean
  • Whether or not the scissor test is enabled.

    Returns boolean

  • set doScissorTest(value: boolean): void
  • Parameters

    • value: boolean

    Returns void

  • get drawingBufferColorSpace(): PredefinedColorSpace
  • The color space of the drawing buffer of this rendering context.

    Returns PredefinedColorSpace

  • set drawingBufferColorSpace(value: PredefinedColorSpace): void
  • Parameters

    • value: PredefinedColorSpace

    Returns void

  • get maxCombinedTextureImageUnits(): number
  • The maximum number of texture units that can be used. Effectively all systems support at least 8.

    Returns number

  • get unpackAlignment(): 1 | 2 | 4 | 8
  • The alignment to use when unpacking pixel data from memory.

    Returns 1 | 2 | 4 | 8

  • set unpackAlignment(value: 1 | 2 | 4 | 8): void
  • Parameters

    • value: 1 | 2 | 4 | 8

    Returns void

Methods

  • Clear the specified buffers to the specified values.

    Parameters

    • color: boolean | Color = true

      The value to clear the color buffer to or a boolean to use the previous clear color.

    • depth: number | boolean = true

      The value to clear the depth buffer to or a boolean to use the previous clear depth.

    • stencil: number | boolean = true

      The value to clear the stencil buffer to or a boolean to use the previous clear stencil.

    • framebuffer: null | Framebuffer = null

      The framebuffer to clear, or null for the default framebuffer (canvas).

    Returns void

    clear

  • Resize this rendering context's canvas' drawing buffer to match its physical size.

    Returns boolean

    Whether or not the drawing buffer was resized.

  • Resize this rendering context's viewport to match the size of a drawing buffer.

    Parameters

    • Optionalframebuffer: Framebuffer

      The framebuffer to fit the size of, or undefined for the default framebuffer (canvas).

    Returns void

    BadValueError if the framebuffer is larger than MAX_VIEWPORT_DIMS.

  • Resize this rendering context's canvas' drawing buffer to match its physical size and resizes the viewport to match the given framebuffer.

    Parameters

    • Optionalframebuffer: Framebuffer

      The framebuffer to fit the size of, or undefined for the default framebuffer (canvas).

    Returns boolean

    Whether or not the drawing buffer was resized.

    BadValueError if the framebuffer is larger than MAX_VIEWPORT_DIMS.

  • Resize this rendering context's canvas' drawing buffer to match its physical size and resizes the viewport to match the given size.

    Parameters

    • rectangle: Rectangle

      The rectangle that represents the viewport.

    Returns boolean

    Whether or not the drawing buffer was resized.

    BadValueError if the rectangle is larger than MAX_VIEWPORT_DIMS.

  • Throw a JavaScript error if a WebGL error has occurred.

    Returns void

    WebglError if a WebGL error has occurred.

  • Create a Context or get an existing Context if one already exists for the given rendering context. This is preferable to calling the Context constructor in cases where multiple Contexts may be created for the same canvas (i.e. in a Next.js page).

    Parameters

    • gl: WebGL2RenderingContext

      The rendering context.

    Returns Context

    A rendering context.

  • Create a Context or get an existing Context if one already exists for the given canvas. This is preferable to calling the Context constructor in cases where multiple Contexts may be created for the same canvas (i.e. in a Next.js page).

    Parameters

    • canvas: HTMLCanvasElement | OffscreenCanvas

      The canvas of the rendering context.

    • Optionaloptions: WebGLContextAttributes

      The options to create the rendering context with if necessary.

    • OptionaldoPrefillCache: boolean

      Whether or not cached values should be prefilled with their default values. It is recommended that this is set to true unless the rendering context may have been modified prior to the creation of this object.

    Returns Context

    A rendering context.