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 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>
20 <script id=
"vshader" type=
"x-shader/x-vertex">
21 attribute vec4 a_position;
22 attribute vec4 a_color;
25 gl_Position = a_position;
29 <script id=
"fshader" type=
"x-shader/x-fragment">
30 precision mediump float;
33 gl_FragColor = v_color;
38 description("This test verifies the functionality of the Query objects.");
42 var wtu
= WebGLTestUtils
;
43 var canvas
= document
.getElementById("canvas");
44 var gl
= wtu
.create3DContext(canvas
, null, 2);
49 testFailed("WebGL context does not exist");
51 testPassed("WebGL context exists");
53 runCurrentQueryTest();
55 // TODO: Test buffer binding, drawing, etc.
56 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "there should be no errors");
59 function runCurrentQueryTest() {
61 debug("Testing Beginning, Ending, and checking the state of query objects");
63 shouldBe("gl.ANY_SAMPLES_PASSED", "0x8C2F");
64 shouldBe("gl.ANY_SAMPLES_PASSED_CONSERVATIVE", "0x8D6A");
65 shouldBe("gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN", "0x8C88");
67 gl
.getQuery(gl
.ANY_SAMPLES_PASSED
, gl
.CURRENT_QUERY
);
68 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "ANY_SAMPLES_PASSED query should succeed");
70 gl
.getQuery(gl
.ANY_SAMPLES_PASSED_CONSERVATIVE
, gl
.CURRENT_QUERY
);
71 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "ANY_SAMPLES_PASSED query should succeed");
73 gl
.getQuery(gl
.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
, gl
.CURRENT_QUERY
);
74 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "ANY_SAMPLES_PASSED query should succeed");
76 // Default value is null
77 shouldBeNull("gl.getQuery(gl.ANY_SAMPLES_PASSED, gl.CURRENT_QUERY)");
78 shouldBeNull("gl.getQuery(gl.ANY_SAMPLES_PASSED_CONSERVATIVE, gl.CURRENT_QUERY)");
79 shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)");
81 q1
= gl
.createQuery();
82 q2
= gl
.createQuery();
83 shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)");
84 gl
.beginQuery(gl
.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
, q1
);
85 shouldBeTrue("gl.isQuery(q1)");
86 shouldBe("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)", "q1");
88 gl
.beginQuery(gl
.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
, q2
);
89 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
, "Can't begin a query while one is already active");
90 shouldBe("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)", "q1");
92 gl
.endQuery(gl
.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
);
93 shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)");
95 gl
.endQuery(gl
.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
);
96 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
, "Can't end a query if one is not active");
98 gl
.beginQuery(gl
.ANY_SAMPLES_PASSED
, q1
);
99 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
, "Can't re-use query objects for incompatible targets");
100 shouldBeNull("gl.getQuery(gl.ANY_SAMPLES_PASSED, gl.CURRENT_QUERY)");
102 gl
.beginQuery(gl
.ANY_SAMPLES_PASSED
, q2
);
103 shouldBe("gl.getQuery(gl.ANY_SAMPLES_PASSED, gl.CURRENT_QUERY)", "q2");
105 gl
.beginQuery(gl
.ANY_SAMPLES_PASSED_CONSERVATIVE
, q2
);
106 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
, "Can't call beginQuery on an already active query object");
107 shouldBeNull("gl.getQuery(gl.ANY_SAMPLES_PASSED_CONSERVATIVE, gl.CURRENT_QUERY)");
109 gl
.endQuery(gl
.ANY_SAMPLES_PASSED
);
111 gl
.beginQuery(gl
.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
, q1
);
112 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "Should be able to have multiple unrelated query types active at once");
113 shouldBe("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)", "q1");
117 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "deleting queries should not produce errors");
119 shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)");
120 shouldBeNull("gl.getQuery(gl.ANY_SAMPLES_PASSED_CONSERVATIVE, gl.CURRENT_QUERY)");
122 gl
.beginQuery(gl
.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
, q1
);
123 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
, "beginning a deleted query object");
124 shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)");
127 debug("Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1636525");
129 q1
= gl
.createQuery();
131 wtu
.glErrorShouldBe(gl
, 0, "DeleteQuery after CreateQuery");
132 gl
.beginQuery(gl
.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
, q1
);
133 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
, "Begining a deleted query");
134 shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)");
137 function runObjectTest() {
139 debug("Testing object creation");
141 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should have no previous errors");
143 q1
= gl
.createQuery();
144 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "createQuery should not set an error");
145 shouldBeNonNull("q1");
147 // Expect false if never bound
148 shouldBeFalse("gl.isQuery(q1)");
149 gl
.beginQuery(gl
.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
, q1
);
150 shouldBeTrue("gl.isQuery(q1)");
151 gl
.endQuery(gl
.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
);
152 shouldBeTrue("gl.isQuery(q1)");
154 shouldBeFalse("gl.isQuery(q1)");
156 shouldBeFalse("gl.isQuery(null)");
162 var successfullyParsed
= true;
164 <script src=
"../../js/js-test-post.js"></script>