mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-18 17:38:46 +01:00
Better webGL test (also covers webgl2).
This commit is contained in:
parent
932ec56079
commit
f28d635e64
@ -1,20 +1,34 @@
|
|||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
["webgl", "webgl2"].forEach(function(context, index){
|
||||||
|
var output = document.createElement("div");
|
||||||
|
document.getElementById("output").appendChild(output);
|
||||||
|
try {
|
||||||
var canvas = document.createElement("canvas");
|
var canvas = document.createElement("canvas");
|
||||||
canvas.width = 11;
|
canvas.width = 11;
|
||||||
canvas.height = 13;
|
canvas.height = 13;
|
||||||
var gl = canvas.getContext("webgl");
|
var gl = canvas.getContext(context) || canvas.getContext("experimental-" + context);
|
||||||
|
|
||||||
// paint it completely black
|
// paint it completely black
|
||||||
gl.clearColor(0, 0, 0, 1);
|
gl.clearColor(index * 0.25, index * 0.25, index * 0.25, 1);
|
||||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
var pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4);
|
var pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4);
|
||||||
gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
||||||
var values = {};
|
var values = {};
|
||||||
|
var max = 0;
|
||||||
for (var i = 0; i < pixels.length; i += 1){
|
for (var i = 0; i < pixels.length; i += 1){
|
||||||
values[pixels[i]] = (values[pixels[i]] || 0) + 1;
|
values[pixels[i]] = (values[pixels[i]] || 0) + 1;
|
||||||
|
max = Math.max(max, values[pixels[i]]);
|
||||||
}
|
}
|
||||||
document.getElementById("output").textContent = JSON.stringify(values);
|
|
||||||
|
output.textContent = context + ": " + (max !== 3 * values[255]? "": "not ") + "faked";
|
||||||
|
output.title = JSON.stringify(values);
|
||||||
|
}
|
||||||
|
catch (e){
|
||||||
|
output.textContent = context + ": ERROR";
|
||||||
|
output.title = e;
|
||||||
|
}
|
||||||
|
});
|
||||||
}());
|
}());
|
Loading…
x
Reference in New Issue
Block a user