4 ** Copyright (c) 2012 The Khronos Group Inc.
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:
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
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.
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>
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 -->
47 description("This test verifies the functionality of the WEBGL_debug_shaders extension, if it is available.");
51 var wtu = WebGLTestUtils;
52 var gl = wtu.create3DContext("canvas");
58 var newTranslatedSource;
61 testFailed("WebGL context does not exist");
63 testPassed("WebGL context exists");
65 // Query the extension and store globally so shouldBe can access it
66 ext = gl.getExtension("WEBGL_debug_shaders");
68 testPassed("No WEBGL_debug_shaders support -- this is legal");
70 runSupportedTest(false);
72 testPassed("Successfully enabled WEBGL_debug_shaders extension");
74 runSupportedTest(true);
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");
85 testFailed("WEBGL_debug_shaders listed as supported but getExtension failed");
88 if (extensionEnabled) {
89 testFailed("WEBGL_debug_shaders not listed as supported but getExtension succeeded");
91 testPassed("WEBGL_debug_shaders not listed as supported and getExtension failed -- this is legal");
96 function runTestEnabled() {
97 debug("Testing function with extension enabled");
101 source: "void main() { gl_Position = vec4(1.0, 0.0, 0.0, 1.0); }",
102 type: gl.VERTEX_SHADER
105 source: "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }",
106 type: gl.FRAGMENT_SHADER
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];
117 shader = gl.createShader(info.type);
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()");
131 testFailed("Calling getTranslatedShaderSource() failed");
133 gl.attachShader(program, shader);
135 gl.linkProgram(program);
136 shouldBeTrue("gl.getProgramParameter(program, gl.LINK_STATUS)");
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');
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');
161 var successfullyParsed = true;
163 <script src="../../resources/js-test-post.js"></script>