Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / webgl / shader-precision-format.html
blob94f2c07dbbcb40ab50c5cd7480bd074ff02f6299
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>WebGL shader precision format test.</title>
6 <script src="../../../resources/js-test.js"></script>
7 <script src="resources/webgl-test.js"> </script>
8 <script src="resources/webgl-test-utils.js"> </script>
9 </head>
10 <body>
11 <canvas id="canvas" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
12 <div id="description"></div>
13 <div id="console"></div>
14 <script>
15 if (window.initNonKhronosFramework) {
16 window.initNonKhronosFramework(true);
19 if (window.internals)
20 window.internals.settings.setWebGLErrorsToConsoleEnabled(false);
22 var wtu = WebGLTestUtils;
23 description(document.title);
24 debug("Tests that WebGLShaderPrecisionFormat class and getShaderPrecisionFormat work.");
25 debug("");
26 var gl = create3DContext(document.getElementById("canvas"));
28 function verifyShaderPrecisionFormat(shadertype, precisiontype) {
29 shouldBeTrue('gl.getShaderPrecisionFormat(' + shadertype + ', ' +
30 precisiontype + ') instanceof WebGLShaderPrecisionFormat');
33 debug("");
34 debug("Test that getShaderPrecisionFormat returns a WebGLShaderPrecisionFormat object.");
35 debug("");
37 verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.LOW_FLOAT');
38 verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.MEDIUM_FLOAT');
39 verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.HIGH_FLOAT');
40 verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.LOW_INT');
41 verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.MEDIUM_INT');
42 verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.HIGH_INT');
43 verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.LOW_FLOAT');
44 verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.MEDIUM_FLOAT');
45 verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.HIGH_FLOAT');
46 verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.LOW_INT');
47 verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.MEDIUM_INT');
48 verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.HIGH_INT');
50 debug("");
51 debug("Test that getShaderPrecisionFormat throws an error with invalid parameters.");
52 debug("");
54 shouldGenerateGLError(gl, gl.INVALID_ENUM, 'gl.getShaderPrecisionFormat(gl.HIGH_INT, gl.VERTEX_SHADER)');
56 debug("");
57 debug("Test that WebGLShaderPrecisionFormat values are sensible.");
58 debug("");
60 // The minimum values are from OpenGL ES Shading Language spec, section 4.5.
62 var shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT);
63 shouldBeTrue('shaderPrecisionFormat.rangeMin >= 1');
64 shouldBeTrue('shaderPrecisionFormat.rangeMax >= 1');
65 shouldBeTrue('shaderPrecisionFormat.precision >= 8');
67 shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_FLOAT);
68 shouldBeTrue('shaderPrecisionFormat.rangeMin >= 14');
69 shouldBeTrue('shaderPrecisionFormat.rangeMax >= 14');
70 shouldBeTrue('shaderPrecisionFormat.precision >= 10');
72 shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT);
73 shouldBeTrue('shaderPrecisionFormat.rangeMin >= 62');
74 shouldBeTrue('shaderPrecisionFormat.rangeMax >= 62');
75 shouldBeTrue('shaderPrecisionFormat.precision >= 16');
77 shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_INT);
78 shouldBeTrue('shaderPrecisionFormat.rangeMin >= 8');
79 shouldBeTrue('shaderPrecisionFormat.rangeMax >= 8');
80 shouldBeTrue('shaderPrecisionFormat.precision == 0');
82 shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_INT);
83 shouldBeTrue('shaderPrecisionFormat.rangeMin >= 10');
84 shouldBeTrue('shaderPrecisionFormat.rangeMax >= 10');
85 shouldBeTrue('shaderPrecisionFormat.precision == 0');
87 shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_INT);
88 shouldBeTrue('shaderPrecisionFormat.rangeMin >= 16');
89 shouldBeTrue('shaderPrecisionFormat.rangeMax >= 16');
90 shouldBeTrue('shaderPrecisionFormat.precision == 0');
92 debug("");
93 debug("Test that getShaderPrecisionFormat returns the same thing every call.");
94 debug("");
96 shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT);
97 var shaderPrecisionFormat2 = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT);
98 shouldBeTrue('shaderPrecisionFormat.rangeMin == shaderPrecisionFormat2.rangeMin');
99 shouldBeTrue('shaderPrecisionFormat.rangeMax == shaderPrecisionFormat2.rangeMax');
100 shouldBeTrue('shaderPrecisionFormat.precision == shaderPrecisionFormat2.precision');
102 finishTest();
103 </script>
105 </body>
106 </html>