浏览代码

WebGPURenderer: optimize interleaved buffer update (#28704)

* optimize: remove useless interleavedBuffer update

* fix: fix webgl instance error
ypy 1 年之前
父节点
当前提交
7a50693865
共有 1 个文件被更改,包括 28 次插入5 次删除
  1. 28 5
      examples/jsm/renderers/common/Geometries.js

+ 28 - 5
examples/jsm/renderers/common/Geometries.js

@@ -76,7 +76,8 @@ class Geometries extends DataMap {
 		this.info = info;
 
 		this.wireframes = new WeakMap();
-		this.attributeVersion = new WeakMap();
+
+		this.attributeCall = new WeakMap();
 
 	}
 
@@ -170,13 +171,35 @@ class Geometries extends DataMap {
 
 	updateAttribute( attribute, type ) {
 
-		const attributeData = attribute.isInterleavedBufferAttribute ? attribute.data : attribute;
+		const callId = this.info.render.calls;
+
+		if ( ! attribute.isInterleavedBufferAttribute ) {
+
+			if ( this.attributeCall.get( attribute ) !== callId ) {
+
+				this.attributes.update( attribute, type );
+
+				this.attributeCall.set( attribute, callId );
+
+			}
+
+		} else {
+
+			if ( this.attributeCall.get( attribute ) === undefined ) {
+
+				this.attributes.update( attribute, type );
+
+				this.attributeCall.set( attribute, callId );
 
-		if ( this.attributeVersion.get( attribute ) !== attributeData.version ) {
+			} else if ( this.attributeCall.get( attribute.data ) !== callId ) {
 
-			this.attributes.update( attribute, type );
+				this.attributes.update( attribute, type );
 
-			this.attributeVersion.set( attribute, attributeData.version );
+				this.attributeCall.set( attribute.data, callId );
+
+				this.attributeCall.set( attribute, callId );
+
+			}
 
 		}