From dc985f746e50877878223994a92c7489836370ca Mon Sep 17 00:00:00 2001 From: yushijinhun Date: Wed, 24 Jun 2020 19:15:17 +0800 Subject: [PATCH] Make loop unrolling completely whitespace-insensitive This is just another #19726. Since #20012 is accepted, I think it's okay to make loop unrolling completely whitespace-insensitive. --- docs/api/en/materials/ShaderMaterial.html | 3 --- docs/api/zh/materials/ShaderMaterial.html | 3 --- src/renderers/webgl/WebGLProgram.js | 4 ++-- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/docs/api/en/materials/ShaderMaterial.html b/docs/api/en/materials/ShaderMaterial.html index 29c547a6dc5aa9..9981a41b33d1e3 100644 --- a/docs/api/en/materials/ShaderMaterial.html +++ b/docs/api/en/materials/ShaderMaterial.html @@ -54,9 +54,6 @@

[name]

  • The loop variable has to be *i*.
  • -
  • - The loop has to use a certain whitespace formatting. -
  • #pragma unroll_loop_start diff --git a/docs/api/zh/materials/ShaderMaterial.html b/docs/api/zh/materials/ShaderMaterial.html index 6d8e796eb41d60..53cab6a728d864 100644 --- a/docs/api/zh/materials/ShaderMaterial.html +++ b/docs/api/zh/materials/ShaderMaterial.html @@ -43,9 +43,6 @@

    着色器材质([name])

  • 循环变量必须是*i*。
  • -
  • - 循环必须使用某种空格格式。 -
  • #pragma unroll_loop_start diff --git a/src/renderers/webgl/WebGLProgram.js b/src/renderers/webgl/WebGLProgram.js index 523b49cc5f6eca..105af70eb3d82b 100644 --- a/src/renderers/webgl/WebGLProgram.js +++ b/src/renderers/webgl/WebGLProgram.js @@ -220,7 +220,7 @@ function includeReplacer( match, include ) { // Unroll Loops const deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g; -const unrollLoopPattern = /#pragma unroll_loop_start[\s]+?for\s*\(\s*int i \= (\d+)\; i < (\d+)\; i\s*\+\+\s*\)\s*{([\s\S]+?)(?=\})\}[\s]+?#pragma unroll_loop_end/g; +const unrollLoopPattern = /#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g; function unrollLoops( string ) { @@ -244,7 +244,7 @@ function loopReplacer( match, start, end, snippet ) { for ( let i = parseInt( start ); i < parseInt( end ); i ++ ) { string += snippet - .replace( /\[ i \]/g, '[ ' + i + ' ]' ) + .replace( /\[\s*i\s*\]/g, '[ ' + i + ' ]' ) .replace( /UNROLLED_LOOP_INDEX/g, i ); }