浏览代码

Add index cache for vao

shawn 5 年之前
父节点
当前提交
feb7612972
共有 1 个文件被更改,包括 10 次插入5 次删除
  1. 10 5
      src/renderers/webgl/WebGLBindingStates.js

+ 10 - 5
src/renderers/webgl/WebGLBindingStates.js

@@ -25,9 +25,9 @@
 
 
 			}
 			}
 
 
-			updateBuffers = needsUpdate( geometry );
+			updateBuffers = needsUpdate( geometry, index );
 
 
-			if ( updateBuffers ) saveCache( geometry );
+			if ( updateBuffers ) saveCache( geometry, index );
 
 
 		} else {
 		} else {
 
 
@@ -157,13 +157,14 @@
 			enabledAttributes: enabledAttributes,
 			enabledAttributes: enabledAttributes,
 			attributeDivisors: attributeDivisors,
 			attributeDivisors: attributeDivisors,
 			object: vao,
 			object: vao,
-			attributes: {}
+			attributes: {},
+			index: null
 
 
 		};
 		};
 
 
 	}
 	}
 
 
-	function needsUpdate( geometry ) {
+	function needsUpdate( geometry, index ) {
 
 
 		const cachedAttributes = currentState.attributes;
 		const cachedAttributes = currentState.attributes;
 		const geometryAttributes = geometry.attributes;
 		const geometryAttributes = geometry.attributes;
@@ -181,11 +182,13 @@
 
 
 		}
 		}
 
 
+		if ( currentState.index !== index ) return true;
+
 		return false;
 		return false;
 
 
 	}
 	}
 
 
-	function saveCache( geometry ) {
+	function saveCache( geometry, index ) {
 
 
 		const cache = {};
 		const cache = {};
 		const attributes = geometry.attributes;
 		const attributes = geometry.attributes;
@@ -209,6 +212,8 @@
 
 
 		currentState.attributes = cache;
 		currentState.attributes = cache;
 
 
+		currentState.index = index;
+
 	}
 	}
 
 
 	function initAttributes() {
 	function initAttributes() {