Creates a new WebglGraphicsDevice instance.
The canvas to which the graphics device will render.
Optionaloptions: {Options passed when creating the WebGL context.
Optionalalpha?: booleanBoolean that indicates if the canvas contains an alpha buffer. Defaults to true.
Optionalantialias?: booleanBoolean that indicates whether or not to perform anti-aliasing if possible. Defaults to true.
Optionaldepth?: booleanBoolean that indicates that the drawing buffer is requested to have a depth buffer of at least 16 bits. Defaults to true.
Optionaldesynchronized?: booleanBoolean that hints the user agent to reduce the latency by desynchronizing the canvas paint cycle from the event loop. Defaults to false.
OptionalfailIfMajorPerformanceCaveat?: booleanBoolean that indicates if a context will be created if the system performance is low or if no hardware GPU is available. Defaults to false.
Optionalgl?: WebGL2RenderingContextThe rendering context to use. If not specified, a new context will be created.
OptionalpowerPreference?: "default" | "high-performance" | "low-power"A hint to the user agent indicating what configuration of GPU is suitable for the WebGL context. Possible values are:
Defaults to 'default'.
OptionalpremultipliedAlpha?: booleanBoolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha. Defaults to true.
OptionalpreserveDrawingBuffer?: booleanIf the value is true the buffers will not be cleared and will preserve their values until cleared or overwritten by the author. Defaults to false.
Optionalstencil?: booleanBoolean that indicates that the drawing buffer is requested to have a stencil buffer of at least 8 bits. Defaults to true.
OptionalxrCompatible?: booleanBoolean that hints to the user agent to use a compatible graphics adapter for an immersive XR device.
ReadonlycanvasThe canvas DOM element that provides the underlying WebGL context used by the graphics device.
The GPU profiler.
True if the back-buffer is using HDR format, which means that the browser will display the rendered images in high dynamic range mode. This is true if the options.displayFormat is set to DISPLAYFORMAT_HDR when creating the graphics device using createGraphicsDevice, and HDR is supported by the device.
ReadonlyisTrue if the deviceType is Null
ReadonlyisTrue if the deviceType is WebGPU
ReadonlymaxThe maximum supported texture anisotropy setting.
ReadonlymaxThe maximum supported number of color buffers attached to a render target.
ReadonlymaxThe maximum supported dimension of a cube map.
The maximum number of indirect draw calls that can be used within a single frame. Used on WebGPU only. This needs to be adjusted based on the maximum number of draw calls that can be used within a single frame. Defaults to 1024.
ReadonlymaxThe maximum supported number of hardware anti-aliasing samples.
ReadonlymaxThe maximum supported dimension of a texture.
ReadonlymaxThe maximum supported dimension of a 3D texture (any axis).
ReadonlyprecisionThe highest shader precision supported by this graphics device. Can be 'hiphp', 'mediump' or 'lowp'.
ReadonlysamplesThe number of hardware anti-aliasing samples used by the frame buffer.
ReadonlyscopeThe scope namespace for shader attributes and variables.
True if the device supports clip distances (WebGPU only). Clip distances allow you to restrict primitives' clip volume with user-defined half-spaces in the output of vertex stage.
ReadonlysupportsTrue if the device supports compute shaders.
True if the device supports multi-draw. This is always supported on WebGPU, and support on WebGL2 is optional, but pretty common.
ReadonlysupportsTrue if the device can read from StorageTexture in the compute shader. By default, the
storage texture can be only used with the write operation.
When a shader uses this feature, it's recommended to use a requires directive to signal the
potential for non-portability at the top of the WGSL shader code:
requires readonly_and_readwrite_storage_textures;
ReadonlytextureTrue if filtering can be applied when sampling float textures.
ReadonlytextureTrue if 32-bit floating-point textures can be used as a frame buffer.
ReadonlytextureTrue if 16-bit floating-point textures can be used as a frame buffer.
ReadonlytextureTrue if small-float textures with format PIXELFORMAT_111110F can be used as a frame buffer. This is always true on WebGL2, but optional on WebGPU device.
Gets the type of the device. Can be:
Gets whether the device is currently in fullscreen mode.
Sets whether the device is currently in fullscreen mode.
Height of the back buffer in pixels.
Returns the buffer used to store arguments for indirect draw calls. The size of the buffer is controlled by the maxIndirectDrawCount property. This buffer can be passed to a Compute shader along with a slot obtained by calling getIndirectDrawSlot, in order to prepare indirect draw parameters. Also see MeshInstance#setIndirect.
Only available on WebGPU, returns null on other platforms.
Gets the maximum pixel ratio.
Sets the maximum pixel ratio.
Width of the back buffer in pixels.
Clears the frame buffer of the currently set render target.
Optionaloptions: { color?: number[]; depth?: number; flags?: number; stencil?: number }Optional options object that controls the behavior of the clear operation defined as follows:
Optionalcolor?: number[]The color to clear the color buffer to in the range 0 to 1 for each component.
Optionaldepth?: numberThe depth value to clear the depth buffer to in the range 0 to 1. Defaults to 1.
Optionalflags?: numberThe buffers to clear (the types being color, depth and stencil). Can be any bitwise combination of:
Optionalstencil?: numberThe stencil value to clear the stencil buffer to. Defaults to 0.
// Clear color buffer to black and depth buffer to 1
device.clear();
// Clear just the color buffer to red
device.clear({
color: [1, 0, 0, 1],
flags: pc.CLEARFLAG_COLOR
});
// Clear color buffer to yellow and depth to 1.0
device.clear({
color: [1, 1, 0, 1],
depth: 1,
flags: pc.CLEARFLAG_COLOR | pc.CLEARFLAG_DEPTH
});
Dispatch multiple compute shaders inside a single compute shader pass.
An array of compute shaders to dispatch.
Optionalname: string = 'Unnamed'The name of the dispatch, used for debugging and reporting only.
Copies source render target into destination render target. Mostly used by post-effects.
Optionalsource: RenderTargetThe source render target. Defaults to frame buffer.
Optionaldest: RenderTargetThe destination render target. Defaults to frame buffer.
Optionalcolor: booleanIf true, will copy the color buffer. Defaults to false.
Optionaldepth: booleanIf true, will copy the depth buffer. Defaults to false.
True if the copy was successful, false otherwise.
Destroy the graphics device.
Fire an event, all additional arguments are passed on to the event listener.
Name of event to fire.
Optionalarg1: anyFirst argument that is passed to the event handler.
Optionalarg2: anySecond argument that is passed to the event handler.
Optionalarg3: anyThird argument that is passed to the event handler.
Optionalarg4: anyFourth argument that is passed to the event handler.
Optionalarg5: anyFifth argument that is passed to the event handler.
Optionalarg6: anySixth argument that is passed to the event handler.
Optionalarg7: anySeventh argument that is passed to the event handler.
Optionalarg8: anyEighth argument that is passed to the event handler.
Self for chaining.
Retrieves the first available slot in the indirectDrawBuffer used for indirect rendering, which can be utilized by a Compute shader to generate indirect draw parameters and by MeshInstance#setIndirect to configure indirect draw calls.
When reserving multiple consecutive slots, specify the optional count parameter.
Optionalcount: number = 1Number of consecutive slots to reserve. Defaults to 1.
Get a renderable HDR pixel format supported by the graphics device.
Note:
filterable parameter is set to false, this function returns one of the supported
formats on the majority of devices apart from some very old iOS and Android devices (99%).filterable parameter is set to true, the function returns a format on a
considerably lower number of devices (70%).Optionalformats: number[] = ...An array of pixel formats to check for support. Can contain:
Optionalfilterable: boolean = trueIf true, the format also needs to be filterable. Defaults to true.
Optionalsamples: number = 1The number of samples to check for. Some formats are not compatible with multi-sampling, for example PIXELFORMAT_RGBA32F on WebGPU platform. Defaults to 1.
The first supported renderable HDR format or undefined if none is supported.
Queries the currently set render target on the device.
The current render target.
Test if there are any handlers bound to an event name.
The name of the event to test.
True if the object has handlers bound to the specified event name.
Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.
Optionalname: stringName of the event to unbind.
Optionalcallback: HandleEventCallbackFunction to be unbound.
Optionalscope: anyScope that was used as the this when the event is fired.
Self for chaining.
const handler = () => {};
obj.on('test', handler);
obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
Attach an event handler to an event.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optionalscope: any = ...Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
Attach an event handler to an event. This handler will be removed after being fired once.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optionalscope: any = ...Object to use as 'this' when the event is fired, defaults to current this.
Function that executes after the device has been created.
Sets the specified blend state.
New blend state.
Controls how triangles are culled based on their face direction. The default cull mode is CULLFACE_BACK.
The cull mode to set. Can be:
Sets the specified depth state.
New depth state.
Sets the specified render target on the device. If null is passed as a parameter, the back buffer becomes the current target for all rendering operations.
The render target to activate.
Set the active scissor rectangle on the specified device.
The pixel space x-coordinate of the bottom left corner of the scissor rectangle.
The pixel space y-coordinate of the bottom left corner of the scissor rectangle.
The width of the scissor rectangle in pixels.
The height of the scissor rectangle in pixels.
Sets the active shader to be used during subsequent draw calls.
The shader to assign to the device.
OptionalasyncCompile: boolean = falseIf true, rendering will be skipped until the shader is compiled, otherwise the rendering will wait for the shader compilation to finish. Defaults to false.
Sets the specified stencil state. If both stencilFront and stencilBack are null, stencil operation is disabled.
The front stencil parameters. Defaults to StencilParameters.DEFAULT if not specified.
The back stencil parameters. Defaults to StencilParameters.DEFAULT if not specified.
Set the active rectangle for rendering on the specified device.
The pixel space x-coordinate of the bottom left corner of the viewport.
The pixel space y-coordinate of the bottom left corner of the viewport.
The width of the viewport in pixels.
The height of the viewport in pixels.
ProtectedvalidateProtectedValidate that all attributes required by the shader are present in the currently assigned vertex buffers.
The shader to validate.
The format of the first vertex buffer.
The format of the second vertex buffer.
WebglGraphicsDevice extends the base GraphicsDevice to provide rendering capabilities utilizing the WebGL 2.0 specification.