|
4 | 4 | *
|
5 | 5 | * GPU Accelerated JavaScript
|
6 | 6 | *
|
7 |
| - * @version 2.6.2 |
8 |
| - * @date Sun Jan 19 2020 07:44:57 GMT-0500 (Eastern Standard Time) |
| 7 | + * @version 2.6.3 |
| 8 | + * @date Tue Jan 21 2020 07:26:16 GMT-0500 (Eastern Standard Time) |
9 | 9 | *
|
10 | 10 | * @license MIT
|
11 | 11 | * The MIT License
|
@@ -5330,7 +5330,12 @@ class CPUFunctionNode extends FunctionNode {
|
5330 | 5330 | if (i > 0) {
|
5331 | 5331 | retArr.push(',');
|
5332 | 5332 | }
|
5333 |
| - this.astGeneric(declarations[i], retArr); |
| 5333 | + const declaration = declarations[i]; |
| 5334 | + const info = this.getDeclaration(declaration.id); |
| 5335 | + if (!info.valueType) { |
| 5336 | + info.valueType = this.getType(declaration.init); |
| 5337 | + } |
| 5338 | + this.astGeneric(declaration, retArr); |
5334 | 5339 | }
|
5335 | 5340 | if (!this.isState('in-for-loop-init')) {
|
5336 | 5341 | retArr.push(';');
|
@@ -11349,18 +11354,18 @@ void color(sampler2D image) {
|
11349 | 11354 | actualColor = texture2D(image, vTexCoord);
|
11350 | 11355 | }
|
11351 | 11356 |
|
11352 |
| -float modulo(float num1, float num2) { |
11353 |
| - if (num2 == 0.0) { |
11354 |
| - return 0.0; |
| 11357 | +float modulo(float number, float divisor) { |
| 11358 | + if (number < 0.0) { |
| 11359 | + number = abs(number); |
| 11360 | + if (divisor < 0.0) { |
| 11361 | + divisor = abs(divisor); |
| 11362 | + } |
| 11363 | + return -mod(number, divisor); |
11355 | 11364 | }
|
11356 |
| - bool isPositive = num1 >= 0.0; |
11357 |
| - num1 = abs(num1); |
11358 |
| - num2 = abs(num2); |
11359 |
| - for (int i = 0; i < LOOP_MAX; i++) { |
11360 |
| - if (num1 < num2) break; |
11361 |
| - num1 = num1 - num2; |
| 11365 | + if (divisor < 0.0) { |
| 11366 | + divisor = abs(divisor); |
11362 | 11367 | }
|
11363 |
| - return isPositive ? num1 : -num1; |
| 11368 | + return mod(number, divisor); |
11364 | 11369 | }
|
11365 | 11370 |
|
11366 | 11371 | __INJECTED_NATIVE__;
|
@@ -11591,7 +11596,7 @@ class WebGLFunctionNode extends FunctionNode {
|
11591 | 11596 | }
|
11592 | 11597 |
|
11593 | 11598 | if (this.fixIntegerDivisionAccuracy && ast.operator === '/') {
|
11594 |
| - retArr.push('div_with_int_check('); |
| 11599 | + retArr.push('divWithIntCheck('); |
11595 | 11600 | this.pushState('building-float');
|
11596 | 11601 | switch (this.getType(ast.left)) {
|
11597 | 11602 | case 'Integer':
|
@@ -11772,7 +11777,7 @@ class WebGLFunctionNode extends FunctionNode {
|
11772 | 11777 | return bitwiseResult;
|
11773 | 11778 | }
|
11774 | 11779 | const upconvertableOperators = {
|
11775 |
| - '%': 'modulo', |
| 11780 | + '%': this.fixIntegerDivisionAccuracy ? 'integerCorrectionModulo' : 'modulo', |
11776 | 11781 | '**': 'pow',
|
11777 | 11782 | };
|
11778 | 11783 | const foundOperator = upconvertableOperators[ast.operator];
|
@@ -12655,7 +12660,7 @@ class WebGLFunctionNode extends FunctionNode {
|
12655 | 12660 | if (targetType === argumentType) {
|
12656 | 12661 | if (argument.type === 'Identifier') {
|
12657 | 12662 | retArr.push(`user_${argument.name}`);
|
12658 |
| - } else if (argument.type === 'ArrayExpression') { |
| 12663 | + } else if (argument.type === 'ArrayExpression' || argument.type === 'MemberExpression') { |
12659 | 12664 | this.astGeneric(argument, retArr);
|
12660 | 12665 | } else {
|
12661 | 12666 | throw this.astErrorOutput(`Unhandled argument type ${ argument.type }`, ast);
|
@@ -15006,11 +15011,25 @@ class WebGLKernel extends GLKernel {
|
15006 | 15011 |
|
15007 | 15012 | _getDivideWithIntegerCheckString() {
|
15008 | 15013 | return this.fixIntegerDivisionAccuracy ?
|
15009 |
| - `float div_with_int_check(float x, float y) { |
| 15014 | + `float divWithIntCheck(float x, float y) { |
15010 | 15015 | if (floor(x) == x && floor(y) == y && integerMod(x, y) == 0.0) {
|
15011 |
| - return float(int(x)/int(y)); |
| 15016 | + return float(int(x) / int(y)); |
15012 | 15017 | }
|
15013 | 15018 | return x / y;
|
| 15019 | +} |
| 15020 | + |
| 15021 | +float integerCorrectionModulo(float number, float divisor) { |
| 15022 | + if (number < 0.0) { |
| 15023 | + number = abs(number); |
| 15024 | + if (divisor < 0.0) { |
| 15025 | + divisor = abs(divisor); |
| 15026 | + } |
| 15027 | + return -(number - (divisor * floor(divWithIntCheck(number, divisor)))); |
| 15028 | + } |
| 15029 | + if (divisor < 0.0) { |
| 15030 | + divisor = abs(divisor); |
| 15031 | + } |
| 15032 | + return number - (divisor * floor(divWithIntCheck(number, divisor))); |
15014 | 15033 | }` :
|
15015 | 15034 | '';
|
15016 | 15035 | }
|
@@ -15850,18 +15869,18 @@ void color(float r, float g, float b) {
|
15850 | 15869 | color(r,g,b,1.0);
|
15851 | 15870 | }
|
15852 | 15871 |
|
15853 |
| -float modulo(float num1, float num2) { |
15854 |
| - if (num2 == 0.0) { |
15855 |
| - return 0.0; |
| 15872 | +float modulo(float number, float divisor) { |
| 15873 | + if (number < 0.0) { |
| 15874 | + number = abs(number); |
| 15875 | + if (divisor < 0.0) { |
| 15876 | + divisor = abs(divisor); |
| 15877 | + } |
| 15878 | + return -mod(number, divisor); |
15856 | 15879 | }
|
15857 |
| - bool isPositive = num1 >= 0.0; |
15858 |
| - num1 = abs(num1); |
15859 |
| - num2 = abs(num2); |
15860 |
| - for (int i = 0; i < LOOP_MAX; i++) { |
15861 |
| - if (num1 < num2) break; |
15862 |
| - num1 = num1 - num2; |
| 15880 | + if (divisor < 0.0) { |
| 15881 | + divisor = abs(divisor); |
15863 | 15882 | }
|
15864 |
| - return isPositive ? num1 : -num1; |
| 15883 | + return mod(number, divisor); |
15865 | 15884 | }
|
15866 | 15885 |
|
15867 | 15886 | __INJECTED_NATIVE__;
|
|
0 commit comments