Browse Source

WebGLProgram: Flattened unrollLoops().

Mr.doob 5 years ago
parent
commit
0f30055d74
1 changed files with 15 additions and 11 deletions
  1. 15 11
      src/renderers/webgl/WebGLProgram.js

+ 15 - 11
src/renderers/webgl/WebGLProgram.js

@@ -221,30 +221,34 @@ function includeReplacer( match, include ) {
 
 
 }
 }
 
 
-function unrollLoops( string ) {
+// Unroll Loops
+
+var loopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
 
 
-	var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
+function unrollLoops( string ) {
 
 
-	function replace( match, start, end, snippet ) {
+	return string.replace( loopPattern, loopReplacer );
 
 
-		var unroll = '';
+}
 
 
-		for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
+function loopReplacer( match, start, end, snippet ) {
 
 
-			unroll += snippet
-				.replace( /\[ i \]/g, '[ ' + i + ' ]' )
-				.replace( /UNROLLED_LOOP_INDEX/g, i );
+	var string = '';
 
 
-		}
+	for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
 
 
-		return unroll;
+		string += snippet
+			.replace( /\[ i \]/g, '[ ' + i + ' ]' )
+			.replace( /UNROLLED_LOOP_INDEX/g, i );
 
 
 	}
 	}
 
 
-	return string.replace( pattern, replace );
+	return string;
 
 
 }
 }
 
 
+//
+
 function generatePrecision( parameters ) {
 function generatePrecision( parameters ) {
 
 
 	var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
 	var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";