Skip to content

Commit

Permalink
Renderer: Document more modules. (mrdoob#30244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored Dec 31, 2024
1 parent 79497a2 commit eebeffe
Show file tree
Hide file tree
Showing 11 changed files with 736 additions and 39 deletions.
16 changes: 8 additions & 8 deletions src/renderers/common/Backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,15 @@ class Backend {
// textures

/**
* Creates a sampler for the given texture.
* Creates a GPU sampler for the given texture.
*
* @abstract
* @param {Texture} texture - The texture to create the sampler for.
*/
createSampler( /*texture*/ ) { }

/**
* Destroys the sampler for the given texture.
* Destroys the GPU sampler for the given texture.
*
* @abstract
* @param {Texture} texture - The texture to destroy the sampler for.
Expand Down Expand Up @@ -298,7 +298,7 @@ class Backend {
updateTexture( /*texture, options = {}*/ ) { }

/**
* Generates mipmaps for the given texture
* Generates mipmaps for the given texture.
*
* @abstract
* @param {Texture} texture - The texture.
Expand Down Expand Up @@ -352,39 +352,39 @@ class Backend {
// attributes

/**
* Creates the buffer of a shader attribute.
* Creates the GPU buffer of a shader attribute.
*
* @abstract
* @param {BufferAttribute} attribute - The buffer attribute.
*/
createAttribute( /*attribute*/ ) { }

/**
* Creates the buffer of an indexed shader attribute.
* Creates the GPU buffer of an indexed shader attribute.
*
* @abstract
* @param {BufferAttribute} attribute - The indexed buffer attribute.
*/
createIndexAttribute( /*attribute*/ ) { }

/**
* Creates the buffer of a storage attribute.
* Creates the GPU buffer of a storage attribute.
*
* @abstract
* @param {BufferAttribute} attribute - The buffer attribute.
*/
createStorageAttribute( /*attribute*/ ) { }

/**
* Updates the buffer of a shader attribute.
* Updates the GPU buffer of a shader attribute.
*
* @abstract
* @param {BufferAttribute} attribute - The buffer attribute to update.
*/
updateAttribute( /*attribute*/ ) { }

/**
* Destroys the buffer of a shader attribute.
* Destroys the GPU buffer of a shader attribute.
*
* @abstract
* @param {BufferAttribute} attribute - The buffer attribute to destroy.
Expand Down
14 changes: 7 additions & 7 deletions src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class WebGLBackend extends Backend {
* @param {Boolean} [parameters.stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
* @param {Boolean} [parameters.antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
* @param {Number} [parameters.samples=0] - When `antialias` is `true`, `4` samples are used by default. Set this parameter to any other integer value than 0 to overwrite the default.
* @param {Boolean} [parameters.forceWebGL=false] - If set to `true`, the renderer uses it WebGL 2 backend no matter if WebGPU is supported or not.
* @param {Boolean} [parameters.forceWebGL=false] - If set to `true`, the renderer uses a WebGL 2 backend no matter if WebGPU is supported or not.
* @param {WebGL2RenderingContext} [parameters.context=undefined] - A WebGL 2 rendering context.
*/
constructor( parameters = {} ) {
Expand Down Expand Up @@ -1137,7 +1137,7 @@ class WebGLBackend extends Backend {
}

/**
* Generates mipmaps for the given texture
* Generates mipmaps for the given texture.
*
* @param {Texture} texture - The texture.
*/
Expand Down Expand Up @@ -1660,7 +1660,7 @@ class WebGLBackend extends Backend {
// attributes

/**
* Creates the buffer of an indexed shader attribute.
* Creates the GPU buffer of an indexed shader attribute.
*
* @param {BufferAttribute} attribute - The indexed buffer attribute.
*/
Expand All @@ -1673,7 +1673,7 @@ class WebGLBackend extends Backend {
}

/**
* Creates the buffer of a shader attribute.
* Creates the GPU buffer of a shader attribute.
*
* @param {BufferAttribute} attribute - The buffer attribute.
*/
Expand All @@ -1688,7 +1688,7 @@ class WebGLBackend extends Backend {
}

/**
* Creates the buffer of a storage attribute.
* Creates the GPU buffer of a storage attribute.
*
* @param {BufferAttribute} attribute - The buffer attribute.
*/
Expand All @@ -1703,7 +1703,7 @@ class WebGLBackend extends Backend {
}

/**
* Updates the buffer of a shader attribute.
* Updates the GPU buffer of a shader attribute.
*
* @param {BufferAttribute} attribute - The buffer attribute to update.
*/
Expand All @@ -1714,7 +1714,7 @@ class WebGLBackend extends Backend {
}

/**
* Destroys the buffer of a shader attribute.
* Destroys the GPU buffer of a shader attribute.
*
* @param {BufferAttribute} attribute - The buffer attribute to destroy.
*/
Expand Down
57 changes: 57 additions & 0 deletions src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { IntType } from '../../../constants.js';

let _id = 0;

/**
* This module is internally used in context of compute shaders.
* This type of shader is not natively supported in WebGL 2 and
* thus implemented via Transform Feedback. `DualAttributeData`
* manages the related data.
*
* @private
*/
class DualAttributeData {

constructor( attributeData, dualBuffer ) {
Expand Down Expand Up @@ -46,14 +54,35 @@ class DualAttributeData {

}

/**
* A WebGL 2 backend utility module for managing shader attributes.
*
* @private
*/
class WebGLAttributeUtils {

/**
* Constructs a new utility object.
*
* @param {WebGLBackend} backend - The WebGL 2 backend.
*/
constructor( backend ) {

/**
* A reference to the WebGPU backend.
*
* @type {WebGLBackend}
*/
this.backend = backend;

}

/**
* Creates the GPU buffer for the given buffer attribute.
*
* @param {BufferAttribute} attribute - The buffer attribute.
* @param {GLenum } bufferType - A flag that indicates the buffer type and thus binding point target.
*/
createAttribute( attribute, bufferType ) {

const backend = this.backend;
Expand Down Expand Up @@ -151,6 +180,11 @@ class WebGLAttributeUtils {

}

/**
* Updates the GPU buffer of the given buffer attribute.
*
* @param {BufferAttribute} attribute - The buffer attribute.
*/
updateAttribute( attribute ) {

const backend = this.backend;
Expand Down Expand Up @@ -190,6 +224,11 @@ class WebGLAttributeUtils {

}

/**
* Destroys the GPU buffer of the given buffer attribute.
*
* @param {BufferAttribute} attribute - The buffer attribute.
*/
destroyAttribute( attribute ) {

const backend = this.backend;
Expand All @@ -209,6 +248,14 @@ class WebGLAttributeUtils {

}

/**
* Transfers buffer data from a storage buffer attribute
* from the GPU to the CPU in context of compute shaders.
*
* @async
* @param {StorageBufferAttribute} attribute - The storage buffer attribute.
* @return {Promise<ArrayBuffer>} A promise that resolves with the buffer data when the data are ready.
*/
async getArrayBufferAsync( attribute ) {

const backend = this.backend;
Expand Down Expand Up @@ -247,6 +294,16 @@ class WebGLAttributeUtils {

}

/**
* Creates a WebGL buffer with the given data.
*
* @private
* @param {WebGL2RenderingContext} gl - The rendering context.
* @param {GLenum } bufferType - A flag that indicates the buffer type and thus binding point target.
* @param {TypedArray} array - The array of the buffer attribute.
* @param {GLenum} usage - The usage.
* @return {WebGLBuffer} The WebGL buffer.
*/
_createBuffer( gl, bufferType, array, usage ) {

const bufferGPU = gl.createBuffer();
Expand Down
27 changes: 13 additions & 14 deletions src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';

import { WebGPUCoordinateSystem } from '../../constants.js';


/**
* A backend implementation targeting WebGPU.
*
Expand All @@ -34,11 +33,11 @@ class WebGPUBackend extends Backend {
* @param {Boolean} [parameters.stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
* @param {Boolean} [parameters.antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
* @param {Number} [parameters.samples=0] - When `antialias` is `true`, `4` samples are used by default. Set this parameter to any other integer value than 0 to overwrite the default.
* @param {Boolean} [parameters.forceWebGL=false] - If set to `true`, the renderer uses it WebGL 2 backend no matter if WebGPU is supported or not.
* @param {Boolean} [parameters.forceWebGL=false] - If set to `true`, the renderer uses a WebGL 2 backend no matter if WebGPU is supported or not.
* @param {Boolean} [parameters.trackTimestamp=false] - Whether to track timestamps with a Timestamp Query API or not.
* @param {String?} [parameters.powerPreference=null] - The power preference.
* @param {String?} [parameters.requiredLimits={}] - Specifies the limits that are required by the device request.
* The request will fail if the adapter cannot provide these limits.
* @param {String} [parameters.powerPreference=undefined] - The power preference.
* @param {Object} [parameters.requiredLimits=undefined] - Specifies the limits that are required by the device request. The request will fail if the adapter cannot provide these limits.
* @param {GPUDevice} [parameters.device=undefined] - If there is an exisitng GPU device on app level, it can be passed to the renderer as a parameter.
*/
constructor( parameters = {} ) {

Expand Down Expand Up @@ -282,7 +281,7 @@ class WebGPUBackend extends Backend {
* Returns the default render pass descriptor.
*
* In WebGPU, the default framebuffer must be configured
* like custom fraemebuffers so the backend needs a render
* like custom framebuffers so the backend needs a render
* pass descriptor even when rendering directly to screen.
*
* @private
Expand Down Expand Up @@ -1358,7 +1357,7 @@ class WebGPUBackend extends Backend {
// textures

/**
* Creates a sampler for the given texture.
* Creates a GPU sampler for the given texture.
*
* @param {Texture} texture - The texture to create the sampler for.
*/
Expand All @@ -1369,7 +1368,7 @@ class WebGPUBackend extends Backend {
}

/**
* Destroys the sampler for the given texture.
* Destroys the GPU sampler for the given texture.
*
* @param {Texture} texture - The texture to destroy the sampler for.
*/
Expand Down Expand Up @@ -1416,7 +1415,7 @@ class WebGPUBackend extends Backend {
}

/**
* Generates mipmaps for the given texture
* Generates mipmaps for the given texture.
*
* @param {Texture} texture - The texture.
*/
Expand Down Expand Up @@ -1746,7 +1745,7 @@ class WebGPUBackend extends Backend {
}

/**
* Creates the buffer of a shader attribute.
* Creates the GPU buffer of a shader attribute.
*
* @param {BufferAttribute} attribute - The buffer attribute.
*/
Expand All @@ -1757,7 +1756,7 @@ class WebGPUBackend extends Backend {
}

/**
* Creates the buffer of a storage attribute.
* Creates the GPU buffer of a storage attribute.
*
* @param {BufferAttribute} attribute - The buffer attribute.
*/
Expand All @@ -1768,7 +1767,7 @@ class WebGPUBackend extends Backend {
}

/**
* Creates the buffer of an indirect storage attribute.
* Creates the GPU buffer of an indirect storage attribute.
*
* @param {BufferAttribute} attribute - The buffer attribute.
*/
Expand All @@ -1779,7 +1778,7 @@ class WebGPUBackend extends Backend {
}

/**
* Updates the buffer of a shader attribute.
* Updates the GPU buffer of a shader attribute.
*
* @param {BufferAttribute} attribute - The buffer attribute to update.
*/
Expand All @@ -1790,7 +1789,7 @@ class WebGPUBackend extends Backend {
}

/**
* Destroys the buffer of a shader attribute.
* Destroys the GPU buffer of a shader attribute.
*
* @param {BufferAttribute} attribute - The buffer attribute to destroy.
*/
Expand Down
6 changes: 2 additions & 4 deletions src/renderers/webgpu/WebGPURenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ class WebGPURenderer extends Renderer {
* @param {Boolean} [parameters.depth=true] - Whether the default framebuffer should have a depth buffer or not.
* @param {Boolean} [parameters.stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
* @param {Boolean} [parameters.antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
* @param {Number} [parameters.samples=0] - When `antialias` is `true`, `4` samples are used by default. Set this parameter to any other integer value than 0
* to overwrite the default.
* @param {Boolean} [parameters.forceWebGL=false] - If set to `true`, the renderer uses it
* WebGL 2 backend no matter if WebGPU is supported or not.
* @param {Number} [parameters.samples=0] - When `antialias` is `true`, `4` samples are used by default. Set this parameter to any other integer value than 0 to overwrite the default.
* @param {Boolean} [parameters.forceWebGL=false] - If set to `true`, the renderer uses a WebGL 2 backend no matter if WebGPU is supported or not.
*/
constructor( parameters = {} ) {

Expand Down
Loading

0 comments on commit eebeffe

Please sign in to comment.