Răsfoiți Sursa

Renderer: Document more modules. (#30224)

* Renderer: Document more modules.

* Renderer: Document more modules.

* Fix typo.
Michael Herzog 1 an în urmă
părinte
comite
9d4c2918ae

+ 41 - 0
src/renderers/common/BindGroup.js

@@ -1,14 +1,55 @@
 let _id = 0;
 
+/**
+ * Represents a bind group.
+ *
+ * @private
+ */
 class BindGroup {
 
+	/**
+	 * Constructs a new bind group.
+	 *
+	 * @param {String} name - The bind group's name.
+	 * @param {Array<Binding>} bindings - An array of bindings.
+	 * @param {Number} index - The group index.
+	 * @param {Array<Binding>} bindingsReference - An array of reference bindings.
+	 */
 	constructor( name = '', bindings = [], index = 0, bindingsReference = [] ) {
 
+		/**
+		 * The bind group's name.
+		 *
+		 * @type {String}
+		 */
 		this.name = name;
+
+		/**
+		 * An array of bindings.
+		 *
+		 * @type {Array<Binding>}
+		 */
 		this.bindings = bindings;
+
+		/**
+		 * The group index.
+		 *
+		 * @type {Number}
+		 */
 		this.index = index;
+
+		/**
+		 * An array of reference bindings.
+		 *
+		 * @type {Array<Binding>}
+		 */
 		this.bindingsReference = bindingsReference;
 
+		/**
+		 * The group's ID.
+		 *
+		 * @type {Number}
+		 */
 		this.id = _id ++;
 
 	}

+ 89 - 0
src/renderers/common/Bindings.js

@@ -1,23 +1,80 @@
 import DataMap from './DataMap.js';
 import { AttributeType } from './Constants.js';
 
+/**
+ * This renderer module manages the bindings of the renderer.
+ *
+ * @private
+ * @augments DataMap
+ */
 class Bindings extends DataMap {
 
+	/**
+	 * Constructs a new bindings management component.
+	 *
+	 * @param {Backend} backend - The renderer's backend.
+	 * @param {Nodes} nodes - Renderer component for managing nodes related logic.
+	 * @param {Textures} textures - Renderer component for managing textures.
+	 * @param {Attributes} attributes - Renderer component for managing attributes.
+	 * @param {Pipelines} pipelines - Renderer component for managing pipelines.
+	 * @param {Info} info - Renderer component for managing metrics and monitoring data.
+	 */
 	constructor( backend, nodes, textures, attributes, pipelines, info ) {
 
 		super();
 
+		/**
+		 * The renderer's backend.
+		 *
+		 * @type {Backend}
+		 */
 		this.backend = backend;
+
+		/**
+		 * Renderer component for managing textures.
+		 *
+		 * @type {Textures}
+		 */
 		this.textures = textures;
+
+		/**
+		 * Renderer component for managing pipelines.
+		 *
+		 * @type {Pipelines}
+		 */
 		this.pipelines = pipelines;
+
+		/**
+		 * Renderer component for managing attributes.
+		 *
+		 * @type {Attributes}
+		 */
 		this.attributes = attributes;
+
+		/**
+		 * Renderer component for managing nodes related logic.
+		 *
+		 * @type {Nodes}
+		 */
 		this.nodes = nodes;
+
+		/**
+		 * Renderer component for managing metrics and monitoring data.
+		 *
+		 * @type {Info}
+		 */
 		this.info = info;
 
 		this.pipelines.bindings = this; // assign bindings to pipelines
 
 	}
 
+	/**
+	 * Returns the bind groups for the given render object.
+	 *
+	 * @param {RenderObject} renderObject - The render object.
+	 * @return {Array<BindGroup>} The bind groups.
+	 */
 	getForRender( renderObject ) {
 
 		const bindings = renderObject.getBindings();
@@ -44,6 +101,12 @@ class Bindings extends DataMap {
 
 	}
 
+	/**
+	 * Returns the bind groups for the given compute node.
+	 *
+	 * @param {Node} computeNode - The compute node.
+	 * @return {Array<BindGroup>} The bind groups.
+	 */
 	getForCompute( computeNode ) {
 
 		const bindings = this.nodes.getForCompute( computeNode ).bindings;
@@ -68,18 +131,33 @@ class Bindings extends DataMap {
 
 	}
 
+	/**
+	 * Updates the bindings for the given compute node.
+	 *
+	 * @param {Node} computeNode - The compute node.
+	 */
 	updateForCompute( computeNode ) {
 
 		this._updateBindings( this.getForCompute( computeNode ) );
 
 	}
 
+	/**
+	 * Updates the bindings for the given render object.
+	 *
+	 * @param {RenderObject} renderObject - The render object.
+	 */
 	updateForRender( renderObject ) {
 
 		this._updateBindings( this.getForRender( renderObject ) );
 
 	}
 
+	/**
+	 * Updates the given array of bindings.
+	 *
+	 * @param {Array<BindGroup>} bindings - The bind groups.
+	 */
 	_updateBindings( bindings ) {
 
 		for ( const bindGroup of bindings ) {
@@ -90,6 +168,11 @@ class Bindings extends DataMap {
 
 	}
 
+	/**
+	 * Initializes the given bind group.
+	 *
+	 * @param {BindGroup} bindGroup - The bind group to initialize.
+	 */
 	_init( bindGroup ) {
 
 		for ( const binding of bindGroup.bindings ) {
@@ -111,6 +194,12 @@ class Bindings extends DataMap {
 
 	}
 
+	/**
+	 * Updates the given bind group.
+	 *
+	 * @param {BindGroup} bindGroup - The bind group to update.
+	 * @param {Array<BindGroup>} bindings - The bind groups.
+	 */
 	_update( bindGroup, bindings ) {
 
 		const { backend } = this;

+ 1 - 1
src/renderers/common/Buffer.js

@@ -61,7 +61,7 @@ class Buffer extends Binding {
 	/**
 	 * A reference to the internal buffer.
 	 *
-	 * @type {Number}
+	 * @type {Float32Array}
 	 * @readonly
 	 */
 	get buffer() {

+ 1 - 0
src/renderers/common/Pipelines.js

@@ -7,6 +7,7 @@ import ProgrammableStage from './ProgrammableStage.js';
  * This renderer module manages the pipelines of the renderer.
  *
  * @private
+ * @augments DataMap
  */
 class Pipelines extends DataMap {
 

+ 24 - 0
src/renderers/common/StorageBuffer.js

@@ -1,13 +1,37 @@
 import Buffer from './Buffer.js';
 
+/**
+ * Represents a storage buffer binding type.
+ *
+ * @private
+ * @augments Buffer
+ */
 class StorageBuffer extends Buffer {
 
+	/**
+	 * Constructs a new uniform buffer.
+	 *
+	 * @param {String} name - The buffer's name.
+	 * @param {BufferAttribute} attribute - The buffer attribute.
+	 */
 	constructor( name, attribute ) {
 
 		super( name, attribute ? attribute.array : null );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {BufferAttribute}
+		 */
 		this.attribute = attribute;
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isStorageBuffer = true;
 
 	}

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

@@ -10,6 +10,7 @@ const _size = /*@__PURE__*/ new Vector3();
  * This module manages the textures of the renderer.
  *
  * @private
+ * @augments DataMap
  */
 class Textures extends DataMap {
 

+ 188 - 2
src/renderers/common/Uniform.js

@@ -5,26 +5,79 @@ import { Vector2 } from '../../math/Vector2.js';
 import { Vector3 } from '../../math/Vector3.js';
 import { Vector4 } from '../../math/Vector4.js';
 
+/**
+ * Abstract base class for uniforms.
+ *
+ * @abstract
+ * @private
+ */
 class Uniform {
 
+	/**
+	 * Constructs a new uniform.
+	 *
+	 * @param {String} name - The uniform's name.
+	 * @param {Any} value - The uniform's value.
+	 */
 	constructor( name, value ) {
 
+		/**
+		 * The uniform's name.
+		 *
+		 * @type {String}
+		 */
 		this.name = name;
+
+		/**
+		 * The uniform's value.
+		 *
+		 * @type {Any}
+		 */
 		this.value = value;
 
-		this.boundary = 0; // used to build the uniform buffer according to the STD140 layout
+		/**
+		 * Used to build the uniform buffer according to the STD140 layout.
+		 * Derived uniforms will set this property to a data type specific
+		 * value.
+		 *
+		 * @type {Number}
+		 */
+		this.boundary = 0;
+
+		/**
+		 * The item size. Derived uniforms will set this property to a data
+		 * type specific value.
+		 *
+		 * @type {Number}
+		 */
 		this.itemSize = 0;
 
-		this.offset = 0; // this property is set by WebGPUUniformsGroup and marks the start position in the uniform buffer
+		/**
+		 * This property is set by {@link UniformsGroup} and marks
+		 * the start position in the uniform buffer.
+		 *
+		 * @type {Number}
+		 */
+		this.offset = 0;
 
 	}
 
+	/**
+	 * Sets the uniform's value.
+	 *
+	 * @param {Any} value - The value to set.
+	 */
 	setValue( value ) {
 
 		this.value = value;
 
 	}
 
+	/**
+	 * Returns the uniform's value.
+	 *
+	 * @return {Any} The value.
+	 */
 	getValue() {
 
 		return this.value;
@@ -33,12 +86,31 @@ class Uniform {
 
 }
 
+/**
+ * Represents a Number uniform.
+ *
+ * @private
+ * @augments Uniform
+ */
 class NumberUniform extends Uniform {
 
+	/**
+	 * Constructs a new Number uniform.
+	 *
+	 * @param {String} name - The uniform's name.
+	 * @param {Number} value - The uniform's value.
+	 */
 	constructor( name, value = 0 ) {
 
 		super( name, value );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isNumberUniform = true;
 
 		this.boundary = 4;
@@ -48,12 +120,31 @@ class NumberUniform extends Uniform {
 
 }
 
+/**
+ * Represents a Vector2 uniform.
+ *
+ * @private
+ * @augments Uniform
+ */
 class Vector2Uniform extends Uniform {
 
+	/**
+	 * Constructs a new Number uniform.
+	 *
+	 * @param {String} name - The uniform's name.
+	 * @param {Vector2} value - The uniform's value.
+	 */
 	constructor( name, value = new Vector2() ) {
 
 		super( name, value );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isVector2Uniform = true;
 
 		this.boundary = 8;
@@ -63,12 +154,31 @@ class Vector2Uniform extends Uniform {
 
 }
 
+/**
+ * Represents a Vector3 uniform.
+ *
+ * @private
+ * @augments Uniform
+ */
 class Vector3Uniform extends Uniform {
 
+	/**
+	 * Constructs a new Number uniform.
+	 *
+	 * @param {String} name - The uniform's name.
+	 * @param {Vector3} value - The uniform's value.
+	 */
 	constructor( name, value = new Vector3() ) {
 
 		super( name, value );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isVector3Uniform = true;
 
 		this.boundary = 16;
@@ -78,12 +188,31 @@ class Vector3Uniform extends Uniform {
 
 }
 
+/**
+ * Represents a Vector4 uniform.
+ *
+ * @private
+ * @augments Uniform
+ */
 class Vector4Uniform extends Uniform {
 
+	/**
+	 * Constructs a new Number uniform.
+	 *
+	 * @param {String} name - The uniform's name.
+	 * @param {Vector4} value - The uniform's value.
+	 */
 	constructor( name, value = new Vector4() ) {
 
 		super( name, value );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isVector4Uniform = true;
 
 		this.boundary = 16;
@@ -93,12 +222,31 @@ class Vector4Uniform extends Uniform {
 
 }
 
+/**
+ * Represents a Color uniform.
+ *
+ * @private
+ * @augments Uniform
+ */
 class ColorUniform extends Uniform {
 
+	/**
+	 * Constructs a new Number uniform.
+	 *
+	 * @param {String} name - The uniform's name.
+	 * @param {Color} value - The uniform's value.
+	 */
 	constructor( name, value = new Color() ) {
 
 		super( name, value );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isColorUniform = true;
 
 		this.boundary = 16;
@@ -108,12 +256,31 @@ class ColorUniform extends Uniform {
 
 }
 
+/**
+ * Represents a Matrix3 uniform.
+ *
+ * @private
+ * @augments Uniform
+ */
 class Matrix3Uniform extends Uniform {
 
+	/**
+	 * Constructs a new Number uniform.
+	 *
+	 * @param {String} name - The uniform's name.
+	 * @param {Matrix3} value - The uniform's value.
+	 */
 	constructor( name, value = new Matrix3() ) {
 
 		super( name, value );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isMatrix3Uniform = true;
 
 		this.boundary = 48;
@@ -123,12 +290,31 @@ class Matrix3Uniform extends Uniform {
 
 }
 
+/**
+ * Represents a Matrix4 uniform.
+ *
+ * @private
+ * @augments Uniform
+ */
 class Matrix4Uniform extends Uniform {
 
+	/**
+	 * Constructs a new Number uniform.
+	 *
+	 * @param {String} name - The uniform's name.
+	 * @param {Matrix4} value - The uniform's value.
+	 */
 	constructor( name, value = new Matrix4() ) {
 
 		super( name, value );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isMatrix4Uniform = true;
 
 		this.boundary = 64;

+ 139 - 2
src/renderers/common/UniformsGroup.js

@@ -1,22 +1,59 @@
 import UniformBuffer from './UniformBuffer.js';
 import { GPU_CHUNK_BYTES } from './Constants.js';
 
+/**
+ * This class represents a uniform buffer binding but with
+ * an API that allows to maintain individual uniform objects.
+ *
+ * @private
+ * @augments UniformBuffer
+ */
 class UniformsGroup extends UniformBuffer {
 
+	/**
+	 * Constructs a new uniforms group.
+	 *
+	 * @param {String} name - The group's name.
+	 */
 	constructor( name ) {
 
 		super( name );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isUniformsGroup = true;
 
+		/**
+		 * An array with the raw uniform values.
+		 *
+		 * @private
+		 * @type {Array<Number>?}
+		 * @default null
+		 */
 		this._values = null;
 
-		// the order of uniforms in this array must match the order of uniforms in the shader
-
+		/**
+		 * An array of uniform objects.
+		 *
+		 * The order of uniforms in this array must match the order of uniforms in the shader.
+		 *
+		 * @type {Array<Uniform>}
+		 */
 		this.uniforms = [];
 
 	}
 
+	/**
+	 * Adds a uniform to this group.
+	 *
+	 * @param {Uniform} uniform - The uniform to add.
+	 * @return {UniformsGroup} A reference to this group.
+	 */
 	addUniform( uniform ) {
 
 		this.uniforms.push( uniform );
@@ -25,6 +62,12 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * Removes a uniform from this group.
+	 *
+	 * @param {Uniform} uniform - The uniform to remove.
+	 * @return {UniformsGroup} A reference to this group.
+	 */
 	removeUniform( uniform ) {
 
 		const index = this.uniforms.indexOf( uniform );
@@ -39,6 +82,11 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * An array with the raw uniform values.
+	 *
+	 * @type {Array<Number>}
+	 */
 	get values() {
 
 		if ( this._values === null ) {
@@ -51,6 +99,11 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * A Float32 array buffer with the uniform values.
+	 *
+	 * @type {Float32Array}
+	 */
 	get buffer() {
 
 		let buffer = this._buffer;
@@ -69,6 +122,11 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * The byte length of the buffer with correct buffer alignment.
+	 *
+	 * @type {Number}
+	 */
 	get byteLength() {
 
 		let offset = 0; // global buffer offset in bytes
@@ -110,6 +168,15 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * Updates this group by updating each uniform object of
+	 * the internal uniform list. The uniform objects check if their
+	 * values has actually changed so this method only returns
+	 * `true` if there is a real value change.
+	 *
+	 * @return {Boolean} Whether the uniforms have been updated and
+	 * must be uploaded to the GPU.
+	 */
 	update() {
 
 		let updated = false;
@@ -128,6 +195,13 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * Updates a given uniform by calling an update method matching
+	 * the uniforms type.
+	 *
+	 * @param {Uniform} uniform - The uniform to update.
+	 * @return {Boolean} Whether the uniform has been updated or not.
+	 */
 	updateByType( uniform ) {
 
 		if ( uniform.isNumberUniform ) return this.updateNumber( uniform );
@@ -142,6 +216,12 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * Updates a given Number uniform.
+	 *
+	 * @param {NumberUniform} uniform - The Number uniform.
+	 * @return {Boolean} Whether the uniform has been updated or not.
+	 */
 	updateNumber( uniform ) {
 
 		let updated = false;
@@ -164,6 +244,12 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * Updates a given Vector2 uniform.
+	 *
+	 * @param {Vector2Uniform} uniform - The Vector2 uniform.
+	 * @return {Boolean} Whether the uniform has been updated or not.
+	 */
 	updateVector2( uniform ) {
 
 		let updated = false;
@@ -188,6 +274,12 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * Updates a given Vector3 uniform.
+	 *
+	 * @param {Vector3Uniform} uniform - The Vector3 uniform.
+	 * @return {Boolean} Whether the uniform has been updated or not.
+	 */
 	updateVector3( uniform ) {
 
 		let updated = false;
@@ -213,6 +305,12 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * Updates a given Vector4 uniform.
+	 *
+	 * @param {Vector4Uniform} uniform - The Vector4 uniform.
+	 * @return {Boolean} Whether the uniform has been updated or not.
+	 */
 	updateVector4( uniform ) {
 
 		let updated = false;
@@ -239,6 +337,12 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * Updates a given Color uniform.
+	 *
+	 * @param {ColorUniform} uniform - The Color uniform.
+	 * @return {Boolean} Whether the uniform has been updated or not.
+	 */
 	updateColor( uniform ) {
 
 		let updated = false;
@@ -263,6 +367,12 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * Updates a given Matrix3 uniform.
+	 *
+	 * @param {Matrix3Uniform} uniform - The Matrix3 uniform.
+	 * @return {Boolean} Whether the uniform has been updated or not.
+	 */
 	updateMatrix3( uniform ) {
 
 		let updated = false;
@@ -295,6 +405,12 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * Updates a given Matrix4 uniform.
+	 *
+	 * @param {Matrix4Uniform} uniform - The Matrix4 uniform.
+	 * @return {Boolean} Whether the uniform has been updated or not.
+	 */
 	updateMatrix4( uniform ) {
 
 		let updated = false;
@@ -316,6 +432,12 @@ class UniformsGroup extends UniformBuffer {
 
 	}
 
+	/**
+	 * Returns a typed array that matches the given data type.
+	 *
+	 * @param {String} type - The data type.
+	 * @return {TypedArray} The typed array.
+	 */
 	_getBufferForType( type ) {
 
 		if ( type === 'int' || type === 'ivec2' || type === 'ivec3' || type === 'ivec4' ) return new Int32Array( this.buffer.buffer );
@@ -326,6 +448,13 @@ class UniformsGroup extends UniformBuffer {
 
 }
 
+/**
+ * Sets the values of the second array to the first array.
+ *
+ * @param {TypedArray} a - The first array.
+ * @param {TypedArray} b - The second array.
+ * @param {Number} offset - An index offset for the first array.
+ */
 function setArray( a, b, offset ) {
 
 	for ( let i = 0, l = b.length; i < l; i ++ ) {
@@ -336,6 +465,14 @@ function setArray( a, b, offset ) {
 
 }
 
+/**
+ * Returns `true` if the given arrays are equal.
+ *
+ * @param {TypedArray} a - The first array.
+ * @param {TypedArray} b - The second array.
+ * @param {Number} offset - An index offset for the first array.
+ * @return {Boolean} Whether the given arrays are equal or not.
+ */
 function arraysEqual( a, b, offset ) {
 
 	for ( let i = 0, l = b.length; i < l; i ++ ) {

+ 91 - 2
src/renderers/common/nodes/NodeSampledTexture.js

@@ -1,24 +1,69 @@
 import { SampledTexture } from '../SampledTexture.js';
 
+/**
+ * A special form of sampled texture binding type.
+ * It's texture value is managed by a node object.
+ *
+ * @private
+ * @augments SampledTexture
+ */
 class NodeSampledTexture extends SampledTexture {
 
+	/**
+	 * Constructs a new node-based sampled texture.
+	 *
+	 * @param {String} name - The textures's name.
+	 * @param {TextureNode} textureNode - The texture node.
+	 * @param {UniformGroupNode} groupNode - The uniform group node.
+	 * @param {String?} [access=null] - The access type.
+	 */
 	constructor( name, textureNode, groupNode, access = null ) {
 
 		super( name, textureNode ? textureNode.value : null );
 
+		/**
+		 * The texture node.
+		 *
+		 * @type {TextureNode}
+		 */
 		this.textureNode = textureNode;
+
+		/**
+		 * The uniform group node.
+		 *
+		 * @type {UniformGroupNode}
+		 */
 		this.groupNode = groupNode;
 
+		/**
+		 * The access type.
+		 *
+		 * @type {String?}
+		 * @default null
+		 */
 		this.access = access;
 
 	}
 
+	/**
+	 * Overwrites the default to additionally check if the node value has changed.
+	 *
+	 * @param {Number} generation - The generation.
+	 * @return {Boolean} Whether an update is required or not.
+	 */
 	needsBindingsUpdate( generation ) {
 
 		return this.textureNode.value !== this.texture || super.needsBindingsUpdate( generation );
 
 	}
 
+	/**
+	 * 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 { textureNode } = this;
@@ -37,24 +82,68 @@ class NodeSampledTexture extends SampledTexture {
 
 }
 
+/**
+ * A special form of sampled cube texture binding type.
+ * It's texture value is managed by a node object.
+ *
+ * @private
+ * @augments NodeSampledTexture
+ */
 class NodeSampledCubeTexture extends NodeSampledTexture {
 
-	constructor( name, textureNode, groupNode, access ) {
+	/**
+	 * Constructs a new node-based sampled cube texture.
+	 *
+	 * @param {String} name - The textures's name.
+	 * @param {TextureNode} textureNode - The texture node.
+	 * @param {UniformGroupNode} groupNode - The uniform group node.
+	 * @param {String?} [access=null] - The access type.
+	 */
+	constructor( name, textureNode, groupNode, access = null ) {
 
 		super( name, textureNode, groupNode, access );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isSampledCubeTexture = true;
 
 	}
 
 }
 
+/**
+ * A special form of sampled 3D texture binding type.
+ * It's texture value is managed by a node object.
+ *
+ * @private
+ * @augments NodeSampledTexture
+ */
 class NodeSampledTexture3D extends NodeSampledTexture {
 
-	constructor( name, textureNode, groupNode, access ) {
+	/**
+	 * Constructs a new node-based sampled 3D texture.
+	 *
+	 * @param {String} name - The textures's name.
+	 * @param {TextureNode} textureNode - The texture node.
+	 * @param {UniformGroupNode} groupNode - The uniform group node.
+	 * @param {String?} [access=null] - The access type.
+	 */
+	constructor( name, textureNode, groupNode, access = null ) {
 
 		super( name, textureNode, groupNode, access );
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isSampledTexture3D = true;
 
 	}

+ 28 - 0
src/renderers/common/nodes/NodeSampler.js

@@ -1,16 +1,44 @@
 import Sampler from '../Sampler.js';
 
+/**
+ * A special form of sampler binding type.
+ * It's texture value is managed by a node object.
+ *
+ * @private
+ * @augments Sampler
+ */
 class NodeSampler extends Sampler {
 
+	/**
+	 * Constructs a new node-based sampler.
+	 *
+	 * @param {String} name - The samplers's name.
+	 * @param {TextureNode} textureNode - The texture node.
+	 * @param {UniformGroupNode} groupNode - The uniform group node.
+	 */
 	constructor( name, textureNode, groupNode ) {
 
 		super( name, textureNode ? textureNode.value : null );
 
+		/**
+		 * The texture node.
+		 *
+		 * @type {TextureNode}
+		 */
 		this.textureNode = textureNode;
+
+		/**
+		 * The uniform group node.
+		 *
+		 * @type {UniformGroupNode}
+		 */
 		this.groupNode = groupNode;
 
 	}
 
+	/**
+	 * Updates the texture value of this sampler.
+	 */
 	update() {
 
 		this.texture = this.textureNode.value;

+ 35 - 0
src/renderers/common/nodes/NodeStorageBuffer.js

@@ -3,18 +3,53 @@ import { NodeAccess } from '../../../nodes/core/constants.js';
 
 let _id = 0;
 
+/**
+ * A special form of storage buffer binding type.
+ * It's buffer value is managed by a node object.
+ *
+ * @private
+ * @augments StorageBuffer
+ */
 class NodeStorageBuffer extends StorageBuffer {
 
+	/**
+	 * Constructs a new node-based storage buffer.
+	 *
+	 * @param {StorageBufferNode} nodeUniform - The storage buffer node.
+	 * @param {UniformGroupNode} groupNode - The uniform group node.
+	 */
 	constructor( nodeUniform, groupNode ) {
 
 		super( 'StorageBuffer_' + _id ++, nodeUniform ? nodeUniform.value : null );
 
+		/**
+		 * The node uniform.
+		 *
+		 * @type {StorageBufferNode}
+		 */
 		this.nodeUniform = nodeUniform;
+
+		/**
+		 * The access type.
+		 *
+		 * @type {String}
+		 */
 		this.access = nodeUniform ? nodeUniform.access : NodeAccess.READ_WRITE;
+
+		/**
+		 * The uniform group node.
+		 *
+		 * @type {UniformGroupNode}
+		 */
 		this.groupNode = groupNode;
 
 	}
 
+	/**
+	 * The storage buffer.
+	 *
+	 * @type {BufferAttribute}
+	 */
 	get buffer() {
 
 		return this.nodeUniform.value;

+ 189 - 0
src/renderers/common/nodes/NodeUniform.js

@@ -3,22 +3,49 @@ import {
 	ColorUniform, Matrix3Uniform, Matrix4Uniform
 } from '../Uniform.js';
 
+/**
+ * A special form of Number uniform binding type.
+ * It's value is managed by a node object.
+ *
+ * @private
+ * @augments NumberUniform
+ */
 class NumberNodeUniform extends NumberUniform {
 
+	/**
+	 * Constructs a new node-based Number uniform.
+	 *
+	 * @param {NodeUniform} nodeUniform - The node uniform.
+	 */
 	constructor( nodeUniform ) {
 
 		super( nodeUniform.name, nodeUniform.value );
 
+		/**
+		 * The node uniform.
+		 *
+		 * @type {NodeUniform}
+		 */
 		this.nodeUniform = nodeUniform;
 
 	}
 
+	/**
+	 * Overwritten to return the value of the node uniform.
+	 *
+	 * @return {Number} The value.
+	 */
 	getValue() {
 
 		return this.nodeUniform.value;
 
 	}
 
+	/**
+	 * Returns the node uniform data type.
+	 *
+	 * @return {String} The data type.
+	 */
 	getType() {
 
 		return this.nodeUniform.type;
@@ -27,22 +54,49 @@ class NumberNodeUniform extends NumberUniform {
 
 }
 
+/**
+ * A special form of Vector2 uniform binding type.
+ * It's value is managed by a node object.
+ *
+ * @private
+ * @augments Vector2Uniform
+ */
 class Vector2NodeUniform extends Vector2Uniform {
 
+	/**
+	 * Constructs a new node-based Vector2 uniform.
+	 *
+	 * @param {NodeUniform} nodeUniform - The node uniform.
+	 */
 	constructor( nodeUniform ) {
 
 		super( nodeUniform.name, nodeUniform.value );
 
+		/**
+		 * The node uniform.
+		 *
+		 * @type {NodeUniform}
+		 */
 		this.nodeUniform = nodeUniform;
 
 	}
 
+	/**
+	 * Overwritten to return the value of the node uniform.
+	 *
+	 * @return {Vector2} The value.
+	 */
 	getValue() {
 
 		return this.nodeUniform.value;
 
 	}
 
+	/**
+	 * Returns the node uniform data type.
+	 *
+	 * @return {String} The data type.
+	 */
 	getType() {
 
 		return this.nodeUniform.type;
@@ -51,22 +105,49 @@ class Vector2NodeUniform extends Vector2Uniform {
 
 }
 
+/**
+ * A special form of Vector3 uniform binding type.
+ * It's value is managed by a node object.
+ *
+ * @private
+ * @augments Vector3Uniform
+ */
 class Vector3NodeUniform extends Vector3Uniform {
 
+	/**
+	 * Constructs a new node-based Vector3 uniform.
+	 *
+	 * @param {NodeUniform} nodeUniform - The node uniform.
+	 */
 	constructor( nodeUniform ) {
 
 		super( nodeUniform.name, nodeUniform.value );
 
+		/**
+		 * The node uniform.
+		 *
+		 * @type {NodeUniform}
+		 */
 		this.nodeUniform = nodeUniform;
 
 	}
 
+	/**
+	 * Overwritten to return the value of the node uniform.
+	 *
+	 * @return {Vector3} The value.
+	 */
 	getValue() {
 
 		return this.nodeUniform.value;
 
 	}
 
+	/**
+	 * Returns the node uniform data type.
+	 *
+	 * @return {String} The data type.
+	 */
 	getType() {
 
 		return this.nodeUniform.type;
@@ -75,22 +156,49 @@ class Vector3NodeUniform extends Vector3Uniform {
 
 }
 
+/**
+ * A special form of Vector4 uniform binding type.
+ * It's value is managed by a node object.
+ *
+ * @private
+ * @augments Vector4Uniform
+ */
 class Vector4NodeUniform extends Vector4Uniform {
 
+	/**
+	 * Constructs a new node-based Vector4 uniform.
+	 *
+	 * @param {NodeUniform} nodeUniform - The node uniform.
+	 */
 	constructor( nodeUniform ) {
 
 		super( nodeUniform.name, nodeUniform.value );
 
+		/**
+		 * The node uniform.
+		 *
+		 * @type {NodeUniform}
+		 */
 		this.nodeUniform = nodeUniform;
 
 	}
 
+	/**
+	 * Overwritten to return the value of the node uniform.
+	 *
+	 * @return {Vector4} The value.
+	 */
 	getValue() {
 
 		return this.nodeUniform.value;
 
 	}
 
+	/**
+	 * Returns the node uniform data type.
+	 *
+	 * @return {String} The data type.
+	 */
 	getType() {
 
 		return this.nodeUniform.type;
@@ -99,22 +207,49 @@ class Vector4NodeUniform extends Vector4Uniform {
 
 }
 
+/**
+ * A special form of Color uniform binding type.
+ * It's value is managed by a node object.
+ *
+ * @private
+ * @augments ColorUniform
+ */
 class ColorNodeUniform extends ColorUniform {
 
+	/**
+	 * Constructs a new node-based Color uniform.
+	 *
+	 * @param {NodeUniform} nodeUniform - The node uniform.
+	 */
 	constructor( nodeUniform ) {
 
 		super( nodeUniform.name, nodeUniform.value );
 
+		/**
+		 * The node uniform.
+		 *
+		 * @type {NodeUniform}
+		 */
 		this.nodeUniform = nodeUniform;
 
 	}
 
+	/**
+	 * Overwritten to return the value of the node uniform.
+	 *
+	 * @return {Color} The value.
+	 */
 	getValue() {
 
 		return this.nodeUniform.value;
 
 	}
 
+	/**
+	 * Returns the node uniform data type.
+	 *
+	 * @return {String} The data type.
+	 */
 	getType() {
 
 		return this.nodeUniform.type;
@@ -123,22 +258,49 @@ class ColorNodeUniform extends ColorUniform {
 
 }
 
+/**
+ * A special form of Matrix3 uniform binding type.
+ * It's value is managed by a node object.
+ *
+ * @private
+ * @augments Matrix3Uniform
+ */
 class Matrix3NodeUniform extends Matrix3Uniform {
 
+	/**
+	 * Constructs a new node-based Matrix3 uniform.
+	 *
+	 * @param {NodeUniform} nodeUniform - The node uniform.
+	 */
 	constructor( nodeUniform ) {
 
 		super( nodeUniform.name, nodeUniform.value );
 
+		/**
+		 * The node uniform.
+		 *
+		 * @type {NodeUniform}
+		 */
 		this.nodeUniform = nodeUniform;
 
 	}
 
+	/**
+	 * Overwritten to return the value of the node uniform.
+	 *
+	 * @return {Matrix3} The value.
+	 */
 	getValue() {
 
 		return this.nodeUniform.value;
 
 	}
 
+	/**
+	 * Returns the node uniform data type.
+	 *
+	 * @return {String} The data type.
+	 */
 	getType() {
 
 		return this.nodeUniform.type;
@@ -147,22 +309,49 @@ class Matrix3NodeUniform extends Matrix3Uniform {
 
 }
 
+/**
+ * A special form of Matrix4 uniform binding type.
+ * It's value is managed by a node object.
+ *
+ * @private
+ * @augments Matrix4Uniform
+ */
 class Matrix4NodeUniform extends Matrix4Uniform {
 
+	/**
+	 * Constructs a new node-based Matrix4 uniform.
+	 *
+	 * @param {NodeUniform} nodeUniform - The node uniform.
+	 */
 	constructor( nodeUniform ) {
 
 		super( nodeUniform.name, nodeUniform.value );
 
+		/**
+		 * The node uniform.
+		 *
+		 * @type {NodeUniform}
+		 */
 		this.nodeUniform = nodeUniform;
 
 	}
 
+	/**
+	 * Overwritten to return the value of the node uniform.
+	 *
+	 * @return {Matrix4} The value.
+	 */
 	getValue() {
 
 		return this.nodeUniform.value;
 
 	}
 
+	/**
+	 * Returns the node uniform data type.
+	 *
+	 * @return {String} The data type.
+	 */
 	getType() {
 
 		return this.nodeUniform.type;

+ 29 - 0
src/renderers/common/nodes/NodeUniformBuffer.js

@@ -2,17 +2,46 @@ import UniformBuffer from '../UniformBuffer.js';
 
 let _id = 0;
 
+/**
+ * A special form of uniform buffer binding type.
+ * It's buffer value is managed by a node object.
+ *
+ * @private
+ * @augments UniformBuffer
+ */
 class NodeUniformBuffer extends UniformBuffer {
 
+	/**
+	 * Constructs a new node-based uniform buffer.
+	 *
+	 * @param {BufferNode} nodeUniform - The uniform buffer node.
+	 * @param {UniformGroupNode} groupNode - The uniform group node.
+	 */
 	constructor( nodeUniform, groupNode ) {
 
 		super( 'UniformBuffer_' + _id ++, nodeUniform ? nodeUniform.value : null );
 
+		/**
+		 * The uniform buffer node.
+		 *
+		 * @type {BufferNode}
+		 */
 		this.nodeUniform = nodeUniform;
+
+		/**
+		 * The uniform group node.
+		 *
+		 * @type {UniformGroupNode}
+		 */
 		this.groupNode = groupNode;
 
 	}
 
+	/**
+	 * The uniform buffer.
+	 *
+	 * @type {Float32Array}
+	 */
 	get buffer() {
 
 		return this.nodeUniform.value;

+ 31 - 18
src/renderers/common/nodes/NodeUniformsGroup.js

@@ -2,37 +2,50 @@ import UniformsGroup from '../UniformsGroup.js';
 
 let _id = 0;
 
+/**
+ * A special form of uniforms group that represents
+ * the individual uniforms as node-based uniforms.
+ *
+ * @private
+ * @augments UniformsGroup
+ */
 class NodeUniformsGroup extends UniformsGroup {
 
+	/**
+	 * Constructs a new node-based uniforms group.
+	 *
+	 * @param {String} name - The group's name.
+	 * @param {UniformGroupNode} groupNode - The uniform group node.
+	 */
 	constructor( name, groupNode ) {
 
 		super( name );
 
+		/**
+		 * The group's ID.
+		 *
+		 * @type {Number}
+		 */
 		this.id = _id ++;
+
+		/**
+		 * The uniform group node.
+		 *
+		 * @type {UniformGroupNode}
+		 */
 		this.groupNode = groupNode;
 
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {Boolean}
+		 * @readonly
+		 * @default true
+		 */
 		this.isNodeUniformsGroup = true;
 
 	}
 
-	getNodes() {
-
-		const nodes = [];
-
-		for ( const uniform of this.uniforms ) {
-
-			const node = uniform.nodeUniform.node;
-
-			if ( ! node ) throw new Error( 'NodeUniformsGroup: Uniform has no node.' );
-
-			nodes.push( node );
-
-		}
-
-		return nodes;
-
-	}
-
 }
 
 export default NodeUniformsGroup;

粤ICP备19079148号