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 Occlusion Query 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 <canvas id=
"canvas" style=
"width: 50px; height: 50px;"> </canvas>
19 <div id=
"console"></div>
22 description("This test verifies the functionality of occlusion query objects.");
28 var currentTestIndex
= 0;
29 var numberOfTestAttempts
= 4; // Just to stress implementations a bit more.
31 var numberOfCompletionAttempts
= 0;
33 function setupTests(gl
) {
36 target
: gl
.ANY_SAMPLES_PASSED_CONSERVATIVE
,
37 name
: "ANY_SAMPLES_PASSED_CONSERVATIVE",
41 target
: gl
.ANY_SAMPLES_PASSED
,
42 name
: "ANY_SAMPLES_PASSED",
48 function runOcclusionQueryTest() {
49 currentTest
= tests
[currentTestIndex
];
52 debug("Testing completion and behavior of " + currentTest
.name
+ " occlusion query");
53 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
54 var program
= wtu
.setupSimpleColorProgram(gl
, 0);
55 gl
.uniform4f(gl
.getUniformLocation(program
, "u_color"), 0, 1, 0, 1);
56 wtu
.setupUnitQuad(gl
, 0);
57 query
= gl
.createQuery();
58 var target
= currentTest
.target
;
59 gl
.beginQuery(target
, query
);
63 // Verify as best as possible that the implementation doesn't
64 // allow a query's result to become available the same frame, by
65 // spin-looping for some time and ensuring that none of the
66 // queries' results become available.
67 var numEarlyTests
= 20000;
68 while (--numEarlyTests
> 0) {
70 if (gl
.getQueryParameter(query
, gl
.QUERY_RESULT_AVAILABLE
)) {
71 testFailed("Query's result became available too early");
77 testPassed("Query's result didn't become available too early");
78 numberOfCompletionAttempts
= 0;
79 requestAnimationFrame(completeOcclusionQueryTest
);
82 function completeOcclusionQueryTest() {
83 ++numberOfCompletionAttempts
;
85 if (numberOfCompletionAttempts
> 500) {
86 testFailed("Query didn't become available in a reasonable time");
91 if (!gl
.getQueryParameter(query
, gl
.QUERY_RESULT_AVAILABLE
)) {
92 requestAnimationFrame(completeOcclusionQueryTest
);
96 // No matter whether the test was run with ANY_SAMPLES_PASSED or
97 // ANY_SAMPLES_PASSED_CONSERVATIVE, the query object should always
98 // report a non-zero result.
99 var result
= gl
.getQueryParameter(query
, gl
.QUERY_RESULT
);
100 if (result
== currentTest
.result
) {
101 testPassed("Occlusion query " + currentTest
.name
+ " returned a correct result (" + result
+ ")");
103 testFailed("Occlusion query " + currentTest
.name
+ " returned an incorrect result " + result
+ " (expected " + currentTest
.result
+ ")");
106 gl
.deleteQuery(query
);
110 if (currentTestIndex
>= tests
.length
) {
111 --numberOfTestAttempts
;
112 if (numberOfTestAttempts
== 0) {
115 currentTestIndex
= 0;
116 requestAnimationFrame(runOcclusionQueryTest
);
119 requestAnimationFrame(runOcclusionQueryTest
);
123 var wtu
= WebGLTestUtils
;
124 var canvas
= document
.getElementById("canvas");
125 var gl
= wtu
.create3DContext(canvas
, null, 2);
128 testFailed("WebGL context does not exist");
130 testPassed("WebGL context exists");
133 runOcclusionQueryTest();