4
4
*
5
5
* GPU Accelerated JavaScript
6
6
*
7
- * @version 2.6.6
8
- * @date Fri Jan 24 2020 10:39:16 GMT-0500 (Eastern Standard Time)
7
+ * @version 2.7.0
8
+ * @date Tue Mar 10 2020 15:46:55 GMT-0400 (Eastern Daylight Time)
9
9
*
10
10
* @license MIT
11
11
* The MIT License
@@ -2984,6 +2984,7 @@ class FunctionNode {
2984
2984
'sin' ,
2985
2985
'sqrt' ,
2986
2986
'tan' ,
2987
+ 'tanh'
2987
2988
] ;
2988
2989
return ast . type === 'CallExpression' &&
2989
2990
ast . callee &&
@@ -4352,12 +4353,13 @@ function getToArrayString(kernelResult, textureName) {
4352
4353
throw new Error ( 'unhandled fromObject' ) ;
4353
4354
}
4354
4355
} ,
4355
- thisLookup : ( property ) => {
4356
+ thisLookup : ( property , isDeclaration ) => {
4356
4357
if ( property === 'texture' ) {
4357
4358
return textureName ;
4358
4359
}
4359
4360
if ( property === 'context' ) {
4360
- return null ;
4361
+ if ( isDeclaration ) return null ;
4362
+ return 'gl' ;
4361
4363
}
4362
4364
if ( property === '_framebuffer' ) {
4363
4365
return '_framebuffer' ;
@@ -5502,10 +5504,7 @@ class GLTextureFloat extends GLTexture {
5502
5504
}
5503
5505
renderRawOutput ( ) {
5504
5506
const { context : gl , size } = this ;
5505
- if ( ! this . _framebuffer ) {
5506
- this . _framebuffer = gl . createFramebuffer ( ) ;
5507
- }
5508
- gl . bindFramebuffer ( gl . FRAMEBUFFER , this . _framebuffer ) ;
5507
+ gl . bindFramebuffer ( gl . FRAMEBUFFER , this . framebuffer ( ) ) ;
5509
5508
gl . framebufferTexture2D (
5510
5509
gl . FRAMEBUFFER ,
5511
5510
gl . COLOR_ATTACHMENT0 ,
@@ -5570,12 +5569,7 @@ class GLTexture extends Texture {
5570
5569
console . warn ( 'cloning internal texture' ) ;
5571
5570
}
5572
5571
const existingFramebuffer = gl . getParameter ( gl . FRAMEBUFFER_BINDING ) ;
5573
- if ( ! this . _framebuffer ) {
5574
- this . _framebuffer = gl . createFramebuffer ( ) ;
5575
- }
5576
- this . _framebuffer . width = size [ 0 ] ;
5577
- this . _framebuffer . height = size [ 1 ] ;
5578
- gl . bindFramebuffer ( gl . FRAMEBUFFER , this . _framebuffer ) ;
5572
+ gl . bindFramebuffer ( gl . FRAMEBUFFER , this . framebuffer ( ) ) ;
5579
5573
selectTexture ( gl , texture ) ;
5580
5574
gl . framebufferTexture2D ( gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , gl . TEXTURE_2D , texture , 0 ) ;
5581
5575
const target = gl . createTexture ( ) ;
@@ -5589,13 +5583,32 @@ class GLTexture extends Texture {
5589
5583
}
5590
5584
}
5591
5585
5586
+ clear ( ) {
5587
+ const { context : gl , size, texture } = this ;
5588
+ gl . bindFramebuffer ( gl . FRAMEBUFFER , this . framebuffer ( ) ) ;
5589
+ gl . bindTexture ( gl . TEXTURE_2D , texture ) ;
5590
+ selectTexture ( gl , texture ) ;
5591
+ gl . framebufferTexture2D ( gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , gl . TEXTURE_2D , texture , 0 ) ;
5592
+ gl . clearColor ( 0 , 0 , 0 , 0 ) ;
5593
+ gl . clear ( gl . COLOR_BUFFER_BIT | gl . DEPTH_BUFFER_BIT ) ;
5594
+ }
5595
+
5592
5596
delete ( ) {
5593
5597
super . delete ( ) ;
5594
5598
if ( this . texture . _refs === 0 && this . _framebuffer ) {
5595
5599
this . context . deleteFramebuffer ( this . _framebuffer ) ;
5596
5600
this . _framebuffer = null ;
5597
5601
}
5598
5602
}
5603
+
5604
+ framebuffer ( ) {
5605
+ if ( ! this . _framebuffer ) {
5606
+ this . _framebuffer = this . context . createFramebuffer ( ) ;
5607
+ }
5608
+ this . _framebuffer . width = this . size [ 0 ] ;
5609
+ this . _framebuffer . height = this . size [ 1 ] ;
5610
+ return this . _framebuffer ;
5611
+ }
5599
5612
}
5600
5613
5601
5614
function selectTexture ( gl , texture ) {
@@ -5908,7 +5921,6 @@ class KernelValue {
5908
5921
this . name = name ;
5909
5922
this . origin = origin ;
5910
5923
this . tactic = tactic ;
5911
- this . id = `${ this . origin } _${ name } ` ;
5912
5924
this . varName = origin === 'constants' ? `constants.${ name } ` : name ;
5913
5925
this . kernel = kernel ;
5914
5926
this . strictIntegers = strictIntegers ;
@@ -5923,6 +5935,10 @@ class KernelValue {
5923
5935
this . forceUploadEachRun = null ;
5924
5936
}
5925
5937
5938
+ get id ( ) {
5939
+ return `${ this . origin } _${ name } ` ;
5940
+ }
5941
+
5926
5942
getSource ( ) {
5927
5943
throw new Error ( `"getSource" not defined on ${ this . constructor . name } ` ) ;
5928
5944
}
@@ -7962,7 +7978,7 @@ class WebGLFunctionNode extends FunctionNode {
7962
7978
case 'Array(2)' :
7963
7979
case 'Array(3)' :
7964
7980
case 'Array(4)' :
7965
- retArr . push ( `constants_${ name } ` ) ;
7981
+ retArr . push ( `constants_${ utils . sanitizeName ( name ) } ` ) ;
7966
7982
return retArr ;
7967
7983
}
7968
7984
}
@@ -7998,12 +8014,12 @@ class WebGLFunctionNode extends FunctionNode {
7998
8014
case 'Integer' :
7999
8015
case 'Float' :
8000
8016
case 'Boolean' :
8001
- retArr . push ( `${ origin } _${ name } ` ) ;
8017
+ retArr . push ( `${ origin } _${ utils . sanitizeName ( name ) } ` ) ;
8002
8018
return retArr ;
8003
8019
}
8004
8020
}
8005
8021
8006
- const markupName = `${ origin } _${ name } ` ;
8022
+ const markupName = `${ origin } _${ utils . sanitizeName ( name ) } ` ;
8007
8023
8008
8024
switch ( type ) {
8009
8025
case 'Array(2)' :
@@ -8235,7 +8251,7 @@ class WebGLFunctionNode extends FunctionNode {
8235
8251
if ( targetType === argumentType ) {
8236
8252
if ( argument . type === 'Identifier' ) {
8237
8253
retArr . push ( `user_${ utils . sanitizeName ( argument . name ) } ` ) ;
8238
- } else if ( argument . type === 'ArrayExpression' || argument . type === 'MemberExpression' ) {
8254
+ } else if ( argument . type === 'ArrayExpression' || argument . type === 'MemberExpression' || argument . type === 'CallExpression' ) {
8239
8255
this . astGeneric ( argument , retArr ) ;
8240
8256
} else {
8241
8257
throw this . astErrorOutput ( `Unhandled argument type ${ argument . type } ` , ast ) ;
@@ -9013,6 +9029,7 @@ module.exports = {
9013
9029
WebGLKernelValueHTMLVideo
9014
9030
} ;
9015
9031
} , { "./html-image" :53 } ] , 55 :[ function ( require , module , exports ) {
9032
+ const { utils } = require ( '../../../utils' ) ;
9016
9033
const { KernelValue } = require ( '../../kernel-value' ) ;
9017
9034
9018
9035
class WebGLKernelValue extends KernelValue {
@@ -9029,6 +9046,10 @@ class WebGLKernelValue extends KernelValue {
9029
9046
this . prevArg = null ;
9030
9047
}
9031
9048
9049
+ get id ( ) {
9050
+ return `${ this . origin } _${ utils . sanitizeName ( this . name ) } ` ;
9051
+ }
9052
+
9032
9053
setup ( ) { }
9033
9054
9034
9055
getTransferArrayType ( value ) {
@@ -9067,7 +9088,7 @@ class WebGLKernelValue extends KernelValue {
9067
9088
module . exports = {
9068
9089
WebGLKernelValue
9069
9090
} ;
9070
- } , { "../../kernel-value" :34 } ] , 56 :[ function ( require , module , exports ) {
9091
+ } , { "../../../utils" : 113 , "../../ kernel-value" :34 } ] , 56 :[ function ( require , module , exports ) {
9071
9092
const { utils } = require ( '../../../utils' ) ;
9072
9093
const { WebGLKernelValue } = require ( './index' ) ;
9073
9094
@@ -9977,7 +9998,7 @@ class WebGLKernel extends GLKernel {
9977
9998
9978
9999
for ( let index = 0 ; index < args . length ; index ++ ) {
9979
10000
const value = args [ index ] ;
9980
- const name = utils . sanitizeName ( this . argumentNames [ index ] ) ;
10001
+ const name = this . argumentNames [ index ] ;
9981
10002
let type ;
9982
10003
if ( needsArgumentTypes ) {
9983
10004
type = utils . getVariableType ( value , this . strictIntegers ) ;
@@ -10026,8 +10047,7 @@ class WebGLKernel extends GLKernel {
10026
10047
}
10027
10048
this . constantBitRatios = { } ;
10028
10049
let textureIndexes = 0 ;
10029
- for ( const p in this . constants ) {
10030
- const name = utils . sanitizeName ( p ) ;
10050
+ for ( const name in this . constants ) {
10031
10051
const value = this . constants [ name ] ;
10032
10052
let type ;
10033
10053
if ( needsConstantTypes ) {
@@ -14246,7 +14266,7 @@ const utils = {
14246
14266
}
14247
14267
case 'VariableDeclarator' :
14248
14268
if ( ast . init . object && ast . init . object . type === 'ThisExpression' ) {
14249
- const lookup = thisLookup ( ast . init . property . name ) ;
14269
+ const lookup = thisLookup ( ast . init . property . name , true ) ;
14250
14270
if ( lookup ) {
14251
14271
return `${ ast . id . name } = ${ flatten ( ast . init ) } ` ;
14252
14272
} else {
0 commit comments