Skip to content

Commit a55ad11

Browse files
Merge pull request #356 from sandeepmistry/webgl-fallback-when-no-webgl2
Use WebGLRunner if canvas does not support WebGL2
2 parents 0838fa8 + 67488f1 commit a55ad11

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/core/gpu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class GPU extends GPUCore {
277277

278278

279279
getGPURunner() {
280-
if (typeof WebGL2RenderingContext !== 'undefined') return WebGL2Runner;
280+
if (typeof WebGL2RenderingContext !== 'undefined' && utils.isWebGl2Supported()) return WebGL2Runner;
281281
if (typeof WebGLRenderingContext !== 'undefined') return WebGLRunner;
282282
}
283283

src/core/utils-core.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,27 @@ class UtilsCore {
124124
return webGlObj && typeof webGlObj.getExtension === 'function';
125125
}
126126

127+
/**
128+
*
129+
* @name isWebGl2
130+
* @function
131+
* @static
132+
* @memberOf UtilsCore
133+
*
134+
* @desc Return TRUE, on a valid webGl2Context object
135+
*
136+
* Note: This does just a VERY simply sanity check. And may give false positives.
137+
*
138+
* @param {webGlContext} webGl2Obj - Object to validate
139+
*
140+
* @returns {Boolean} TRUE if the object is a webGl2Context object
141+
*
142+
*/
143+
static isWebGl2(webGl2Obj) {
144+
return webGl2Obj && typeof WebGL2RenderingContext !== 'undefined' &&
145+
webGl2Obj instanceof WebGL2RenderingContext;
146+
}
147+
127148
/**
128149
* @name isWebGlSupported
129150
* @function
@@ -139,6 +160,21 @@ class UtilsCore {
139160
return _isWebGlSupported;
140161
}
141162

163+
/**
164+
* @name isWebGlSupported2
165+
* @function
166+
* @static
167+
* @memberOf UtilsCore
168+
*
169+
* @desc Return TRUE, if browser supports webgl2
170+
*
171+
* @returns {Boolean} TRUE if browser supports webgl2
172+
*
173+
*/
174+
static isWebGl2Supported() {
175+
return _isWebGl2Supported;
176+
}
177+
142178
static isWebGlDrawBuffersSupported() {
143179
return _isWebGlDrawBuffersSupported;
144180
}
@@ -253,7 +289,9 @@ class UtilsCore {
253289

254290
const _isCanvasSupported = typeof document !== 'undefined' ? UtilsCore.isCanvas(document.createElement('canvas')) : false;
255291
const _testingWebGl = UtilsCore.initWebGl(UtilsCore.initCanvas());
292+
const _testingWebGl2 = UtilsCore.initWebGl2(UtilsCore.initCanvas());
256293
const _isWebGlSupported = UtilsCore.isWebGl(_testingWebGl);
294+
const _isWebGl2Supported = UtilsCore.isWebGl2(_testingWebGl2);
257295
const _isWebGlDrawBuffersSupported = _isWebGlSupported && Boolean(_testingWebGl.getExtension('WEBGL_draw_buffers'));
258296

259297
if (_isWebGlSupported) {

0 commit comments

Comments
 (0)