The following list describes each attribute in the WebGLContextAttributes object and its use. The default value for each attribute is shown
above. The default value is used either if no second parameter is passed to getContext, or if a user object is passed which has no
attribute of the given name.
alpha
If the value is true, the drawing buffer has an alpha channel for the purposes of performing OpenGL destination alpha operations and
compositing with the page. If the value is false, no alpha buffer is available.
depth
If the value is true, the drawing buffer has a depth buffer of at least 16 bits. If the value is false, no depth buffer is available.
stencil
If the value is true, the drawing buffer has a stencil buffer of at least 8 bits. If the value is false, no stencil buffer is available.
antialias
If the value is true and the implementation supports antialiasing the drawing buffer will perform antialiasing using its choice of
technique (multisample/supersample) and quality. If the value is false or the implementation does not support antialiasing, no
antialiasing is performed.
premultipliedAlpha
If the value is true the page compositor will assume the drawing buffer contains colors with premultiplied alpha. If the value is false the
page compositor will assume that colors in the drawing buffer are not premultiplied. This flag is ignored if the alpha flag is false. See
Premultiplied Alpha for more information on the effects of the premultipliedAlpha flag.
preserveDrawingBuffer
If false, once the drawing buffer is presented as described in theDrawing Buffer section, the contents of the drawing buffer are cleared
to their default values. All elements of the drawing buffer (color, depth and stencil) are cleared. If the value is true the buffers will not
be cleared and will preserve their values until cleared or overwritten by the author.
On some hardware setting the preserveDrawingBuffer flag to true can have significant performance implications.
powerPreference
Provides a hint to the user agent indicating what configuration of GPU is suitable for this WebGL context. This may influence which
GPU is used in a system with multiple GPUs. For example, a dual-GPU system might have one GPU that consumes less power at the
expense of rendering performance. Note that this property is only a hint and a WebGL implementation may choose to ignore it.
WebGL implementations use context lost and restored events to regulate power and memory consumption, regardless of the value of
this attribute. At WebGLRenderingContext creation time, this attribute will be ignored if no event listeners exist which would handle
both "webglcontextlost" and "webglcontextrestored" events dispatched to the canvas element.
The allowed values are:
default
Let the user agent decide which GPU configuration is most suitable. This is the default value.
high-performance
Indicates a request for a GPU configuration that prioritizes rendering performance over power consumption. Any content that
chooses this value should be aware that it is more likely that the user agent will force a lost context at any time. Implementations
may decide to initially respect this request and, after some time, lose the context and restore a new context ignoring the request.
Developers are encouraged to only specify this value if they believe it is absolutely necessary, since it may significantly decrease
battery life on mobile devices.
low-power
Indicates a request for a GPU configuration that prioritizes power saving over rendering performance. Generally, content should
use this if it is unlikely to be constrained by drawing performance; for example, if it renders only one frame per second, draws only
relatively simple geometry with simple shaders, or uses a small HTML canvas element. Developers are encouraged to use this
value if their content allows, since it may significantly improve battery life on mobile devices.
failIfMajorPerformanceCaveat
If the value is true, context creation will fail if the implementation determines that the performance of the created WebGL context
would be dramatically lower than that of a native application making equivalent OpenGL calls. This could happen for a number of
reasons, including:
An implementation might switch to a software rasterizer if the user's GPU driver is known to be unstable.
An implementation might require reading back the framebuffer from GPU memory to system memory before compositing it with
the rest of the page, significantly reducing performance.
Applications that don't require high performance should leave this parameter at its default value of false. Applications that require
high performance may set this parameter to true, and if context creation fails then the application may prefer to use a fallback
rendering path such as a 2D canvas context. Alternatively the application can retry WebGL context creation with this parameter set to
false, with the knowledge that a reduced-fidelity rendering mode should be used to improve performance.
Here is an ECMAScript example which passes a WebGLContextAttributes argument to getContext. It assumes the presence of a
canvas element named "canvas1" on the page.
var canvas = document.getElementById('canvas1');
var context = canvas.getContext('webgl',
{ antialias: false,
stencil: true });
Example III