Class: WebGLContext

WebGLContext(canvas)

Wrapper around a WebGL2 rendering context and its canvas. Responsible for: - creating and validating the WebGL2 context - managing the canvas size and viewport - clearing the color and depth buffers

Constructor

new WebGLContext(canvas)

Creates a new WebGLContext bound to the provided canvas element.
Parameters:
Name Type Description
canvas HTMLCanvasElement Target canvas element used for WebGL rendering.
Source:
Throws:
  • If the provided value is not an HTMLCanvasElement.
    Type
    TypeError
  • If WebGL2 is not supported by the browser.
    Type
    Error

Classes

WebGLContext

Members

context

Returns the underlying `WebGL2RenderingContext` for direct low-level access.
Source:

Methods

clear()

Clears both the color and depth buffers using the current clear color.
Source:

resizeToDisplaySize(optionsopt) → {boolean}

Resizes the underlying canvas drawing buffer to match its display size and updates the viewport.
Parameters:
Name Type Attributes Description
options ResizeToDisplaySizeOptions <optional>
Optional resize options.
Source:
Returns:
- True if the canvas was resized, false otherwise.
Type
boolean

(static) setDefaultClearColor(red, green, blue, alpha)

Sets the default clear color used when initializing new WebGLContext instances.
Parameters:
Name Type Description
red number Red component , from 0 to 1.
green number Green component , from 0 to 1.
blue number Blue component , from 0 to 1.
alpha number Alpha component , from 0 to 1.
Source:
Throws:
  • If any component is not a number.
    Type
    TypeError
  • If any component is outside the [0, 1] range.
    Type
    RangeError

(static) setDepthTestEnabled(enabled)

Enables or disables depth testing for all future WebGLContext instances.
Parameters:
Name Type Description
enabled boolean Whether depth testing should be enabled.
Source:
Throws:
If the provided value is not a boolean.
Type
TypeError