d622524b9e815dd3bd707b259eab10997f5d7ac9
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / conformance-suites / 1.0.2 / conformance / extensions / webgl-debug-shaders.html
1 <!--
2
3 /*
4 ** Copyright (c) 2012 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 WebGL_debug_shaders Conformance Tests</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></script>
35 <script src="../../resources/js-test-pre.js"></script>
36 <script src="../resources/webgl-test.js"></script>
37 <script src="../resources/webgl-test-utils.js"></script>
38 </head>
39 <body>
40 <div id="description"></div>
41 <canvas id="canvas" style="width: 1px; height: 1px;"> </canvas>
42 <div id="console"></div>
43 <!-- Shaders for testing standard derivatives -->
44
45 <script>
46 "use strict";
47 description("This test verifies the functionality of the WEBGL_debug_shaders extension, if it is available.");
48
49 debug("");
50
51 var wtu = WebGLTestUtils;
52 var gl = wtu.create3DContext("canvas");
53 var ext = null;
54 var shader = null;
55 var program = null;
56 var info = null;
57 var translatedSource;
58 var newTranslatedSource;
59
60 if (!gl) {
61     testFailed("WebGL context does not exist");
62 } else {
63     testPassed("WebGL context exists");
64
65     // Query the extension and store globally so shouldBe can access it
66     ext = gl.getExtension("WEBGL_debug_shaders");
67     if (!ext) {
68         testPassed("No WEBGL_debug_shaders support -- this is legal");
69
70         runSupportedTest(false);
71     } else {
72         testPassed("Successfully enabled WEBGL_debug_shaders extension");
73
74         runSupportedTest(true);
75         runTestEnabled();
76     }
77 }
78
79 function runSupportedTest(extensionEnabled) {
80     var supported = gl.getSupportedExtensions();
81     if (supported.indexOf("WEBGL_debug_shaders") >= 0) {
82         if (extensionEnabled) {
83             testPassed("WEBGL_debug_shaders listed as supported and getExtension succeeded");
84         } else {
85             testFailed("WEBGL_debug_shaders listed as supported but getExtension failed");
86         }
87     } else {
88         if (extensionEnabled) {
89             testFailed("WEBGL_debug_shaders not listed as supported but getExtension succeeded");
90         } else {
91             testPassed("WEBGL_debug_shaders not listed as supported and getExtension failed -- this is legal");
92         }
93     }
94 }
95
96 function runTestEnabled() {
97     debug("Testing function with extension enabled");
98
99     var shaderInfos = [
100       {
101         source: "void main() { gl_Position = vec4(1.0, 0.0, 0.0, 1.0); }",
102         type: gl.VERTEX_SHADER
103       },
104       {
105         source: "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }",
106         type: gl.FRAGMENT_SHADER
107       }
108     ];
109
110     // Do this twice to test for caching issues.
111     for (var jj = 0; jj < 2; ++jj) {
112         debug("pass:" + (jj + 1));
113         program = gl.createProgram();
114         for (var ii = 0; ii < shaderInfos.length; ++ii) {
115             info = shaderInfos[ii];
116
117             shader = gl.createShader(info.type);
118
119             // if no source has been defined or compileShader() has not been called,
120             // getTranslatedShaderSource() should return an empty string.
121             shouldBe("ext.getTranslatedShaderSource(shader)", '""');
122             gl.shaderSource(shader, info.source);
123             shouldBe("ext.getTranslatedShaderSource(shader)", '""');
124             gl.compileShader(shader);
125             shouldBeTrue("gl.getShaderParameter(shader, gl.COMPILE_STATUS)");
126             translatedSource = ext.getTranslatedShaderSource(shader);
127             glErrorShouldBe(gl, gl.NO_ERROR, "No gl error should occur");
128             if (translatedSource && translatedSource.length > 0) {
129                 testPassed("Successfully called getTranslatedShaderSource()");
130             } else {
131                 testFailed("Calling getTranslatedShaderSource() failed");
132             }
133             gl.attachShader(program, shader);
134         }
135         gl.linkProgram(program);
136         shouldBeTrue("gl.getProgramParameter(program, gl.LINK_STATUS)");
137     }
138
139     // Test changing the source. Make sure we get the correct source each time.
140     debug("test changing source");
141     shader = gl.createShader(gl.FRAGMENT_SHADER);
142     gl.shaderSource(shader, "void main() { gl_FragColor = vec4(gl_FragCoord.x, 0.0, 0.0, 1.0); }");
143     gl.compileShader(shader);
144     shouldBeTrue("gl.getShaderParameter(shader, gl.COMPILE_STATUS)");
145     translatedSource = ext.getTranslatedShaderSource(shader);
146     shouldBeTrue('translatedSource && translatedSource.indexOf("gl_FragCoord") >= 0');
147     // change the source but don't compile.
148     gl.shaderSource(shader, "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }");
149     // the source should NOT change. It should be the same as the old source.
150     newTranslatedSource = ext.getTranslatedShaderSource(shader);
151     shouldBe('newTranslatedSource', 'translatedSource');
152     // now compile.
153     gl.compileShader(shader);
154     shouldBeTrue("gl.getShaderParameter(shader, gl.COMPILE_STATUS)");
155     // the source should have change.
156     newTranslatedSource = ext.getTranslatedShaderSource(shader);
157     shouldNotBe('newTranslatedSource', 'translatedSource');
158 }
159
160 debug("");
161 var successfullyParsed = true;
162 </script>
163 <script src="../../resources/js-test-post.js"></script>
164
165 </body>
166 </html>