浏览代码

WebGPURenderPipelines: Avoid usage of objectProperties. (#21768)

Michael Herzog 4 年之前
父节点
当前提交
6acaabc7b8
共有 1 个文件被更改,包括 25 次插入15 次删除
  1. 25 15
      examples/jsm/renderers/webgpu/WebGPURenderPipelines.js

+ 25 - 15
examples/jsm/renderers/webgpu/WebGPURenderPipelines.js

@@ -29,13 +29,13 @@ class WebGPURenderPipelines {
 		const properties = this.properties;
 		const properties = this.properties;
 
 
 		const material = object.material;
 		const material = object.material;
-
 		const materialProperties = properties.get( material );
 		const materialProperties = properties.get( material );
-		const objectProperties = properties.get( object );
 
 
-		let currentPipeline = objectProperties.currentPipeline;
+		const cache = this._getCache( object );
+
+		let currentPipeline;
 
 
-		if ( this._needsUpdate( object ) ) {
+		if ( this._needsUpdate( object, cache ) ) {
 
 
 			// get shader
 			// get shader
 
 
@@ -64,7 +64,7 @@ class WebGPURenderPipelines {
 			// determine render pipeline
 			// determine render pipeline
 
 
 			currentPipeline = this._acquirePipeline( stageVertex, stageFragment, object, nodeBuilder );
 			currentPipeline = this._acquirePipeline( stageVertex, stageFragment, object, nodeBuilder );
-			objectProperties.currentPipeline = currentPipeline;
+			cache.currentPipeline = currentPipeline;
 
 
 			// keep track of all pipelines which are used by a material
 			// keep track of all pipelines which are used by a material
 
 
@@ -98,6 +98,10 @@ class WebGPURenderPipelines {
 
 
 			}
 			}
 
 
+		} else {
+
+			currentPipeline = cache.currentPipeline;
+
 		}
 		}
 
 
 		return currentPipeline;
 		return currentPipeline;
@@ -174,6 +178,21 @@ class WebGPURenderPipelines {
 
 
 	}
 	}
 
 
+	_getCache( object ) {
+
+		let cache = this.objectCache.get( object );
+
+		if ( cache === undefined ) {
+
+			cache = {};
+			this.objectCache.set( object, cache );
+
+		}
+
+		return cache;
+
+	}
+
 	_releasePipeline( pipeline ) {
 	_releasePipeline( pipeline ) {
 
 
 		if ( -- pipeline.usedTimes === 0 ) {
 		if ( -- pipeline.usedTimes === 0 ) {
@@ -204,16 +223,7 @@ class WebGPURenderPipelines {
 
 
 	}
 	}
 
 
-	_needsUpdate( object ) {
-
-		let cache = this.objectCache.get( object );
-
-		if ( cache === undefined ) {
-
-			cache = {};
-			this.objectCache.set( object, cache );
-
-		}
+	_needsUpdate( object, cache ) {
 
 
 		const material = object.material;
 		const material = object.material;