query.html (6164B)
1 <!-- 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. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 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> 15 </head> 16 <body> 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; 23 varying vec4 v_color; 24 void main(void) { 25 gl_Position = a_position; 26 v_color = a_color; 27 } 28 </script> 29 <script id="fshader" type="x-shader/x-fragment"> 30 precision mediump float; 31 varying vec4 v_color; 32 void main(void) { 33 gl_FragColor = v_color; 34 } 35 </script> 36 <script> 37 "use strict"; 38 description("This test verifies the functionality of the Query objects."); 39 40 debug(""); 41 42 var wtu = WebGLTestUtils; 43 var canvas = document.getElementById("canvas"); 44 var gl = wtu.create3DContext(canvas, null, 2); 45 var q1 = null; 46 var q2 = null; 47 48 if (!gl) { 49 testFailed("WebGL context does not exist"); 50 } else { 51 testPassed("WebGL context exists"); 52 53 runCurrentQueryTest(); 54 runObjectTest(); 55 // TODO: Test buffer binding, drawing, etc. 56 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); 57 } 58 59 function runCurrentQueryTest() { 60 debug(""); 61 debug("Testing Beginning, Ending, and checking the state of query objects"); 62 63 shouldBe("gl.ANY_SAMPLES_PASSED", "0x8C2F"); 64 shouldBe("gl.ANY_SAMPLES_PASSED_CONSERVATIVE", "0x8D6A"); 65 shouldBe("gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN", "0x8C88"); 66 67 gl.getQuery(gl.ANY_SAMPLES_PASSED, gl.CURRENT_QUERY); 68 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "ANY_SAMPLES_PASSED query should succeed"); 69 70 gl.getQuery(gl.ANY_SAMPLES_PASSED_CONSERVATIVE, gl.CURRENT_QUERY); 71 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "ANY_SAMPLES_PASSED query should succeed"); 72 73 gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY); 74 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "ANY_SAMPLES_PASSED query should succeed"); 75 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)"); 80 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"); 87 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"); 91 92 gl.endQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); 93 shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)"); 94 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"); 97 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)"); 101 102 gl.beginQuery(gl.ANY_SAMPLES_PASSED, q2); 103 shouldBe("gl.getQuery(gl.ANY_SAMPLES_PASSED, gl.CURRENT_QUERY)", "q2"); 104 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)"); 108 109 gl.endQuery(gl.ANY_SAMPLES_PASSED); 110 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"); 114 115 gl.deleteQuery(q1); 116 gl.deleteQuery(q2); 117 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "deleting queries should not produce errors"); 118 119 shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)"); 120 shouldBeNull("gl.getQuery(gl.ANY_SAMPLES_PASSED_CONSERVATIVE, gl.CURRENT_QUERY)"); 121 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)"); 125 126 debug(""); 127 debug("Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1636525"); 128 129 q1 = gl.createQuery(); 130 gl.deleteQuery(q1); 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)"); 135 } 136 137 function runObjectTest() { 138 debug(""); 139 debug("Testing object creation"); 140 141 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should have no previous errors"); 142 143 q1 = gl.createQuery(); 144 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "createQuery should not set an error"); 145 shouldBeNonNull("q1"); 146 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)"); 153 gl.deleteQuery(q1); 154 shouldBeFalse("gl.isQuery(q1)"); 155 156 shouldBeFalse("gl.isQuery(null)"); 157 158 q1 = null; 159 } 160 161 debug(""); 162 var successfullyParsed = true; 163 </script> 164 <script src="../../js/js-test-post.js"></script> 165 166 </body> 167 </html>