blob: d94ef1d6b3e0f716070f2b4e7ec839c38976e61b [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="../resources/runner.js"></script>
<script src="resources/canvas_runner.js"></script>
<script>
var canvas2D = document.createElement("canvas");
var ctx2D = canvas2D.getContext("2d");
var canvas3D = document.createElement('canvas');
var gl = canvas3D.getContext('webgl');
if(!gl)
CanvasRunner.logFatalError("WebGL is not supported or enabled on this platform!");
var tex = null;
function setSize(width, height) {
canvas2D.width = width;
canvas2D.height = height;
canvas3D.width = width;
canvas3D.height = height;
}
function rand(range) {
return Math.floor(Math.random() * range);
}
function fillCanvas(ctx2d, canvas2d) {
ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")";
ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height);
}
function preRun() {
tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
}
function doRun() {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2D);
}
function ensureComplete() {
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4));
}
function postRun() {
gl.deleteTexture(tex);
}
window.onload = function () {
setSize(1024, 1024);
fillCanvas(ctx2D, canvas2D);
CanvasRunner.start({
description: "This bench test checks the speed on uploading 2d Canvas(1024x1024) to Webgl Texture(1024x1024).",
preRun: preRun,
doRun: doRun,
ensureComplete: ensureComplete,
postRun: postRun});
}
</script>
</body>
</html>