blob: 4c1d8b660b3ce22e530dd695a3755cc940bd0888 [file] [log] [blame]
<!--
/*
** Copyright (c) 2017 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Texture Switch Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("Ensures that switching the texture referenced by a sampler uniform performs reasonably well.");
var wtu = WebGLTestUtils;
var canvas = document.createElement('canvas');
canvas.width = 32;
canvas.height = 32;
var gl = wtu.create3DContext(canvas);
if (!gl) {
testFailed("context does not exist");
finishTest();
} else {
var program = wtu.setupTexturedQuad(gl);
var tex = gl.createTexture();
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
var tex2 = gl.createTexture();
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
var loc = gl.getUniformLocation(program, "tex");
var RUNTIME = 2000;
var THRESHOLD = 0.8;
var baseStartTime = 0;
var baseFrameCount = 0;
var testStartTime = 0;
var testFrameCount = 0;
baseStartTime = Date.now();
function drawBaseline() {
for (var i = 0; i < 400; ++i) {
gl.uniform1i(loc, 0);
gl.drawArrays(gl.TRIANGLES, 0, 6);
gl.uniform1i(loc, 0);
gl.drawArrays(gl.TRIANGLES, 0, 6);
}
++baseFrameCount;
if (Date.now() - baseStartTime > RUNTIME) {
testStartTime = Date.now();
requestAnimationFrame(drawTest);
} else {
requestAnimationFrame(drawBaseline);
}
}
function drawTest() {
for (var i = 0; i < 400; ++i) {
gl.uniform1i(loc, 0);
gl.drawArrays(gl.TRIANGLES, 0, 6);
gl.uniform1i(loc, 1);
gl.drawArrays(gl.TRIANGLES, 0, 6);
}
++testFrameCount;
if (Date.now() - testStartTime > RUNTIME) {
var perfString = " - achieved " + testFrameCount + " frames in " + ((Date.now() - testStartTime) / 1000.0) +
" seconds (" + (testFrameCount / baseFrameCount).toFixed(2) + " times baseline performance)";
if (testFrameCount > baseFrameCount * THRESHOLD) {
testPassed("Texture switching did not significantly hurt performance" + perfString);
} else {
testFailed("Texture switching significantly hurt performance" + perfString);
}
console.log(testFrameCount);
finishTest();
} else {
requestAnimationFrame(drawTest);
}
}
requestAnimationFrame(drawBaseline);
}
var successfullyParsed = true;
</script>
</body>
</html>