Skip to content

Commit 8bb5e6b

Browse files
fix: Check getExtension is truthy before calling and unit tests
fix: Add missing test for headlessgl to all.html
1 parent b9f7d7b commit 8bb5e6b

File tree

12 files changed

+173
-160
lines changed

12 files changed

+173
-160
lines changed

bin/gpu-browser-core.js

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.0.0-rc.8
8-
* @date Tue Apr 23 2019 22:02:53 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.0.0-rc.9
8+
* @date Wed Apr 24 2019 07:46:43 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -3624,7 +3624,6 @@ module.exports = {
36243624
GLKernel,
36253625
renderStrategy
36263626
};
3627-
36283627
},{"../texture":27,"../utils":28,"./kernel":11}],10:[function(require,module,exports){
36293628
const getContext = require('gl');
36303629
const {
@@ -4102,7 +4101,6 @@ class Kernel {
41024101
module.exports = {
41034102
Kernel
41044103
};
4105-
41064104
},{"../input":24,"../utils":28}],12:[function(require,module,exports){
41074105
const fragmentShader = `__HEADER__;
41084106
precision highp float;
@@ -4310,7 +4308,6 @@ void main(void) {
43104308
module.exports = {
43114309
fragmentShader
43124310
};
4313-
43144311
},{}],13:[function(require,module,exports){
43154312
const {
43164313
FunctionNode
@@ -5537,7 +5534,6 @@ function webGLKernelString(gpuKernel, name) {
55375534
module.exports = {
55385535
webGLKernelString
55395536
};
5540-
55415537
},{"../../kernel-run-shortcut":25,"../../utils":28}],15:[function(require,module,exports){
55425538
const {
55435539
GLKernel
@@ -5591,17 +5587,16 @@ class WebGLKernel extends GLKernel {
55915587
} else if (typeof OffscreenCanvas !== 'undefined') {
55925588
testCanvas = new OffscreenCanvas(0, 0);
55935589
}
5594-
5595-
if (testCanvas) {
5596-
testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
5597-
testExtensions = {
5598-
OES_texture_float: testContext.getExtension('OES_texture_float'),
5599-
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
5600-
OES_element_index_uint: testContext.getExtension('OES_element_index_uint'),
5601-
WEBGL_draw_buffers: testContext.getExtension('WEBGL_draw_buffers'),
5602-
};
5603-
features = this.getFeatures();
5604-
}
5590+
if (!testCanvas) return;
5591+
testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
5592+
if (!testContext || !testContext.getExtension) return;
5593+
testExtensions = {
5594+
OES_texture_float: testContext.getExtension('OES_texture_float'),
5595+
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
5596+
OES_element_index_uint: testContext.getExtension('OES_element_index_uint'),
5597+
WEBGL_draw_buffers: testContext.getExtension('WEBGL_draw_buffers'),
5598+
};
5599+
features = this.getFeatures();
56055600
}
56065601

56075602
static isContextMatch(context) {
@@ -7263,7 +7258,6 @@ class WebGLKernel extends GLKernel {
72637258
module.exports = {
72647259
WebGLKernel
72657260
};
7266-
72677261
},{"../../plugins/triangle-noise":26,"../../texture":27,"../../utils":28,"../function-builder":7,"../gl-kernel":9,"./fragment-shader":12,"./function-node":13,"./kernel-string":14,"./vertex-shader":16}],16:[function(require,module,exports){
72687262
const vertexShader = `precision highp float;
72697263
precision highp int;
@@ -7478,7 +7472,6 @@ void main(void) {
74787472
module.exports = {
74797473
fragmentShader
74807474
};
7481-
74827475
},{}],18:[function(require,module,exports){
74837476
const {
74847477
WebGLFunctionNode
@@ -7559,16 +7552,14 @@ class WebGL2Kernel extends WebGLKernel {
75597552
} else if (typeof OffscreenCanvas !== 'undefined') {
75607553
testCanvas = new OffscreenCanvas(0, 0);
75617554
}
7562-
7563-
if (testCanvas) {
7564-
testContext = testCanvas.getContext('webgl2');
7565-
if (!testContext) return;
7566-
testExtensions = {
7567-
EXT_color_buffer_float: testContext.getExtension('EXT_color_buffer_float'),
7568-
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
7569-
};
7570-
features = this.getFeatures();
7571-
}
7555+
if (!testCanvas) return;
7556+
testContext = testCanvas.getContext('webgl2');
7557+
if (!testContext || !testContext.getExtension) return;
7558+
testExtensions = {
7559+
EXT_color_buffer_float: testContext.getExtension('EXT_color_buffer_float'),
7560+
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
7561+
};
7562+
features = this.getFeatures();
75727563
}
75737564

75747565
static isContextMatch(context) {

bin/gpu-browser-core.min.js

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.0.0-rc.8
8-
* @date Tue Apr 23 2019 22:02:55 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.0.0-rc.9
8+
* @date Wed Apr 24 2019 07:46:45 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -17,8 +17,8 @@
1717
*
1818
* GPU Accelerated JavaScript
1919
*
20-
* @version 2.0.0-rc.8
21-
* @date Tue Apr 23 2019 22:02:53 GMT-0400 (Eastern Daylight Time)
20+
* @version 2.0.0-rc.9
21+
* @date Wed Apr 24 2019 07:46:43 GMT-0400 (Eastern Daylight Time)
2222
*
2323
* @license MIT
2424
* The MIT License
@@ -3637,7 +3637,6 @@ module.exports = {
36373637
GLKernel,
36383638
renderStrategy
36393639
};
3640-
36413640
},{"../texture":27,"../utils":28,"./kernel":11}],10:[function(require,module,exports){
36423641
const getContext = require('gl');
36433642
const {
@@ -4115,7 +4114,6 @@ class Kernel {
41154114
module.exports = {
41164115
Kernel
41174116
};
4118-
41194117
},{"../input":24,"../utils":28}],12:[function(require,module,exports){
41204118
const fragmentShader = `__HEADER__;
41214119
precision highp float;
@@ -4323,7 +4321,6 @@ void main(void) {
43234321
module.exports = {
43244322
fragmentShader
43254323
};
4326-
43274324
},{}],13:[function(require,module,exports){
43284325
const {
43294326
FunctionNode
@@ -5550,7 +5547,6 @@ function webGLKernelString(gpuKernel, name) {
55505547
module.exports = {
55515548
webGLKernelString
55525549
};
5553-
55545550
},{"../../kernel-run-shortcut":25,"../../utils":28}],15:[function(require,module,exports){
55555551
const {
55565552
GLKernel
@@ -5604,17 +5600,16 @@ class WebGLKernel extends GLKernel {
56045600
} else if (typeof OffscreenCanvas !== 'undefined') {
56055601
testCanvas = new OffscreenCanvas(0, 0);
56065602
}
5607-
5608-
if (testCanvas) {
5609-
testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
5610-
testExtensions = {
5611-
OES_texture_float: testContext.getExtension('OES_texture_float'),
5612-
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
5613-
OES_element_index_uint: testContext.getExtension('OES_element_index_uint'),
5614-
WEBGL_draw_buffers: testContext.getExtension('WEBGL_draw_buffers'),
5615-
};
5616-
features = this.getFeatures();
5617-
}
5603+
if (!testCanvas) return;
5604+
testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
5605+
if (!testContext || !testContext.getExtension) return;
5606+
testExtensions = {
5607+
OES_texture_float: testContext.getExtension('OES_texture_float'),
5608+
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
5609+
OES_element_index_uint: testContext.getExtension('OES_element_index_uint'),
5610+
WEBGL_draw_buffers: testContext.getExtension('WEBGL_draw_buffers'),
5611+
};
5612+
features = this.getFeatures();
56185613
}
56195614

56205615
static isContextMatch(context) {
@@ -7276,7 +7271,6 @@ class WebGLKernel extends GLKernel {
72767271
module.exports = {
72777272
WebGLKernel
72787273
};
7279-
72807274
},{"../../plugins/triangle-noise":26,"../../texture":27,"../../utils":28,"../function-builder":7,"../gl-kernel":9,"./fragment-shader":12,"./function-node":13,"./kernel-string":14,"./vertex-shader":16}],16:[function(require,module,exports){
72817275
const vertexShader = `precision highp float;
72827276
precision highp int;
@@ -7491,7 +7485,6 @@ void main(void) {
74917485
module.exports = {
74927486
fragmentShader
74937487
};
7494-
74957488
},{}],18:[function(require,module,exports){
74967489
const {
74977490
WebGLFunctionNode
@@ -7572,16 +7565,14 @@ class WebGL2Kernel extends WebGLKernel {
75727565
} else if (typeof OffscreenCanvas !== 'undefined') {
75737566
testCanvas = new OffscreenCanvas(0, 0);
75747567
}
7575-
7576-
if (testCanvas) {
7577-
testContext = testCanvas.getContext('webgl2');
7578-
if (!testContext) return;
7579-
testExtensions = {
7580-
EXT_color_buffer_float: testContext.getExtension('EXT_color_buffer_float'),
7581-
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
7582-
};
7583-
features = this.getFeatures();
7584-
}
7568+
if (!testCanvas) return;
7569+
testContext = testCanvas.getContext('webgl2');
7570+
if (!testContext || !testContext.getExtension) return;
7571+
testExtensions = {
7572+
EXT_color_buffer_float: testContext.getExtension('EXT_color_buffer_float'),
7573+
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
7574+
};
7575+
features = this.getFeatures();
75857576
}
75867577

75877578
static isContextMatch(context) {

bin/gpu-browser.js

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.0.0-rc.8
8-
* @date Tue Apr 23 2019 22:02:53 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.0.0-rc.9
8+
* @date Wed Apr 24 2019 07:46:43 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -8388,7 +8388,6 @@ module.exports = {
83888388
GLKernel,
83898389
renderStrategy
83908390
};
8391-
83928391
},{"../texture":28,"../utils":29,"./kernel":12}],11:[function(require,module,exports){
83938392
const getContext = require('gl');
83948393
const {
@@ -8866,7 +8865,6 @@ class Kernel {
88668865
module.exports = {
88678866
Kernel
88688867
};
8869-
88708868
},{"../input":25,"../utils":29}],13:[function(require,module,exports){
88718869
const fragmentShader = `__HEADER__;
88728870
precision highp float;
@@ -9074,7 +9072,6 @@ void main(void) {
90749072
module.exports = {
90759073
fragmentShader
90769074
};
9077-
90789075
},{}],14:[function(require,module,exports){
90799076
const {
90809077
FunctionNode
@@ -10301,7 +10298,6 @@ function webGLKernelString(gpuKernel, name) {
1030110298
module.exports = {
1030210299
webGLKernelString
1030310300
};
10304-
1030510301
},{"../../kernel-run-shortcut":26,"../../utils":29}],16:[function(require,module,exports){
1030610302
const {
1030710303
GLKernel
@@ -10355,17 +10351,16 @@ class WebGLKernel extends GLKernel {
1035510351
} else if (typeof OffscreenCanvas !== 'undefined') {
1035610352
testCanvas = new OffscreenCanvas(0, 0);
1035710353
}
10358-
10359-
if (testCanvas) {
10360-
testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
10361-
testExtensions = {
10362-
OES_texture_float: testContext.getExtension('OES_texture_float'),
10363-
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
10364-
OES_element_index_uint: testContext.getExtension('OES_element_index_uint'),
10365-
WEBGL_draw_buffers: testContext.getExtension('WEBGL_draw_buffers'),
10366-
};
10367-
features = this.getFeatures();
10368-
}
10354+
if (!testCanvas) return;
10355+
testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
10356+
if (!testContext || !testContext.getExtension) return;
10357+
testExtensions = {
10358+
OES_texture_float: testContext.getExtension('OES_texture_float'),
10359+
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
10360+
OES_element_index_uint: testContext.getExtension('OES_element_index_uint'),
10361+
WEBGL_draw_buffers: testContext.getExtension('WEBGL_draw_buffers'),
10362+
};
10363+
features = this.getFeatures();
1036910364
}
1037010365

1037110366
static isContextMatch(context) {
@@ -12027,7 +12022,6 @@ class WebGLKernel extends GLKernel {
1202712022
module.exports = {
1202812023
WebGLKernel
1202912024
};
12030-
1203112025
},{"../../plugins/triangle-noise":27,"../../texture":28,"../../utils":29,"../function-builder":8,"../gl-kernel":10,"./fragment-shader":13,"./function-node":14,"./kernel-string":15,"./vertex-shader":17}],17:[function(require,module,exports){
1203212026
const vertexShader = `precision highp float;
1203312027
precision highp int;
@@ -12242,7 +12236,6 @@ void main(void) {
1224212236
module.exports = {
1224312237
fragmentShader
1224412238
};
12245-
1224612239
},{}],19:[function(require,module,exports){
1224712240
const {
1224812241
WebGLFunctionNode
@@ -12323,16 +12316,14 @@ class WebGL2Kernel extends WebGLKernel {
1232312316
} else if (typeof OffscreenCanvas !== 'undefined') {
1232412317
testCanvas = new OffscreenCanvas(0, 0);
1232512318
}
12326-
12327-
if (testCanvas) {
12328-
testContext = testCanvas.getContext('webgl2');
12329-
if (!testContext) return;
12330-
testExtensions = {
12331-
EXT_color_buffer_float: testContext.getExtension('EXT_color_buffer_float'),
12332-
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
12333-
};
12334-
features = this.getFeatures();
12335-
}
12319+
if (!testCanvas) return;
12320+
testContext = testCanvas.getContext('webgl2');
12321+
if (!testContext || !testContext.getExtension) return;
12322+
testExtensions = {
12323+
EXT_color_buffer_float: testContext.getExtension('EXT_color_buffer_float'),
12324+
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
12325+
};
12326+
features = this.getFeatures();
1233612327
}
1233712328

1233812329
static isContextMatch(context) {

0 commit comments

Comments
 (0)