Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance2 / core / frag-depth.html
1 <!--
2
3 /*
4 ** Copyright (c) 2013 The Khronos Group Inc.
5 **
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
16 **
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
24 */
25
26 -->
27
28 <!DOCTYPE html>
29 <html>
30 <head>
31 <meta charset="utf-8">
32 <title>WebGL Frag Depth Conformance Tests</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/js-test-pre.js"></script>
35 <script src="../../conformance/resources/webgl-test-utils.js"></script>
36 </head>
37 <body>
38 <div id="description"></div>
39 <canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
40 <div id="console"></div>
41 <!-- Shaders for testing fragment depth writing -->
42
43 <!-- Shader omitting the required #version -->
44 <script id="fragmentShaderESSL1" type="x-shader/x-fragment">
45 precision mediump float;
46 void main() {
47     gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
48     gl_FragDepth = 1.0;
49 }
50 </script>
51 <!-- Shader with required #version -->
52 <script id="fragmentShaderESSL3" type="x-shader/x-fragment">#version 300 es
53 precision mediump float;
54 out vec4 my_FragColor;
55 void main() {
56     my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
57     gl_FragDepth = 1.0;
58 }
59 </script>
60 <!-- Shader using the EXT suffix -->
61 <script id="fragmentShaderESSL3EXT" type="x-shader/x-fragment">#version 300 es
62 precision mediump float;
63 out vec4 my_FragColor;
64 void main() {
65     my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
66     gl_FragDepthEXT = 1.0;
67 }
68 </script>
69 <!-- Shaders to link with test fragment shaders -->
70 <script id="vertexShaderESSL1" type="x-shader/x-vertex">
71 attribute vec4 vPosition;
72 void main() {
73     gl_Position = vPosition;
74 }
75 </script>
76 <script id="vertexShaderESSL3" type="x-shader/x-vertex">#version 300 es
77 in vec4 vPosition;
78 void main() {
79     gl_Position = vPosition;
80 }
81 </script>
82
83 <!-- Shader to test output -->
84 <script id="outputFragmentShader" type="x-shader/x-fragment">#version 300 es
85 precision mediump float;
86 uniform float uDepth;
87
88 out vec4 my_FragColor;
89 void main() {
90     my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
91     gl_FragDepth = uDepth;
92 }
93 </script>
94
95 <script>
96 "use strict";
97 description("This test verifies the functionality of setting fragment depth in a shader.");
98
99 debug("");
100
101 var wtu = WebGLTestUtils;
102 var canvas = document.getElementById("canvas");
103 var gl = wtu.create3DContext(canvas, null, 2);
104
105 if (!gl) {
106     testFailed("WebGL context does not exist");
107 } else {
108     testPassed("WebGL context exists");
109
110     runShaderTests();
111     debug("");
112     runOutputTests();
113 }
114
115 function runShaderTests() {
116     debug("");
117     debug("Testing various shader compiles");
118
119     // Always expect ESSL1 shaders to fail
120     var fragmentProgramESSL1 = wtu.loadProgramFromScriptExpectError(gl, "vertexShaderESSL1", "fragmentShaderESSL1");
121     if (fragmentProgramESSL1) {
122         testFailed("gl_FragDepth allowed in ESSL1 shader - should be disallowed");
123     } else {
124         testPassed("gl_FragDepth disallowed in ESSL1 shader");
125     }
126
127     // Try to compile a shader using the built-ins that should only succeed if enabled
128     var testFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "vertexShaderESSL3", "fragmentShaderESSL3");
129     if (testFragmentProgram) {
130         testPassed("gl_FragDepth allowed in ESSL3 shader");
131     } else {
132         testFailed("gl_FragDepth disallowed in ESSL3 shader");
133     }
134
135     var testFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "vertexShaderESSL3", "fragmentShaderESSL3EXT");
136     if (testFragmentProgram) {
137         testFailed("gl_FragDepthEXT allowed in ESSL3 shader - should only allow gl_FragDepth");
138     } else {
139         testPassed("gl_FragDepthEXT disallowed in ESSL3 shader");
140     }
141 }
142
143 function runOutputTests() {
144     debug("Testing rendering results from writing to gl_FragData");
145
146     canvas.width = 50; canvas.height = 50;
147     gl.viewport(0, 0, canvas.width, canvas.height);
148     
149     // Enable depth testing with a clearDepth of 0.5
150     // This makes it so that fragments are only rendered when
151     // gl_FragDepth is < 0.5
152     gl.clearDepth(0.5);
153     gl.enable(gl.DEPTH_TEST);
154
155     var positionLoc = 0;
156     var texcoordLoc = 1;
157     var program = wtu.setupProgram(gl, ["vertexShaderESSL3", "outputFragmentShader"], ['vPosition'], [0]);
158     var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
159     var depthUniform = gl.getUniformLocation(program, "uDepth");
160
161     // Draw 1: Greater than clear depth
162     gl.uniform1f(depthUniform, 1.0);
163     wtu.clearAndDrawUnitQuad(gl);
164     wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [255, 255, 255, 255]);
165
166     // Draw 2: Less than clear depth
167     gl.uniform1f(depthUniform, 0.0);
168     wtu.clearAndDrawUnitQuad(gl);
169     wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [255, 0, 0, 255]);
170 }
171
172 debug("");
173 var successfullyParsed = true;
174 </script>
175 <script src="../../resources/js-test-post.js"></script>
176
177 </body>
178 </html>