Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: third_party/webgl/sdk/tests/conformance/extensions/oes-standard-derivatives.html

Issue 10399113: Roll webgl conformance tests to r17874: part 2, adding r17874 (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 OES_standard_derivatives 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 standard derivatives -->
44
45 <!-- Shader omitting the required #extension pragma -->
46 <script id="missingPragmaFragmentShader" type="x-shader/x-fragment">
47 precision mediump float;
48 varying vec2 texCoord;
49 void main() {
50 float dx = dFdx(texCoord.x);
51 float dy = dFdy(texCoord.y);
52 float w = fwidth(texCoord.x);
53 gl_FragColor = vec4(dx, dy, w, 1.0);
54 }
55 </script>
56
57 <!-- Shader to test macro definition -->
58 <script id="macroFragmentShader" type="x-shader/x-fragment">
59 precision mediump float;
60 void main() {
61 #ifdef GL_OES_standard_derivatives
62 gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
63 #else
64 // Error expected
65 #error no GL_OES_standard_derivatives;
66 #endif
67 }
68 </script>
69
70 <!-- Shader with required #extension pragma -->
71 <script id="testFragmentShader" type="x-shader/x-fragment">
72 #extension GL_OES_standard_derivatives : enable
73 precision mediump float;
74 varying vec2 texCoord;
75 void main() {
76 float dx = dFdx(texCoord.x);
77 float dy = dFdy(texCoord.y);
78 float w = fwidth(texCoord.x);
79 gl_FragColor = vec4(dx, dy, w, 1.0);
80 }
81 </script>
82 <!-- Shaders to link with test fragment shaders -->
83 <script id="goodVertexShader" type="x-shader/x-vertex">
84 attribute vec4 vPosition;
85 varying vec2 texCoord;
86 void main() {
87 texCoord = vPosition.xy;
88 gl_Position = vPosition;
89 }
90 </script>
91 <!-- Shaders to test output -->
92 <script id="outputVertexShader" type="x-shader/x-vertex">
93 attribute vec4 vPosition;
94 varying vec4 position;
95 void main() {
96 position = vPosition;
97 gl_Position = vPosition;
98 }
99 </script>
100 <script id="outputFragmentShader" type="x-shader/x-fragment">
101 #extension GL_OES_standard_derivatives : enable
102 precision mediump float;
103 varying vec4 position;
104 void main() {
105 float dzdx = dFdx(position.z);
106 float dzdy = dFdy(position.z);
107 float fw = fwidth(position.z);
108 gl_FragColor = vec4(abs(dzdx), abs(dzdy), fw, 1.0);
109 }
110 </script>
111
112 <script>
113 description("This test verifies the functionality of the OES_standard_derivative s extension, if it is available.");
114
115 debug("");
116
117 var wtu = WebGLTestUtils;
118 var canvas = document.getElementById("canvas");
119 var gl = create3DContext(canvas);
120 var ext = null;
121
122 if (!gl) {
123 testFailed("WebGL context does not exist");
124 } else {
125 testPassed("WebGL context exists");
126
127 // Run tests with extension disabled
128 runHintTestDisabled();
129 runShaderTests(false);
130
131 // Query the extension and store globally so shouldBe can access it
132 ext = gl.getExtension("OES_standard_derivatives");
133 if (!ext) {
134 testPassed("No OES_standard_derivatives support -- this is legal");
135
136 runSupportedTest(false);
137 } else {
138 testPassed("Successfully enabled OES_standard_derivatives extension");
139
140 runSupportedTest(true);
141
142 runHintTestEnabled();
143 runShaderTests(true);
144 runOutputTests();
145 runUniqueObjectTest();
146 }
147 }
148
149 function runSupportedTest(extensionEnabled) {
150 var supported = gl.getSupportedExtensions();
151 if (supported.indexOf("OES_standard_derivatives") >= 0) {
152 if (extensionEnabled) {
153 testPassed("OES_standard_derivatives listed as supported and getExte nsion succeeded");
154 } else {
155 testFailed("OES_standard_derivatives listed as supported but getExte nsion failed");
156 }
157 } else {
158 if (extensionEnabled) {
159 testFailed("OES_standard_derivatives not listed as supported but get Extension succeeded");
160 } else {
161 testPassed("OES_standard_derivatives not listed as supported and get Extension failed -- this is legal");
162 }
163 }
164 }
165
166 function runHintTestDisabled() {
167 debug("Testing FRAGMENT_SHADER_DERIVATIVE_HINT_OES with extension disabled") ;
168
169 // Use the constant directly as we don't have the extension
170 var FRAGMENT_SHADER_DERIVATIVE_HINT_OES = 0x8B8B;
171
172 gl.getParameter(FRAGMENT_SHADER_DERIVATIVE_HINT_OES);
173 glErrorShouldBe(gl, gl.INVALID_ENUM, "FRAGMENT_SHADER_DERIVATIVE_HINT_OES sh ould not be queryable if extension is disabled");
174
175 gl.hint(FRAGMENT_SHADER_DERIVATIVE_HINT_OES, gl.DONT_CARE);
176 glErrorShouldBe(gl, gl.INVALID_ENUM, "hint should not accept FRAGMENT_SHADER _DERIVATIVE_HINT_OES if extension is disabled");
177 }
178
179 function runHintTestEnabled() {
180 debug("Testing FRAGMENT_SHADER_DERIVATIVE_HINT_OES with extension enabled");
181
182 shouldBe("ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES", "0x8B8B");
183
184 gl.getParameter(ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES);
185 glErrorShouldBe(gl, gl.NO_ERROR, "FRAGMENT_SHADER_DERIVATIVE_HINT_OES query should succeed if extension is enabled");
186
187 // Default value is DONT_CARE
188 if (gl.getParameter(ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES) == gl.DONT_CARE ) {
189 testPassed("Default value of FRAGMENT_SHADER_DERIVATIVE_HINT_OES is DONT _CARE");
190 } else {
191 testFailed("Default value of FRAGMENT_SHADER_DERIVATIVE_HINT_OES is not DONT_CARE");
192 }
193
194 // Ensure that we can set the target
195 gl.hint(ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES, gl.DONT_CARE);
196 glErrorShouldBe(gl, gl.NO_ERROR, "hint should accept FRAGMENT_SHADER_DERIVAT IVE_HINT_OES");
197
198 // Test all the hint modes
199 var validModes = ["FASTEST", "NICEST", "DONT_CARE"];
200 var anyFailed = false;
201 for (var n = 0; n < validModes.length; n++) {
202 var mode = validModes[n];
203 gl.hint(ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES, gl[mode]);
204 if (gl.getParameter(ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES) != gl[mode] ) {
205 testFailed("Round-trip of hint()/getParameter() failed on mode " + m ode);
206 anyFailed = true;
207 }
208 }
209 if (!anyFailed) {
210 testPassed("Round-trip of hint()/getParameter() with all supported modes ");
211 }
212 }
213
214 function runShaderTests(extensionEnabled) {
215 debug("");
216 debug("Testing various shader compiles with extension " + (extensionEnabled ? "enabled" : "disabled"));
217
218 // Expect the macro shader to succeed ONLY if enabled
219 var macroFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVer texShader", "macroFragmentShader");
220 if (extensionEnabled) {
221 if (macroFragmentProgram) {
222 // Expected result
223 testPassed("GL_OES_standard_derivatives defined in shaders when exte nsion is enabled");
224 } else {
225 testFailed("GL_OES_standard_derivatives not defined in shaders when extension is enabled");
226 }
227 } else {
228 if (macroFragmentProgram) {
229 testFailed("GL_OES_standard_derivatives defined in shaders when exte nsion is disabled");
230 } else {
231 testPassed("GL_OES_standard_derivatives not defined in shaders when extension disabled");
232 }
233 }
234
235 // Always expect the shader missing the #pragma to fail (whether enabled or not)
236 var missingPragmaFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "missingPragmaFragmentShader");
237 if (missingPragmaFragmentProgram) {
238 testFailed("Shader built-ins allowed without #extension pragma");
239 } else {
240 testPassed("Shader built-ins disallowed without #extension pragma");
241 }
242
243 // Try to compile a shader using the built-ins that should only succeed if e nabled
244 var testFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVert exShader", "testFragmentShader");
245 if (extensionEnabled) {
246 if (testFragmentProgram) {
247 testPassed("Shader built-ins compiled successfully when extension en abled");
248 } else {
249 testFailed("Shader built-ins failed to compile when extension enable d");
250 }
251 } else {
252 if (testFragmentProgram) {
253 testFailed("Shader built-ins compiled successfully when extension di sabled");
254 } else {
255 testPassed("Shader built-ins failed to compile when extension disabl ed");
256 }
257 }
258 }
259
260 function runOutputTests() {
261 // This tests does several draws with various values of z.
262 // The output of the fragment shader is:
263 // [dFdx(z), dFdy(z), fwidth(z), 1.0]
264 // The expected math: (note the conversion to uint8)
265 // canvas.width = canvas.height = 50
266 // dFdx = totalChange.x / canvas.width = 0.5 / 50.0 = 0.01
267 // dFdy = totalChange.y / canvas.height = 0.5 / 50.0 = 0.01
268 // fw = abs(dFdx + dFdy) = 0.01 + 0.01 = 0.02
269 // r = floor(dFdx * 255) = 3
270 // g = floor(dFdy * 255) = 3
271 // b = floor(fw * 255) = 5
272
273 var e = 2; // Amount of variance to allow in result pixels - may need to be tweaked higher
274
275 debug("Testing various draws for valid built-in function behavior");
276
277 canvas.width = 50; canvas.height = 50;
278 gl.viewport(0, 0, canvas.width, canvas.height);
279 gl.hint(ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES, gl.NICEST);
280
281 var program = wtu.setupProgram(gl, ["outputVertexShader", "outputFragmentSha der"], ['vPosition', 'texCoord0'], [0, 1]);
282 var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
283
284 function readLocation(x, y) {
285 var pixels = new Uint8Array(1 * 1 * 4);
286 var px = Math.floor(x * canvas.width);
287 var py = Math.floor(y * canvas.height);
288 gl.readPixels(px, py, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
289 return pixels;
290 };
291 function toString(arr) {
292 var s = "[";
293 for (var n = 0; n < arr.length; n++) {
294 s += arr[n];
295 if (n < arr.length - 1) {
296 s += ", ";
297 }
298 }
299 return s + "]";
300 };
301 function expectResult(target, successMessage, failureMessage) {
302 var locations = [
303 readLocation(0.1, 0.1),
304 readLocation(0.9, 0.1),
305 readLocation(0.1, 0.9),
306 readLocation(0.9, 0.9),
307 readLocation(0.5, 0.5)
308 ];
309 var anyDiffer = false;
310 for (var n = 0; n < locations.length; n++) {
311 var source = locations[n];
312 for (var m = 0; m < 4; m++) {
313 if (Math.abs(source[m] - target[m]) > e) {
314 anyDiffer = true;
315 testFailed(failureMessage + "; should be " + toString(target ) + ", was " + toString(source));
316 break;
317 }
318 }
319 }
320 if (!anyDiffer) {
321 testPassed(successMessage);
322 }
323 };
324
325 function setupBuffers(tl, tr, bl, br) {
326 gl.bindBuffer(gl.ARRAY_BUFFER, quadParameters[0]);
327 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
328 1.0, 1.0, tr,
329 -1.0, 1.0, tl,
330 -1.0, -1.0, bl,
331 1.0, 1.0, tr,
332 -1.0, -1.0, bl,
333 1.0, -1.0, br]), gl.STATIC_DRAW);
334 };
335
336 // Draw 1: (no variation)
337 setupBuffers(0.0, 0.0, 0.0, 0.0);
338 wtu.drawQuad(gl);
339 expectResult([0, 0, 0, 255],
340 "Draw 1 (no variation) returned the correct data",
341 "Draw 1 (no variation) returned incorrect data");
342
343 // Draw 2: (variation in x)
344 setupBuffers(1.0, 0.0, 1.0, 0.0);
345 wtu.drawQuad(gl);
346 expectResult([5, 0, 5, 255],
347 "Draw 2 (variation in x) returned the correct data",
348 "Draw 2 (variation in x) returned incorrect data");
349
350 // Draw 3: (variation in y)
351 setupBuffers(1.0, 1.0, 0.0, 0.0);
352 wtu.drawQuad(gl);
353 expectResult([0, 5, 5, 255],
354 "Draw 3 (variation in y) returned the correct data",
355 "Draw 3 (variation in y) returned incorrect data");
356
357 // Draw 4: (variation in x & y)
358 setupBuffers(1.0, 0.5, 0.5, 0.0);
359 wtu.drawQuad(gl);
360 expectResult([3, 3, 5, 255],
361 "Draw 4 (variation in x & y) returned the correct data",
362 "Draw 4 (variation in x & y) returned incorrect data");
363
364 }
365
366 function runUniqueObjectTest()
367 {
368 debug("Testing that getExtension() returns the same object each time");
369 gl.getExtension("OES_standard_derivatives").myProperty = 2;
370 gc();
371 shouldBe('gl.getExtension("OES_standard_derivatives").myProperty', '2');
372 }
373
374 debug("");
375 successfullyParsed = true;
376 </script>
377 <script src="../../resources/js-test-post.js"></script>
378
379 </body>
380 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698