OLD | NEW |
| (Empty) |
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
2 "http://www.w3.org/TR/html4/loose.dtd"> | |
3 <html> | |
4 <head> | |
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
6 <title>WebGL GLSL Conformance Tests</title> | |
7 <script src="../../../resources/js-test.js"></script> | |
8 <script src="resources/webgl-test.js"></script> | |
9 <script src="resources/webgl-test-utils.js"></script> | |
10 </head> | |
11 <body> | |
12 <div id="description"></div> | |
13 <div id="console"></div> | |
14 <script id="vshader" type="text/something-not-javascript"> | |
15 attribute vec4 vPosition; | |
16 void main() | |
17 { | |
18 gl_Position = vPosition; | |
19 } | |
20 </script> | |
21 <script id="fshader" type="text/something-not-javascript"> | |
22 precision mediump float; | |
23 void main() | |
24 { | |
25 gl_FragColor = vec4(1.0,0.0,0.0,1.0); | |
26 } | |
27 </script> | |
28 <script id="fshaderWithPrecision" type="text/something-not-javascript"> | |
29 void main() | |
30 { | |
31 mediump vec4 color = vec4(1.0,0.0,0.0,1.0); | |
32 gl_FragColor = color; | |
33 } | |
34 </script> | |
35 <script id="vshaderWithDefaultPrecision" type="text/something-not-javascript"> | |
36 precision mediump float; | |
37 attribute vec4 vPosition; | |
38 void main() | |
39 { | |
40 gl_Position = vPosition; | |
41 } | |
42 </script> | |
43 <script id="fshaderWithDefaultPrecision" type="text/something-not-javascript"> | |
44 precision mediump float; | |
45 void main() | |
46 { | |
47 gl_FragColor = vec4(1.0,0.0,0.0,1.0); | |
48 } | |
49 </script> | |
50 <script id="fshaderWithOutPrecision" type="text/something-not-javascript"> | |
51 uniform vec4 color; | |
52 void main() | |
53 { | |
54 gl_FragColor = color; | |
55 } | |
56 </script> | |
57 <script id="fshaderWithInvalidIdentifier" type="text/something-not-javascript"> | |
58 precision mediump float; | |
59 uniform float gl_foo; | |
60 void main() | |
61 { | |
62 gl_FragColor = vec4(gl_foo,0.0,0.0,1.0); | |
63 } | |
64 </script> | |
65 <script id="fshaderWithGL_ESeq1" type="text/something-not-javascript"> | |
66 #if GL_ES == 1 | |
67 precision mediump float; | |
68 void main() | |
69 { | |
70 gl_FragColor = vec4(0.0,0.0,0.0,1.0); | |
71 } | |
72 #else | |
73 foo | |
74 #endif | |
75 </script> | |
76 <script id="fshaderWithGLSLPreprocessorSymbol" type="text/something-not-javascri
pt"> | |
77 #if defined(GL_ES) | |
78 precision mediump float; | |
79 void main() | |
80 { | |
81 gl_FragColor = vec4(0.0,0.0,0.0,1.0); | |
82 } | |
83 #else | |
84 foo | |
85 #endif | |
86 </script> | |
87 <script id="fshaderWithVERSION100PreprocessorSymbol" type="text/something-not-ja
vascript"> | |
88 #if __VERSION__ == 100 | |
89 precision mediump float; | |
90 void main() | |
91 { | |
92 gl_FragColor = vec4(0.0,0.0,0.0,1.0); | |
93 } | |
94 #else | |
95 foo | |
96 #endif | |
97 </script> | |
98 <script id="fshaderWithFragDepth" type="text/something-not-javascript"> | |
99 precision mediump float; | |
100 void main() | |
101 { | |
102 gl_FragColor = vec4(0.0,0.0,0.0,1.0); | |
103 gl_FragDepth = 1.0; | |
104 } | |
105 </script> | |
106 <script id="vshaderWithClipVertex" type="text/something-not-javascript"> | |
107 attribute vec4 vPosition; | |
108 void main() | |
109 { | |
110 gl_Position = vPosition; | |
111 gl_ClipVertex = vPosition; | |
112 } | |
113 </script> | |
114 <script id="fshaderWith__Define" type="text/something-not-javascript"> | |
115 #define __foo 1 | |
116 precision mediump float; | |
117 void main() | |
118 { | |
119 gl_FragColor = vec4(0.0,0.0,0.0,1.0); | |
120 } | |
121 </script> | |
122 <script id="fshaderWithGL_Define" type="text/something-not-javascript"> | |
123 #define GL_FOO 1 | |
124 precision mediump float; | |
125 void main() | |
126 { | |
127 gl_FragColor = vec4(0.0,0.0,0.0,1.0); | |
128 } | |
129 </script> | |
130 <script id="fshaderWithDefineLineContinuation" type="text/something-not-javascri
pt"> | |
131 #define foo this \ | |
132 is a test | |
133 precision mediump float; | |
134 void main() | |
135 { | |
136 gl_FragColor = vec4(0.0,0.0,0.0,1.0); | |
137 } | |
138 </script> | |
139 <script id="vshaderWithgl_Color" type="text/something-not-javascript"> | |
140 attribute vec4 vPosition; | |
141 void main() | |
142 { | |
143 gl_Position = gl_Color; | |
144 } | |
145 </script> | |
146 <script id="vshaderWithgl_ProjectionMatrix" type="text/something-not-javascript"
> | |
147 attribute vec4 vPosition; | |
148 void main() | |
149 { | |
150 gl_Position = vPosition * gl_ProjectionMatrix; | |
151 } | |
152 </script> | |
153 <script id="vshaderWithAttributeArray" type="text/something-not-javascript"> | |
154 attribute vec4 vPosition[2]; | |
155 void main() | |
156 { | |
157 gl_Position = vPosition[0] + vPosition[1]; | |
158 } | |
159 </script> | |
160 <script id="vshaderWithwebgl_" type="text/something-not-javascript"> | |
161 attribute vec4 webgl_vPosition; | |
162 void main() | |
163 { | |
164 gl_Position = webgl_vPosition; | |
165 } | |
166 </script> | |
167 <script id="vshaderWith_webgl_" type="text/something-not-javascript"> | |
168 attribute vec4 _webgl_vPosition; | |
169 void main() | |
170 { | |
171 gl_Position = _webgl_vPosition; | |
172 } | |
173 </script> | |
174 <script id="vshaderWithImplicitVec3Cast" type="text/something-not-javascript"> | |
175 attribute vec4 vPosition; | |
176 void main() | |
177 { | |
178 highp vec3 k = vec3(1, 2, 3); | |
179 gl_Position = k; | |
180 } | |
181 </script> | |
182 <script id="vshaderWithExplicitIntCast" type="text/something-not-javascript"> | |
183 attribute vec4 vPosition; | |
184 void main() | |
185 { | |
186 int k = 123; | |
187 gl_Position = vec4(vPosition.x, vPosition.y, vPosition.z, float(k)); | |
188 } | |
189 </script> | |
190 <script id="vshaderWithVersion130" type="text/something-not-javascript"> | |
191 #version 130 | |
192 attribute vec4 vPosition; | |
193 void main() | |
194 { | |
195 gl_Position = vPosition; | |
196 } | |
197 </script> | |
198 <script id="vshaderWithVersion120" type="text/something-not-javascript"> | |
199 #version 120 | |
200 attribute vec4 vPosition; | |
201 void main() | |
202 { | |
203 gl_Position = vPosition; | |
204 } | |
205 </script> | |
206 <script id="vshaderWithVersion100" type="text/something-not-javascript"> | |
207 #version 100 | |
208 attribute vec4 vPosition; | |
209 void main() | |
210 { | |
211 gl_Position = vPosition; | |
212 } | |
213 </script> | |
214 <script id="vshaderWith__FILE__" type="text/something-not-javascript"> | |
215 __FILE__ | |
216 </script> | |
217 <canvas id="canvas" width="2" height="2"> </canvas> | |
218 <script> | |
219 description("This test ensures WebGL implementations allow proper GLES2 shaders
compile and improper ones fail."); | |
220 | |
221 debug(""); | |
222 debug("Canvas.getContext"); | |
223 | |
224 if (window.internals) | |
225 window.internals.settings.setWebGLErrorsToConsoleEnabled(false); | |
226 | |
227 var wtu = WebGLTestUtils; | |
228 wtu.loggingOff(); | |
229 var gl = wtu.create3DContext(document.getElementById("canvas")); | |
230 if (!gl) { | |
231 testFailed("context does not exist"); | |
232 } else { | |
233 testPassed("context exists"); | |
234 | |
235 debug(""); | |
236 debug("Checking various GLSL programs."); | |
237 | |
238 function log(msg) { | |
239 if (window.console && window.console.log) { | |
240 //window.console.log(msg); | |
241 } | |
242 } | |
243 | |
244 var shaderInfo = [ | |
245 { vShaderId: 'vshader', | |
246 vShaderSuccess: true, | |
247 fShaderId: 'fshaderWithPrecision', | |
248 fShaderSuccess: true, | |
249 linkSuccess: true, | |
250 passMsg: 'frament shader with precision compiled and linked' | |
251 }, | |
252 { vShaderId: 'vshader', | |
253 vShaderSuccess: true, | |
254 fShaderId: 'fshaderWithDefaultPrecision', | |
255 fShaderSuccess: true, | |
256 linkSuccess: true, | |
257 passMsg: 'fragment shader with default precision compiled and linked' | |
258 }, | |
259 { vShaderId: 'vshaderWithDefaultPrecision', | |
260 vShaderSuccess: true, | |
261 fShaderId: 'fshader', | |
262 fShaderSuccess: true, | |
263 linkSuccess: true, | |
264 passMsg: 'vertex shader with default precision compiled and linked' | |
265 }, | |
266 { vShaderId: 'vshader', | |
267 vShaderSuccess: true, | |
268 fShaderId: 'fshaderWithOutPrecision', | |
269 fShaderSuccess: false, | |
270 linkSuccess: false, | |
271 passMsg: 'fragment shader without precision should fail', | |
272 }, | |
273 { vShaderId: 'vshader', | |
274 vShaderSuccess: true, | |
275 fShaderId: 'fshaderWithInvalidIdentifier', | |
276 fShaderSuccess: false, | |
277 linkSuccess: false, | |
278 passMsg: 'fragment shader with gl_ identifier should fail', | |
279 }, | |
280 { vShaderId: 'vshader', | |
281 vShaderSuccess: true, | |
282 fShaderId: 'fshaderWithGL_ESeq1', | |
283 fShaderSuccess: true, | |
284 linkSuccess: true, | |
285 passMsg: 'fragment shader that expects GL_ES == 1 should succeed', | |
286 }, | |
287 { vShaderId: 'vshader', | |
288 vShaderSuccess: true, | |
289 fShaderId: 'fshaderWithGLSLPreprocessorSymbol', | |
290 fShaderSuccess: true, | |
291 linkSuccess: true, | |
292 passMsg: 'fragment shader that uses GL_ES preprocessor symbol should succe
ed', | |
293 }, | |
294 { vShaderId: 'vshader', | |
295 vShaderSuccess: true, | |
296 fShaderId: 'fshaderWithVERSION100PreprocessorSymbol', | |
297 fShaderSuccess: true, | |
298 linkSuccess: true, | |
299 passMsg: 'fragment shader that uses __VERSION__==100 should succeed', | |
300 }, | |
301 { vShaderId: 'vshader', | |
302 vShaderSuccess: true, | |
303 fShaderId: 'fshaderWithFragDepth', | |
304 fShaderSuccess: false, | |
305 linkSuccess: false, | |
306 passMsg: 'fragment shader that uses gl_FragDepth should fail', | |
307 }, | |
308 { vShaderId: 'vshaderWithClipVertex', | |
309 vShaderSuccess: false, | |
310 fShaderId: 'fshader', | |
311 fShaderSuccess: true, | |
312 linkSuccess: false, | |
313 passMsg: 'vertex shader that uses gl_ClipVertex should fail', | |
314 }, | |
315 //{ vShaderId: 'vshader', | |
316 // vShaderSuccess: true, | |
317 // fShaderId: 'fshaderWith__Define', | |
318 // fShaderSuccess: false, | |
319 // linkSuccess: false, | |
320 // passMsg: 'fragment shader that uses __ define should fail', | |
321 //}, | |
322 //{ vShaderId: 'vshader', | |
323 // vShaderSuccess: true, | |
324 // fShaderId: 'fshaderWithGL_Define', | |
325 // fShaderSuccess: false, | |
326 // linkSuccess: false, | |
327 // passMsg: 'fragment shader that uses GL_ define should fail', | |
328 //}, | |
329 { vShaderId: 'vshader', | |
330 vShaderSuccess: true, | |
331 fShaderId: 'fshaderWithDefineLineContinuation', | |
332 fShaderSuccess: false, | |
333 linkSuccess: false, | |
334 passMsg: 'fragment shader that uses has line continuation macro should fai
l', | |
335 }, | |
336 { vShaderId: 'vshaderWithgl_Color', | |
337 vShaderSuccess: false, | |
338 fShaderId: 'fshader', | |
339 fShaderSuccess: true, | |
340 linkSuccess: false, | |
341 passMsg: 'vertex shader that uses gl_Color should fail', | |
342 }, | |
343 { vShaderId: 'vshaderWithgl_ProjectionMatrix', | |
344 vShaderSuccess: false, | |
345 fShaderId: 'fshader', | |
346 fShaderSuccess: true, | |
347 linkSuccess: false, | |
348 passMsg: 'vertex shader that uses gl_ProjectionMatrix should fail', | |
349 }, | |
350 { vShaderId: 'vshaderWithAttributeArray', | |
351 vShaderSuccess: false, | |
352 fShaderId: 'fshader', | |
353 fShaderSuccess: true, | |
354 linkSuccess: false, | |
355 passMsg: 'vertex shader that uses attribute array should fail as per GLSL
page 110, appendix A, section 5', | |
356 }, | |
357 { vShaderId: 'vshaderWithwebgl_', | |
358 vShaderSuccess: false, | |
359 fShaderId: 'fshader', | |
360 fShaderSuccess: true, | |
361 linkSuccess: false, | |
362 passMsg: 'vertex shader that uses _webgl identifier should fail', | |
363 }, | |
364 { vShaderId: 'vshaderWith_webgl_', | |
365 vShaderSuccess: false, | |
366 fShaderId: 'fshader', | |
367 fShaderSuccess: true, | |
368 linkSuccess: false, | |
369 passMsg: 'vertex shader that uses _webgl_ identifier should fail', | |
370 }, | |
371 { vShaderId: 'vshaderWithExplicitIntCast', | |
372 vShaderSuccess: true, | |
373 fShaderId: 'fshader', | |
374 fShaderSuccess: true, | |
375 linkSuccess: true, | |
376 passMsg: 'vertex shader that explicit int to float cast should succeed', | |
377 }, | |
378 { vShaderId: 'vshaderWithImplicitVec3Cast', | |
379 vShaderSuccess: false, | |
380 fShaderId: 'fshader', | |
381 fShaderSuccess: true, | |
382 linkSuccess: false, | |
383 passMsg: 'vertex shader that implicit vec3 to vec4 cast should fail', | |
384 }, | |
385 { vShaderId: 'vshaderWithVersion130', | |
386 vShaderSuccess: false, | |
387 fShaderId: 'fshader', | |
388 fShaderSuccess: true, | |
389 linkSuccess: false, | |
390 passMsg: 'vertex shader uses the #version not 100 directive should fail', | |
391 }, | |
392 { vShaderId: 'vshaderWithVersion120', | |
393 vShaderSuccess: false, | |
394 fShaderId: 'fshader', | |
395 fShaderSuccess: true, | |
396 linkSuccess: false, | |
397 passMsg: 'vertex shader uses the #version not 100 directive should fail', | |
398 }, | |
399 { vShaderId: 'vshaderWithVersion100', | |
400 vShaderSuccess: true, | |
401 fShaderId: 'fshader', | |
402 fShaderSuccess: true, | |
403 linkSuccess: true, | |
404 passMsg: 'vertex shader uses the #version 100 directive should succeed', | |
405 }, | |
406 ]; | |
407 | |
408 // Read in all the shader source. | |
409 for (var ii = 0; ii < shaderInfo.length; ++ii) { | |
410 var si = shaderInfo[ii]; | |
411 si.vShaderSource = document.getElementById(si.vShaderId).text; | |
412 si.fShaderSource = document.getElementById(si.fShaderId).text; | |
413 } | |
414 | |
415 // Add more tests from external file | |
416 var simpleVertShader = document.getElementById('vshader').text; | |
417 var simpleFragShader = document.getElementById('fshader').text; | |
418 | |
419 addExternalShaders('shaders/00_shaders.txt'); | |
420 | |
421 function addExternalShaders(filename, passMsg) { | |
422 var files = wtu.readFileList(filename); | |
423 for (var ii = 0; ii < files.length; ++ii) { | |
424 var file = files[ii]; | |
425 var shaderSource = wtu.readFile(file); | |
426 var firstLine = shaderSource.split("\n")[0]; | |
427 var success = undefined; | |
428 if (wtu.endsWith(firstLine, " fail") || | |
429 wtu.endsWith(firstLine, " fail.")) { | |
430 success = false; | |
431 } else if (wtu.endsWith(firstLine, " succeed") || | |
432 wtu.endsWith(firstLine, " succeed.")) { | |
433 success = true; | |
434 } | |
435 if (success === undefined) { | |
436 testFailed("bad first line in " + file); | |
437 continue; | |
438 } | |
439 if (!wtu.startsWith(firstLine, "// ")) { | |
440 testFailed("bad first line in " + file); | |
441 continue; | |
442 } | |
443 var passMsg = firstLine.substr(3); | |
444 if (wtu.endsWith(file, ".vert")) { | |
445 shaderInfo.push({ | |
446 vShaderId: file, | |
447 vShaderSource: shaderSource, | |
448 vShaderSuccess: success, | |
449 fShaderId: 'fshader', | |
450 fShaderSource: simpleFragShader, | |
451 fShaderSuccess: true, | |
452 linkSuccess: success, | |
453 passMsg: passMsg, | |
454 }); | |
455 } else if (wtu.endsWith(file, ".frag")) { | |
456 shaderInfo.push({ | |
457 vShaderId: 'vshader', | |
458 vShaderSource: simpleVertShader, | |
459 vShaderSuccess: true, | |
460 fShaderId: file, | |
461 fShaderSource: shaderSource, | |
462 fShaderSuccess: success, | |
463 linkSuccess: success, | |
464 passMsg: passMsg, | |
465 }); | |
466 } | |
467 } | |
468 } | |
469 | |
470 for (var ii = 0; ii < shaderInfo.length; ++ii) { | |
471 var info = shaderInfo[ii]; | |
472 var passMsg = '[' + info.vShaderId + '/' + info.fShaderId + ']: ' + | |
473 info.passMsg | |
474 log(passMsg); | |
475 //debug(info.fShaderId); | |
476 var vShader = wtu.loadShader(gl, info.vShaderSource, gl.VERTEX_SHADER); | |
477 if (info.vShaderTest) { | |
478 if (!info.vShaderTest(vShader)) { | |
479 testFailed(passMsg); | |
480 continue; | |
481 } | |
482 } | |
483 if ((vShader != null) != info.vShaderSuccess) { | |
484 testFailed(passMsg); | |
485 continue; | |
486 } | |
487 var fShader = wtu.loadShader(gl, info.fShaderSource, gl.FRAGMENT_SHADER); | |
488 //debug(fShader == null ? "fail" : "succeed"); | |
489 if ((fShader != null) != info.fShaderSuccess) { | |
490 testFailed(passMsg); | |
491 continue; | |
492 } | |
493 | |
494 if (vShader && fShader) { | |
495 var program = gl.createProgram(); | |
496 gl.attachShader(program, vShader); | |
497 gl.attachShader(program, fShader); | |
498 gl.linkProgram(program); | |
499 var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0); | |
500 if (!linked) { | |
501 var error = gl.getProgramInfoLog(shader); | |
502 log("*** Error linking program '"+program+"':"+error); | |
503 } | |
504 if (linked != info.linkSuccess) { | |
505 testFailed(passMsg); | |
506 continue; | |
507 } | |
508 } else { | |
509 if (info.linkSuccess) { | |
510 testFailed(passMsg); | |
511 continue; | |
512 } | |
513 } | |
514 testPassed(passMsg); | |
515 } | |
516 } | |
517 | |
518 debug(""); | |
519 | |
520 </script> | |
521 | |
522 <script> | |
523 </script> | |
524 | |
525 </body> | |
526 </html> | |
OLD | NEW |