Most of the rendering related logic is implemented in the Renderer module and related management components. Sometimes it is required though to execute commands which are specific to the current 3D backend (which is WebGPU or WebGL 2). This abstract base class defines an interface that encapsulates all backend-related logic. Derived classes for each backend must implement the interface.
Constructs a new backend.
parameters
An object holding parameters for the backend.
The coordinate system of the backend.
This weak map holds backend-specific data of objects like textures, attributes or render targets.
A reference to the canvas element the renderer is drawing to.
Default is null.
Whether the backend supports query timestamps or not.
The parameters of the backend.
A reference to the renderer.
Default is null.
A reference to the timestamp query pool.
Whether to track timestamps with a Timestamp Query API or not.
Default is false.
Returns the query pool for the given uid.
uid
The unique identifier.
Returns: The query pool.
This method is executed at the beginning of a compute call and can be used by the backend to prepare the state for upcoming compute tasks.
computeGroup
The compute node(s).
This method is executed at the beginning of a render call and can be used by the backend to prepare the state for upcoming draw calls.
renderContext
The render context.
Executes a compute command for the given compute node.
computeGroup
The group of compute nodes of a compute call. Can be a single compute node.
computeNode
The compute node.
bindings
The bindings.
computePipeline
The compute pipeline.
Copies the current bound framebuffer to the given texture.
texture
The destination texture.
renderContext
The render context.
rectangle
A four dimensional vector defining the origin and dimension of the copy.
Returns texture data as a typed array.
texture
The texture to copy.
x
The x coordinate of the copy origin.
y
The y coordinate of the copy origin.
width
The width of the copy.
height
The height of the copy.
faceIndex
The face index.
Returns: A Promise that resolves with a typed array when the copy operation has finished.
Copies data of the given source texture to the given destination texture.
srcTexture
The source texture.
dstTexture
The destination texture.
srcRegion
The region of the source texture to copy.
Default is null.
dstPosition
The destination position of the copy.
Default is null.
srcLevel
The source mip level to copy from.
Default is 0.
dstLevel
The destination mip level to copy to.
Default is 0.
Creates the GPU buffer of a shader attribute.
attribute
The buffer attribute.
Creates bindings from the given bind group definition.
bindGroup
The bind group.
bindings
Array of bind groups.
cacheIndex
The cache index.
version
The version.
Creates a compute pipeline for the given compute node.
computePipeline
The compute pipeline.
bindings
The bindings.
Creates a default texture for the given texture that can be used as a placeholder until the actual texture is ready for usage.
texture
The texture to create a default texture for.
Creates the GPU buffer of an indexed shader attribute.
attribute
The indexed buffer attribute.
Returns a node builder for the given render object.
renderObject
The render object.
renderer
The renderer.
Returns: The node builder.
Creates a shader program from the given programmable stage.
program
The programmable stage.
Creates a render pipeline for the given render object.
renderObject
The render object.
promises
An array of compilation promises which are used in compileAsync().
Creates the GPU buffer of a storage attribute.
attribute
The buffer attribute.
Defines a texture on the GPU for the given texture object.
texture
The texture.
options
Optional configuration parameter.
Default is {}.
Creates a uniform buffer.
uniformBuffer
The uniform buffer.
Deletes an object from the internal data structure.
object
The object to delete.
Delete GPU data associated with a bind group.
bindGroup
The bind group.
Destroys the GPU buffer of a shader attribute.
attribute
The buffer attribute to destroy.
Destroys the shader program of the given programmable stage.
program
The programmable stage.
Frees the GPU sampler for the given sampler binding.
binding
The sampler binding to free.
Destroys the GPU data for the given texture object.
texture
The texture.
isDefaultTexture
Whether the texture uses a default GPU texture or not.
Default is false.
Destroys a uniform buffer.
uniformBuffer
The uniform buffer.
Frees internal resources.
Executes a draw command for the given render object.
renderObject
The render object to draw.
info
Holds a series of statistical information about the GPU memory and the rendering process.
This method is executed at the end of a compute call and can be used by the backend to finalize work after compute tasks.
computeGroup
The compute node(s).
This method is executed at the end of a render call and can be used by the backend to finalize work after draw calls.
renderContext
The render context.
Generates mipmaps for the given texture.
texture
The texture.
Returns the dictionary for the given object.
object
The object.
Returns: The object's dictionary.
This method performs a readback operation by moving buffer data from a storage buffer attribute from the GPU to the CPU.
attribute
The storage buffer attribute.
Returns: A promise that resolves with the buffer data when the data are ready.
Returns the clear color and alpha into a single color object.
Returns: The clear color.
Returns the backend's rendering context.
Returns: The rendering context.
Returns the DOM element. If no DOM element exists, the backend creates a new one.
Returns: The DOM element.
Returns the drawing buffer size.
Returns: The drawing buffer size.
Returns a cache key that is used to identify render pipelines.
renderObject
The render object.
Returns: The cache key.
Returns the timestamp for the given uid.
uid
The unique identifier.
Returns: The timestamp.
Returns all timestamp frames for the given type.
type
The type of the time stamp.
Returns: The timestamp frames.
Returns a unique identifier for the given render context that can be used to allocate resources like occlusion queries or timestamp queries.
abstractRenderContext
The render context.
Returns: The unique identifier.
Checks if the given object has a dictionary with data defined.
object
The object.
Returns: Whether a dictionary for the given object as been defined or not.
Checks if the backend has the given compatibility.
name
The compatibility.
Returns: Whether the backend has the given compatibility or not.
Checks if the given feature is supported by the backend.
name
The feature's name.
Returns: Whether the feature is supported or not.
Checks if the given feature is supported by the backend.
name
The feature's name.
Returns: A Promise that resolves with a bool that indicates whether the feature is supported or not.
Returns true if a timestamp for the given uid is available.
uid
The unique identifier.
Returns: Whether the timestamp is available or not.
Initializes the backend so it is ready for usage. Concrete backends are supposed to implement their rendering context creation and related operations in this method.
renderer
The renderer.
Returns: A Promise that resolves when the backend has been initialized.
Initializes the render target defined in the given render context.
renderContext
The render context.
Returns true if the given 3D object is fully occluded by other 3D objects in the scene. Backends must implement this method by using a Occlusion Query API.
renderContext
The render context.
object
The 3D object to test.
Returns: Whether the 3D object is fully occluded or not.
Returns true if the render pipeline requires an update.
renderObject
The render object.
Returns: Whether the render pipeline requires an update or not.
Resolves the time stamp for the given render context and type.
type
The type of the time stamp.
Default is 'render'.
Returns: A Promise that resolves with the time stamp.
Sets a dictionary for the given object into the internal data structure.
object
The object.
value
The dictionary to set.
Defines the scissor test.
boolean
Whether the scissor test should be enabled or not.
Sets the XR rendering destination.
Backends that render directly into XR framebuffers can override this hook.
xrTarget
The XR rendering destination.
Updates the GPU buffer of a shader attribute.
attribute
The buffer attribute to update.
Updates a buffer binding.
binding
The buffer binding to update.
Updates the given bind group definition.
bindGroup
The bind group.
bindings
Array of bind groups.
cacheIndex
The cache index.
version
The version.
Updates a GPU sampler for the given texture.
binding
The sampler binding to update.
Returns: The current sampler key.
Backends can use this method if they have to run logic when the renderer gets resized.
Uploads the updated texture data to the GPU.
texture
The texture.
options
Optional configuration parameter.
Default is {}.
Updates a unique identifier for the given render context that can be used to allocate resources like occlusion queries or timestamp queries.
abstractRenderContext
The render context.
Updates the viewport with the values from the given render context.
renderContext
The render context.