55 * GPU Accelerated JavaScript
66 *
77 * @version 1.6.0
8- * @date Thu Aug 30 2018 13:55:05 GMT-0500 (Central Daylight Time)
8+ * @date Thu Aug 30 2018 18:28:28 GMT-0500 (Central Daylight Time)
99 *
1010 * @license MIT
1111 * The MIT License
@@ -2632,7 +2632,7 @@ module.exports = function (_WebGLKernel) {
26322632 var gl = this . _webGl ;
26332633 var texSize = this . texSize ;
26342634 var texture = this . outputTexture = this . _webGl . createTexture ( ) ;
2635- gl . activeTexture ( gl . TEXTURE0 + this . paramNames . length ) ;
2635+ gl . activeTexture ( gl . TEXTURE0 + this . constantsLength + this . paramNames . length ) ;
26362636 gl . bindTexture ( gl . TEXTURE_2D , texture ) ;
26372637 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
26382638 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
@@ -2658,7 +2658,7 @@ module.exports = function (_WebGLKernel) {
26582658 var texture = this . _webGl . createTexture ( ) ;
26592659 textures . push ( texture ) ;
26602660 drawBuffersMap . push ( gl . COLOR_ATTACHMENT0 + i + 1 ) ;
2661- gl . activeTexture ( gl . TEXTURE0 + this . paramNames . length + i ) ;
2661+ gl . activeTexture ( gl . TEXTURE0 + this . constantsLength + this . paramNames . length + i ) ;
26622662 gl . bindTexture ( gl . TEXTURE_2D , texture ) ;
26632663 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
26642664 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
@@ -2690,7 +2690,7 @@ module.exports = function (_WebGLKernel) {
26902690 floatTextures : this . floatTextures ,
26912691 floatOutput : this . floatOutput
26922692 } , dim ) ;
2693- gl . activeTexture ( gl . TEXTURE0 + this . argumentsLength ) ;
2693+ gl . activeTexture ( gl . TEXTURE0 + this . constantsLength + this . argumentsLength ) ;
26942694 gl . bindTexture ( gl . TEXTURE_2D , argumentTexture ) ;
26952695 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
26962696 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
@@ -2733,7 +2733,7 @@ module.exports = function (_WebGLKernel) {
27332733 floatTextures : this . floatTextures ,
27342734 floatOutput : this . floatOutput
27352735 } , _dim ) ;
2736- gl . activeTexture ( gl . TEXTURE0 + this . argumentsLength ) ;
2736+ gl . activeTexture ( gl . TEXTURE0 + this . constantsLength + this . argumentsLength ) ;
27372737 gl . bindTexture ( gl . TEXTURE_2D , argumentTexture ) ;
27382738 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
27392739 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
@@ -2767,7 +2767,7 @@ module.exports = function (_WebGLKernel) {
27672767 var _dim2 = [ inputImage . width , inputImage . height , 1 ] ;
27682768 var _size2 = [ inputImage . width , inputImage . height ] ;
27692769
2770- gl . activeTexture ( gl . TEXTURE0 + this . argumentsLength ) ;
2770+ gl . activeTexture ( gl . TEXTURE0 + this . constantsLength + this . argumentsLength ) ;
27712771 gl . bindTexture ( gl . TEXTURE_2D , argumentTexture ) ;
27722772 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
27732773 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
@@ -2790,7 +2790,7 @@ module.exports = function (_WebGLKernel) {
27902790 var _dim3 = [ inputImages [ 0 ] . width , inputImages [ 0 ] . height , inputImages . length ] ;
27912791 var _size3 = [ inputImages [ 0 ] . width , inputImages [ 0 ] . height ] ;
27922792
2793- gl . activeTexture ( gl . TEXTURE0 + this . argumentsLength ) ;
2793+ gl . activeTexture ( gl . TEXTURE0 + this . constantsLength + this . argumentsLength ) ;
27942794 gl . bindTexture ( gl . TEXTURE_2D_ARRAY , argumentTexture ) ;
27952795 gl . texParameteri ( gl . TEXTURE_2D_ARRAY , gl . TEXTURE_MAG_FILTER , gl . NEAREST ) ;
27962796 gl . texParameteri ( gl . TEXTURE_2D_ARRAY , gl . TEXTURE_MIN_FILTER , gl . NEAREST ) ;
@@ -2821,7 +2821,7 @@ module.exports = function (_WebGLKernel) {
28212821 var _dim4 = inputTexture . dimensions ;
28222822 var _size4 = inputTexture . size ;
28232823
2824- gl . activeTexture ( gl . TEXTURE0 + this . argumentsLength ) ;
2824+ gl . activeTexture ( gl . TEXTURE0 + this . constantsLength + this . argumentsLength ) ;
28252825 gl . bindTexture ( gl . TEXTURE_2D , inputTexture . texture ) ;
28262826
28272827 this . setUniform3iv ( 'user_' + name + 'Dim' , _dim4 ) ;
@@ -2837,6 +2837,137 @@ module.exports = function (_WebGLKernel) {
28372837 }
28382838
28392839
2840+ } , {
2841+ key : '_addConstant' ,
2842+ value : function _addConstant ( value , type , name ) {
2843+ var gl = this . _webGl ;
2844+ var argumentTexture = this . getArgumentTexture ( name ) ;
2845+ if ( value instanceof Texture ) {
2846+ type = 'Texture' ;
2847+ }
2848+ switch ( type ) {
2849+ case 'Array' :
2850+ {
2851+ var dim = utils . getDimensions ( value , true ) ;
2852+ var size = utils . dimToTexSize ( {
2853+ floatTextures : this . floatTextures ,
2854+ floatOutput : this . floatOutput
2855+ } , dim ) ;
2856+ gl . activeTexture ( gl . TEXTURE0 + this . constantsLength ) ;
2857+ gl . bindTexture ( gl . TEXTURE_2D , argumentTexture ) ;
2858+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
2859+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
2860+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . NEAREST ) ;
2861+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , gl . NEAREST ) ;
2862+
2863+ var length = size [ 0 ] * size [ 1 ] ;
2864+
2865+ var _formatArrayTransfer3 = this . _formatArrayTransfer ( value , length ) ,
2866+ valuesFlat = _formatArrayTransfer3 . valuesFlat ,
2867+ bitRatio = _formatArrayTransfer3 . bitRatio ;
2868+
2869+ var buffer = void 0 ;
2870+ if ( this . floatTextures ) {
2871+ gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , size [ 0 ] , size [ 1 ] , 0 , gl . RGBA , gl . FLOAT , valuesFlat ) ;
2872+ } else {
2873+ buffer = new Uint8Array ( valuesFlat . buffer ) ;
2874+ gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , size [ 0 ] / bitRatio , size [ 1 ] , 0 , gl . RGBA , gl . UNSIGNED_BYTE , buffer ) ;
2875+ }
2876+
2877+ if ( ! this . hardcodeConstants ) {
2878+ this . setUniform3iv ( 'constants_' + name + 'Dim' , dim ) ;
2879+ this . setUniform2iv ( 'constants_' + name + 'Size' , size ) ;
2880+ }
2881+ this . setUniform1i ( 'constants_' + name + 'BitRatio' , bitRatio ) ;
2882+ this . setUniform1i ( 'constants_' + name , this . constantsLength ) ;
2883+ break ;
2884+ }
2885+ case 'Integer' :
2886+ case 'Float' :
2887+ {
2888+ this . setUniform1f ( 'constants_' + name , value ) ;
2889+ break ;
2890+ }
2891+ case 'Input' :
2892+ {
2893+ var input = value ;
2894+ var _dim5 = input . size ;
2895+ var _size5 = utils . dimToTexSize ( {
2896+ floatTextures : this . floatTextures ,
2897+ floatOutput : this . floatOutput
2898+ } , _dim5 ) ;
2899+ gl . activeTexture ( gl . TEXTURE0 + this . constantsLength ) ;
2900+ gl . bindTexture ( gl . TEXTURE_2D , argumentTexture ) ;
2901+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
2902+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
2903+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . NEAREST ) ;
2904+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , gl . NEAREST ) ;
2905+
2906+ var _length2 = _size5 [ 0 ] * _size5 [ 1 ] ;
2907+
2908+ var _formatArrayTransfer4 = this . _formatArrayTransfer ( value . value , _length2 ) ,
2909+ _valuesFlat2 = _formatArrayTransfer4 . valuesFlat ,
2910+ _bitRatio2 = _formatArrayTransfer4 . bitRatio ;
2911+
2912+ if ( this . floatTextures ) {
2913+ gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA32F , _size5 [ 0 ] , _size5 [ 1 ] , 0 , gl . RGBA , gl . FLOAT , inputArray ) ;
2914+ } else {
2915+ var _buffer2 = new Uint8Array ( _valuesFlat2 . buffer ) ;
2916+ gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , _size5 [ 0 ] / _bitRatio2 , _size5 [ 1 ] , 0 , gl . RGBA , gl . UNSIGNED_BYTE , _buffer2 ) ;
2917+ }
2918+
2919+ if ( ! this . hardcodeConstants ) {
2920+ this . setUniform3iv ( 'constants_' + name + 'Dim' , _dim5 ) ;
2921+ this . setUniform2iv ( 'constants_' + name + 'Size' , _size5 ) ;
2922+ }
2923+ this . setUniform1i ( 'constants_' + name + 'BitRatio' , _bitRatio2 ) ;
2924+ this . setUniform1i ( 'constants_' + name , this . constantsLength ) ;
2925+ break ;
2926+ }
2927+ case 'HTMLImage' :
2928+ {
2929+ var inputImage = value ;
2930+ var _dim6 = [ inputImage . width , inputImage . height , 1 ] ;
2931+ var _size6 = [ inputImage . width , inputImage . height ] ;
2932+
2933+ gl . activeTexture ( gl . TEXTURE0 + this . constantsLength ) ;
2934+ gl . bindTexture ( gl . TEXTURE_2D , argumentTexture ) ;
2935+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
2936+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
2937+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . NEAREST ) ;
2938+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , gl . NEAREST ) ;
2939+ gl . pixelStorei ( gl . UNPACK_FLIP_Y_WEBGL , true ) ;
2940+ var mipLevel = 0 ;
2941+ var internalFormat = gl . RGBA ;
2942+ var srcFormat = gl . RGBA ;
2943+ var srcType = gl . UNSIGNED_BYTE ;
2944+ gl . texImage2D ( gl . TEXTURE_2D , mipLevel , internalFormat , srcFormat , srcType , inputImage ) ;
2945+ this . setUniform3iv ( 'constants_' + name + 'Dim' , _dim6 ) ;
2946+ this . setUniform2iv ( 'constants_' + name + 'Size' , _size6 ) ;
2947+ this . setUniform1i ( 'constants_' + name , this . constantsLength ) ;
2948+ break ;
2949+ }
2950+ case 'Texture' :
2951+ {
2952+ var inputTexture = value ;
2953+ var _dim7 = inputTexture . dimensions ;
2954+ var _size7 = inputTexture . size ;
2955+
2956+ gl . activeTexture ( gl . TEXTURE0 + this . constantsLength ) ;
2957+ gl . bindTexture ( gl . TEXTURE_2D , inputTexture . texture ) ;
2958+
2959+ this . setUniform3iv ( 'constants_' + name + 'Dim' , _dim7 ) ;
2960+ this . setUniform2iv ( 'constants_' + name + 'Size' , _size7 ) ;
2961+ this . setUniform1i ( 'constants_' + name + 'BitRatio' , 1 ) ;
2962+ this . setUniform1i ( 'constants_' + name , this . constantsLength ) ;
2963+ break ;
2964+ }
2965+ default :
2966+ throw new Error ( 'Input type not supported (WebGL): ' + value ) ;
2967+ }
2968+ }
2969+
2970+
28402971 } , {
28412972 key : '_getGetResultString' ,
28422973 value : function _getGetResultString ( ) {
@@ -4363,10 +4494,12 @@ module.exports = function (_KernelBase) {
43634494 gl . bindFramebuffer ( gl . FRAMEBUFFER , this . framebuffer ) ;
43644495
43654496 for ( var p in this . constants ) {
4497+ var value = this . constants [ p ] ;
43664498 var type = utils . getArgumentType ( value ) ;
43674499 if ( type === 'Decimal' || type === 'Integer' ) {
43684500 continue ;
43694501 }
4502+ gl . useProgram ( this . program ) ;
43704503 this . _addConstant ( this . constants [ p ] , type , p ) ;
43714504 this . constantsLength ++ ;
43724505 }
@@ -4953,7 +5086,6 @@ module.exports = function (_KernelBase) {
49535086 default :
49545087 throw new Error ( 'Input type not supported (WebGL): ' + value ) ;
49555088 }
4956- this . constantsLength ++ ;
49575089 }
49585090
49595091
@@ -5136,15 +5268,14 @@ module.exports = function (_KernelBase) {
51365268 if ( this . constants ) {
51375269 for ( var name in this . constants ) {
51385270 if ( ! this . constants . hasOwnProperty ( name ) ) continue ;
5139- var _value = this . constants [ name ] ;
5140- var type = utils . getArgumentType ( _value ) ;
5141- console . log ( "Constant detected of type:" , type ) ;
5271+ var value = this . constants [ name ] ;
5272+ var type = utils . getArgumentType ( value ) ;
51425273 switch ( type ) {
51435274 case 'Integer' :
5144- result . push ( 'const float constants_' + name + ' = ' + parseInt ( _value ) + '.0' ) ;
5275+ result . push ( 'const float constants_' + name + ' = ' + parseInt ( value ) + '.0' ) ;
51455276 break ;
51465277 case 'Float' :
5147- result . push ( 'const float constants_' + name + ' = ' + parseFloat ( _value ) ) ;
5278+ result . push ( 'const float constants_' + name + ' = ' + parseFloat ( value ) ) ;
51485279 break ;
51495280 case 'Texture' :
51505281 result . push ( 'uniform sampler2D constants_' + name , 'uniform ivec2 constants_' + name + 'Size' , 'uniform ivec3 constants_' + name + 'Dim' , 'uniform highp int constants_' + name + 'BitRatio' ) ;
0 commit comments