Enhanced webGL test page

For #329
This commit is contained in:
kkapsner 2019-09-19 00:41:20 +02:00
parent 506f062c07
commit 64d4aa3f73
2 changed files with 76 additions and 4 deletions

View File

@ -8,7 +8,16 @@
</head>
<body>
<h1>webGL test</h1>
Checks if the addon also supports webGL.
<h2>Expected result</h2>
<ul>
<li>both webGL versions should be supported (unless you disabled it in the browser settings) - reload if one is showing "not supported"</li>
<li>upon page reload the hashes change</li>
<li>upon page reload some of the parameters change</li>
<li>the "vendor" und "renderer" (also unmasked) parameters reflect the values you chose for them</li>
</ul>
<h3>Support</h3>
<div id="output"></div>
<h3>Parameters</h3>
<div id="parameters"></div>
<script src="webGL-Test.js"></script>
</body></html>

View File

@ -22,9 +22,72 @@
values[pixels[i]] = (values[pixels[i]] || 0) + 1;
max = Math.max(max, values[pixels[i]]);
}
output.textContent = context + ": " + (max !== 3 * values[255]? "": "not ") + "supported";
output.title = JSON.stringify(values);
const parameters = [];
for (var name in gl){
if (name.toUpperCase() === name){
var value = gl.getParameter(gl[name]);
if (value !== null){
parameters.push({name: name, value: value});
}
}
}
const debugExtension = gl.getExtension("WEBGL_debug_renderer_info");
for (name in debugExtension){
if (name.toUpperCase() === name){
value = gl.getParameter(debugExtension[name]);
if (value !== null){
parameters.push({name: name, value: value});
}
}
}
var frontParameters = ["VENDOR", "RENDERER", "UNMASKED_VENDOR_WEBGL", "UNMASKED_RENDERER_WEBGL"];
parameters.sort(function(a, b){
var frontA = frontParameters.indexOf(a.name);
var frontB = frontParameters.indexOf(b.name);
if (frontA !== -1){
if (frontB !== -1){
return frontA - frontB;
}
else {
return -1;
}
}
else {
if (frontB !== -1){
return 1;
}
else {
return a.name < b.name? -1: 1;
}
}
});
if (context === "webgl2"){
var parameterOutput = document.createElement("table");
document.getElementById("parameters").appendChild(parameterOutput);
parameters.forEach(function(parameter){
var parameterRow = document.createElement("tr");
parameterRow.innerHTML = "<td>" + parameter.name + "</td><td>" + parameter.value + "</td>";
parameterOutput.appendChild(parameterRow);
});
}
crypto.subtle.digest("SHA-256", new TextEncoder("utf-8").encode(parameters.map(function(parameter){
return parameter.name + ": " + parameter.value;
}).join(",")))
.then(function(hash){
var chunks = [];
(new Uint32Array(hash)).forEach(function(num){
chunks.push(num.toString(16));
});
return chunks.map(function(chunk){
return "0".repeat(8 - chunk.length) + chunk;
}).join("");
}).then(function(hash) {
output.textContent = context + ": " +
(max !== 3 * values[255]? "": "not ") + "supported " +
"(parameter hash: " + hash + ")";
output.title = JSON.stringify(values);
});
}
catch (e){
output.textContent = context + ": ERROR";