blob: 94f2c07dbbcb40ab50c5cd7480bd074ff02f6299 [file] [log] [blame]
zmo@google.com2a44ea32012-04-03 21:48:37 +00001<!DOCTYPE html>
2<html>
3<head>
4<meta charset="utf-8">
5<title>WebGL shader precision format test.</title>
ap@apple.comfab549e2014-12-27 23:22:02 +00006<script src="../../../resources/js-test.js"></script>
zmo@google.com2a44ea32012-04-03 21:48:37 +00007<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>
tony@chromium.org73e37062012-09-10 17:05:27 +000015if (window.initNonKhronosFramework) {
16 window.initNonKhronosFramework(true);
17}
18
commit-queue@webkit.orgb6950fe2013-01-25 19:20:08 +000019if (window.internals)
20 window.internals.settings.setWebGLErrorsToConsoleEnabled(false);
21
zmo@google.com2a44ea32012-04-03 21:48:37 +000022var wtu = WebGLTestUtils;
23description(document.title);
24debug("Tests that WebGLShaderPrecisionFormat class and getShaderPrecisionFormat work.");
25debug("");
26var gl = create3DContext(document.getElementById("canvas"));
27
28function verifyShaderPrecisionFormat(shadertype, precisiontype) {
29 shouldBeTrue('gl.getShaderPrecisionFormat(' + shadertype + ', ' +
30 precisiontype + ') instanceof WebGLShaderPrecisionFormat');
31}
32
33debug("");
34debug("Test that getShaderPrecisionFormat returns a WebGLShaderPrecisionFormat object.");
35debug("");
36
37verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.LOW_FLOAT');
38verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.MEDIUM_FLOAT');
39verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.HIGH_FLOAT');
40verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.LOW_INT');
41verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.MEDIUM_INT');
42verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.HIGH_INT');
43verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.LOW_FLOAT');
44verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.MEDIUM_FLOAT');
45verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.HIGH_FLOAT');
46verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.LOW_INT');
47verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.MEDIUM_INT');
48verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.HIGH_INT');
49
50debug("");
51debug("Test that getShaderPrecisionFormat throws an error with invalid parameters.");
52debug("");
53
54shouldGenerateGLError(gl, gl.INVALID_ENUM, 'gl.getShaderPrecisionFormat(gl.HIGH_INT, gl.VERTEX_SHADER)');
55
56debug("");
zmo@google.com20a6c5c2012-04-10 17:25:01 +000057debug("Test that WebGLShaderPrecisionFormat values are sensible.");
58debug("");
59
60// The minimum values are from OpenGL ES Shading Language spec, section 4.5.
61
62var shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT);
63shouldBeTrue('shaderPrecisionFormat.rangeMin >= 1');
64shouldBeTrue('shaderPrecisionFormat.rangeMax >= 1');
65shouldBeTrue('shaderPrecisionFormat.precision >= 8');
66
67shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_FLOAT);
68shouldBeTrue('shaderPrecisionFormat.rangeMin >= 14');
69shouldBeTrue('shaderPrecisionFormat.rangeMax >= 14');
70shouldBeTrue('shaderPrecisionFormat.precision >= 10');
71
72shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT);
73shouldBeTrue('shaderPrecisionFormat.rangeMin >= 62');
74shouldBeTrue('shaderPrecisionFormat.rangeMax >= 62');
75shouldBeTrue('shaderPrecisionFormat.precision >= 16');
76
77shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_INT);
78shouldBeTrue('shaderPrecisionFormat.rangeMin >= 8');
79shouldBeTrue('shaderPrecisionFormat.rangeMax >= 8');
80shouldBeTrue('shaderPrecisionFormat.precision == 0');
81
82shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_INT);
83shouldBeTrue('shaderPrecisionFormat.rangeMin >= 10');
84shouldBeTrue('shaderPrecisionFormat.rangeMax >= 10');
85shouldBeTrue('shaderPrecisionFormat.precision == 0');
86
87shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_INT);
88shouldBeTrue('shaderPrecisionFormat.rangeMin >= 16');
89shouldBeTrue('shaderPrecisionFormat.rangeMax >= 16');
90shouldBeTrue('shaderPrecisionFormat.precision == 0');
91
92debug("");
zmo@google.com2a44ea32012-04-03 21:48:37 +000093debug("Test that getShaderPrecisionFormat returns the same thing every call.");
94debug("");
95
zmo@google.com20a6c5c2012-04-10 17:25:01 +000096shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT);
zmo@google.com2a44ea32012-04-03 21:48:37 +000097var shaderPrecisionFormat2 = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT);
98shouldBeTrue('shaderPrecisionFormat.rangeMin == shaderPrecisionFormat2.rangeMin');
99shouldBeTrue('shaderPrecisionFormat.rangeMax == shaderPrecisionFormat2.rangeMax');
100shouldBeTrue('shaderPrecisionFormat.precision == shaderPrecisionFormat2.precision');
101
102finishTest();
103</script>
104
105</body>
106</html>
107
108