2d3d889dd84423017db95251252f4bf81a9c0554
[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="missingPragmaFragmentShader" 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
52 <!-- Shader with required #version -->
53 <script id="testFragmentShader" type="x-shader/x-fragment">
54 #version 300 es
55 precision mediump float;
56 void main() {
57     gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
58     gl_FragDepth = 1.0;
59 }
60 </script>
61 <!-- Shaders to link with test fragment shaders -->
62 <script id="goodVertexShader" type="x-shader/x-vertex">
63 attribute vec4 vPosition;
64 void main() {
65     gl_Position = vPosition;
66 }
67 </script>
68 <!-- Shaders to test output -->
69 <script id="outputVertexShader" type="x-shader/x-vertex">
70 attribute vec4 vPosition;
71 void main() {
72     gl_Position = vPosition;
73 }
74 </script>
75 <script id="outputFragmentShader" type="x-shader/x-fragment">
76 #version 300 es
77 precision mediump float;
78 uniform float uDepth;
79 void main() {
80     gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
81     gl_FragDepthEXT = uDepth;
82 }
83 </script>
84
85 <script>
86 "use strict";
87 description("This test verifies the functionality of setting fragment depth in a shader.");
88
89 debug("");
90
91 var wtu = WebGLTestUtils;
92 var canvas = document.getElementById("canvas");
93 var gl = wtu.create3DContext(canvas, null, 2);
94
95 if (!gl) {
96     testFailed("WebGL context does not exist");
97 } else {
98     testPassed("WebGL context exists");
99
100     runShaderTests();
101     runOutputTests();
102 }
103
104 function runShaderTests() {
105     debug("");
106     debug("Testing various shader compiles");
107
108     // Always expect the shader missing the #version to fail
109     var missingPragmaFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "missingPragmaFragmentShader");
110     if (missingPragmaFragmentProgram) {
111         testFailed("Shader built-ins allowed without #version");
112     } else {
113         testPassed("Shader built-ins disallowed without #version");
114     }
115
116     // Try to compile a shader using the built-ins that should only succeed if enabled
117     var testFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "testFragmentShader");
118     if (testFragmentProgram) {
119         testPassed("Shader built-ins compiled successfully");
120     } else {
121         testFailed("Shader built-ins failed to compile");
122     }
123 }
124
125 function runOutputTests() {
126     debug("Testing various draws for valid built-in function behavior");
127
128     canvas.width = 50; canvas.height = 50;
129     gl.viewport(0, 0, canvas.width, canvas.height);
130     
131     // Enable depth testing with a clearDepth of 0.5
132     // This makes it so that fragments are only rendered when
133     // gl_fragDepth is < 0.5
134     gl.clearDepth(0.5);
135     gl.enable(gl.DEPTH_TEST);
136
137     var positionLoc = 0;
138     var texcoordLoc = 1;
139     var program = wtu.setupProgram(gl, ["outputVertexShader", "outputFragmentShader"], ['vPosition'], [0]);
140     var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
141     var depthUniform = gl.getUniformLocation(program, "uDepth");
142
143     // Draw 1: Greater than clear depth
144     gl.uniform1f(depthUniform, 1.0);
145     wtu.clearAndDrawUnitQuad(gl);
146     wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [255, 255, 255, 255]);
147
148     // Draw 2: Less than clear depth
149     gl.uniform1f(depthUniform, 0.0);
150     wtu.clearAndDrawUnitQuad(gl);
151     wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [255, 0, 0, 255]);
152 }
153
154 debug("");
155 var successfullyParsed = true;
156 </script>
157 <script src="../../resources/js-test-post.js"></script>
158
159 </body>
160 </html>