content/canvas/test/webgl-conformance/conformance/misc/shader-precision-format.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!--
michael@0 2 Copyright (c) 2011 Mozilla Foundation. All rights reserved.
michael@0 3 Use of this source code is governed by a BSD-style license that can be
michael@0 4 found in the LICENSE file.
michael@0 5 -->
michael@0 6 <!DOCTYPE html>
michael@0 7 <html>
michael@0 8 <head>
michael@0 9 <meta charset="utf-8">
michael@0 10 <title>WebGL shader precision format test.</title>
michael@0 11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
michael@0 12 <script src="../../resources/js-test-pre.js"></script>
michael@0 13 <script src="../resources/webgl-test.js"> </script>
michael@0 14 <script src="../resources/webgl-test-utils.js"> </script>
michael@0 15 </head>
michael@0 16 <body>
michael@0 17 <canvas id="canvas" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
michael@0 18 <div id="description"></div>
michael@0 19 <div id="console"></div>
michael@0 20 <script>
michael@0 21 var wtu = WebGLTestUtils;
michael@0 22 description(document.title);
michael@0 23 debug("Tests that WebGLShaderPrecisionFormat class and getShaderPrecisionFormat work.");
michael@0 24 debug("");
michael@0 25 var gl = wtu.create3DContext("canvas");
michael@0 26
michael@0 27 function verifyShaderPrecisionFormat(shadertype, precisiontype) {
michael@0 28 shouldBeTrue('gl.getShaderPrecisionFormat(' + shadertype + ', ' +
michael@0 29 precisiontype + ') instanceof WebGLShaderPrecisionFormat');
michael@0 30 }
michael@0 31
michael@0 32 if (gl.getShaderPrecisionFormat == null || typeof gl.getShaderPrecisionFormat != 'function') {
michael@0 33 debug("getShaderPrecisionFormat() function not found.");
michael@0 34 } else {
michael@0 35 debug("");
michael@0 36 debug("Test that getShaderPrecisionFormat returns a WebGLShaderPrecisionFormat object.");
michael@0 37 debug("");
michael@0 38
michael@0 39 verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.LOW_FLOAT');
michael@0 40 verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.MEDIUM_FLOAT');
michael@0 41 verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.HIGH_FLOAT');
michael@0 42 verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.LOW_INT');
michael@0 43 verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.MEDIUM_INT');
michael@0 44 verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.HIGH_INT');
michael@0 45 verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.LOW_FLOAT');
michael@0 46 verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.MEDIUM_FLOAT');
michael@0 47 verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.HIGH_FLOAT');
michael@0 48 verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.LOW_INT');
michael@0 49 verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.MEDIUM_INT');
michael@0 50 verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.HIGH_INT');
michael@0 51
michael@0 52 debug("");
michael@0 53 debug("Test that getShaderPrecisionFormat throws an error with invalid parameters.");
michael@0 54 debug("");
michael@0 55
michael@0 56 shouldGenerateGLError(gl, gl.INVALID_ENUM, 'gl.getShaderPrecisionFormat(gl.HIGH_INT, gl.VERTEX_SHADER)');
michael@0 57
michael@0 58 debug("");
michael@0 59 debug("Test that WebGLShaderPrecisionFormat values are sensible.");
michael@0 60 debug("");
michael@0 61
michael@0 62 var shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT);
michael@0 63 shouldBeTrue('shaderPrecisionFormat.rangeMin >= 0 && shaderPrecisionFormat.rangeMin <= 128');
michael@0 64 shouldBeTrue('shaderPrecisionFormat.rangeMax >= 0 && shaderPrecisionFormat.rangeMax <= 128');
michael@0 65 shouldBeTrue('shaderPrecisionFormat.precision >= 0 && shaderPrecisionFormat.precision <= 128');
michael@0 66
michael@0 67 debug("");
michael@0 68 debug("Test that getShaderPrecisionFormat returns the same thing every call.");
michael@0 69 debug("");
michael@0 70
michael@0 71 var shaderPrecisionFormat2 = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT);
michael@0 72 shouldBeTrue('shaderPrecisionFormat.rangeMin == shaderPrecisionFormat2.rangeMin');
michael@0 73 shouldBeTrue('shaderPrecisionFormat.rangeMax == shaderPrecisionFormat2.rangeMax');
michael@0 74 shouldBeTrue('shaderPrecisionFormat.precision == shaderPrecisionFormat2.precision');
michael@0 75 }
michael@0 76
michael@0 77 finishTest();
michael@0 78 </script>
michael@0 79
michael@0 80 </body>
michael@0 81 </html>
michael@0 82
michael@0 83

mercurial