@lakuna/ugl
    Preparing search index...

    Class Context

    A WebGL2 rendering context.

    Hierarchy (View Summary)

    Index

    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 attributes(): null | WebGLContextAttributes

      The attributes of this rendering context, or null if this rendering context is lost.

      Returns null | WebGLContextAttributes

    • get doPolygonOffsetFill(): boolean

      Whether or not adding an offset to depth values of polygon fragments is enabled.

      Returns boolean

    • set doPolygonOffsetFill(value: boolean): void

      Parameters

      • value: boolean

      Returns void

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

      Whether or not to compute the computation of a temporary coverage value determined by the alpha value.

      Returns boolean

    • set doSampleAlphaToCoverage(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get doSampleCoverage(): boolean

      Whether or not to AND the fragment's coverage with the temporary coverage value.

      Returns boolean

    • set doSampleCoverage(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 maxViewportDims(): Pair

      The maximum dimensions of the viewport. Effectively all systems support at least [4096, 4096].

      Returns Pair

    • get packAlignment(): 1 | 2 | 4 | 8

      The alignment to use when packing pixel data into memory.

      Returns 1 | 2 | 4 | 8

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

      Parameters

      • value: 1 | 2 | 4 | 8

      Returns void

    • get polygonOffsetUnits(): number

      The multiplier with which an implementation-specific value is multiplied to create a constant depth offset.

      Returns number

    • set polygonOffsetUnits(value: number): void

      Parameters

      • value: number

      Returns void

    • 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.

    • Empty different buffer commands, causing all commands to be executed as quickly as possible.

      Returns void

      flush

    • Read pixels from a framebuffer.

      Parameters

      • Optionalframebuffer: null | Framebuffer

        The framebuffer to read pixels from, or null for the default framebuffer. Defaults to the default framebuffer.

      • Optionalrectangle: Rectangle

        The rectangle of pixels to read. Defaults to the entire read buffer.

      • Optionalrgba: boolean

        Whether to output RGBA data (as opposed to using the format of the read buffer). Defaults to false.

      • OptionalpackAlignment: 1 | 2 | 4 | 8

        The alignment to use when packing the data, or undefined to let this be automatically determined.

      • Optionalout: undefined

        The buffer or typed array to store the pixel data in.

      • Optionaloffset: number

        The offset at which to start storing pixel data in the buffer or typed array.

      Returns ArrayBufferView

      A typed array of pixel data.

    • Read pixels from a framebuffer.

      Type Parameters

      Parameters

      • framebuffer: null | Framebuffer

        The framebuffer to read pixels from, or null for the default framebuffer. Defaults to the default framebuffer.

      • rectangle: undefined | Rectangle

        The rectangle of pixels to read. Defaults to the entire read buffer.

      • rgba: undefined | boolean

        Whether to output RGBA data (as opposed to using the format of the read buffer). Defaults to false.

      • packAlignment: undefined | 1 | 2 | 4 | 8

        The alignment to use when packing the data, or undefined to let this be automatically determined.

      • out: T

        The buffer or typed array to store the pixel data in.

      • Optionaloffset: number

        The offset at which to start storing pixel data in the buffer or typed array.

      Returns T

      The buffer or typed array to store the pixel data in.

      Error if the given buffer or typed array is too small to store the selected data.

    • 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.