diff options
Diffstat (limited to 'dom/canvas/test/webgl-conf/checkout/conformance2/query')
3 files changed, 338 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/query/00_test_list.txt b/dom/canvas/test/webgl-conf/checkout/conformance2/query/00_test_list.txt new file mode 100644 index 000000000..c40921bf8 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/query/00_test_list.txt @@ -0,0 +1,2 @@ +occlusion-query.html +query.html diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/query/occlusion-query.html b/dom/canvas/test/webgl-conf/checkout/conformance2/query/occlusion-query.html new file mode 100644 index 000000000..cba410e77 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/query/occlusion-query.html @@ -0,0 +1,158 @@ +<!-- + +/* +** Copyright (c) 2015 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 Occlusion Query 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> +<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas> +<div id="console"></div> +<script> +"use strict"; +description("This test verifies the functionality of occlusion query objects."); + +debug(""); + +var tests = []; +var currentTest; +var currentTestIndex = 0; +var numberOfTestAttempts = 4; // Just to stress implementations a bit more. +var query; +var numberOfCompletionAttempts = 0; + +function setupTests(gl) { + tests = [ + { + target: gl.ANY_SAMPLES_PASSED_CONSERVATIVE, + name: "ANY_SAMPLES_PASSED_CONSERVATIVE", + result: 1, + }, + { + target: gl.ANY_SAMPLES_PASSED, + name: "ANY_SAMPLES_PASSED", + result: 1, + }, + ]; +} + +function runOcclusionQueryTest() { + currentTest = tests[currentTestIndex]; + + debug(""); + debug("Testing completion and behavior of " + currentTest.name + " occlusion query"); + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + var program = wtu.setupSimpleColorProgram(gl, 0); + gl.uniform4f(gl.getUniformLocation(program, "u_color"), 0, 1, 0, 1); + wtu.setupUnitQuad(gl, 0); + query = gl.createQuery(); + var target = currentTest.target; + gl.beginQuery(target, query); + wtu.drawUnitQuad(gl); + gl.endQuery(target); + + // Verify as best as possible that the implementation doesn't + // allow a query's result to become available the same frame, by + // spin-looping for some time and ensuring that none of the + // queries' results become available. + var numEarlyTests = 20000; + while (--numEarlyTests > 0) { + gl.finish(); + if (gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE)) { + testFailed("Query's result became available too early"); + finishTest(); + return; + } + } + + testPassed("Query's result didn't become available too early"); + numberOfCompletionAttempts = 0; + requestAnimationFrame(completeOcclusionQueryTest); +} + +function completeOcclusionQueryTest() { + ++numberOfCompletionAttempts; + + if (numberOfCompletionAttempts > 500) { + testFailed("Query didn't become available in a reasonable time"); + finishTest(); + return; + } + + if (!gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE)) { + requestAnimationFrame(completeOcclusionQueryTest); + return; + } + + // No matter whether the test was run with ANY_SAMPLES_PASSED or + // ANY_SAMPLES_PASSED_CONSERVATIVE, the query object should always + // report a non-zero result. + var result = gl.getQueryParameter(query, gl.QUERY_RESULT); + if (result == currentTest.result) { + testPassed("Occlusion query " + currentTest.name + " returned a correct result (" + result + ")"); + } else { + testFailed("Occlusion query " + currentTest.name + " returned an incorrect result " + result + " (expected " + currentTest.result + ")"); + } + + gl.deleteQuery(query); + query = null; + + ++currentTestIndex; + if (currentTestIndex >= tests.length) { + --numberOfTestAttempts; + if (numberOfTestAttempts == 0) { + finishTest(); + } else { + currentTestIndex = 0; + requestAnimationFrame(runOcclusionQueryTest); + } + } else { + requestAnimationFrame(runOcclusionQueryTest); + } +} + +var wtu = WebGLTestUtils; +var canvas = document.getElementById("canvas"); +var gl = wtu.create3DContext(canvas, null, 2); + +if (!gl) { + testFailed("WebGL context does not exist"); +} else { + testPassed("WebGL context exists"); + + setupTests(gl); + runOcclusionQueryTest(); +} +</script> +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/query/query.html b/dom/canvas/test/webgl-conf/checkout/conformance2/query/query.html new file mode 100644 index 000000000..79e2403b8 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/query/query.html @@ -0,0 +1,178 @@ +<!-- + +/* +** Copyright (c) 2015 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 Query 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> +<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas> +<div id="console"></div> +<script id="vshader" type="x-shader/x-vertex"> +attribute vec4 a_position; +attribute vec4 a_color; +varying vec4 v_color; +void main(void) { + gl_Position = a_position; + v_color = a_color; +} +</script> +<script id="fshader" type="x-shader/x-fragment"> +precision mediump float; +varying vec4 v_color; +void main(void) { + gl_FragColor = v_color; +} +</script> +<script> +"use strict"; +description("This test verifies the functionality of the Query objects."); + +debug(""); + +var wtu = WebGLTestUtils; +var canvas = document.getElementById("canvas"); +var gl = wtu.create3DContext(canvas, null, 2); +var q1 = null; +var q2 = null; + +if (!gl) { + testFailed("WebGL context does not exist"); +} else { + testPassed("WebGL context exists"); + + runCurrentQueryTest(); + runObjectTest(); + // TODO: Test buffer binding, drawing, etc. + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); +} + +function runCurrentQueryTest() { + debug(""); + debug("Testing Beginning, Ending, and checking the state of query objects"); + + shouldBe("gl.ANY_SAMPLES_PASSED", "0x8C2F"); + shouldBe("gl.ANY_SAMPLES_PASSED_CONSERVATIVE", "0x8D6A"); + shouldBe("gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN", "0x8C88"); + + gl.getQuery(gl.ANY_SAMPLES_PASSED, gl.CURRENT_QUERY); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "ANY_SAMPLES_PASSED query should succeed"); + + gl.getQuery(gl.ANY_SAMPLES_PASSED_CONSERVATIVE, gl.CURRENT_QUERY); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "ANY_SAMPLES_PASSED query should succeed"); + + gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "ANY_SAMPLES_PASSED query should succeed"); + + // Default value is null + shouldBeNull("gl.getQuery(gl.ANY_SAMPLES_PASSED, gl.CURRENT_QUERY)"); + shouldBeNull("gl.getQuery(gl.ANY_SAMPLES_PASSED_CONSERVATIVE, gl.CURRENT_QUERY)"); + shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)"); + + q1 = gl.createQuery(); + q2 = gl.createQuery(); + shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)"); + gl.beginQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, q1); + shouldBeTrue("gl.isQuery(q1)"); + shouldBe("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)", "q1"); + + gl.beginQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, q2); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "Can't begin a query while one is already active"); + shouldBe("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)", "q1"); + + gl.endQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); + shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)"); + + gl.endQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "Can't end a query if one is not active"); + + gl.beginQuery(gl.ANY_SAMPLES_PASSED, q1); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "Can't re-use query objects for incompatible targets"); + shouldBeNull("gl.getQuery(gl.ANY_SAMPLES_PASSED, gl.CURRENT_QUERY)"); + + gl.beginQuery(gl.ANY_SAMPLES_PASSED, q2); + shouldBe("gl.getQuery(gl.ANY_SAMPLES_PASSED, gl.CURRENT_QUERY)", "q2"); + + gl.beginQuery(gl.ANY_SAMPLES_PASSED_CONSERVATIVE, q2); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "Can't call beginQuery on an already active query object"); + shouldBeNull("gl.getQuery(gl.ANY_SAMPLES_PASSED_CONSERVATIVE, gl.CURRENT_QUERY)"); + + gl.endQuery(gl.ANY_SAMPLES_PASSED); + + gl.beginQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, q1); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be able to have multiple unrelated query types active at once"); + shouldBe("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)", "q1"); + + gl.deleteQuery(q1); + gl.deleteQuery(q2); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "deleting queries should not produce errors"); + + shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)"); + shouldBeNull("gl.getQuery(gl.ANY_SAMPLES_PASSED_CONSERVATIVE, gl.CURRENT_QUERY)"); + + gl.beginQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, q1); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "beginning a deleted query object"); + shouldBeNull("gl.getQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, gl.CURRENT_QUERY)"); +} + +function runObjectTest() { + debug(""); + debug("Testing object creation"); + + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should have no previous errors"); + + q1 = gl.createQuery(); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "createQuery should not set an error"); + shouldBeNonNull("q1"); + + // Expect false if never bound + shouldBeFalse("gl.isQuery(q1)"); + gl.beginQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, q1); + shouldBeTrue("gl.isQuery(q1)"); + gl.endQuery(gl.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); + shouldBeTrue("gl.isQuery(q1)"); + gl.deleteQuery(q1); + shouldBeFalse("gl.isQuery(q1)"); + + shouldBeFalse("gl.isQuery(null)"); + + q1 = null; +} + +debug(""); +var successfullyParsed = true; +</script> +<script src="../../js/js-test-post.js"></script> + +</body> +</html> |