1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
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>
12 <div id=
"description"></div>
13 <div id=
"console"></div>
14 <script id=
"vshader" type=
"text/something-not-javascript">
15 attribute vec4 vPosition;
18 gl_Position = vPosition;
21 <script id=
"fshader" type=
"text/something-not-javascript">
22 precision mediump float;
25 gl_FragColor = vec4(
1.0,
0.0,
0.0,
1.0);
28 <script id=
"fshaderWithPrecision" type=
"text/something-not-javascript">
31 mediump vec4 color = vec4(
1.0,
0.0,
0.0,
1.0);
35 <script id=
"vshaderWithDefaultPrecision" type=
"text/something-not-javascript">
36 precision mediump float;
37 attribute vec4 vPosition;
40 gl_Position = vPosition;
43 <script id=
"fshaderWithDefaultPrecision" type=
"text/something-not-javascript">
44 precision mediump float;
47 gl_FragColor = vec4(
1.0,
0.0,
0.0,
1.0);
50 <script id=
"fshaderWithOutPrecision" type=
"text/something-not-javascript">
57 <script id=
"fshaderWithInvalidIdentifier" type=
"text/something-not-javascript">
58 precision mediump float;
62 gl_FragColor = vec4(gl_foo,
0.0,
0.0,
1.0);
65 <script id=
"fshaderWithGL_ESeq1" type=
"text/something-not-javascript">
67 precision mediump float;
70 gl_FragColor = vec4(
0.0,
0.0,
0.0,
1.0);
76 <script id=
"fshaderWithGLSLPreprocessorSymbol" type=
"text/something-not-javascript">
78 precision mediump float;
81 gl_FragColor = vec4(
0.0,
0.0,
0.0,
1.0);
87 <script id=
"fshaderWithVERSION100PreprocessorSymbol" type=
"text/something-not-javascript">
88 #if __VERSION__ ==
100
89 precision mediump float;
92 gl_FragColor = vec4(
0.0,
0.0,
0.0,
1.0);
98 <script id=
"fshaderWithFragDepth" type=
"text/something-not-javascript">
99 precision mediump float;
102 gl_FragColor = vec4(
0.0,
0.0,
0.0,
1.0);
106 <script id=
"vshaderWithClipVertex" type=
"text/something-not-javascript">
107 attribute vec4 vPosition;
110 gl_Position = vPosition;
111 gl_ClipVertex = vPosition;
114 <script id=
"fshaderWith__Define" type=
"text/something-not-javascript">
116 precision mediump float;
119 gl_FragColor = vec4(
0.0,
0.0,
0.0,
1.0);
122 <script id=
"fshaderWithGL_Define" type=
"text/something-not-javascript">
124 precision mediump float;
127 gl_FragColor = vec4(
0.0,
0.0,
0.0,
1.0);
130 <script id=
"fshaderWithDefineLineContinuation" type=
"text/something-not-javascript">
133 precision mediump float;
136 gl_FragColor = vec4(
0.0,
0.0,
0.0,
1.0);
139 <script id=
"vshaderWithgl_Color" type=
"text/something-not-javascript">
140 attribute vec4 vPosition;
143 gl_Position = gl_Color;
146 <script id=
"vshaderWithgl_ProjectionMatrix" type=
"text/something-not-javascript">
147 attribute vec4 vPosition;
150 gl_Position = vPosition * gl_ProjectionMatrix;
153 <script id=
"vshaderWithAttributeArray" type=
"text/something-not-javascript">
154 attribute vec4 vPosition[
2];
157 gl_Position = vPosition[
0] + vPosition[
1];
160 <script id=
"vshaderWithwebgl_" type=
"text/something-not-javascript">
161 attribute vec4 webgl_vPosition;
164 gl_Position = webgl_vPosition;
167 <script id=
"vshaderWith_webgl_" type=
"text/something-not-javascript">
168 attribute vec4 _webgl_vPosition;
171 gl_Position = _webgl_vPosition;
174 <script id=
"vshaderWithImplicitVec3Cast" type=
"text/something-not-javascript">
175 attribute vec4 vPosition;
178 highp vec3 k = vec3(
1,
2,
3);
182 <script id=
"vshaderWithExplicitIntCast" type=
"text/something-not-javascript">
183 attribute vec4 vPosition;
187 gl_Position = vec4(vPosition.x, vPosition.y, vPosition.z, float(k));
190 <script id=
"vshaderWithVersion130" type=
"text/something-not-javascript">
192 attribute vec4 vPosition;
195 gl_Position = vPosition;
198 <script id=
"vshaderWithVersion120" type=
"text/something-not-javascript">
200 attribute vec4 vPosition;
203 gl_Position = vPosition;
206 <script id=
"vshaderWithVersion100" type=
"text/something-not-javascript">
208 attribute vec4 vPosition;
211 gl_Position = vPosition;
214 <script id=
"vshaderWith__FILE__" type=
"text/something-not-javascript">
217 <canvas id=
"canvas" width=
"2" height=
"2"> </canvas>
219 description("This test ensures WebGL implementations allow proper GLES2 shaders compile and improper ones fail.");
222 debug("Canvas.getContext");
224 if (window
.internals
)
225 window
.internals
.settings
.setWebGLErrorsToConsoleEnabled(false);
227 var wtu
= WebGLTestUtils
;
229 var gl
= wtu
.create3DContext(document
.getElementById("canvas"));
231 testFailed("context does not exist");
233 testPassed("context exists");
236 debug("Checking various GLSL programs.");
239 if (window
.console
&& window
.console
.log
) {
240 //window.console.log(msg);
245 { vShaderId
: 'vshader',
246 vShaderSuccess
: true,
247 fShaderId
: 'fshaderWithPrecision',
248 fShaderSuccess
: true,
250 passMsg
: 'frament shader with precision compiled and linked'
252 { vShaderId
: 'vshader',
253 vShaderSuccess
: true,
254 fShaderId
: 'fshaderWithDefaultPrecision',
255 fShaderSuccess
: true,
257 passMsg
: 'fragment shader with default precision compiled and linked'
259 { vShaderId
: 'vshaderWithDefaultPrecision',
260 vShaderSuccess
: true,
261 fShaderId
: 'fshader',
262 fShaderSuccess
: true,
264 passMsg
: 'vertex shader with default precision compiled and linked'
266 { vShaderId
: 'vshader',
267 vShaderSuccess
: true,
268 fShaderId
: 'fshaderWithOutPrecision',
269 fShaderSuccess
: false,
271 passMsg
: 'fragment shader without precision should fail',
273 { vShaderId
: 'vshader',
274 vShaderSuccess
: true,
275 fShaderId
: 'fshaderWithInvalidIdentifier',
276 fShaderSuccess
: false,
278 passMsg
: 'fragment shader with gl_ identifier should fail',
280 { vShaderId
: 'vshader',
281 vShaderSuccess
: true,
282 fShaderId
: 'fshaderWithGL_ESeq1',
283 fShaderSuccess
: true,
285 passMsg
: 'fragment shader that expects GL_ES == 1 should succeed',
287 { vShaderId
: 'vshader',
288 vShaderSuccess
: true,
289 fShaderId
: 'fshaderWithGLSLPreprocessorSymbol',
290 fShaderSuccess
: true,
292 passMsg
: 'fragment shader that uses GL_ES preprocessor symbol should succeed',
294 { vShaderId
: 'vshader',
295 vShaderSuccess
: true,
296 fShaderId
: 'fshaderWithVERSION100PreprocessorSymbol',
297 fShaderSuccess
: true,
299 passMsg
: 'fragment shader that uses __VERSION__==100 should succeed',
301 { vShaderId
: 'vshader',
302 vShaderSuccess
: true,
303 fShaderId
: 'fshaderWithFragDepth',
304 fShaderSuccess
: false,
306 passMsg
: 'fragment shader that uses gl_FragDepth should fail',
308 { vShaderId
: 'vshaderWithClipVertex',
309 vShaderSuccess
: false,
310 fShaderId
: 'fshader',
311 fShaderSuccess
: true,
313 passMsg
: 'vertex shader that uses gl_ClipVertex should fail',
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',
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',
329 { vShaderId
: 'vshader',
330 vShaderSuccess
: true,
331 fShaderId
: 'fshaderWithDefineLineContinuation',
332 fShaderSuccess
: false,
334 passMsg
: 'fragment shader that uses has line continuation macro should fail',
336 { vShaderId
: 'vshaderWithgl_Color',
337 vShaderSuccess
: false,
338 fShaderId
: 'fshader',
339 fShaderSuccess
: true,
341 passMsg
: 'vertex shader that uses gl_Color should fail',
343 { vShaderId
: 'vshaderWithgl_ProjectionMatrix',
344 vShaderSuccess
: false,
345 fShaderId
: 'fshader',
346 fShaderSuccess
: true,
348 passMsg
: 'vertex shader that uses gl_ProjectionMatrix should fail',
350 { vShaderId
: 'vshaderWithAttributeArray',
351 vShaderSuccess
: false,
352 fShaderId
: 'fshader',
353 fShaderSuccess
: true,
355 passMsg
: 'vertex shader that uses attribute array should fail as per GLSL page 110, appendix A, section 5',
357 { vShaderId
: 'vshaderWithwebgl_',
358 vShaderSuccess
: false,
359 fShaderId
: 'fshader',
360 fShaderSuccess
: true,
362 passMsg
: 'vertex shader that uses _webgl identifier should fail',
364 { vShaderId
: 'vshaderWith_webgl_',
365 vShaderSuccess
: false,
366 fShaderId
: 'fshader',
367 fShaderSuccess
: true,
369 passMsg
: 'vertex shader that uses _webgl_ identifier should fail',
371 { vShaderId
: 'vshaderWithExplicitIntCast',
372 vShaderSuccess
: true,
373 fShaderId
: 'fshader',
374 fShaderSuccess
: true,
376 passMsg
: 'vertex shader that explicit int to float cast should succeed',
378 { vShaderId
: 'vshaderWithImplicitVec3Cast',
379 vShaderSuccess
: false,
380 fShaderId
: 'fshader',
381 fShaderSuccess
: true,
383 passMsg
: 'vertex shader that implicit vec3 to vec4 cast should fail',
385 { vShaderId
: 'vshaderWithVersion130',
386 vShaderSuccess
: false,
387 fShaderId
: 'fshader',
388 fShaderSuccess
: true,
390 passMsg
: 'vertex shader uses the #version not 100 directive should fail',
392 { vShaderId
: 'vshaderWithVersion120',
393 vShaderSuccess
: false,
394 fShaderId
: 'fshader',
395 fShaderSuccess
: true,
397 passMsg
: 'vertex shader uses the #version not 100 directive should fail',
399 { vShaderId
: 'vshaderWithVersion100',
400 vShaderSuccess
: true,
401 fShaderId
: 'fshader',
402 fShaderSuccess
: true,
404 passMsg
: 'vertex shader uses the #version 100 directive should succeed',
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
;
415 // Add more tests from external file
416 var simpleVertShader
= document
.getElementById('vshader').text
;
417 var simpleFragShader
= document
.getElementById('fshader').text
;
419 addExternalShaders('shaders/00_shaders.txt');
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.")) {
431 } else if (wtu
.endsWith(firstLine
, " succeed") ||
432 wtu
.endsWith(firstLine
, " succeed.")) {
435 if (success
=== undefined) {
436 testFailed("bad first line in " + file
);
439 if (!wtu
.startsWith(firstLine
, "// ")) {
440 testFailed("bad first line in " + file
);
443 var passMsg
= firstLine
.substr(3);
444 if (wtu
.endsWith(file
, ".vert")) {
447 vShaderSource
: shaderSource
,
448 vShaderSuccess
: success
,
449 fShaderId
: 'fshader',
450 fShaderSource
: simpleFragShader
,
451 fShaderSuccess
: true,
452 linkSuccess
: success
,
455 } else if (wtu
.endsWith(file
, ".frag")) {
457 vShaderId
: 'vshader',
458 vShaderSource
: simpleVertShader
,
459 vShaderSuccess
: true,
461 fShaderSource
: shaderSource
,
462 fShaderSuccess
: success
,
463 linkSuccess
: success
,
470 for (var ii
= 0; ii
< shaderInfo
.length
; ++ii
) {
471 var info
= shaderInfo
[ii
];
472 var passMsg
= '[' + info
.vShaderId
+ '/' + info
.fShaderId
+ ']: ' +
475 //debug(info.fShaderId);
476 var vShader
= wtu
.loadShader(gl
, info
.vShaderSource
, gl
.VERTEX_SHADER
);
477 if (info
.vShaderTest
) {
478 if (!info
.vShaderTest(vShader
)) {
483 if ((vShader
!= null) != info
.vShaderSuccess
) {
487 var fShader
= wtu
.loadShader(gl
, info
.fShaderSource
, gl
.FRAGMENT_SHADER
);
488 //debug(fShader == null ? "fail" : "succeed");
489 if ((fShader
!= null) != info
.fShaderSuccess
) {
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);
501 var error
= gl
.getProgramInfoLog(shader
);
502 log("*** Error linking program '"+program
+"':"+error
);
504 if (linked
!= info
.linkSuccess
) {
509 if (info
.linkSuccess
) {