Skip to content

Commit ba9a513

Browse files
committed
Detect if browser actually supports readPixels with float type, if it does not, use fallback readPixels mode
1 parent 66edda8 commit ba9a513

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/backend/mode_gpu.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,11 @@
142142
function ret() {
143143
if (opt.floatTextures === true && !GPUUtils.OES_texture_float) {
144144
throw "Float textures are not supported on this browser";
145+
} else if (opt.floatOutput === true && opt.floatOutputForce !== true && !GPUUtils.test_floatReadPixels(gpu)) {
146+
throw "Float texture outputs are not supported on this browser";
145147
} else if (opt.floatTextures === undefined && GPUUtils.OES_texture_float) {
146148
opt.floatTextures = true;
149+
opt.floatOutput = GPUUtils.test_floatReadPixels(gpu);
147150
}
148151

149152
if (!opt.dimensions || opt.dimensions.length === 0) {

src/utils.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,5 +416,36 @@ var GPUUtils = (function() {
416416
}
417417
GPUUtils.init_webgl = init_webgl;
418418

419+
// test_readPixels closure based memoizer
420+
var test_floatReadPixels_memoizer = null;
421+
///
422+
/// Function: test_floatReadPixels_memoizer
423+
///
424+
/// Checks if the browser supports readPixels with float type
425+
///
426+
/// Parameters:
427+
/// gpu - {gpu.js object} the gpu object
428+
///
429+
/// Returns:
430+
/// {Boolean} true if browser supports
431+
///
432+
function test_floatReadPixels(gpu) {
433+
if (test_floatReadPixels_memoizer !== null) {
434+
return test_floatReadPixels_memoizer
435+
}
436+
437+
var x = gpu.createKernel(function() {
438+
return 1;
439+
}, {
440+
'dimensions': [2],
441+
'floatTextures': true,
442+
'floatOutput': true,
443+
'floatOutputForce': true
444+
}).dimensions([2])();
445+
446+
return x[0] == 1;
447+
}
448+
GPUUtils.test_floatReadPixels = test_floatReadPixels;
449+
419450
return GPUUtils;
420451
})();

0 commit comments

Comments
 (0)