OLD | NEW |
(Empty) | |
| 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 EXT_frag_depth 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: 50px; height: 50px;"> </canvas> |
| 42 <div id="console"></div> |
| 43 <!-- Shaders for testing fragment depth writing --> |
| 44 |
| 45 <!-- Shader omitting the required #extension pragma --> |
| 46 <script id="missingPragmaFragmentShader" type="x-shader/x-fragment"> |
| 47 precision mediump float; |
| 48 void main() { |
| 49 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
| 50 gl_FragDepthEXT = 1.0; |
| 51 } |
| 52 </script> |
| 53 |
| 54 <!-- Shader to test macro definition --> |
| 55 <script id="macroFragmentShader" type="x-shader/x-fragment"> |
| 56 precision mediump float; |
| 57 void main() { |
| 58 #ifdef GL_EXT_frag_depth |
| 59 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
| 60 #else |
| 61 // Error expected |
| 62 #error no GL_EXT_frag_depth; |
| 63 #endif |
| 64 } |
| 65 </script> |
| 66 |
| 67 <!-- Shader with required #extension pragma --> |
| 68 <script id="testFragmentShader" type="x-shader/x-fragment"> |
| 69 #extension GL_EXT_frag_depth : enable |
| 70 precision mediump float; |
| 71 void main() { |
| 72 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
| 73 gl_FragDepthEXT = 1.0; |
| 74 } |
| 75 </script> |
| 76 <!-- Shaders to link with test fragment shaders --> |
| 77 <script id="goodVertexShader" type="x-shader/x-vertex"> |
| 78 attribute vec4 vPosition; |
| 79 void main() { |
| 80 gl_Position = vPosition; |
| 81 } |
| 82 </script> |
| 83 <!-- Shaders to test output --> |
| 84 <script id="outputVertexShader" type="x-shader/x-vertex"> |
| 85 attribute vec4 vPosition; |
| 86 void main() { |
| 87 gl_Position = vPosition; |
| 88 } |
| 89 </script> |
| 90 <script id="outputFragmentShader" type="x-shader/x-fragment"> |
| 91 #extension GL_EXT_frag_depth : enable |
| 92 precision mediump float; |
| 93 uniform float uDepth; |
| 94 void main() { |
| 95 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
| 96 gl_FragDepthEXT = uDepth; |
| 97 } |
| 98 </script> |
| 99 |
| 100 <script> |
| 101 "use strict"; |
| 102 description("This test verifies the functionality of the EXT_frag_depth extensio
n, if it is available."); |
| 103 |
| 104 debug(""); |
| 105 |
| 106 var wtu = WebGLTestUtils; |
| 107 var canvas = document.getElementById("canvas"); |
| 108 var gl = wtu.create3DContext(canvas); |
| 109 var ext = null; |
| 110 |
| 111 if (!gl) { |
| 112 testFailed("WebGL context does not exist"); |
| 113 } else { |
| 114 testPassed("WebGL context exists"); |
| 115 |
| 116 runShaderTests(false); |
| 117 |
| 118 // Query the extension and store globally so shouldBe can access it |
| 119 ext = wtu.getExtensionWithKnownPrefixes(gl, "EXT_frag_depth"); |
| 120 if (!ext) { |
| 121 testPassed("No EXT_frag_depth support -- this is legal"); |
| 122 |
| 123 runSupportedTest(false); |
| 124 } else { |
| 125 testPassed("Successfully enabled EXT_frag_depth extension"); |
| 126 |
| 127 runSupportedTest(true); |
| 128 |
| 129 runShaderTests(true); |
| 130 runOutputTests(); |
| 131 runUniqueObjectTest(); |
| 132 } |
| 133 } |
| 134 |
| 135 function runSupportedTest(extensionEnabled) { |
| 136 var supported = gl.getSupportedExtensions(); |
| 137 if (supported.indexOf("EXT_frag_depth") >= 0) { |
| 138 if (extensionEnabled) { |
| 139 testPassed("EXT_frag_depth listed as supported and getExtension succ
eeded"); |
| 140 } else { |
| 141 testFailed("EXT_frag_depth listed as supported but getExtension fail
ed"); |
| 142 } |
| 143 } else { |
| 144 if (extensionEnabled) { |
| 145 testFailed("EXT_frag_depth not listed as supported but getExtension
succeeded"); |
| 146 } else { |
| 147 testPassed("EXT_frag_depth not listed as supported and getExtension
failed -- this is legal"); |
| 148 } |
| 149 } |
| 150 } |
| 151 |
| 152 function runShaderTests(extensionEnabled) { |
| 153 debug(""); |
| 154 debug("Testing various shader compiles with extension " + (extensionEnabled
? "enabled" : "disabled")); |
| 155 |
| 156 // Expect the macro shader to succeed ONLY if enabled |
| 157 var macroFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVer
texShader", "macroFragmentShader"); |
| 158 if (extensionEnabled) { |
| 159 if (macroFragmentProgram) { |
| 160 // Expected result |
| 161 testPassed("GL_EXT_frag_depth defined in shaders when extension is e
nabled"); |
| 162 } else { |
| 163 testFailed("GL_EXT_frag_depth not defined in shaders when extension
is enabled"); |
| 164 } |
| 165 } else { |
| 166 if (macroFragmentProgram) { |
| 167 testFailed("GL_EXT_frag_depth defined in shaders when extension is d
isabled"); |
| 168 } else { |
| 169 testPassed("GL_EXT_frag_depth not defined in shaders when extension
disabled"); |
| 170 } |
| 171 } |
| 172 |
| 173 // Always expect the shader missing the #pragma to fail (whether enabled or
not) |
| 174 var missingPragmaFragmentProgram = wtu.loadProgramFromScriptExpectError(gl,
"goodVertexShader", "missingPragmaFragmentShader"); |
| 175 if (missingPragmaFragmentProgram) { |
| 176 testFailed("Shader built-ins allowed without #extension pragma"); |
| 177 } else { |
| 178 testPassed("Shader built-ins disallowed without #extension pragma"); |
| 179 } |
| 180 |
| 181 // Try to compile a shader using the built-ins that should only succeed if e
nabled |
| 182 var testFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVert
exShader", "testFragmentShader"); |
| 183 if (extensionEnabled) { |
| 184 if (testFragmentProgram) { |
| 185 testPassed("Shader built-ins compiled successfully when extension en
abled"); |
| 186 } else { |
| 187 testFailed("Shader built-ins failed to compile when extension enable
d"); |
| 188 } |
| 189 } else { |
| 190 if (testFragmentProgram) { |
| 191 testFailed("Shader built-ins compiled successfully when extension di
sabled"); |
| 192 } else { |
| 193 testPassed("Shader built-ins failed to compile when extension disabl
ed"); |
| 194 } |
| 195 } |
| 196 } |
| 197 |
| 198 function runOutputTests() { |
| 199 var e = 2; // Amount of variance to allow in result pixels - may need to be
tweaked higher |
| 200 |
| 201 debug("Testing various draws for valid built-in function behavior"); |
| 202 |
| 203 canvas.width = 50; canvas.height = 50; |
| 204 gl.viewport(0, 0, canvas.width, canvas.height); |
| 205 |
| 206 // Enable depth testing with a clearDepth of 0.5 |
| 207 // This makes it so that fragments are only rendered when |
| 208 // gl_fragDepthEXT is < 0.5 |
| 209 gl.clearDepth(0.5); |
| 210 gl.enable(gl.DEPTH_TEST); |
| 211 |
| 212 var positionLoc = 0; |
| 213 var texcoordLoc = 1; |
| 214 var program = wtu.setupProgram(gl, ["outputVertexShader", "outputFragmentSha
der"], ['vPosition'], [0]); |
| 215 var quadParameters = wtu.setupUnitQuad(gl, 0, 1); |
| 216 var depthUniform = gl.getUniformLocation(program, "uDepth"); |
| 217 |
| 218 // Draw 1: Greater than clear depth |
| 219 gl.uniform1f(depthUniform, 1.0); |
| 220 wtu.clearAndDrawUnitQuad(gl); |
| 221 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [255, 255, 255, 2
55]); |
| 222 |
| 223 // Draw 2: Less than clear depth |
| 224 gl.uniform1f(depthUniform, 0.0); |
| 225 wtu.clearAndDrawUnitQuad(gl); |
| 226 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [255, 0, 0, 255])
; |
| 227 } |
| 228 |
| 229 function runUniqueObjectTest() |
| 230 { |
| 231 debug("Testing that getExtension() returns the same object each time"); |
| 232 gl.getExtension("EXT_frag_depth").myProperty = 2; |
| 233 gc(); |
| 234 shouldBe('gl.getExtension("EXT_frag_depth").myProperty', '2'); |
| 235 } |
| 236 |
| 237 debug(""); |
| 238 var successfullyParsed = true; |
| 239 </script> |
| 240 <script src="../../resources/js-test-post.js"></script> |
| 241 |
| 242 </body> |
| 243 </html> |
OLD | NEW |