OLD | NEW |
(Empty) | |
| 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"></s
cript> |
| 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 ext
ension, 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 |
| 59 if (!gl) { |
| 60 testFailed("WebGL context does not exist"); |
| 61 } else { |
| 62 testPassed("WebGL context exists"); |
| 63 |
| 64 // Query the extension and store globally so shouldBe can access it |
| 65 ext = gl.getExtension("WEBGL_debug_shaders"); |
| 66 if (!ext) { |
| 67 testPassed("No WEBGL_debug_shaders support -- this is legal"); |
| 68 |
| 69 runSupportedTest(false); |
| 70 } else { |
| 71 testPassed("Successfully enabled WEBGL_debug_shaders extension"); |
| 72 |
| 73 runSupportedTest(true); |
| 74 runTestEnabled(); |
| 75 } |
| 76 } |
| 77 |
| 78 function runSupportedTest(extensionEnabled) { |
| 79 var supported = gl.getSupportedExtensions(); |
| 80 if (supported.indexOf("WEBGL_debug_shaders") >= 0) { |
| 81 if (extensionEnabled) { |
| 82 testPassed("WEBGL_debug_shaders listed as supported and getExtension
succeeded"); |
| 83 } else { |
| 84 testFailed("WEBGL_debug_shaders listed as supported but getExtension
failed"); |
| 85 } |
| 86 } else { |
| 87 if (extensionEnabled) { |
| 88 testFailed("WEBGL_debug_shaders not listed as supported but getExten
sion succeeded"); |
| 89 } else { |
| 90 testPassed("WEBGL_debug_shaders not listed as supported and getExten
sion failed -- this is legal"); |
| 91 } |
| 92 } |
| 93 } |
| 94 |
| 95 function runTestEnabled() { |
| 96 debug("Testing function with extension enabled"); |
| 97 |
| 98 var shaderInfos = [ |
| 99 { |
| 100 source: "void main() { gl_Position = vec4(1.0, 0.0, 0.0, 1.0); }", |
| 101 type: gl.VERTEX_SHADER |
| 102 }, |
| 103 { |
| 104 source: "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }", |
| 105 type: gl.FRAGMENT_SHADER |
| 106 } |
| 107 ]; |
| 108 |
| 109 // Do this twice to test for caching issues. |
| 110 for (var jj = 0; jj < 2; ++jj) { |
| 111 debug("pass:" + (jj + 1)); |
| 112 program = gl.createProgram(); |
| 113 for (var ii = 0; ii < shaderInfos.length; ++ii) { |
| 114 info = shaderInfos[ii]; |
| 115 |
| 116 shader = gl.createShader(info.type); |
| 117 |
| 118 // if no source has been defined or compileShader() has not been cal
led, |
| 119 // getTranslatedShaderSource() should return an empty string. |
| 120 shouldBeNull("ext.getTranslatedShaderSource(shader)"); |
| 121 gl.shaderSource(shader, info.source); |
| 122 shouldBeNull("ext.getTranslatedShaderSource(shader)"); |
| 123 gl.compileShader(shader); |
| 124 shouldBeTrue("gl.getShaderParameter(shader, gl.COMPILE_STATUS)"); |
| 125 translatedSource = ext.getTranslatedShaderSource(shader); |
| 126 glErrorShouldBe(gl, gl.NO_ERROR, "No gl error should occur"); |
| 127 if (translatedSource && translatedSource.length > 0) { |
| 128 testPassed("Successfully called getTranslatedShaderSource()"); |
| 129 } else { |
| 130 testFailed("Calling getTranslatedShaderSource() failed"); |
| 131 } |
| 132 gl.attachShader(program, shader); |
| 133 } |
| 134 gl.linkProgram(program); |
| 135 shouldBeTrue("gl.getProgramParameter(program, gl.LINK_STATUS)"); |
| 136 } |
| 137 |
| 138 // Test changing the source. Make sure we get the correct source each time. |
| 139 debug("test changing source"); |
| 140 shader = gl.createShader(gl.FRAGMENT_SHADER); |
| 141 gl.shaderSource(shader, "void main() { gl_FragColor = vec4(gl_FragCoord.x, 0
.0, 0.0, 1.0); }"); |
| 142 gl.compileShader(shader); |
| 143 shouldBeTrue("gl.getShaderParameter(shader, gl.COMPILE_STATUS)"); |
| 144 translatedSource = ext.getTranslatedShaderSource(shader); |
| 145 shouldBeTrue('translatedSource && translatedSource.indexOf("gl_FragCoord") >
= 0'); |
| 146 // change the source but don't compile. |
| 147 gl.shaderSource(shader, "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.
0); }"); |
| 148 // the source should NOT change. It should be the same as the old source. |
| 149 newTranslatedSource = ext.getTranslatedShaderSource(shader); |
| 150 shouldBe('newTranslatedSource', 'translatedSource'); |
| 151 // now compile. |
| 152 gl.compileShader(shader); |
| 153 shouldBeTrue("gl.getShaderParameter(shader, gl.COMPILE_STATUS)"); |
| 154 // the source should have change. |
| 155 newTranslatedSource = ext.getTranslatedShaderSource(shader); |
| 156 shouldNotBe('newTranslatedSource', 'translatedSource'); |
| 157 } |
| 158 |
| 159 debug(""); |
| 160 var successfullyParsed = true; |
| 161 </script> |
| 162 <script src="../../resources/js-test-post.js"></script> |
| 163 |
| 164 </body> |
| 165 </html> |
OLD | NEW |