Capítulo 636 de 859

Chapter 636: Backend

Core Idea

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.

Key Concepts

  • coordinateSystem : number (abstract, readonly): The coordinate system of the backend.
  • data : WeakMap.<Object, Object>: This weak map holds backend-specific data of objects like textures, attributes or render targets.
  • domElement : HTMLCanvasElement | OffscreenCanvas: A reference to the canvas element the renderer is drawing to.
  • hasTimestamp : boolean (readonly): Whether the backend supports query timestamps or not.
  • parameters : Object: The parameters of the backend.
  • renderer : Renderer: A reference to the renderer.
  • timestampQueryPool : Object: A reference to the timestamp query pool.
  • trackTimestamp : boolean: Whether to track timestamps with a Timestamp Query API or not.

Reference Tables

Constructor

Signature
new Backend( parameters : Object ) (abstract)

Properties

PropertyDescription
.coordinateSystem : number (abstract, readonly)The coordinate system of the backend.
.data : WeakMap.<Object, Object>This weak map holds backend-specific data of objects like textures, attributes or render targets.
`.domElement : HTMLCanvasElementOffscreenCanvas`
.hasTimestamp : boolean (readonly)Whether the backend supports query timestamps or not.
.parameters : ObjectThe parameters of the backend.
.renderer : RendererA reference to the renderer.
.timestampQueryPool : ObjectA reference to the timestamp query pool.
.trackTimestamp : booleanWhether to track timestamps with a Timestamp Query API or not.

Methods

MethodDescription
._getQueryPool( uid : string ) : TimestampQueryPoolReturns the query pool for the given uid.
`.beginCompute( computeGroup : NodeArray.<Node> ) (abstract)`
.beginRender( renderContext : RenderContext ) (abstract)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.
`.compute( computeGroup : NodeArray.<Node>, computeNode : Node, bindings : Array.<BindGroup>, computePipeline : ComputePipeline ) (abstract)`
.copyFramebufferToTexture( texture : Texture, renderContext : RenderContext, rectangle : Vector4 ) (abstract)Copies the current bound framebuffer to the given texture.
.copyTextureToBuffer( texture : Texture, x : number, y : number, width : number, height : number, faceIndex : number ) : Promise.<TypedArray> (async, abstract)Returns texture data as a typed array.
`.copyTextureToTexture( srcTexture : Texture, dstTexture : Texture, srcRegion : Box3Box2, dstPosition : Vector2
.createAttribute( attribute : BufferAttribute ) (abstract)Creates the GPU buffer of a shader attribute.
.createBindings( bindGroup : BindGroup, bindings : Array.<BindGroup>, cacheIndex : number, version : number ) (abstract)Creates bindings from the given bind group definition.
.createComputePipeline( computePipeline : ComputePipeline, bindings : Array.<BindGroup> ) (abstract)Creates a compute pipeline for the given compute node.
.createDefaultTexture( texture : Texture ) (abstract)Creates a default texture for the given texture that can be used as a placeholder until the actual texture is ready for usage.
.createIndexAttribute( attribute : BufferAttribute ) (abstract)Creates the GPU buffer of an indexed shader attribute.
.createNodeBuilder( renderObject : RenderObject, renderer : Renderer ) : NodeBuilder (abstract)Returns a node builder for the given render object.
.createProgram( program : ProgrammableStage ) (abstract)Creates a shader program from the given programmable stage.
.createRenderPipeline( renderObject : RenderObject, promises : Array.<Promise> ) (abstract)Creates a render pipeline for the given render object.
.createStorageAttribute( attribute : BufferAttribute ) (abstract)Creates the GPU buffer of a storage attribute.
.createTexture( texture : Texture, options : Object ) (abstract)Defines a texture on the GPU for the given texture object.
.createUniformBuffer( uniformBuffer : Buffer ) (abstract)Creates a uniform buffer.
.delete( object : Object )Deletes an object from the internal data structure.
.deleteBindGroupData( bindGroup : BindGroup ) (abstract)Delete GPU data associated with a bind group.
.destroyAttribute( attribute : BufferAttribute ) (abstract)Destroys the GPU buffer of a shader attribute.
.destroyProgram( program : ProgrammableStage ) (abstract)Destroys the shader program of the given programmable stage.
.destroySampler( binding : Sampler ) (abstract)Frees the GPU sampler for the given sampler binding.
.destroyTexture( texture : Texture, isDefaultTexture : boolean ) (abstract)Destroys the GPU data for the given texture object.
.destroyUniformBuffer( uniformBuffer : Buffer ) (abstract)Destroys a uniform buffer.
.dispose() (abstract)Frees internal resources.
.draw( renderObject : RenderObject, info : Info ) (abstract)Executes a draw command for the given render object.
`.finishCompute( computeGroup : NodeArray.<Node> ) (abstract)`
.finishRender( renderContext : RenderContext ) (abstract)This method is executed at the end of a render call and can be used by the backend to finalize work after draw calls.
.generateMipmaps( texture : Texture ) (abstract)Generates mipmaps for the given texture.
.get( object : Object ) : ObjectReturns the dictionary for the given object.
.getArrayBufferAsync( attribute : StorageBufferAttribute ) : Promise.<ArrayBuffer> (async)This method performs a readback operation by moving buffer data from a storage buffer attribute from the GPU to the CPU.
.getClearColor() : Color4Returns the clear color and alpha into a single color object.
.getContext() : Object (abstract)Returns the backend's rendering context.
.getDomElement() : HTMLCanvasElementReturns the DOM element. If no DOM element exists, the backend creates a new one.
.getDrawingBufferSize() : Vector2Returns the drawing buffer size.
.getRenderCacheKey( renderObject : RenderObject ) : string (abstract)Returns a cache key that is used to identify render pipelines.
.getTimestamp( uid : string ) : numberReturns the timestamp for the given uid.
.getTimestampFrames( type : string ) : Array.<number>Returns all timestamp frames for the given type.
`.getTimestampUID( abstractRenderContext : RenderContextComputeNode ) : string`
.has( object : Object ) : booleanChecks if the given object has a dictionary with data defined.
.hasCompatibility( name : string ) : boolean (abstract)Checks if the backend has the given compatibility.
.hasFeature( name : string ) : boolean (abstract)Checks if the given feature is supported by the backend.
.hasFeatureAsync( name : string ) : Promise.<boolean> (async, abstract)Checks if the given feature is supported by the backend.
.hasTimestampQuery( uid : string ) : booleanReturns true if a timestamp for the given uid is available.
.init( renderer : Renderer ) : Promise (async)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.
.initRenderTarget( renderContext : RenderContext ) (abstract)Initializes the render target defined in the given render context.
.isOccluded( renderContext : RenderContext, object : Object3D ) : boolean (abstract)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.
.needsRenderUpdate( renderObject : RenderObject ) : boolean (abstract)Returns true if the render pipeline requires an update.
.resolveTimestampsAsync( type : string ) : Promise.<number> (async, abstract)Resolves the time stamp for the given render context and type.
.set( object : Object, value : Object )Sets a dictionary for the given object into the internal data structure.
.setScissorTest( boolean : boolean ) (abstract)Defines the scissor test.
.setXRTarget( xrTarget : Object )Sets the XR rendering destination.
.updateAttribute( attribute : BufferAttribute ) (abstract)Updates the GPU buffer of a shader attribute.
.updateBinding( binding : Buffer ) (abstract)Updates a buffer binding.
.updateBindings( bindGroup : BindGroup, bindings : Array.<BindGroup>, cacheIndex : number, version : number ) (abstract)Updates the given bind group definition.
.updateSampler( binding : Sampler ) : string (abstract)Updates a GPU sampler for the given texture.
.updateSize() (abstract)Backends can use this method if they have to run logic when the renderer gets resized.
.updateTexture( texture : Texture, options : Object ) (abstract)Uploads the updated texture data to the GPU.
`.updateTimeStampUID( abstractRenderContext : RenderContextComputeNode )`
.updateViewport( renderContext : RenderContext ) (abstract)Updates the viewport with the values from the given render context.

Key Takeaways

  1. Most relevant properties: coordinateSystem, data, domElement, hasTimestamp.
  2. Key methods: _getQueryPool, beginCompute, beginRender, compute.

Connects To