Browse Source

Renderer: Document more modules. (#30221)

* Renderer: Document more modules.

* Fix typo.

* Fix typo.
Michael Herzog 1 year ago
parent
commit
b35ad2adf5

+ 1 - 1
src/nodes/accessors/BufferAttributeNode.js

@@ -24,7 +24,7 @@ import { StaticDrawUsage, DynamicDrawUsage } from '../../constants.js';
  * material.colorNode = bufferAttribute( new THREE.Float32BufferAttribute( colors, 3 ) );
  * ```
  * This new approach is especially interesting when geometry data are generated via
- * compute shaders. The below line converts a storage buffer into an attribute.
+ * compute shaders. The below line converts a storage buffer into an attribute node.
  * ```js
  * material.positionNode = positionBuffer.toAttribute();
  * ```

+ 3 - 3
src/nodes/accessors/StorageBufferNode.js

@@ -12,7 +12,7 @@ import { getTypeFromLength } from '../core/NodeUtils.js';
  * storage buffer for data. A typical workflow is to create instances of
  * this node with the convenience functions `attributeArray()` or `instancedArray()`,
  * setup up a compute shader that writes into the buffers and then convert
- * the storage buffers to attributes for rendering.
+ * the storage buffers to attribute nodes for rendering.
  *
  * ```js
  * const positionBuffer = instancedArray( particleCount, 'vec3' ); // the storage buffer node
@@ -49,7 +49,7 @@ class StorageBufferNode extends BufferNode {
 	/**
 	 * Constructs a new storage buffer node.
 	 *
-	 * @param {StorageBufferAttribute|StorageInstancedBufferAttribute} value - The buffer data.
+	 * @param {StorageBufferAttribute|StorageInstancedBufferAttribute|BufferAttribute} value - The buffer data.
 	 * @param {String?} [bufferType=null] - The buffer type (e.g. `'vec3'`).
 	 * @param {Number} [bufferCount=0] - The buffer count.
 	 */
@@ -337,7 +337,7 @@ export default StorageBufferNode;
  * TSL function for creating a storage buffer node.
  *
  * @function
- * @param {StorageBufferAttribute|StorageInstancedBufferAttribute} value - The buffer data.
+ * @param {StorageBufferAttribute|StorageInstancedBufferAttribute|BufferAttribute} value - The buffer data.
  * @param {String?} [type=null] - The buffer type (e.g. `'vec3'`).
  * @param {Number} [count=0] - The buffer count.
  * @returns {StorageBufferNode}

+ 49 - 0
src/objects/ClippingGroup.js

@@ -1,15 +1,64 @@
 import { Group } from './Group.js';
 
+/**
+ * In earlier three.js versions, clipping was defined globally
+ * on the renderer or on material level. This special version of
+ * `THREE.Group` allows to encode the clipping state into the scene
+ * graph. Meaning if you create an instance of this group, all
+ * descendant 3D objects will be affected by the respective clipping
+ * planes.
+ *
+ * Note: `ClippingGroup` can only be used with `WebGPURenderer`.
+ *
+ * @augments Group
+ */
 class ClippingGroup extends Group {
 
+	/**
+	 * Constructs a new clipping group.
+	 */
 	constructor() {
 
 		super();
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isClippingGroup = true;
+
+		/**
+		 * An array with clipping planes.
+		 *
+		 * @type {Array<Plane>}
+		 */
 		this.clippingPlanes = [];
+
+		/**
+		 * Whether clipping should be enabled or not.
+		 *
+		 * @type {Boolean}
+		 * @default true
+		 */
 		this.enabled = true;
+
+		/**
+		 * Whether the intersection of the clipping planes is used to clip objects, rather than their union.
+		 *
+		 * @type {Boolean}
+		 * @default false
+		 */
 		this.clipIntersection = false;
+
+		/**
+		 * Whether shadows should be clipped or not.
+		 *
+		 * @type {Boolean}
+		 * @default false
+		 */
 		this.clipShadows = false;
 
 	}

+ 35 - 0
src/renderers/common/Binding.js

@@ -1,19 +1,54 @@
+/**
+ * A binding represents the connection between a resource (like a texture, sampler
+ * or uniform buffer) and the resource definition in a shader stage.
+ *
+ * This module is an abstract base class for all concrete bindings types.
+ *
+ * @abstract
+ * @private
+ */
 class Binding {
 
+	/**
+	 * Constructs a new binding.
+	 *
+	 * @param {String} [name=''] - The binding's name.
+	 */
 	constructor( name = '' ) {
 
+		/**
+		 * The binding's name.
+		 *
+		 * @type {String}
+		 */
 		this.name = name;
 
+		/**
+		 * A bitmask that defines in what shader stages the
+		 * binding's resource is accessible.
+		 *
+		 * @type {String}
+		 */
 		this.visibility = 0;
 
 	}
 
+	/**
+	 * Makes sure binding's resource is visible for the given shader stage.
+	 *
+	 * @param {Number} visibility - The shader stage.
+	 */
 	setVisibility( visibility ) {
 
 		this.visibility |= visibility;
 
 	}
 
+	/**
+	 * Clones the binding.
+	 *
+	 * @return {Binding} The cloned binding.
+	 */
 	clone() {
 
 		return Object.assign( new this.constructor(), this );

+ 49 - 0
src/renderers/common/Buffer.js

@@ -1,32 +1,81 @@
 import Binding from './Binding.js';
 import { getFloatLength } from './BufferUtils.js';
 
+/**
+ * Represents a buffer binding type.
+ *
+ * @private
+ * @abstract
+ * @augments Binding
+ */
 class Buffer extends Binding {
 
+	/**
+	 * Constructs a new buffer.
+	 *
+	 * @param {String} name - The buffer's name.
+	 * @param {TypedArray} [buffer=null] - The buffer.
+	 */
 	constructor( name, buffer = null ) {
 
 		super( name );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isBuffer = true;
 
+		/**
+		 * The bytes per element.
+		 *
+		 * @type {Number}
+		 */
 		this.bytesPerElement = Float32Array.BYTES_PER_ELEMENT;
 
+		/**
+		 * A reference to the internal buffer.
+		 *
+		 * @private
+		 * @type {TypedArray}
+		 */
 		this._buffer = buffer;
 
 	}
 
+	/**
+	 * The buffer's byte length.
+	 *
+	 * @type {Number}
+	 * @readonly
+	 */
 	get byteLength() {
 
 		return getFloatLength( this._buffer.byteLength );
 
 	}
 
+	/**
+	 * A reference to the internal buffer.
+	 *
+	 * @type {Number}
+	 * @readonly
+	 */
 	get buffer() {
 
 		return this._buffer;
 
 	}
 
+	/**
+	 * Updates the binding.
+	 *
+	 * @return {Boolean} Whether the buffer has been updated and must be
+	 * uploaded to the GPU.
+	 */
 	update() {
 
 		return true;

+ 107 - 14
src/renderers/common/ClippingContext.js

@@ -4,41 +4,110 @@ import { Vector4 } from '../../math/Vector4.js';
 
 const _plane = /*@__PURE__*/ new Plane();
 
+/**
+ * Represents the state that is used to perform clipping via clipping planes.
+ * There is a default clipping context for each render context. When the
+ * scene holds instances of `ClippingGroup`, there will be a context for each
+ * group.
+ *
+ * @private
+ */
 class ClippingContext {
 
+	/**
+	 * Constructs a new clipping context.
+	 *
+	 * @param {ClippingContext?} [parentContext=null] - A reference to the parent clipping context.
+	 */
 	constructor( parentContext = null ) {
 
+		/**
+		 * The clipping context's version.
+		 *
+		 * @type {Number}
+		 * @readonly
+		 */
 		this.version = 0;
 
+		/**
+		 * Whether the intersection of the clipping planes is used to clip objects, rather than their union.
+		 *
+		 * @type {Boolean?}
+		 * @default null
+		 */
 		this.clipIntersection = null;
-		this.cacheKey = '';
-
-
-		if ( parentContext === null ) {
 
-			this.intersectionPlanes = [];
-			this.unionPlanes = [];
-
-			this.viewNormalMatrix = new Matrix3();
-			this.clippingGroupContexts = new WeakMap();
+		/**
+		 * The clipping context's cache key.
+		 *
+		 * @type {String}
+		 */
+		this.cacheKey = '';
 
-			this.shadowPass = false;
+		/**
+		 * Whether the shadow pass is active or not.
+		 *
+		 * @type {Boolean}
+		 * @default false
+		 */
+		this.shadowPass = false;
+
+		/**
+		 * The view normal matrix.
+		 *
+		 * @type {Matrix3}
+		 */
+		this.viewNormalMatrix = new Matrix3();
+
+		/**
+		 * Internal cache for maintaining clipping contexts.
+		 *
+		 * @type {WeakMap<ClippingGroup,ClippingContext>}
+		 */
+		this.clippingGroupContexts = new WeakMap();
+
+		/**
+		 * The intersection planes.
+		 *
+		 * @type {Array<Vector4>}
+		 */
+		this.intersectionPlanes = [];
+
+		/**
+		 * The intersection planes.
+		 *
+		 * @type {Array<Vector4>}
+		 */
+		this.unionPlanes = [];
+
+		/**
+		 * The version of the clipping context's parent context.
+		 *
+		 * @type {Number?}
+		 * @readonly
+		 */
+		this.parentVersion = null;
 
-		} else {
+		if ( parentContext !== null ) {
 
 			this.viewNormalMatrix = parentContext.viewNormalMatrix;
 			this.clippingGroupContexts = parentContext.clippingGroupContexts;
 
 			this.shadowPass = parentContext.shadowPass;
-
 			this.viewMatrix = parentContext.viewMatrix;
 
 		}
 
-		this.parentVersion = null;
-
 	}
 
+	/**
+	 * Projects the given source clipping planes and writes the result into the
+	 * destination array.
+	 *
+	 * @param {Array<Plane>} source - The source clipping planes.
+	 * @param {Array<Vector4>} destination - The destination.
+	 * @param {Number} offset - The offset.
+	 */
 	projectPlanes( source, destination, offset ) {
 
 		const l = source.length;
@@ -59,6 +128,12 @@ class ClippingContext {
 
 	}
 
+	/**
+	 * Updates the root clipping context of a scene.
+	 *
+	 * @param {Scene} scene - The scene.
+	 * @param {Camera} camera - The camera that is used to render the scene.
+	 */
 	updateGlobal( scene, camera ) {
 
 		this.shadowPass = ( scene.overrideMaterial !== null && scene.overrideMaterial.isShadowNodeMaterial );
@@ -68,6 +143,12 @@ class ClippingContext {
 
 	}
 
+	/**
+	 * Updates the clipping context.
+	 *
+	 * @param {ClippingContext} parentContext - The parent context.
+	 * @param {ClippingGroup} clippingGroup - The clipping group this context belongs to.
+	 */
 	update( parentContext, clippingGroup ) {
 
 		let update = false;
@@ -139,6 +220,12 @@ class ClippingContext {
 
 	}
 
+	/**
+	 * Returns a clipping context for the given clipping group.
+	 *
+	 * @param {ClippingGroup} clippingGroup - The clipping group.
+	 * @return {ClippingContext} The clipping context.
+	 */
 	getGroupContext( clippingGroup ) {
 
 		if ( this.shadowPass && ! clippingGroup.clipShadows ) return this;
@@ -158,6 +245,12 @@ class ClippingContext {
 
 	}
 
+	/**
+	 * The count of union clipping planes.
+	 *
+	 * @type {Number}
+	 * @readonly
+	 */
 	get unionClippingCount() {
 
 		return this.unionPlanes.length;

+ 13 - 0
src/renderers/common/CubeRenderTarget.js

@@ -12,6 +12,12 @@ import { BackSide, NoBlending, LinearFilter, LinearMipmapLinearFilter } from '..
 
 // @TODO: Consider rename WebGLCubeRenderTarget to just CubeRenderTarget
 
+/**
+ * This class represents a cube render target. It is a special version
+ * of `WebGLCubeRenderTarget` which is compatible with `WebGPURenderer`.
+ *
+ * @augments WebGLCubeRenderTarget
+ */
 class CubeRenderTarget extends WebGLCubeRenderTarget {
 
 	constructor( size = 1, options = {} ) {
@@ -22,6 +28,13 @@ class CubeRenderTarget extends WebGLCubeRenderTarget {
 
 	}
 
+	/**
+	 * Converts the given equirectangular texture to a cube map.
+	 *
+	 * @param {Renderer} renderer - The renderer.
+	 * @param {Texture} texture - The equirectangular texture.
+	 * @return {CubeRenderTarget} A reference to this cube render target.
+	 */
 	fromEquirectangularTexture( renderer, texture ) {
 
 		const currentMinFilter = texture.minFilter;

+ 25 - 2
src/renderers/common/IndirectStorageBufferAttribute.js

@@ -1,11 +1,34 @@
 import StorageBufferAttribute from './StorageBufferAttribute.js';
 
+/**
+ * This special type of buffer attribute is intended for compute shaders.
+ * It can be used to encode draw parameters for indirect draw calls.
+ *
+ * Note: This type of buffer attribute can only be used with `WebGPURenderer`
+ * and a WebGPU backend.
+ *
+ * @augments StorageBufferAttribute
+ */
 class IndirectStorageBufferAttribute extends StorageBufferAttribute {
 
-	constructor( array, itemSize ) {
+	/**
+	 * Constructs a new storage buffer attribute.
+	 *
+	 * @param {Number|Uint32Array} count - The item count. It is also valid to pass a `Uint32Array` as an argument.
+	 * The subsequent parameter is then obsolete.
+	 * @param {Number} itemSize - The item size.
+	 */
+	constructor( count, itemSize ) {
 
-		super( array, itemSize, Uint32Array );
+		super( count, itemSize, Uint32Array );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isIndirectStorageBufferAttribute = true;
 
 	}

+ 121 - 0
src/renderers/common/SampledTexture.js

@@ -2,23 +2,80 @@ import Binding from './Binding.js';
 
 let _id = 0;
 
+/**
+ * Represents a sampled texture binding type.
+ *
+ * @private
+ * @augments Binding
+ */
 class SampledTexture extends Binding {
 
+	/**
+	 * Constructs a new sampled texture.
+	 *
+	 * @param {String} name - The sampled texture's name.
+	 * @param {Texture?} texture - The texture this binding is referring to.
+	 */
 	constructor( name, texture ) {
 
 		super( name );
 
+		/**
+		 * This identifier.
+		 *
+		 * @type {Number}
+		 */
 		this.id = _id ++;
 
+		/**
+		 * The texture this binding is referring to.
+		 *
+		 * @type {Texture?}
+		 */
 		this.texture = texture;
+
+		/**
+		 * The binding's version.
+		 *
+		 * @type {Number}
+		 */
 		this.version = texture ? texture.version : 0;
+
+		/**
+		 * Whether the texture is a storage texture or not.
+		 *
+		 * @type {Boolean}
+		 * @default false
+		 */
 		this.store = false;
+
+		/**
+		 * The binding's generation which is an additional version
+		 * qualifier.
+		 *
+		 * @type {Number?}
+		 * @default null
+		 */
 		this.generation = null;
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isSampledTexture = true;
 
 	}
 
+	/**
+	 * Returns `true` whether this binding requires an update for the
+	 * given generation.
+	 *
+	 * @param {Number} generation - The generation.
+	 * @return {Boolean} Whether an update is required or not.
+	 */
 	needsBindingsUpdate( generation ) {
 
 		const { texture } = this;
@@ -35,6 +92,13 @@ class SampledTexture extends Binding {
 
 	}
 
+	/**
+	 * Updates the binding.
+	 *
+	 * @param {Number} generation - The generation.
+	 * @return {Boolean} Whether the texture has been updated and must be
+	 * uploaded to the GPU.
+	 */
 	update() {
 
 		const { texture, version } = this;
@@ -53,36 +117,93 @@ class SampledTexture extends Binding {
 
 }
 
+/**
+ * Represents a sampled array texture binding type.
+ *
+ * @private
+ * @augments SampledTexture
+ */
 class SampledArrayTexture extends SampledTexture {
 
+	/**
+	 * Constructs a new sampled array texture.
+	 *
+	 * @param {String} name - The sampled array texture's name.
+	 * @param {(DataArrayTexture|CompressedArrayTexture)?} texture - The texture this binding is referring to.
+	 */
 	constructor( name, texture ) {
 
 		super( name, texture );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isSampledArrayTexture = true;
 
 	}
 
 }
 
+/**
+ * Represents a sampled 3D texture binding type.
+ *
+ * @private
+ * @augments SampledTexture
+ */
 class Sampled3DTexture extends SampledTexture {
 
+	/**
+	 * Constructs a new sampled 3D texture.
+	 *
+	 * @param {String} name - The sampled 3D texture's name.
+	 * @param {Data3DTexture?} texture - The texture this binding is referring to.
+	 */
 	constructor( name, texture ) {
 
 		super( name, texture );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isSampled3DTexture = true;
 
 	}
 
 }
 
+/**
+ * Represents a sampled cube texture binding type.
+ *
+ * @private
+ * @augments SampledTexture
+ */
 class SampledCubeTexture extends SampledTexture {
 
+	/**
+	 * Constructs a new sampled cube texture.
+	 *
+	 * @param {String} name - The sampled cube texture's name.
+	 * @param {(CubeTexture|CompressedCubeTexture)?} texture - The texture this binding is referring to.
+	 */
 	constructor( name, texture ) {
 
 		super( name, texture );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isSampledCubeTexture = true;
 
 	}

+ 30 - 0
src/renderers/common/Sampler.js

@@ -1,14 +1,44 @@
 import Binding from './Binding.js';
 
+/**
+ * Represents a sampler binding type.
+ *
+ * @private
+ * @augments Binding
+ */
 class Sampler extends Binding {
 
+	/**
+	 * Constructs a new sampler.
+	 *
+	 * @param {String} name - The samplers's name.
+	 * @param {Texture?} texture - The texture this binding is referring to.
+	 */
 	constructor( name, texture ) {
 
 		super( name );
 
+		/**
+		 * The texture the sampler is referring to.
+		 *
+		 * @type {Texture?}
+		 */
 		this.texture = texture;
+
+		/**
+		 * The binding's version.
+		 *
+		 * @type {Number}
+		 */
 		this.version = texture ? texture.version : 0;
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isSampler = true;
 
 	}

+ 31 - 2
src/renderers/common/StorageBufferAttribute.js

@@ -1,13 +1,42 @@
 import { BufferAttribute } from '../../core/BufferAttribute.js';
 
+/**
+ * This special type of buffer attribute is intended for compute shaders.
+ * In earlier three.js versions it was only possible to update attribute data
+ * on the CPU via JavaScript and then upload the data to the GPU. With the
+ * new material system and renderer it is now possible to use compute shaders
+ * to compute the data for an attribute more efficiently on the GPU.
+ *
+ * The idea is to create an instance of this class and provide it as an input
+ * to {@link module:StorageBufferNode}.
+ *
+ * Note: This type of buffer attribute can only be used with `WebGPURenderer`.
+ *
+ * @augments BufferAttribute
+ */
 class StorageBufferAttribute extends BufferAttribute {
 
-	constructor( array, itemSize, typeClass = Float32Array ) {
+	/**
+	 * Constructs a new storage buffer attribute.
+	 *
+	 * @param {Number|TypedArray} count - The item count. It is also valid to pass a typed array as an argument.
+	 * The subsequent parameters are then obsolete.
+	 * @param {Number} itemSize - The item size.
+	 * @param {TypedArray.contructor} [typeClass=Float32Array] - A typed array constructor.
+	 */
+	constructor( count, itemSize, typeClass = Float32Array ) {
 
-		if ( ArrayBuffer.isView( array ) === false ) array = new typeClass( array * itemSize );
+		const array = ArrayBuffer.isView( count ) ? count : new typeClass( count * itemSize );
 
 		super( array, itemSize );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isStorageBufferAttribute = true;
 
 	}

+ 31 - 2
src/renderers/common/StorageInstancedBufferAttribute.js

@@ -1,13 +1,42 @@
 import { InstancedBufferAttribute } from '../../core/InstancedBufferAttribute.js';
 
+/**
+ * This special type of instanced buffer attribute is intended for compute shaders.
+ * In earlier three.js versions it was only possible to update attribute data
+ * on the CPU via JavaScript and then upload the data to the GPU. With the
+ * new material system and renderer it is now possible to use compute shaders
+ * to compute the data for an attribute more efficiently on the GPU.
+ *
+ * The idea is to create an instance of this class and provide it as an input
+ * to {@link module:StorageBufferNode}.
+ *
+ * Note: This type of buffer attribute can only be used with `WebGPURenderer`.
+ *
+ * @augments InstancedBufferAttribute
+ */
 class StorageInstancedBufferAttribute extends InstancedBufferAttribute {
 
-	constructor( array, itemSize, typeClass = Float32Array ) {
+	/**
+	 * Constructs a new storage instanced buffer attribute.
+	 *
+	 * @param {Number|TypedArray} count - The item count. It is also valid to pass a typed array as an argument.
+	 * The subsequent parameters are then obsolete.
+	 * @param {Number} itemSize - The item size.
+	 * @param {TypedArray.contructor} [typeClass=Float32Array] - A typed array constructor.
+	 */
+	constructor( count, itemSize, typeClass = Float32Array ) {
 
-		if ( ArrayBuffer.isView( array ) === false ) array = new typeClass( array * itemSize );
+		const array = ArrayBuffer.isView( count ) ? count : new typeClass( count * itemSize );
 
 		super( array, itemSize );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isStorageInstancedBufferAttribute = true;
 
 	}

+ 38 - 0
src/renderers/common/StorageTexture.js

@@ -1,17 +1,55 @@
 import { Texture } from '../../textures/Texture.js';
 import { LinearFilter } from '../../constants.js';
 
+/**
+ * This special type of texture is intended for compute shaders.
+ * It can be used to compute the data of a texture with a compute shader.
+ *
+ * Note: This type of texture can only be used with `WebGPURenderer`
+ * and a WebGPU backend.
+ *
+ * @augments Texture
+ */
 class StorageTexture extends Texture {
 
+	/**
+	 * Constructs a new storage texture.
+	 *
+	 * @param {Number} [width=1] - The storage texture's width.
+	 * @param {Number} [height=1] - The storage texture's height.
+	 */
 	constructor( width = 1, height = 1 ) {
 
 		super();
 
+		/**
+		 * The image object which just represents the texture's dimension.
+		 *
+		 * @type {{width: Number, height:Number}}
+		 */
 		this.image = { width, height };
 
+		/**
+		 * The default `magFilter` for storage textures is `THREE.LinearFilter`.
+		 *
+		 * @type {Number}
+		 */
 		this.magFilter = LinearFilter;
+
+		/**
+		 * The default `minFilter` for storage textures is `THREE.LinearFilter`.
+		 *
+		 * @type {Number}
+		 */
 		this.minFilter = LinearFilter;
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isStorageTexture = true;
 
 	}

+ 82 - 0
src/renderers/common/Textures.js

@@ -6,18 +6,54 @@ import { DepthStencilFormat, DepthFormat, UnsignedIntType, UnsignedInt248Type, E
 
 const _size = /*@__PURE__*/ new Vector3();
 
+/**
+ * This module manages the textures of the renderer.
+ *
+ * @private
+ */
 class Textures extends DataMap {
 
+	/**
+	 * Constructs a new texture management component.
+	 *
+	 * @param {Renderer} renderer - The renderer.
+	 * @param {Backend} backend - The renderer's backend.
+	 * @param {Info} info - Renderer component for managing metrics and monitoring data.
+	 */
 	constructor( renderer, backend, info ) {
 
 		super();
 
+		/**
+		 * The renderer.
+		 *
+		 * @type {Renderer}
+		 */
 		this.renderer = renderer;
+
+		/**
+		 * The backend.
+		 *
+		 * @type {Backend}
+		 */
 		this.backend = backend;
+
+		/**
+		 * Renderer component for managing metrics and monitoring data.
+		 *
+		 * @type {Info}
+		 */
 		this.info = info;
 
 	}
 
+	/**
+	 * Updates the given render target. Based on the given render target configuration,
+	 * it updates the texture states representing the attachments of the framebuffer.
+	 *
+	 * @param {RenderTarget} renderTarget - The render target to update.
+	 * @param {Number} [activeMipmapLevel=0] - The active mipmap level.
+	 */
 	updateRenderTarget( renderTarget, activeMipmapLevel = 0 ) {
 
 		const renderTargetData = this.get( renderTarget );
@@ -139,6 +175,14 @@ class Textures extends DataMap {
 
 	}
 
+	/**
+	 * Updates the given texture. Depending on the texture state, this method
+	 * triggers the upload of texture data to the GPU memory. If the texture data are
+	 * not yet ready for the upload, it uses default texture data for as a placeholder.
+	 *
+	 * @param {Texture} texture - The texture to update.
+	 * @param {Object} [options={}] - The options.
+	 */
 	updateTexture( texture, options = {} ) {
 
 		const textureData = this.get( texture );
@@ -292,6 +336,18 @@ class Textures extends DataMap {
 
 	}
 
+	/**
+	 * Computes the size of the given texture and writes the result
+	 * into the target vector. This vector is also returned by the
+	 * method.
+	 *
+	 * If no texture data are available for the compute yet, the method
+	 * returns default size values.
+	 *
+	 * @param {Texture} texture - The texture to compute the size for.
+	 * @param {Vector3} target - The target vector.
+	 * @return {Vector3} The target vector.
+	 */
 	getSize( texture, target = _size ) {
 
 		let image = texture.images ? texture.images[ 0 ] : texture.image;
@@ -314,6 +370,14 @@ class Textures extends DataMap {
 
 	}
 
+	/**
+	 * Computes the number of mipmap levels for the given texture.
+	 *
+	 * @param {Texture} texture - The texture.
+	 * @param {Number} width - The texture's width.
+	 * @param {Number} height - The texture's height.
+	 * @return {Number} The number of mipmap levels.
+	 */
 	getMipLevels( texture, width, height ) {
 
 		let mipLevelCount;
@@ -340,12 +404,24 @@ class Textures extends DataMap {
 
 	}
 
+	/**
+	 * Returns `true` if the given texture requires mipmaps.
+	 *
+	 * @param {Texture} texture - The texture.
+	 * @return {Boolean} Whether mipmaps are required or not.
+	 */
 	needsMipmaps( texture ) {
 
 		return this.isEnvironmentTexture( texture ) || texture.isCompressedTexture === true || texture.generateMipmaps;
 
 	}
 
+	/**
+	 * Returns `true` if the given texture is an environment map.
+	 *
+	 * @param {Texture} texture - The texture.
+	 * @return {Boolean} Whether the given texture is an environment map or not.
+	 */
 	isEnvironmentTexture( texture ) {
 
 		const mapping = texture.mapping;
@@ -354,6 +430,12 @@ class Textures extends DataMap {
 
 	}
 
+	/**
+	 * Frees internal resource when the given texture isn't
+	 * required anymore.
+	 *
+	 * @param {Texture} texture - The texture to destroy.
+	 */
 	_destroyTexture( texture ) {
 
 		this.backend.destroySampler( texture );

+ 19 - 0
src/renderers/common/UniformBuffer.js

@@ -1,11 +1,30 @@
 import Buffer from './Buffer.js';
 
+/**
+ * Represents a uniform buffer binding type.
+ *
+ * @private
+ * @augments Buffer
+ */
 class UniformBuffer extends Buffer {
 
+	/**
+	 * Constructs a new uniform buffer.
+	 *
+	 * @param {String} name - The buffer's name.
+	 * @param {TypedArray} [buffer=null] - The buffer.
+	 */
 	constructor( name, buffer = null ) {
 
 		super( name, buffer );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isUniformBuffer = true;
 
 	}

粤ICP备19079148号