closer to webgl2, still failing some tests when reusing or multiple targets

This commit is contained in:
Robert Plummer 2018-02-24 19:31:58 -05:00
parent ce8db7fc2b
commit 178d47b0ef
20 changed files with 121 additions and 378 deletions

View File

@ -4,13 +4,13 @@
*
* GPU Accelerated JavaScript
*
* @version 1.0.0-rc.10
* @date Sat Dec 23 2017 10:30:08 GMT-0500 (EST)
* @version 1.0.0
* @date Sat Feb 24 2018 19:31:19 GMT-0500 (EST)
*
* @license MIT
* The MIT License
*
* Copyright (c) 2017 gpu.js Team
* Copyright (c) 2018 gpu.js Team
*/
"use strict";(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
@ -161,15 +161,7 @@ var UtilsCore = function () {
throw new Error('Invalid canvas object - ' + canvasObj);
}
var webGl = canvasObj.getContext('experimental-webgl', UtilsCore.initWebGlDefaultOptions()) || canvasObj.getContext('webgl', UtilsCore.initWebGlDefaultOptions());
if (webGl) {
webGl.OES_texture_float = webGl.getExtension('OES_texture_float');
webGl.OES_texture_float_linear = webGl.getExtension('OES_texture_float_linear');
webGl.OES_element_index_uint = webGl.getExtension('OES_element_index_uint');
}
return webGl;
return canvasObj.getContext('webgl2', UtilsCore.initWebGlDefaultOptions());
}
}]);
@ -180,17 +172,7 @@ var UtilsCore = function () {
var _isCanvasSupported = typeof document !== 'undefined' ? UtilsCore.isCanvas(document.createElement('canvas')) : false;
var _testingWebGl = UtilsCore.initWebGl(UtilsCore.initCanvas());
var _isWebGlSupported = UtilsCore.isWebGl(_testingWebGl);
var _isWebGlDrawBuffersSupported = _isWebGlSupported && Boolean(_testingWebGl.getExtension('WEBGL_draw_buffers'));
if (_isWebGlSupported) {
UtilsCore.OES_texture_float = _testingWebGl.OES_texture_float;
UtilsCore.OES_texture_float_linear = _testingWebGl.OES_texture_float_linear;
UtilsCore.OES_element_index_uint = _testingWebGl.OES_element_index_uint;
} else {
UtilsCore.OES_texture_float = false;
UtilsCore.OES_texture_float_linear = false;
UtilsCore.OES_element_index_uint = false;
}
var _isWebGlDrawBuffersSupported = _isWebGlSupported;
module.exports = UtilsCore;
},{}],3:[function(require,module,exports){

8
bin/gpu-core.min.js vendored
View File

@ -4,12 +4,12 @@
*
* GPU Accelerated JavaScript
*
* @version 1.0.0-rc.10
* @date Fri Dec 15 2017 20:55:34 GMT+0300 (MSK)
* @version 1.0.0
* @date Sat Feb 24 2018 19:31:19 GMT-0500 (EST)
*
* @license MIT
* The MIT License
*
* Copyright (c) 2017 gpu.js Team
* Copyright (c) 2018 gpu.js Team
*/
"use strict";!function e(n,t,r){function i(u,a){if(!t[u]){if(!n[u]){var l="function"==typeof require&&require;if(!a&&l)return l(u,!0);if(o)return o(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var c=t[u]={exports:{}};n[u][0].call(c.exports,function(e){var t=n[u][1][e];return i(t?t:e)},c,c.exports,e,n,t,r)}return t[u].exports}for(var o="function"==typeof require&&require,u=0;u<r.length;u++)i(r[u]);return i}({1:[function(e,n,t){function r(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}();e("./utils-core");n.exports=function(){function e(){r(this,e)}return i(e,null,[{key:"validateKernelObj",value:function(e){if(null===e)throw"KernelObj being validated is NULL";if("string"==typeof e){try{e=JSON.parse(e)}catch(n){throw console.error(n),"Failed to convert KernelObj from JSON string"}if(null===e)throw"Invalid (NULL) KernelObj JSON string representation"}if(e.isKernelObj!==!0)throw"Failed missing isKernelObj flag check";return e}},{key:"loadKernelObj",value:function(e,n){e=validateKernelObj(e)}}]),e}()},{"./utils-core":2}],2:[function(e,n,t){function r(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),o=function(){function e(){r(this,e)}return i(e,null,[{key:"isCanvas",value:function(e){return null!==e&&e.nodeName&&e.getContext&&"CANVAS"===e.nodeName.toUpperCase()}},{key:"isCanvasSupported",value:function(){return u}},{key:"initCanvas",value:function(){if(!u)return null;var e=document.createElement("canvas");return e.width=2,e.height=2,e}},{key:"isWebGl",value:function(e){return e&&"function"==typeof e.getExtension}},{key:"isWebGlSupported",value:function(){return l}},{key:"isWebGlDrawBuffersSupported",value:function(){return f}},{key:"initWebGlDefaultOptions",value:function(){return{alpha:!1,depth:!1,antialias:!1}}},{key:"initWebGl",value:function(n){if(("undefined"!=typeof u||null===n)&&!u)return null;if(!e.isCanvas(n))throw new Error("Invalid canvas object - "+n);var t=n.getContext("experimental-webgl",e.initWebGlDefaultOptions())||n.getContext("webgl",e.initWebGlDefaultOptions());return t&&(t.OES_texture_float=t.getExtension("OES_texture_float"),t.OES_texture_float_linear=t.getExtension("OES_texture_float_linear"),t.OES_element_index_uint=t.getExtension("OES_element_index_uint")),t}}]),e}(),u="undefined"!=typeof document&&o.isCanvas(document.createElement("canvas")),a=o.initWebGl(o.initCanvas()),l=o.isWebGl(a),f=l&&Boolean(a.getExtension("WEBGL_draw_buffers"));l?(o.OES_texture_float=a.OES_texture_float,o.OES_texture_float_linear=a.OES_texture_float_linear,o.OES_element_index_uint=a.OES_element_index_uint):(o.OES_texture_float=!1,o.OES_texture_float_linear=!1,o.OES_element_index_uint=!1),n.exports=o},{}],3:[function(e,n,t){var r=e("./core/gpu-core");"undefined"!=typeof n&&(n.exports=r),"undefined"!=typeof window&&(window.GPUCore=r,null===window.GPU&&(window.GPU=r))},{"./core/gpu-core":1}]},{},[3]);
"use strict";!function e(n,t,r){function i(u,a){if(!t[u]){if(!n[u]){var l="function"==typeof require&&require;if(!a&&l)return l(u,!0);if(o)return o(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var c=t[u]={exports:{}};n[u][0].call(c.exports,function(e){var t=n[u][1][e];return i(t?t:e)},c,c.exports,e,n,t,r)}return t[u].exports}for(var o="function"==typeof require&&require,u=0;u<r.length;u++)i(r[u]);return i}({1:[function(e,n,t){function r(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}();e("./utils-core");n.exports=function(){function e(){r(this,e)}return i(e,null,[{key:"validateKernelObj",value:function(e){if(null===e)throw"KernelObj being validated is NULL";if("string"==typeof e){try{e=JSON.parse(e)}catch(n){throw console.error(n),"Failed to convert KernelObj from JSON string"}if(null===e)throw"Invalid (NULL) KernelObj JSON string representation"}if(e.isKernelObj!==!0)throw"Failed missing isKernelObj flag check";return e}},{key:"loadKernelObj",value:function(e,n){e=validateKernelObj(e)}}]),e}()},{"./utils-core":2}],2:[function(e,n,t){function r(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),o=function(){function e(){r(this,e)}return i(e,null,[{key:"isCanvas",value:function(e){return null!==e&&e.nodeName&&e.getContext&&"CANVAS"===e.nodeName.toUpperCase()}},{key:"isCanvasSupported",value:function(){return u}},{key:"initCanvas",value:function(){if(!u)return null;var e=document.createElement("canvas");return e.width=2,e.height=2,e}},{key:"isWebGl",value:function(e){return e&&"function"==typeof e.getExtension}},{key:"isWebGlSupported",value:function(){return l}},{key:"isWebGlDrawBuffersSupported",value:function(){return f}},{key:"initWebGlDefaultOptions",value:function(){return{alpha:!1,depth:!1,antialias:!1}}},{key:"initWebGl",value:function(n){if(("undefined"!=typeof u||null===n)&&!u)return null;if(!e.isCanvas(n))throw new Error("Invalid canvas object - "+n);return n.getContext("webgl2",e.initWebGlDefaultOptions())}}]),e}(),u="undefined"!=typeof document&&o.isCanvas(document.createElement("canvas")),a=o.initWebGl(o.initCanvas()),l=o.isWebGl(a),f=l;n.exports=o},{}],3:[function(e,n,t){var r=e("./core/gpu-core");"undefined"!=typeof n&&(n.exports=r),"undefined"!=typeof window&&(window.GPUCore=r,null===window.GPU&&(window.GPU=r))},{"./core/gpu-core":1}]},{},[3]);

View File

@ -4,19 +4,17 @@
*
* GPU Accelerated JavaScript
*
* @version 1.0.0-rc.10
* @date Sat Dec 23 2017 10:30:09 GMT-0500 (EST)
* @version 1.0.0
* @date Sat Feb 24 2018 19:31:20 GMT-0500 (EST)
*
* @license MIT
* The MIT License
*
* Copyright (c) 2017 gpu.js Team
* Copyright (c) 2018 gpu.js Team
*/
"use strict";(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@ -38,11 +36,6 @@ module.exports = function (_FunctionBuilderBase) {
return _this;
}
_createClass(CPUFunctionBuilder, [{
key: 'polyfillStandardFunctions',
value: function polyfillStandardFunctions() {}
}]);
return CPUFunctionBuilder;
}(FunctionBuilderBase);
},{"../function-builder-base":6,"./function-node":2}],2:[function(require,module,exports){
@ -1223,11 +1216,6 @@ module.exports = function () {
}
return this.getStringFromFunctionNames(Object.keys(this.nodeMap), opt);
}
}, {
key: 'polyfillStandardFunctions',
value: function polyfillStandardFunctions() {
throw new Error('polyfillStandardFunctions not defined on base function builder');
}
}]);
return FunctionBuilderBase;
@ -1830,7 +1818,6 @@ module.exports = function () {
this.functionBuilder = functionBuilder;
this.fnString = null;
this.endianness = utils.systemEndianness();
this.functionBuilder.polyfillStandardFunctions();
}
@ -1891,8 +1878,6 @@ module.exports = function () {
},{"../core/utils":25,"./kernel-run-shortcut":9}],11:[function(require,module,exports){
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@ -1903,40 +1888,19 @@ var FunctionBuilderBase = require('../function-builder-base');
var WebGLFunctionNode = require('./function-node');
module.exports = function (_FunctionBuilderBase) {
_inherits(WebGLFunctionBuilder, _FunctionBuilderBase);
_inherits(WebGLFunctionBuilder, _FunctionBuilderBase);
function WebGLFunctionBuilder() {
_classCallCheck(this, WebGLFunctionBuilder);
function WebGLFunctionBuilder() {
_classCallCheck(this, WebGLFunctionBuilder);
var _this = _possibleConstructorReturn(this, (WebGLFunctionBuilder.__proto__ || Object.getPrototypeOf(WebGLFunctionBuilder)).call(this));
var _this = _possibleConstructorReturn(this, (WebGLFunctionBuilder.__proto__ || Object.getPrototypeOf(WebGLFunctionBuilder)).call(this));
_this.Node = WebGLFunctionNode;
return _this;
}
_this.Node = WebGLFunctionNode;
return _this;
}
_createClass(WebGLFunctionBuilder, [{
key: 'polyfillStandardFunctions',
value: function polyfillStandardFunctions() {
this.addFunction('round', _round);
}
}], [{
key: 'round',
value: function round(a) {
return _round(a);
}
}]);
return WebGLFunctionBuilder;
return WebGLFunctionBuilder;
}(FunctionBuilderBase);
function _round(a) {
return Math.floor(a + 0.5);
}
},{"../function-builder-base":6,"./function-node":12}],12:[function(require,module,exports){
'use strict';
@ -2775,7 +2739,6 @@ var vertShaderString = require('./shader-vert');
var kernelString = require('./kernel-string');
var canvases = [];
var maxTexSizes = {};
module.exports = function (_KernelBase) {
_inherits(WebGLKernel, _KernelBase);
@ -2796,10 +2759,9 @@ module.exports = function (_KernelBase) {
_this.subKernelOutputTextures = null;
_this.subKernelOutputVariableNames = null;
_this.argumentsLength = 0;
_this.ext = null;
_this.compiledFragShaderString = null;
_this.compiledVertShaderString = null;
_this.extDrawBuffersMap = null;
_this.drawBuffersMap = null;
_this.outputTexture = null;
_this.maxTexSize = null;
if (!_this._webGl) _this._webGl = utils.initWebGl(_this.getCanvas());
@ -2812,11 +2774,11 @@ module.exports = function (_KernelBase) {
key: 'validateOptions',
value: function validateOptions() {
var isFloatReadPixel = utils.isFloatReadPixelsSupported();
if (this.floatTextures === true && !utils.OES_texture_float) {
if (this.floatTextures === true) {
throw new Error('Float textures are not supported on this browser');
} else if (this.floatOutput === true && this.floatOutputForce !== true && !isFloatReadPixel) {
throw new Error('Float texture outputs are not supported on this browser');
} else if (this.floatTextures === undefined && utils.OES_texture_float) {
} else if (this.floatTextures === undefined) {
this.floatTextures = true;
this.floatOutput = isFloatReadPixel;
}
@ -2852,7 +2814,7 @@ module.exports = function (_KernelBase) {
}
this.texSize = utils.clone(this.output);
} else if (this.floatOutput === undefined && utils.OES_texture_float) {
} else if (this.floatOutput === undefined) {
this.floatOutput = true;
}
}
@ -2962,10 +2924,10 @@ module.exports = function (_KernelBase) {
this.setupOutputTexture();
if (this.subKernelOutputTextures !== null) {
var extDrawBuffersMap = this.extDrawBuffersMap = [gl.COLOR_ATTACHMENT0];
var drawBuffersMap = this.drawBuffersMap = [gl.COLOR_ATTACHMENT0];
for (var i = 0; i < this.subKernelOutputTextures.length; i++) {
var subKernelOutputTexture = this.subKernelOutputTextures[i];
extDrawBuffersMap.push(gl.COLOR_ATTACHMENT0 + i + 1);
drawBuffersMap.push(gl.COLOR_ATTACHMENT0 + i + 1);
gl.activeTexture(gl.TEXTURE0 + arguments.length + i);
gl.bindTexture(gl.TEXTURE_2D, subKernelOutputTexture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
@ -3027,7 +2989,7 @@ module.exports = function (_KernelBase) {
var subKernelOutputTexture = this.subKernelOutputTextures[i];
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i + 1, gl.TEXTURE_2D, subKernelOutputTexture, 0);
}
this.ext.drawBuffersWEBGL(this.extDrawBuffersMap);
gl.drawBuffers(this.drawBuffersMap);
}
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
@ -3328,8 +3290,7 @@ module.exports = function (_KernelBase) {
}, {
key: '_getHeaderString',
value: function _getHeaderString() {
return this.subKernels !== null || this.subKernelProperties !== null ?
'#extension GL_EXT_draw_buffers : require\n' : '';
return '';
}
@ -3361,7 +3322,7 @@ module.exports = function (_KernelBase) {
value: function _getTextureCoordinate() {
var names = this.subKernelOutputVariableNames;
if (names === null || names.length < 1) {
return 'varying highp vec2 vTexCoord;\n';
return 'in highp vec2 vTexCoord;\n';
} else {
return 'out highp vec2 vTexCoord;\n';
}
@ -3476,11 +3437,12 @@ module.exports = function (_KernelBase) {
var names = this.subKernelOutputVariableNames;
if (names !== null) {
result.push('highp float kernelResult = 0.0');
result.push('layout(location = 0) out highp vec4 data0');
for (var i = 0; i < names.length; i++) {
result.push('highp float ' + names[i] + ' = 0.0');
result.push('highp float ' + names[i] + ' = 0.0', 'layout(location = ' + (i + 1) + ') out highp vec4 data' + (i + 1));
}
} else {
result.push('out highp vec4 data0');
result.push('highp float kernelResult = 0.0');
}
@ -3499,7 +3461,7 @@ module.exports = function (_KernelBase) {
}
if (this.graphical) {
result.push(' threadId = indexTo3D(index, uOutputDim)', ' kernel()', ' gl_FragColor = actualColor');
result.push(' threadId = indexTo3D(index, uOutputDim)', ' kernel()', ' data0 = actualColor');
} else if (this.floatOutput) {
var channels = ['r', 'g', 'b', 'a'];
@ -3508,13 +3470,13 @@ module.exports = function (_KernelBase) {
result.push(' kernel()');
if (names) {
result.push(' gl_FragData[0].' + channels[i] + ' = kernelResult');
result.push(' data0.' + channels[i] + ' = kernelResult');
for (var j = 0; j < names.length; ++j) {
result.push(' gl_FragData[' + (j + 1) + '].' + channels[i] + ' = ' + names[j]);
result.push(' data' + (j + 1) + '.' + channels[i] + ' = ' + names[j]);
}
} else {
result.push(' gl_FragColor.' + channels[i] + ' = kernelResult');
result.push(' data0.' + channels[i] + ' = kernelResult');
}
if (i < channels.length - 1) {
@ -3522,14 +3484,13 @@ module.exports = function (_KernelBase) {
}
}
} else if (names !== null) {
result.push(' threadId = indexTo3D(index, uOutputDim)');
result.push(' kernel()');
result.push(' gl_FragData[0] = encode32(kernelResult)');
result.push(' data0 = encode32(kernelResult)');
for (var _i3 = 0; _i3 < names.length; _i3++) {
result.push(' gl_FragData[' + (_i3 + 1) + '] = encode32(' + names[_i3] + ')');
result.push(' data' + (_i3 + 1) + ' = encode32(' + names[_i3] + ')');
}
} else {
result.push(' threadId = indexTo3D(index, uOutputDim)', ' kernel()', ' gl_FragColor = encode32(kernelResult)');
result.push(' threadId = indexTo3D(index, uOutputDim)', ' kernel()', ' data0 = encode32(kernelResult)');
}
return this._linesToString(result);
@ -3580,8 +3541,6 @@ module.exports = function (_KernelBase) {
}, this.paramNames, this.paramTypes);
if (this.subKernels !== null) {
var ext = this.ext = gl.getExtension('WEBGL_draw_buffers');
if (!ext) throw new Error('could not instantiate draw buffers extension');
this.subKernelOutputTextures = [];
this.subKernelOutputVariableNames = [];
for (var i = 0; i < this.subKernels.length; i++) {
@ -3597,8 +3556,6 @@ module.exports = function (_KernelBase) {
this.subKernelOutputVariableNames.push(subKernel.name + 'Result');
}
} else if (this.subKernelProperties !== null) {
var _ext = this.ext = gl.getExtension('WEBGL_draw_buffers');
if (!_ext) throw new Error('could not instantiate draw buffers extension');
this.subKernelOutputTextures = [];
this.subKernelOutputVariableNames = [];
var _i4 = 0;
@ -3697,11 +3654,11 @@ module.exports = function (_RunnerBase) {
},{"../../core/utils":25,"../runner-base":10,"./function-builder":11,"./kernel":14}],16:[function(require,module,exports){
"use strict";
module.exports = "__HEADER__;\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nconst float LOOP_MAX = __LOOP_MAX__;\n#define EPSILON 0.0000001;\n\n__CONSTANTS__;\n\nvarying highp vec2 vTexCoord;\n\nvec4 round(vec4 x) {\n return floor(x + 0.5);\n}\n\nhighp float round(highp float x) {\n return floor(x + 0.5);\n}\n\nvec2 integerMod(vec2 x, float y) {\n vec2 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec3 integerMod(vec3 x, float y) {\n vec3 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec4 integerMod(vec4 x, vec4 y) {\n vec4 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nhighp float integerMod(highp float x, highp float y) {\n highp float res = floor(mod(x, y));\n return res * (res > floor(y) - 1.0 ? 0.0 : 1.0);\n}\n\nhighp int integerMod(highp int x, highp int y) {\n return int(integerMod(float(x), float(y)));\n}\n\n// Here be dragons!\n// DO NOT OPTIMIZE THIS CODE\n// YOU WILL BREAK SOMETHING ON SOMEBODY'S MACHINE\n// LEAVE IT AS IT IS, LEST YOU WASTE YOUR OWN TIME\nconst vec2 MAGIC_VEC = vec2(1.0, -256.0);\nconst vec4 SCALE_FACTOR = vec4(1.0, 256.0, 65536.0, 0.0);\nconst vec4 SCALE_FACTOR_INV = vec4(1.0, 0.00390625, 0.0000152587890625, 0.0); // 1, 1/256, 1/65536\nhighp float decode32(highp vec4 rgba) {\n __DECODE32_ENDIANNESS__;\n rgba *= 255.0;\n vec2 gte128;\n gte128.x = rgba.b >= 128.0 ? 1.0 : 0.0;\n gte128.y = rgba.a >= 128.0 ? 1.0 : 0.0;\n float exponent = 2.0 * rgba.a - 127.0 + dot(gte128, MAGIC_VEC);\n float res = exp2(round(exponent));\n rgba.b = rgba.b - 128.0 * gte128.x;\n res = dot(rgba, SCALE_FACTOR) * exp2(round(exponent-23.0)) + res;\n res *= gte128.y * -2.0 + 1.0;\n return res;\n}\n\nhighp vec4 encode32(highp float f) {\n highp float F = abs(f);\n highp float sign = f < 0.0 ? 1.0 : 0.0;\n highp float exponent = floor(log2(F));\n highp float mantissa = (exp2(-exponent) * F);\n // exponent += floor(log2(mantissa));\n vec4 rgba = vec4(F * exp2(23.0-exponent)) * SCALE_FACTOR_INV;\n rgba.rg = integerMod(rgba.rg, 256.0);\n rgba.b = integerMod(rgba.b, 128.0);\n rgba.a = exponent*0.5 + 63.5;\n rgba.ba += vec2(integerMod(exponent+127.0, 2.0), sign) * 128.0;\n rgba = floor(rgba);\n rgba *= 0.003921569; // 1/255\n __ENCODE32_ENDIANNESS__;\n return rgba;\n}\n// Dragons end here\n\nhighp float index;\nhighp vec3 threadId;\n\nhighp vec3 indexTo3D(highp float idx, highp vec3 texDim) {\n highp float z = floor(idx / (texDim.x * texDim.y));\n idx -= z * texDim.x * texDim.y;\n highp float y = floor(idx / texDim.x);\n highp float x = integerMod(idx, texDim.x);\n return vec3(x, y, z);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float z, highp float y, highp float x) {\n highp vec3 xyz = vec3(x, y, z);\n xyz = floor(xyz + 0.5);\n __GET_WRAPAROUND__;\n highp float index = round(xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z));\n __GET_TEXTURE_CHANNEL__;\n highp float w = round(texSize.x);\n vec2 st = vec2(integerMod(index, w), float(int(index) / int(w))) + 0.5;\n __GET_TEXTURE_INDEX__;\n highp vec4 texel = texture2D(tex, st / texSize);\n __GET_RESULT__;\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float y, highp float x) {\n return get(tex, texSize, texDim, 0.0, y, x);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float x) {\n return get(tex, texSize, texDim, 0.0, 0.0, x);\n}\n\nhighp vec4 actualColor;\nvoid color(float r, float g, float b, float a) {\n actualColor = vec4(r,g,b,a);\n}\n\nvoid color(float r, float g, float b) {\n color(r,g,b,1.0);\n}\n\n__MAIN_PARAMS__;\n__MAIN_CONSTANTS__;\n__KERNEL__;\n\nvoid main(void) {\n index = floor(vTexCoord.s * float(uTexSize.x)) + floor(vTexCoord.t * float(uTexSize.y)) * uTexSize.x;\n __MAIN_RESULT__;\n}";
module.exports = "#version 300 es\n__HEADER__;\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nconst float LOOP_MAX = __LOOP_MAX__;\n#define EPSILON 0.0000001;\n\n__CONSTANTS__;\n\nin highp vec2 vTexCoord;\n\nvec2 integerMod(vec2 x, float y) {\n vec2 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec3 integerMod(vec3 x, float y) {\n vec3 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec4 integerMod(vec4 x, vec4 y) {\n vec4 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nhighp float integerMod(highp float x, highp float y) {\n highp float res = floor(mod(x, y));\n return res * (res > floor(y) - 1.0 ? 0.0 : 1.0);\n}\n\nhighp int integerMod(highp int x, highp int y) {\n return int(integerMod(float(x), float(y)));\n}\n\n// Here be dragons!\n// DO NOT OPTIMIZE THIS CODE\n// YOU WILL BREAK SOMETHING ON SOMEBODY'S MACHINE\n// LEAVE IT AS IT IS, LEST YOU WASTE YOUR OWN TIME\nconst vec2 MAGIC_VEC = vec2(1.0, -256.0);\nconst vec4 SCALE_FACTOR = vec4(1.0, 256.0, 65536.0, 0.0);\nconst vec4 SCALE_FACTOR_INV = vec4(1.0, 0.00390625, 0.0000152587890625, 0.0); // 1, 1/256, 1/65536\nhighp float decode32(highp vec4 rgba) {\n __DECODE32_ENDIANNESS__;\n rgba *= 255.0;\n vec2 gte128;\n gte128.x = rgba.b >= 128.0 ? 1.0 : 0.0;\n gte128.y = rgba.a >= 128.0 ? 1.0 : 0.0;\n float exponent = 2.0 * rgba.a - 127.0 + dot(gte128, MAGIC_VEC);\n float res = exp2(round(exponent));\n rgba.b = rgba.b - 128.0 * gte128.x;\n res = dot(rgba, SCALE_FACTOR) * exp2(round(exponent-23.0)) + res;\n res *= gte128.y * -2.0 + 1.0;\n return res;\n}\n\nhighp vec4 encode32(highp float f) {\n highp float F = abs(f);\n highp float sign = f < 0.0 ? 1.0 : 0.0;\n highp float exponent = floor(log2(F));\n highp float mantissa = (exp2(-exponent) * F);\n // exponent += floor(log2(mantissa));\n vec4 rgba = vec4(F * exp2(23.0-exponent)) * SCALE_FACTOR_INV;\n rgba.rg = integerMod(rgba.rg, 256.0);\n rgba.b = integerMod(rgba.b, 128.0);\n rgba.a = exponent*0.5 + 63.5;\n rgba.ba += vec2(integerMod(exponent+127.0, 2.0), sign) * 128.0;\n rgba = floor(rgba);\n rgba *= 0.003921569; // 1/255\n __ENCODE32_ENDIANNESS__;\n return rgba;\n}\n// Dragons end here\n\nhighp float index;\nhighp vec3 threadId;\n\nhighp vec3 indexTo3D(highp float idx, highp vec3 texDim) {\n highp float z = floor(idx / (texDim.x * texDim.y));\n idx -= z * texDim.x * texDim.y;\n highp float y = floor(idx / texDim.x);\n highp float x = integerMod(idx, texDim.x);\n return vec3(x, y, z);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float z, highp float y, highp float x) {\n highp vec3 xyz = vec3(x, y, z);\n xyz = floor(xyz + 0.5);\n __GET_WRAPAROUND__;\n highp float index = round(xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z));\n __GET_TEXTURE_CHANNEL__;\n highp float w = round(texSize.x);\n vec2 st = vec2(integerMod(index, w), float(int(index) / int(w))) + 0.5;\n __GET_TEXTURE_INDEX__;\n highp vec4 texel = texture(tex, st / texSize);\n __GET_RESULT__;\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float y, highp float x) {\n return get(tex, texSize, texDim, 0.0, y, x);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float x) {\n return get(tex, texSize, texDim, 0.0, 0.0, x);\n}\n\nhighp vec4 actualColor;\nvoid color(float r, float g, float b, float a) {\n actualColor = vec4(r,g,b,a);\n}\n\nvoid color(float r, float g, float b) {\n color(r,g,b,1.0);\n}\n\n__MAIN_PARAMS__;\n__MAIN_CONSTANTS__;\n__KERNEL__;\n\nvoid main(void) {\n index = floor(vTexCoord.s * float(uTexSize.x)) + floor(vTexCoord.t * float(uTexSize.y)) * uTexSize.x;\n __MAIN_RESULT__;\n}";
},{}],17:[function(require,module,exports){
"use strict";
module.exports = "precision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nattribute highp vec2 aPos;\nattribute highp vec2 aTexCoord;\n\nvarying highp vec2 vTexCoord;\nuniform vec2 ratio;\n\nvoid main(void) {\n gl_Position = vec4((aPos + vec2(1)) * ratio + vec2(-1), 0, 1);\n vTexCoord = aTexCoord;\n}";
module.exports = "#version 300 es\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nin highp vec2 aPos;\nin highp vec2 aTexCoord;\n\nout highp vec2 vTexCoord;\nuniform vec2 ratio;\n\nvoid main(void) {\n gl_Position = vec4((aPos + vec2(1)) * ratio + vec2(-1), 0, 1);\n vTexCoord = aTexCoord;\n}";
},{}],18:[function(require,module,exports){
'use strict';
@ -4193,15 +4150,7 @@ var UtilsCore = function () {
throw new Error('Invalid canvas object - ' + canvasObj);
}
var webGl = canvasObj.getContext('experimental-webgl', UtilsCore.initWebGlDefaultOptions()) || canvasObj.getContext('webgl', UtilsCore.initWebGlDefaultOptions());
if (webGl) {
webGl.OES_texture_float = webGl.getExtension('OES_texture_float');
webGl.OES_texture_float_linear = webGl.getExtension('OES_texture_float_linear');
webGl.OES_element_index_uint = webGl.getExtension('OES_element_index_uint');
}
return webGl;
return canvasObj.getContext('webgl2', UtilsCore.initWebGlDefaultOptions());
}
}]);
@ -4212,17 +4161,7 @@ var UtilsCore = function () {
var _isCanvasSupported = typeof document !== 'undefined' ? UtilsCore.isCanvas(document.createElement('canvas')) : false;
var _testingWebGl = UtilsCore.initWebGl(UtilsCore.initCanvas());
var _isWebGlSupported = UtilsCore.isWebGl(_testingWebGl);
var _isWebGlDrawBuffersSupported = _isWebGlSupported && Boolean(_testingWebGl.getExtension('WEBGL_draw_buffers'));
if (_isWebGlSupported) {
UtilsCore.OES_texture_float = _testingWebGl.OES_texture_float;
UtilsCore.OES_texture_float_linear = _testingWebGl.OES_texture_float_linear;
UtilsCore.OES_element_index_uint = _testingWebGl.OES_element_index_uint;
} else {
UtilsCore.OES_texture_float = false;
UtilsCore.OES_texture_float_linear = false;
UtilsCore.OES_element_index_uint = false;
}
var _isWebGlDrawBuffersSupported = _isWebGlSupported;
module.exports = UtilsCore;
},{}],25:[function(require,module,exports){

17
bin/gpu.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,5 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@ -31,10 +29,5 @@ module.exports = function (_FunctionBuilderBase) {
return _this;
}
_createClass(CPUFunctionBuilder, [{
key: 'polyfillStandardFunctions',
value: function polyfillStandardFunctions() {}
}]);
return CPUFunctionBuilder;
}(FunctionBuilderBase);

View File

@ -353,11 +353,6 @@ module.exports = function () {
}
return this.getStringFromFunctionNames(Object.keys(this.nodeMap), opt);
}
}, {
key: 'polyfillStandardFunctions',
value: function polyfillStandardFunctions() {
throw new Error('polyfillStandardFunctions not defined on base function builder');
}
}]);
return FunctionBuilderBase;

View File

@ -43,7 +43,6 @@ module.exports = function () {
this.functionBuilder = functionBuilder;
this.fnString = null;
this.endianness = utils.systemEndianness();
this.functionBuilder.polyfillStandardFunctions();
}
/**

View File

@ -1,7 +1,5 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@ -20,51 +18,16 @@ var WebGLFunctionNode = require('./function-node');
*
*/
module.exports = function (_FunctionBuilderBase) {
_inherits(WebGLFunctionBuilder, _FunctionBuilderBase);
_inherits(WebGLFunctionBuilder, _FunctionBuilderBase);
function WebGLFunctionBuilder() {
_classCallCheck(this, WebGLFunctionBuilder);
function WebGLFunctionBuilder() {
_classCallCheck(this, WebGLFunctionBuilder);
var _this = _possibleConstructorReturn(this, (WebGLFunctionBuilder.__proto__ || Object.getPrototypeOf(WebGLFunctionBuilder)).call(this));
var _this = _possibleConstructorReturn(this, (WebGLFunctionBuilder.__proto__ || Object.getPrototypeOf(WebGLFunctionBuilder)).call(this));
_this.Node = WebGLFunctionNode;
return _this;
}
_this.Node = WebGLFunctionNode;
return _this;
}
//---------------------------------------------------------
//
// Polyfill stuff
//
//---------------------------------------------------------
// Round function used in polyfill
_createClass(WebGLFunctionBuilder, [{
key: 'polyfillStandardFunctions',
/**
* @memberOf FunctionBuilderBase#
* @function
* @name polyfillStandardFunctions
*
* @desc Polyfill in the missing Math functions (round)
*
*/
value: function polyfillStandardFunctions() {
this.addFunction('round', _round);
}
}], [{
key: 'round',
value: function round(a) {
return _round(a);
}
}]);
return WebGLFunctionBuilder;
}(FunctionBuilderBase);
function _round(a) {
return Math.floor(a + 0.5);
}
return WebGLFunctionBuilder;
}(FunctionBuilderBase);

View File

@ -16,7 +16,6 @@ var vertShaderString = require('./shader-vert');
var kernelString = require('./kernel-string');
var canvases = [];
var maxTexSizes = {};
module.exports = function (_KernelBase) {
_inherits(WebGLKernel, _KernelBase);
@ -60,10 +59,9 @@ module.exports = function (_KernelBase) {
_this.subKernelOutputTextures = null;
_this.subKernelOutputVariableNames = null;
_this.argumentsLength = 0;
_this.ext = null;
_this.compiledFragShaderString = null;
_this.compiledVertShaderString = null;
_this.extDrawBuffersMap = null;
_this.drawBuffersMap = null;
_this.outputTexture = null;
_this.maxTexSize = null;
if (!_this._webGl) _this._webGl = utils.initWebGl(_this.getCanvas());
@ -86,11 +84,11 @@ module.exports = function (_KernelBase) {
key: 'validateOptions',
value: function validateOptions() {
var isFloatReadPixel = utils.isFloatReadPixelsSupported();
if (this.floatTextures === true && !utils.OES_texture_float) {
if (this.floatTextures === true) {
throw new Error('Float textures are not supported on this browser');
} else if (this.floatOutput === true && this.floatOutputForce !== true && !isFloatReadPixel) {
throw new Error('Float texture outputs are not supported on this browser');
} else if (this.floatTextures === undefined && utils.OES_texture_float) {
} else if (this.floatTextures === undefined) {
this.floatTextures = true;
this.floatOutput = isFloatReadPixel;
}
@ -126,7 +124,7 @@ module.exports = function (_KernelBase) {
}
this.texSize = utils.clone(this.output);
} else if (this.floatOutput === undefined && utils.OES_texture_float) {
} else if (this.floatOutput === undefined) {
this.floatOutput = true;
}
}
@ -245,10 +243,10 @@ module.exports = function (_KernelBase) {
this.setupOutputTexture();
if (this.subKernelOutputTextures !== null) {
var extDrawBuffersMap = this.extDrawBuffersMap = [gl.COLOR_ATTACHMENT0];
var drawBuffersMap = this.drawBuffersMap = [gl.COLOR_ATTACHMENT0];
for (var i = 0; i < this.subKernelOutputTextures.length; i++) {
var subKernelOutputTexture = this.subKernelOutputTextures[i];
extDrawBuffersMap.push(gl.COLOR_ATTACHMENT0 + i + 1);
drawBuffersMap.push(gl.COLOR_ATTACHMENT0 + i + 1);
gl.activeTexture(gl.TEXTURE0 + arguments.length + i);
gl.bindTexture(gl.TEXTURE_2D, subKernelOutputTexture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
@ -324,7 +322,7 @@ module.exports = function (_KernelBase) {
var subKernelOutputTexture = this.subKernelOutputTextures[i];
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i + 1, gl.TEXTURE_2D, subKernelOutputTexture, 0);
}
this.ext.drawBuffersWEBGL(this.extDrawBuffersMap);
gl.drawBuffers(this.drawBuffersMap);
}
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
@ -760,9 +758,7 @@ module.exports = function (_KernelBase) {
}, {
key: '_getHeaderString',
value: function _getHeaderString() {
return this.subKernels !== null || this.subKernelProperties !== null ?
//webgl2 '#version 300 es\n' :
'#extension GL_EXT_draw_buffers : require\n' : '';
return '';
}
/**
@ -826,7 +822,7 @@ module.exports = function (_KernelBase) {
value: function _getTextureCoordinate() {
var names = this.subKernelOutputVariableNames;
if (names === null || names.length < 1) {
return 'varying highp vec2 vTexCoord;\n';
return 'in highp vec2 vTexCoord;\n';
} else {
return 'out highp vec2 vTexCoord;\n';
}
@ -1019,20 +1015,12 @@ module.exports = function (_KernelBase) {
var names = this.subKernelOutputVariableNames;
if (names !== null) {
result.push('highp float kernelResult = 0.0');
result.push('layout(location = 0) out highp vec4 data0');
for (var i = 0; i < names.length; i++) {
result.push('highp float ' + names[i] + ' = 0.0');
result.push('highp float ' + names[i] + ' = 0.0', 'layout(location = ' + (i + 1) + ') out highp vec4 data' + (i + 1));
}
/* this is v2 prep
result.push('highp float kernelResult = 0.0');
result.push('layout(location = 0) out highp float fradData0 = 0.0');
for (let i = 0; i < names.length; i++) {
result.push(
`highp float ${ names[i] } = 0.0`,
`layout(location = ${ i + 1 }) out highp float fragData${ i + 1 } = 0.0`
);
}*/
} else {
result.push('out highp vec4 data0');
result.push('highp float kernelResult = 0.0');
}
@ -1062,7 +1050,7 @@ module.exports = function (_KernelBase) {
}
if (this.graphical) {
result.push(' threadId = indexTo3D(index, uOutputDim)', ' kernel()', ' gl_FragColor = actualColor');
result.push(' threadId = indexTo3D(index, uOutputDim)', ' kernel()', ' data0 = actualColor');
} else if (this.floatOutput) {
var channels = ['r', 'g', 'b', 'a'];
@ -1071,13 +1059,13 @@ module.exports = function (_KernelBase) {
result.push(' kernel()');
if (names) {
result.push(' gl_FragData[0].' + channels[i] + ' = kernelResult');
result.push(' data0.' + channels[i] + ' = kernelResult');
for (var j = 0; j < names.length; ++j) {
result.push(' gl_FragData[' + (j + 1) + '].' + channels[i] + ' = ' + names[j]);
result.push(' data' + (j + 1) + '.' + channels[i] + ' = ' + names[j]);
}
} else {
result.push(' gl_FragColor.' + channels[i] + ' = kernelResult');
result.push(' data0.' + channels[i] + ' = kernelResult');
}
if (i < channels.length - 1) {
@ -1085,14 +1073,13 @@ module.exports = function (_KernelBase) {
}
}
} else if (names !== null) {
result.push(' threadId = indexTo3D(index, uOutputDim)');
result.push(' kernel()');
result.push(' gl_FragData[0] = encode32(kernelResult)');
result.push(' data0 = encode32(kernelResult)');
for (var _i3 = 0; _i3 < names.length; _i3++) {
result.push(' gl_FragData[' + (_i3 + 1) + '] = encode32(' + names[_i3] + ')');
result.push(' data' + (_i3 + 1) + ' = encode32(' + names[_i3] + ')');
}
} else {
result.push(' threadId = indexTo3D(index, uOutputDim)', ' kernel()', ' gl_FragColor = encode32(kernelResult)');
result.push(' threadId = indexTo3D(index, uOutputDim)', ' kernel()', ' data0 = encode32(kernelResult)');
}
return this._linesToString(result);
@ -1170,8 +1157,6 @@ module.exports = function (_KernelBase) {
}, this.paramNames, this.paramTypes);
if (this.subKernels !== null) {
var ext = this.ext = gl.getExtension('WEBGL_draw_buffers');
if (!ext) throw new Error('could not instantiate draw buffers extension');
this.subKernelOutputTextures = [];
this.subKernelOutputVariableNames = [];
for (var i = 0; i < this.subKernels.length; i++) {
@ -1187,8 +1172,6 @@ module.exports = function (_KernelBase) {
this.subKernelOutputVariableNames.push(subKernel.name + 'Result');
}
} else if (this.subKernelProperties !== null) {
var _ext = this.ext = gl.getExtension('WEBGL_draw_buffers');
if (!_ext) throw new Error('could not instantiate draw buffers extension');
this.subKernelOutputTextures = [];
this.subKernelOutputVariableNames = [];
var _i4 = 0;

View File

@ -1,3 +1,3 @@
"use strict";
module.exports = "__HEADER__;\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nconst float LOOP_MAX = __LOOP_MAX__;\n#define EPSILON 0.0000001;\n\n__CONSTANTS__;\n\nvarying highp vec2 vTexCoord;\n\nvec4 round(vec4 x) {\n return floor(x + 0.5);\n}\n\nhighp float round(highp float x) {\n return floor(x + 0.5);\n}\n\nvec2 integerMod(vec2 x, float y) {\n vec2 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec3 integerMod(vec3 x, float y) {\n vec3 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec4 integerMod(vec4 x, vec4 y) {\n vec4 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nhighp float integerMod(highp float x, highp float y) {\n highp float res = floor(mod(x, y));\n return res * (res > floor(y) - 1.0 ? 0.0 : 1.0);\n}\n\nhighp int integerMod(highp int x, highp int y) {\n return int(integerMod(float(x), float(y)));\n}\n\n// Here be dragons!\n// DO NOT OPTIMIZE THIS CODE\n// YOU WILL BREAK SOMETHING ON SOMEBODY'S MACHINE\n// LEAVE IT AS IT IS, LEST YOU WASTE YOUR OWN TIME\nconst vec2 MAGIC_VEC = vec2(1.0, -256.0);\nconst vec4 SCALE_FACTOR = vec4(1.0, 256.0, 65536.0, 0.0);\nconst vec4 SCALE_FACTOR_INV = vec4(1.0, 0.00390625, 0.0000152587890625, 0.0); // 1, 1/256, 1/65536\nhighp float decode32(highp vec4 rgba) {\n __DECODE32_ENDIANNESS__;\n rgba *= 255.0;\n vec2 gte128;\n gte128.x = rgba.b >= 128.0 ? 1.0 : 0.0;\n gte128.y = rgba.a >= 128.0 ? 1.0 : 0.0;\n float exponent = 2.0 * rgba.a - 127.0 + dot(gte128, MAGIC_VEC);\n float res = exp2(round(exponent));\n rgba.b = rgba.b - 128.0 * gte128.x;\n res = dot(rgba, SCALE_FACTOR) * exp2(round(exponent-23.0)) + res;\n res *= gte128.y * -2.0 + 1.0;\n return res;\n}\n\nhighp vec4 encode32(highp float f) {\n highp float F = abs(f);\n highp float sign = f < 0.0 ? 1.0 : 0.0;\n highp float exponent = floor(log2(F));\n highp float mantissa = (exp2(-exponent) * F);\n // exponent += floor(log2(mantissa));\n vec4 rgba = vec4(F * exp2(23.0-exponent)) * SCALE_FACTOR_INV;\n rgba.rg = integerMod(rgba.rg, 256.0);\n rgba.b = integerMod(rgba.b, 128.0);\n rgba.a = exponent*0.5 + 63.5;\n rgba.ba += vec2(integerMod(exponent+127.0, 2.0), sign) * 128.0;\n rgba = floor(rgba);\n rgba *= 0.003921569; // 1/255\n __ENCODE32_ENDIANNESS__;\n return rgba;\n}\n// Dragons end here\n\nhighp float index;\nhighp vec3 threadId;\n\nhighp vec3 indexTo3D(highp float idx, highp vec3 texDim) {\n highp float z = floor(idx / (texDim.x * texDim.y));\n idx -= z * texDim.x * texDim.y;\n highp float y = floor(idx / texDim.x);\n highp float x = integerMod(idx, texDim.x);\n return vec3(x, y, z);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float z, highp float y, highp float x) {\n highp vec3 xyz = vec3(x, y, z);\n xyz = floor(xyz + 0.5);\n __GET_WRAPAROUND__;\n highp float index = round(xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z));\n __GET_TEXTURE_CHANNEL__;\n highp float w = round(texSize.x);\n vec2 st = vec2(integerMod(index, w), float(int(index) / int(w))) + 0.5;\n __GET_TEXTURE_INDEX__;\n highp vec4 texel = texture2D(tex, st / texSize);\n __GET_RESULT__;\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float y, highp float x) {\n return get(tex, texSize, texDim, 0.0, y, x);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float x) {\n return get(tex, texSize, texDim, 0.0, 0.0, x);\n}\n\nhighp vec4 actualColor;\nvoid color(float r, float g, float b, float a) {\n actualColor = vec4(r,g,b,a);\n}\n\nvoid color(float r, float g, float b) {\n color(r,g,b,1.0);\n}\n\n__MAIN_PARAMS__;\n__MAIN_CONSTANTS__;\n__KERNEL__;\n\nvoid main(void) {\n index = floor(vTexCoord.s * float(uTexSize.x)) + floor(vTexCoord.t * float(uTexSize.y)) * uTexSize.x;\n __MAIN_RESULT__;\n}";
module.exports = "#version 300 es\n__HEADER__;\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nconst float LOOP_MAX = __LOOP_MAX__;\n#define EPSILON 0.0000001;\n\n__CONSTANTS__;\n\nin highp vec2 vTexCoord;\n\nvec2 integerMod(vec2 x, float y) {\n vec2 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec3 integerMod(vec3 x, float y) {\n vec3 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec4 integerMod(vec4 x, vec4 y) {\n vec4 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nhighp float integerMod(highp float x, highp float y) {\n highp float res = floor(mod(x, y));\n return res * (res > floor(y) - 1.0 ? 0.0 : 1.0);\n}\n\nhighp int integerMod(highp int x, highp int y) {\n return int(integerMod(float(x), float(y)));\n}\n\n// Here be dragons!\n// DO NOT OPTIMIZE THIS CODE\n// YOU WILL BREAK SOMETHING ON SOMEBODY'S MACHINE\n// LEAVE IT AS IT IS, LEST YOU WASTE YOUR OWN TIME\nconst vec2 MAGIC_VEC = vec2(1.0, -256.0);\nconst vec4 SCALE_FACTOR = vec4(1.0, 256.0, 65536.0, 0.0);\nconst vec4 SCALE_FACTOR_INV = vec4(1.0, 0.00390625, 0.0000152587890625, 0.0); // 1, 1/256, 1/65536\nhighp float decode32(highp vec4 rgba) {\n __DECODE32_ENDIANNESS__;\n rgba *= 255.0;\n vec2 gte128;\n gte128.x = rgba.b >= 128.0 ? 1.0 : 0.0;\n gte128.y = rgba.a >= 128.0 ? 1.0 : 0.0;\n float exponent = 2.0 * rgba.a - 127.0 + dot(gte128, MAGIC_VEC);\n float res = exp2(round(exponent));\n rgba.b = rgba.b - 128.0 * gte128.x;\n res = dot(rgba, SCALE_FACTOR) * exp2(round(exponent-23.0)) + res;\n res *= gte128.y * -2.0 + 1.0;\n return res;\n}\n\nhighp vec4 encode32(highp float f) {\n highp float F = abs(f);\n highp float sign = f < 0.0 ? 1.0 : 0.0;\n highp float exponent = floor(log2(F));\n highp float mantissa = (exp2(-exponent) * F);\n // exponent += floor(log2(mantissa));\n vec4 rgba = vec4(F * exp2(23.0-exponent)) * SCALE_FACTOR_INV;\n rgba.rg = integerMod(rgba.rg, 256.0);\n rgba.b = integerMod(rgba.b, 128.0);\n rgba.a = exponent*0.5 + 63.5;\n rgba.ba += vec2(integerMod(exponent+127.0, 2.0), sign) * 128.0;\n rgba = floor(rgba);\n rgba *= 0.003921569; // 1/255\n __ENCODE32_ENDIANNESS__;\n return rgba;\n}\n// Dragons end here\n\nhighp float index;\nhighp vec3 threadId;\n\nhighp vec3 indexTo3D(highp float idx, highp vec3 texDim) {\n highp float z = floor(idx / (texDim.x * texDim.y));\n idx -= z * texDim.x * texDim.y;\n highp float y = floor(idx / texDim.x);\n highp float x = integerMod(idx, texDim.x);\n return vec3(x, y, z);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float z, highp float y, highp float x) {\n highp vec3 xyz = vec3(x, y, z);\n xyz = floor(xyz + 0.5);\n __GET_WRAPAROUND__;\n highp float index = round(xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z));\n __GET_TEXTURE_CHANNEL__;\n highp float w = round(texSize.x);\n vec2 st = vec2(integerMod(index, w), float(int(index) / int(w))) + 0.5;\n __GET_TEXTURE_INDEX__;\n highp vec4 texel = texture(tex, st / texSize);\n __GET_RESULT__;\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float y, highp float x) {\n return get(tex, texSize, texDim, 0.0, y, x);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float x) {\n return get(tex, texSize, texDim, 0.0, 0.0, x);\n}\n\nhighp vec4 actualColor;\nvoid color(float r, float g, float b, float a) {\n actualColor = vec4(r,g,b,a);\n}\n\nvoid color(float r, float g, float b) {\n color(r,g,b,1.0);\n}\n\n__MAIN_PARAMS__;\n__MAIN_CONSTANTS__;\n__KERNEL__;\n\nvoid main(void) {\n index = floor(vTexCoord.s * float(uTexSize.x)) + floor(vTexCoord.t * float(uTexSize.y)) * uTexSize.x;\n __MAIN_RESULT__;\n}";

View File

@ -1,3 +1,3 @@
"use strict";
module.exports = "precision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nattribute highp vec2 aPos;\nattribute highp vec2 aTexCoord;\n\nvarying highp vec2 vTexCoord;\nuniform vec2 ratio;\n\nvoid main(void) {\n gl_Position = vec4((aPos + vec2(1)) * ratio + vec2(-1), 0, 1);\n vTexCoord = aTexCoord;\n}";
module.exports = "#version 300 es\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nin highp vec2 aPos;\nin highp vec2 aTexCoord;\n\nout highp vec2 vTexCoord;\nuniform vec2 ratio;\n\nvoid main(void) {\n gl_Position = vec4((aPos + vec2(1)) * ratio + vec2(-1), 0, 1);\n vTexCoord = aTexCoord;\n}";

View File

@ -206,17 +206,7 @@ var UtilsCore = function () {
}
// Create a new canvas DOM
var webGl = canvasObj.getContext('experimental-webgl', UtilsCore.initWebGlDefaultOptions()) || canvasObj.getContext('webgl', UtilsCore.initWebGlDefaultOptions());
if (webGl) {
// Get the extension that is needed
webGl.OES_texture_float = webGl.getExtension('OES_texture_float');
webGl.OES_texture_float_linear = webGl.getExtension('OES_texture_float_linear');
webGl.OES_element_index_uint = webGl.getExtension('OES_element_index_uint');
}
// Returns the canvas
return webGl;
return canvasObj.getContext('webgl2', UtilsCore.initWebGlDefaultOptions());
}
}]);
@ -232,16 +222,6 @@ var UtilsCore = function () {
var _isCanvasSupported = typeof document !== 'undefined' ? UtilsCore.isCanvas(document.createElement('canvas')) : false;
var _testingWebGl = UtilsCore.initWebGl(UtilsCore.initCanvas());
var _isWebGlSupported = UtilsCore.isWebGl(_testingWebGl);
var _isWebGlDrawBuffersSupported = _isWebGlSupported && Boolean(_testingWebGl.getExtension('WEBGL_draw_buffers'));
if (_isWebGlSupported) {
UtilsCore.OES_texture_float = _testingWebGl.OES_texture_float;
UtilsCore.OES_texture_float_linear = _testingWebGl.OES_texture_float_linear;
UtilsCore.OES_element_index_uint = _testingWebGl.OES_element_index_uint;
} else {
UtilsCore.OES_texture_float = false;
UtilsCore.OES_texture_float_linear = false;
UtilsCore.OES_element_index_uint = false;
}
var _isWebGlDrawBuffersSupported = _isWebGlSupported;
module.exports = UtilsCore;

View File

@ -16,6 +16,4 @@ module.exports = class CPUFunctionBuilder extends FunctionBuilderBase {
super();
this.Node = CPUFunctionNode;
}
polyfillStandardFunctions() {}
};

View File

@ -314,8 +314,4 @@ module.exports = class FunctionBuilderBase {
}
return this.getStringFromFunctionNames(Object.keys(this.nodeMap), opt);
}
polyfillStandardFunctions() {
throw new Error('polyfillStandardFunctions not defined on base function builder');
}
};

View File

@ -37,7 +37,6 @@ module.exports = class BaseRunner {
this.functionBuilder = functionBuilder;
this.fnString = null;
this.endianness = utils.systemEndianness();
this.functionBuilder.polyfillStandardFunctions();
}
/**

View File

@ -16,31 +16,4 @@ module.exports = class WebGLFunctionBuilder extends FunctionBuilderBase {
super();
this.Node = WebGLFunctionNode;
}
//---------------------------------------------------------
//
// Polyfill stuff
//
//---------------------------------------------------------
// Round function used in polyfill
static round(a) {
return round(a);
}
/**
* @memberOf FunctionBuilderBase#
* @function
* @name polyfillStandardFunctions
*
* @desc Polyfill in the missing Math functions (round)
*
*/
polyfillStandardFunctions() {
this.addFunction('round', round);
}
};
function round(a) {
return Math.floor(a + 0.5);
}
};

View File

@ -8,7 +8,6 @@ const vertShaderString = require('./shader-vert');
const kernelString = require('./kernel-string');
const canvases = [];
const maxTexSizes = {};
const webGlVersion = 2;
module.exports = class WebGLKernel extends KernelBase {
/**
* @constructor WebGLKernel
@ -47,10 +46,9 @@ module.exports = class WebGLKernel extends KernelBase {
this.subKernelOutputTextures = null;
this.subKernelOutputVariableNames = null;
this.argumentsLength = 0;
this.ext = null;
this.compiledFragShaderString = null;
this.compiledVertShaderString = null;
this.extDrawBuffersMap = null;
this.drawBuffersMap = null;
this.outputTexture = null;
this.maxTexSize = null;
if (!this._webGl) this._webGl = utils.initWebGl(this.getCanvas());
@ -68,11 +66,11 @@ module.exports = class WebGLKernel extends KernelBase {
*/
validateOptions() {
const isFloatReadPixel = utils.isFloatReadPixelsSupported();
if (this.floatTextures === true && !utils.OES_texture_float) {
if (this.floatTextures === true) {
throw new Error('Float textures are not supported on this browser');
} else if (this.floatOutput === true && this.floatOutputForce !== true && !isFloatReadPixel) {
throw new Error('Float texture outputs are not supported on this browser');
} else if (this.floatTextures === undefined && utils.OES_texture_float) {
} else if (this.floatTextures === undefined) {
this.floatTextures = true;
this.floatOutput = isFloatReadPixel;
}
@ -108,7 +106,7 @@ module.exports = class WebGLKernel extends KernelBase {
}
this.texSize = utils.clone(this.output);
} else if (this.floatOutput === undefined && utils.OES_texture_float) {
} else if (this.floatOutput === undefined) {
this.floatOutput = true;
}
}
@ -232,10 +230,10 @@ module.exports = class WebGLKernel extends KernelBase {
this.setupOutputTexture();
if (this.subKernelOutputTextures !== null) {
const extDrawBuffersMap = this.extDrawBuffersMap = [gl.COLOR_ATTACHMENT0];
const drawBuffersMap = this.drawBuffersMap = [gl.COLOR_ATTACHMENT0];
for (let i = 0; i < this.subKernelOutputTextures.length; i++) {
const subKernelOutputTexture = this.subKernelOutputTextures[i];
extDrawBuffersMap.push(gl.COLOR_ATTACHMENT0 + i + 1);
drawBuffersMap.push(gl.COLOR_ATTACHMENT0 + i + 1);
gl.activeTexture(gl.TEXTURE0 + arguments.length + i);
gl.bindTexture(gl.TEXTURE_2D, subKernelOutputTexture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
@ -308,7 +306,7 @@ module.exports = class WebGLKernel extends KernelBase {
const subKernelOutputTexture = this.subKernelOutputTextures[i];
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i + 1, gl.TEXTURE_2D, subKernelOutputTexture, 0);
}
this.ext.drawBuffersWEBGL(this.extDrawBuffersMap);
gl.drawBuffers(this.drawBuffersMap);
}
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
@ -708,13 +706,7 @@ module.exports = class WebGLKernel extends KernelBase {
*
*/
_getHeaderString() {
return (
this.subKernels !== null || this.subKernelProperties !== null ?
webGlVersion === 2 ?
'#version 300 es\n' :
'#extension GL_EXT_draw_buffers : require\n' :
''
);
return '';
}
/**
@ -779,7 +771,7 @@ module.exports = class WebGLKernel extends KernelBase {
_getTextureCoordinate() {
const names = this.subKernelOutputVariableNames;
if (names === null || names.length < 1) {
return 'varying highp vec2 vTexCoord;\n';
return 'in highp vec2 vTexCoord;\n';
} else {
return 'out highp vec2 vTexCoord;\n';
}
@ -976,24 +968,16 @@ module.exports = class WebGLKernel extends KernelBase {
const result = [];
const names = this.subKernelOutputVariableNames;
if (names !== null) {
if (webGlVersion === 2) {
result.push('highp float kernelResult = 0.0');
result.push('layout(location = 0) out highp float fradData0 = 0.0');
for (let i = 0; i < names.length; i++) {
result.push(
`highp float ${ names[i] } = 0.0`,
`layout(location = ${ i + 1 }) out highp float fragData${ i + 1 } = 0.0`
);
}
} else {
result.push('highp float kernelResult = 0.0');
for (let i = 0; i < names.length; i++) {
result.push(
`highp float ${ names[i] } = 0.0`
);
}
result.push('highp float kernelResult = 0.0');
result.push('layout(location = 0) out highp vec4 data0');
for (let i = 0; i < names.length; i++) {
result.push(
`highp float ${ names[i] } = 0.0`,
`layout(location = ${ i + 1 }) out highp vec4 data${ i + 1 }`
);
}
} else {
result.push('out highp vec4 data0');
result.push('highp float kernelResult = 0.0');
}
@ -1023,7 +1007,7 @@ module.exports = class WebGLKernel extends KernelBase {
result.push(
' threadId = indexTo3D(index, uOutputDim)',
' kernel()',
' gl_FragColor = actualColor'
' data0 = actualColor'
);
} else if (this.floatOutput) {
const channels = ['r', 'g', 'b', 'a'];
@ -1033,13 +1017,13 @@ module.exports = class WebGLKernel extends KernelBase {
result.push(' kernel()');
if (names) {
result.push(` gl_FragData[0].${channels[i]} = kernelResult`);
result.push(` data0.${channels[i]} = kernelResult`);
for (let j = 0; j < names.length; ++j) {
result.push(` gl_FragData[${ j + 1 }].${channels[i]} = ${ names[j] }`);
result.push(` data${ j + 1 }.${channels[i]} = ${ names[j] }`);
}
} else {
result.push(` gl_FragColor.${channels[i]} = kernelResult`);
result.push(` data0.${channels[i]} = kernelResult`);
}
if (i < channels.length - 1) {
@ -1047,25 +1031,16 @@ module.exports = class WebGLKernel extends KernelBase {
}
}
} else if (names !== null) {
if (webGlVersion === 2) {
result.push(' kernel()');
result.push(' fragData0 = encode32(kernelResult)');
for (let i = 0; i < names.length; i++) {
result.push(` fragData${ i + 1 } = encode32(${ names[i] })`);
}
} else {
result.push(' threadId = indexTo3D(index, uOutputDim)');
result.push(' kernel()');
result.push(' gl_FragData[0] = encode32(kernelResult)');
for (let i = 0; i < names.length; i++) {
result.push(` gl_FragData[${ i + 1 }] = encode32(${ names[i] })`);
}
result.push(' kernel()');
result.push(' data0 = encode32(kernelResult)');
for (let i = 0; i < names.length; i++) {
result.push(` data${ i + 1 } = encode32(${ names[i] })`);
}
} else {
result.push(
' threadId = indexTo3D(index, uOutputDim)',
' kernel()',
' gl_FragColor = encode32(kernelResult)'
' data0 = encode32(kernelResult)'
);
}
@ -1135,8 +1110,6 @@ module.exports = class WebGLKernel extends KernelBase {
}, this.paramNames, this.paramTypes);
if (this.subKernels !== null) {
const ext = this.ext = gl.getExtension('WEBGL_draw_buffers');
if (!ext) throw new Error('could not instantiate draw buffers extension');
this.subKernelOutputTextures = [];
this.subKernelOutputVariableNames = [];
for (let i = 0; i < this.subKernels.length; i++) {
@ -1153,8 +1126,6 @@ module.exports = class WebGLKernel extends KernelBase {
}
} else if (this.subKernelProperties !== null) {
const ext = this.ext = gl.getExtension('WEBGL_draw_buffers');
if (!ext) throw new Error('could not instantiate draw buffers extension');
this.subKernelOutputTextures = [];
this.subKernelOutputVariableNames = [];
let i = 0;

View File

@ -1,4 +1,5 @@
module.exports = `__HEADER__;
module.exports = `#version 300 es
__HEADER__;
precision highp float;
precision highp int;
precision highp sampler2D;
@ -8,15 +9,7 @@ const float LOOP_MAX = __LOOP_MAX__;
__CONSTANTS__;
varying highp vec2 vTexCoord;
vec4 round(vec4 x) {
return floor(x + 0.5);
}
highp float round(highp float x) {
return floor(x + 0.5);
}
in highp vec2 vTexCoord;
vec2 integerMod(vec2 x, float y) {
vec2 res = floor(mod(x, y));
@ -101,7 +94,7 @@ highp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, high
highp float w = round(texSize.x);
vec2 st = vec2(integerMod(index, w), float(int(index) / int(w))) + 0.5;
__GET_TEXTURE_INDEX__;
highp vec4 texel = texture2D(tex, st / texSize);
highp vec4 texel = texture(tex, st / texSize);
__GET_RESULT__;
}

View File

@ -1,11 +1,12 @@
module.exports = `precision highp float;
module.exports = `#version 300 es
precision highp float;
precision highp int;
precision highp sampler2D;
attribute highp vec2 aPos;
attribute highp vec2 aTexCoord;
in highp vec2 aPos;
in highp vec2 aTexCoord;
varying highp vec2 vTexCoord;
out highp vec2 vTexCoord;
uniform vec2 ratio;
void main(void) {

View File

@ -181,19 +181,8 @@ class UtilsCore {
}
// Create a new canvas DOM
const webGl = canvasObj.getContext('webgl2', UtilsCore.initWebGlDefaultOptions());
if (webGl) {
// Get the extension that is needed
webGl.OES_texture_float = webGl.getExtension('OES_texture_float');
webGl.OES_texture_float_linear = webGl.getExtension('OES_texture_float_linear');
webGl.OES_element_index_uint = webGl.getExtension('OES_element_index_uint');
}
// Returns the canvas
return webGl;
return canvasObj.getContext('webgl2', UtilsCore.initWebGlDefaultOptions());
}
}
//-----------------------------------------------------------------------------
@ -205,16 +194,6 @@ class UtilsCore {
const _isCanvasSupported = typeof document !== 'undefined' ? UtilsCore.isCanvas(document.createElement('canvas')) : false;
const _testingWebGl = UtilsCore.initWebGl(UtilsCore.initCanvas());
const _isWebGlSupported = UtilsCore.isWebGl(_testingWebGl);
const _isWebGlDrawBuffersSupported = _isWebGlSupported && Boolean(_testingWebGl.getExtension('WEBGL_draw_buffers'));
if (_isWebGlSupported) {
UtilsCore.OES_texture_float = _testingWebGl.OES_texture_float;
UtilsCore.OES_texture_float_linear = _testingWebGl.OES_texture_float_linear;
UtilsCore.OES_element_index_uint = _testingWebGl.OES_element_index_uint;
} else {
UtilsCore.OES_texture_float = false;
UtilsCore.OES_texture_float_linear = false;
UtilsCore.OES_element_index_uint = false;
}
const _isWebGlDrawBuffersSupported = _isWebGlSupported;
module.exports = UtilsCore;