WebGL Context Options

The first step to create 3D graphics in a HTML canvas is to retrieve a WebGL context object, WebGLRenderingContext, by calling canvas.getContext('webgl', options). The options parameter sets properties of the “context” at the time of its creation. Only the options that are different from their defaults need to be specified. Options can’t be changed later; they must be set when the context is created. For example:

let gl = canvas.getContext('webgl', { antialias: false,
                                      depth: false } );

creates a WebGLRenderingContext object and assigns it to the variable gl while changing the values for the antialias and depth options. To leave all of the options to their default values, simply leave off the options parameter, as in:

let gl = canvas.getContext('webgl');

The options, as described by https://www.khronos.org/registry/webgl/specs/1.0/#5.2.1, are:

Next Section - Textbook References