2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL
2 Texture Switch Conformance Tests
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
21 description("Ensures that switching the texture referenced by a sampler uniform performs reasonably well.");
22 var wtu
= WebGLTestUtils
;
23 var canvas
= document
.createElement('canvas');
26 var gl
= wtu
.create3DContext(canvas
, undefined, 2);
28 testFailed("context does not exist");
31 var program
= wtu
.setupTexturedQuad(gl
);
32 var tex
= gl
.createTexture();
33 gl
.activeTexture(gl
.TEXTURE0
);
34 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
35 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, 1, 1, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, null);
37 var tex2
= gl
.createTexture();
38 gl
.activeTexture(gl
.TEXTURE1
);
39 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
40 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, 1, 1, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, null);
42 var loc
= gl
.getUniformLocation(program
, "tex");
46 var baseStartTime
= 0;
47 var baseFrameCount
= 0;
48 var testStartTime
= 0;
49 var testFrameCount
= 0;
51 baseStartTime
= Date
.now();
52 function drawBaseline() {
53 for (var i
= 0; i
< 400; ++i
) {
55 gl
.drawArrays(gl
.TRIANGLES
, 0, 6);
57 gl
.drawArrays(gl
.TRIANGLES
, 0, 6);
62 if (Date
.now() - baseStartTime
> RUNTIME
) {
63 testStartTime
= Date
.now();
64 requestAnimationFrame(drawTest
);
66 requestAnimationFrame(drawBaseline
);
71 for (var i
= 0; i
< 400; ++i
) {
73 gl
.drawArrays(gl
.TRIANGLES
, 0, 6);
75 gl
.drawArrays(gl
.TRIANGLES
, 0, 6);
80 if (Date
.now() - testStartTime
> RUNTIME
) {
81 var perfString
= " - achieved " + testFrameCount
+ " frames in " + ((Date
.now() - testStartTime
) / 1000.0) +
82 " seconds (" + (testFrameCount
/ baseFrameCount
).toFixed(2) + " times baseline performance)";
83 if (testFrameCount
> baseFrameCount
* THRESHOLD
) {
84 testPassed("Texture switching did not significantly hurt performance" + perfString
);
86 testFailed("Texture switching significantly hurt performance" + perfString
);
88 console
.log(testFrameCount
);
91 requestAnimationFrame(drawTest
);
95 requestAnimationFrame(drawBaseline
);
97 var successfullyParsed
= true;