Class Context

A WebGL2 rendering context.

Hierarchy

  • Context

Constructors

  • Creates a rendering context.

    Parameters

    • gl: WebGL2RenderingContext

      The rendering context.

    Returns Context

  • Creates a rendering context.

    Parameters

    • canvas: Canvas

      The canvas of the rendering context.

    • Optional alpha: boolean

      Whether the canvas contains an alpha buffer.

    • Optional depth: boolean

      Whether the drawing buffer should have a depth buffer of at least 16 bits.

    • Optional stencil: boolean

      Whether the drawing buffer should have a stencil buffer of at least 8 bits.

    • Optional desynchronized: boolean

      Whether the user agent should reduce latency by desynchronizing the canvas paint cycle from the event loop.

    • Optional antialias: boolean

      Whether or not to perform anti-aliasing if possible.

    • Optional failIfMajorPerformanceCaveat: boolean

      Whether the context will fail to be created if the system performance is low or if no hardware GPU is available.

    • Optional powerPreference: PowerPreference

      Which configuration of GPU is suitable for the context.

    • Optional premultipliedAlpha: boolean

      Whether the page compositor will assume that the drawing buffer contains colors with pre-multiplied alpha.

    • Optional preserveDrawingBuffer: boolean

      Whether the buffers will preserve their values until cleared or overwritten by the author.

    Returns Context

Properties

canvas: Canvas

The canvas of this rendering context.

extensions: Map<Extension, ExtensionObject>

A map of enabled extensions to their names.

internal: WebGL2RenderingContext

This rendering context.

Accessors

  • get doDither(): boolean
  • Whether color components are dithered before they get written to the color buffer.

    Returns boolean

  • set doDither(value): void
  • Whether color components are dithered before they get written to the color buffer.

    Parameters

    • value: boolean

    Returns void

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

    Returns boolean

    See

    GPGPU

  • set doRasterizerDiscard(value): void
  • Whether primitives are discarded immediately before the rasterization stage.

    Parameters

    • value: boolean

    Returns void

    See

    GPGPU

  • get doSampleAlphaToCoverage(): boolean
  • Whether a temporary coverage value is computed based on the alpha value.

    Returns boolean

  • set doSampleAlphaToCoverage(value): void
  • Whether a temporary coverage value is computed based on the alpha value.

    Parameters

    • value: boolean

    Returns void

  • get scissorBox(): undefined | Box
  • The scissor box, which limits drawing to a specified rectangle. Disabled if not defined.

    Returns undefined | Box

    See

    scissor

  • set scissorBox(value): void
  • The scissor box, which limits drawing to a specified rectangle. Disabled if not defined.

    Parameters

    • value: undefined | Box

    Returns void

    See

    scissor

  • get viewport(): Box
  • The viewport box, which specifies the affine transformation of coordinates from normalized device coordinates to window coordinates.

    Returns Box

  • set viewport(value): void
  • The viewport box, which specifies the affine transformation of coordinates from normalized device coordinates to window coordinates.

    Parameters

    Returns void

Methods

  • Clears the specified buffers to the specified values.

    Parameters

    • Optional color: ColorLike

      The color to clear the color buffer to, if any.

    • Optional depth: number

      The value to clear the depth buffer to, if any.

    • Optional stencil: number

      The value to clear the stencil buffer to, if any.

    Returns void

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

    Returns boolean

    Whether the drawing buffer was resized.

  • Resizes this context's viewport to match the size of its current drawing buffer.

    Returns void

  • Makes this context XR-compatible.

    Returns Promise<void>

    A promise that resolves once the WebGL context is ready to be used for rendering WebXR content.

  • Resizes this context's canvas' drawing buffer to match its physical size, a viewport to match the drawing buffer, and disables the scissor test.

    Returns boolean

    Whether the drawing buffer was resized.

  • Resizes this context's canvas' drawing buffer to match its physical size, the context's viewport and scissor box to match the given size, and enables the scissor test.

    Parameters

    • x: number

      The horizontal offset of the viewport and scissor box.

    • y: number

      The vertical offset of the viewport and scissor box.

    • width: number

      The horizontal size of the viewport and scissor box.

    • height: number

      The vertical size of the viewport and scissor box.

    Returns boolean

    Whether the drawing buffer was resized.

Generated using TypeDoc