PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/conformance-suites/1.0.0/conformance/glsl-conformance.html

https://github.com/gabadie/WebGL
HTML | 722 lines | 702 code | 15 blank | 5 comment | 0 complexity | b81bf816fa2de2d0d68d49893ab308a3 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <!--
  2. Copyright (c) 2009 The Chromium Authors. All rights reserved.
  3. Use of this source code is governed by a BSD-style license that can be
  4. found in the LICENSE file.
  5. -->
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  7. "http://www.w3.org/TR/html4/loose.dtd">
  8. <html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  11. <title>WebGL GLSL Conformance Tests</title>
  12. <link rel="stylesheet" href="../resources/js-test-style.css"/>
  13. <script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
  14. <script src="../resources/js-test-pre.js"></script>
  15. <script src="resources/webgl-test-utils.js"></script>
  16. </head>
  17. <body>
  18. <div id="description"></div>
  19. <div id="console"></div>
  20. <script id="vshader" type="text/something-not-javascript">
  21. attribute vec4 vPosition;
  22. void main()
  23. {
  24. gl_Position = vPosition;
  25. }
  26. </script>
  27. <script id="fshader" type="text/something-not-javascript">
  28. precision mediump float;
  29. void main()
  30. {
  31. gl_FragColor = vec4(1.0,0.0,0.0,1.0);
  32. }
  33. </script>
  34. <script id="fshaderWithPrecision" type="text/something-not-javascript">
  35. void main()
  36. {
  37. gl_FragColor = mediump vec4(1.0,0.0,0.0,1.0);
  38. }
  39. </script>
  40. <script id="vshaderWithDefaultPrecision" type="text/something-not-javascript">
  41. precision mediump float;
  42. attribute vec4 vPosition;
  43. void main()
  44. {
  45. gl_Position = vPosition;
  46. }
  47. </script>
  48. <script id="fshaderWithDefaultPrecision" type="text/something-not-javascript">
  49. precision mediump float;
  50. void main()
  51. {
  52. gl_FragColor = vec4(1.0,0.0,0.0,1.0);
  53. }
  54. </script>
  55. <script id="fshaderWithOutPrecision" type="text/something-not-javascript">
  56. uniform vec4 color;
  57. void main()
  58. {
  59. gl_FragColor = color;
  60. }
  61. </script>
  62. <script id="fshaderWithInvalidIdentifier" type="text/something-not-javascript">
  63. precision mediump float;
  64. uniform float gl_foo;
  65. void main()
  66. {
  67. gl_FragColor = vec4(gl_foo,0.0,0.0,1.0);
  68. }
  69. </script>
  70. <script id="fshaderWithGL_ESeq1" type="text/something-not-javascript">
  71. #if GL_ES == 1
  72. precision mediump float;
  73. void main()
  74. {
  75. gl_FragColor = vec4(0.0,0.0,0.0,1.0);
  76. }
  77. #else
  78. foo
  79. #endif
  80. </script>
  81. <script id="fshaderWithGLSLPreprocessorSymbol" type="text/something-not-javascript">
  82. #if defined(GL_ES)
  83. precision mediump float;
  84. void main()
  85. {
  86. gl_FragColor = vec4(0.0,0.0,0.0,1.0);
  87. }
  88. #else
  89. foo
  90. #endif
  91. </script>
  92. <script id="fshaderWithVERSION100PreprocessorSymbol" type="text/something-not-javascript">
  93. #if __VERSION__ == 100
  94. precision mediump float;
  95. void main()
  96. {
  97. gl_FragColor = vec4(0.0,0.0,0.0,1.0);
  98. }
  99. #else
  100. foo
  101. #endif
  102. </script>
  103. <script id="fshaderWithUndefinedPreprocessorSymbol" type="text/something-not-javascript">
  104. #if UNDEFINED_FOO
  105. // according to ES GLSL spec 3.4 undefined symbols should fail.
  106. #else
  107. precision mediump float;
  108. void main()
  109. {
  110. gl_FragColor = vec4(0.0,0.0,0.0,1.0);
  111. }
  112. #endif
  113. </script>
  114. <script id="fshaderWithFragDepth" type="text/something-not-javascript">
  115. precision mediump float;
  116. void main()
  117. {
  118. gl_FragColor = vec4(0.0,0.0,0.0,1.0);
  119. gl_FragDepth = 1.0;
  120. }
  121. </script>
  122. <script id="vshaderWithClipVertex" type="text/something-not-javascript">
  123. attribute vec4 vPosition;
  124. void main()
  125. {
  126. gl_Position = vPosition;
  127. gl_ClipVertex = vPosition;
  128. }
  129. </script>
  130. <script id="fshaderWith__Define" type="text/something-not-javascript">
  131. #define __foo 1
  132. precision mediump float;
  133. void main()
  134. {
  135. gl_FragColor = vec4(0.0,0.0,0.0,1.0);
  136. }
  137. </script>
  138. <script id="fshaderWithGL_Define" type="text/something-not-javascript">
  139. #define GL_FOO 1
  140. precision mediump float;
  141. void main()
  142. {
  143. gl_FragColor = vec4(0.0,0.0,0.0,1.0);
  144. }
  145. </script>
  146. <script id="fshaderWithDefineLineContinuation" type="text/something-not-javascript">
  147. #define foo this \
  148. is a test
  149. precision mediump float;
  150. void main()
  151. {
  152. gl_FragColor = vec4(0.0,0.0,0.0,1.0);
  153. }
  154. </script>
  155. <script id="vshaderWithgl_Color" type="text/something-not-javascript">
  156. attribute vec4 vPosition;
  157. void main()
  158. {
  159. gl_Position = gl_Color;
  160. }
  161. </script>
  162. <script id="vshaderWithgl_ProjectionMatrix" type="text/something-not-javascript">
  163. attribute vec4 vPosition;
  164. void main()
  165. {
  166. gl_Position = vPosition * gl_ProjectionMatrix;
  167. }
  168. </script>
  169. <script id="vshaderWithAttributeArray" type="text/something-not-javascript">
  170. attribute vec4 vPosition[2];
  171. void main()
  172. {
  173. gl_Position = vPosition[0] + vPosition[1];
  174. }
  175. </script>
  176. <script id="vshaderWithwebgl_" type="text/something-not-javascript">
  177. attribute vec4 webgl_vPosition;
  178. void main()
  179. {
  180. gl_Position = webgl_vPosition;
  181. }
  182. </script>
  183. <script id="vshaderWith_webgl_" type="text/something-not-javascript">
  184. attribute vec4 _webgl_vPosition;
  185. void main()
  186. {
  187. gl_Position = _webgl_vPosition;
  188. }
  189. </script>
  190. <script id="vshaderWithImplicitVec3Cast" type="text/something-not-javascript">
  191. attribute vec4 vPosition;
  192. void main()
  193. {
  194. highp vec3 k = vec3(1, 2, 3);
  195. gl_Position = k;
  196. }
  197. </script>
  198. <script id="vshaderWithExplicitIntCast" type="text/something-not-javascript">
  199. attribute vec4 vPosition;
  200. void main()
  201. {
  202. int k = 123;
  203. gl_Position = vec4(vPosition.x, vPosition.y, vPosition.z, float(k));
  204. }
  205. </script>
  206. <script id="vshaderWithVersion130" type="text/something-not-javascript">
  207. #version 130
  208. attribute vec4 vPosition;
  209. void main()
  210. {
  211. gl_Position = vPosition;
  212. }
  213. </script>
  214. <script id="vshaderWithVersion120" type="text/something-not-javascript">
  215. #version 120
  216. attribute vec4 vPosition;
  217. void main()
  218. {
  219. gl_Position = vPosition;
  220. }
  221. </script>
  222. <script id="vshaderWithVersion100" type="text/something-not-javascript">
  223. #version 100
  224. attribute vec4 vPosition;
  225. void main()
  226. {
  227. gl_Position = vPosition;
  228. }
  229. </script>
  230. <script id="vshaderWithLineDirective" type="text/something-not-javascript">
  231. #line 123
  232. foo
  233. </script>
  234. <script id="vshaderWith__FILE__" type="text/something-not-javascript">
  235. __FILE__
  236. </script>
  237. <script id="vshaderWithIncludeDirective" type="text/something-not-javascript">
  238. // Sadly I can not force the current path so this could fail beacuse include.vs
  239. // does not exist, not because #include is disallowed.
  240. #include "include.vs"
  241. attribute vec4 vPosition;
  242. void main()
  243. {
  244. gl_Position = vPosition;
  245. }
  246. </script>
  247. <script id="fshaderWithdFdx" type="text/something-not-javascript">
  248. #extension GL_OES_standard_derivatives:enable
  249. precision mediump float;
  250. void main()
  251. {
  252. gl_FragColor = vec4(dFdx(0.5),0.0,0.0,1.0);
  253. }
  254. </script>
  255. <script id="fshaderWithdFdxNoExt" type="text/something-not-javascript">
  256. precision mediump float;
  257. void main()
  258. {
  259. gl_FragColor = vec4(dFdx(0.5),0.0,0.0,1.0);
  260. }
  261. </script>
  262. <script id="fshaderWith256CharacterIdentifier" type="text/something-not-javascript">
  263. precision mediump float;
  264. uniform float a123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345;
  265. void main()
  266. {
  267. gl_FragColor = vec4(a123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345,0.0,0.0,1.0);
  268. }
  269. </script>
  270. <script id="fshaderWith257CharacterIdentifier" type="text/something-not-javascript">
  271. precision mediump float;
  272. uniform float a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456;
  273. void main()
  274. {
  275. gl_FragColor = vec4(a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456,0.0,0.0,1.0);
  276. }
  277. </script>
  278. <script id="fshaderWithLongLine" type="text/something-not-javascript">
  279. precision mediump float;
  280. uniform float fooo;
  281. #if defined(someSymbolNotDefined)
  282. #error long
  283. #endif
  284. void main()
  285. {
  286. gl_FragColor = vec4(fooo+fooo+fooo+fooo, fooo+fooo+fooo+fooo, fooo+fooo+fooo+fooo, 1.0);
  287. }
  288. </script>
  289. <script id="fshaderWithErrorDirective" type="text/something-not-javascript">
  290. #error testing123 testing123
  291. void main()
  292. {
  293. gl_FragColor = vec4(0,0,0,0);
  294. }
  295. </script>
  296. <script id="fshaderWithQuotedErrorDirective" type="text/something-not-javascript">
  297. #error "testing123 testing123" // will return INVALID_VALUE. See WebGL 6.18
  298. void main()
  299. {
  300. gl_FragColor = vec4(0,0,0,0);
  301. }
  302. </script>
  303. <script id="fshaderWithNonASCIIErrorDirective" type="text/something-not-javascript">
  304. #error これはASCIIではない // will return INVALID_VALUE. See WebGL 6.18
  305. void main()
  306. {
  307. gl_FragColor = vec4(0,0,0,0);
  308. }
  309. </script>
  310. <canvas id="canvas" width="2" height="2"> </canvas>
  311. <script>
  312. description("This test ensures WebGL implementations allow proper GLES2 shaders compile and improper ones fail.");
  313. debug("");
  314. debug("Canvas.getContext");
  315. var wtu = WebGLTestUtils;
  316. var gl = wtu.create3DContext(document.getElementById("canvas"));
  317. if (!gl) {
  318. testFailed("context does not exist");
  319. } else {
  320. testPassed("context exists");
  321. debug("");
  322. debug("Checking various GLSL programs.");
  323. function log(msg) {
  324. if (window.console && window.console.log) {
  325. window.console.log(msg);
  326. }
  327. }
  328. var shaderInfo = [
  329. { vShaderId: 'vshader',
  330. vShaderSuccess: true,
  331. fShaderId: 'fshaderWithPrecision',
  332. fShaderSuccess: true,
  333. linkSuccess: true,
  334. passMsg: 'frament shader with precision compiled and linked'
  335. },
  336. { vShaderId: 'vshader',
  337. vShaderSuccess: true,
  338. fShaderId: 'fshaderWithDefaultPrecision',
  339. fShaderSuccess: true,
  340. linkSuccess: true,
  341. passMsg: 'fragment shader with default precision compiled and linked'
  342. },
  343. { vShaderId: 'vshaderWithDefaultPrecision',
  344. vShaderSuccess: true,
  345. fShaderId: 'fshader',
  346. fShaderSuccess: true,
  347. linkSuccess: true,
  348. passMsg: 'vertex shader with default precision compiled and linked'
  349. },
  350. { vShaderId: 'vshader',
  351. vShaderSuccess: true,
  352. fShaderId: 'fshaderWithOutPrecision',
  353. fShaderSuccess: false,
  354. linkSuccess: false,
  355. passMsg: 'fragment shader without precision should fail',
  356. },
  357. { vShaderId: 'vshader',
  358. vShaderSuccess: true,
  359. fShaderId: 'fshaderWithInvalidIdentifier',
  360. fShaderSuccess: false,
  361. linkSuccess: false,
  362. passMsg: 'fragment shader with gl_ identifier should fail',
  363. },
  364. { vShaderId: 'vshader',
  365. vShaderSuccess: true,
  366. fShaderId: 'fshaderWithGL_ESeq1',
  367. fShaderSuccess: true,
  368. linkSuccess: true,
  369. passMsg: 'fragment shader that expects GL_ES == 1 should succeed',
  370. },
  371. { vShaderId: 'vshader',
  372. vShaderSuccess: true,
  373. fShaderId: 'fshaderWithGLSLPreprocessorSymbol',
  374. fShaderSuccess: true,
  375. linkSuccess: true,
  376. passMsg: 'fragment shader that uses GL_ES preprocessor symbol should succeed',
  377. },
  378. { vShaderId: 'vshader',
  379. vShaderSuccess: true,
  380. fShaderId: 'fshaderWithVERSION100PreprocessorSymbol',
  381. fShaderSuccess: true,
  382. linkSuccess: true,
  383. passMsg: 'fragment shader that uses __VERSION__==100 should succeed',
  384. },
  385. { vShaderId: 'vshader',
  386. vShaderSuccess: true,
  387. fShaderId: 'fshaderWithUndefinedPreprocessorSymbol',
  388. fShaderSuccess: false,
  389. linkSuccess: false,
  390. passMsg: 'fragment shader undefined preprocessor symbol should fail (3.4)',
  391. },
  392. { vShaderId: 'vshader',
  393. vShaderSuccess: true,
  394. fShaderId: 'fshaderWithFragDepth',
  395. fShaderSuccess: false,
  396. linkSuccess: false,
  397. passMsg: 'fragment shader that uses gl_FragDepth should fail',
  398. },
  399. { vShaderId: 'vshader',
  400. vShaderSuccess: true,
  401. fShaderId: 'fshaderWithdFdx',
  402. fShaderSuccess: false,
  403. linkSuccess: false,
  404. passMsg: 'fragment shader that uses dFdx should fail',
  405. },
  406. { vShaderId: 'vshader',
  407. vShaderSuccess: true,
  408. fShaderId: 'fshaderWithdFdxNoExt',
  409. fShaderSuccess: false,
  410. linkSuccess: false,
  411. passMsg: 'fragment shader that uses dFdx without #extension should fail',
  412. },
  413. { vShaderId: 'vshaderWithClipVertex',
  414. vShaderSuccess: false,
  415. fShaderId: 'fshader',
  416. fShaderSuccess: true,
  417. linkSuccess: false,
  418. passMsg: 'vertex shader that uses gl_ClipVertex should fail',
  419. },
  420. //{ vShaderId: 'vshader',
  421. // vShaderSuccess: true,
  422. // fShaderId: 'fshaderWith__Define',
  423. // fShaderSuccess: false,
  424. // linkSuccess: false,
  425. // passMsg: 'fragment shader that uses __ define should fail',
  426. //},
  427. //{ vShaderId: 'vshader',
  428. // vShaderSuccess: true,
  429. // fShaderId: 'fshaderWithGL_Define',
  430. // fShaderSuccess: false,
  431. // linkSuccess: false,
  432. // passMsg: 'fragment shader that uses GL_ define should fail',
  433. //},
  434. { vShaderId: 'vshader',
  435. vShaderSuccess: true,
  436. fShaderId: 'fshaderWithDefineLineContinuation',
  437. fShaderSuccess: false,
  438. linkSuccess: false,
  439. passMsg: 'fragment shader that uses has line continuation macro should fail',
  440. },
  441. { vShaderId: 'vshaderWithgl_Color',
  442. vShaderSuccess: false,
  443. fShaderId: 'fshader',
  444. fShaderSuccess: true,
  445. linkSuccess: false,
  446. passMsg: 'vertex shader that uses gl_Color should fail',
  447. },
  448. { vShaderId: 'vshaderWithgl_ProjectionMatrix',
  449. vShaderSuccess: false,
  450. fShaderId: 'fshader',
  451. fShaderSuccess: true,
  452. linkSuccess: false,
  453. passMsg: 'vertex shader that uses gl_ProjectionMatrix should fail',
  454. },
  455. { vShaderId: 'vshaderWithAttributeArray',
  456. vShaderSuccess: false,
  457. fShaderId: 'fshader',
  458. fShaderSuccess: true,
  459. linkSuccess: false,
  460. passMsg: 'vertex shader that uses attribute array should fail as per GLSL page 110, appendix A, section 5',
  461. },
  462. { vShaderId: 'vshaderWithwebgl_',
  463. vShaderSuccess: false,
  464. fShaderId: 'fshader',
  465. fShaderSuccess: true,
  466. linkSuccess: false,
  467. passMsg: 'vertex shader that uses _webgl identifier should fail',
  468. },
  469. { vShaderId: 'vshaderWith_webgl_',
  470. vShaderSuccess: false,
  471. fShaderId: 'fshader',
  472. fShaderSuccess: true,
  473. linkSuccess: false,
  474. passMsg: 'vertex shader that uses _webgl_ identifier should fail',
  475. },
  476. { vShaderId: 'vshaderWithExplicitIntCast',
  477. vShaderSuccess: true,
  478. fShaderId: 'fshader',
  479. fShaderSuccess: true,
  480. linkSuccess: true,
  481. passMsg: 'vertex shader that explicit int to float cast should succeed',
  482. },
  483. { vShaderId: 'vshaderWithImplicitVec3Cast',
  484. vShaderSuccess: false,
  485. fShaderId: 'fshader',
  486. fShaderSuccess: true,
  487. linkSuccess: false,
  488. passMsg: 'vertex shader that implicit vec3 to vec4 cast should fail',
  489. },
  490. { vShaderId: 'vshaderWithVersion130',
  491. vShaderSuccess: false,
  492. fShaderId: 'fshader',
  493. fShaderSuccess: true,
  494. linkSuccess: false,
  495. passMsg: 'vertex shader uses the #version not 100 directive should fail',
  496. },
  497. { vShaderId: 'vshaderWithVersion120',
  498. vShaderSuccess: false,
  499. fShaderId: 'fshader',
  500. fShaderSuccess: true,
  501. linkSuccess: false,
  502. passMsg: 'vertex shader uses the #version not 100 directive should fail',
  503. },
  504. { vShaderId: 'vshaderWithVersion100',
  505. vShaderSuccess: true,
  506. fShaderId: 'fshader',
  507. fShaderSuccess: true,
  508. linkSuccess: true,
  509. passMsg: 'vertex shader uses the #version 100 directive should succeed',
  510. },
  511. { vShaderId: 'vshaderWithLineDirective',
  512. vShaderSuccess: false,
  513. vShaderTest: (function() { return wtu.getLastError().indexOf("124") >= 0; }),
  514. fShaderId: 'fshader',
  515. fShaderSuccess: true,
  516. linkSuccess: false,
  517. passMsg: 'vertex shader uses #line directive should report correct line',
  518. },
  519. { vShaderId: 'vshaderWithIncludeDirective',
  520. vShaderSuccess: false,
  521. fShaderId: 'fshader',
  522. fShaderSuccess: true,
  523. linkSuccess: false,
  524. passMsg: 'vertex shader uses #include should fail',
  525. },
  526. //{ vShaderId: 'vshader',
  527. // vShaderSuccess: true,
  528. // fShaderId: 'fshaderWith257CharacterIdentifier',
  529. // fShaderSuccess: false,
  530. // linkSuccess: false,
  531. // passMsg: 'shader that uses 257 character identifier should fail',
  532. //},
  533. { vShaderId: 'vshader',
  534. vShaderSuccess: true,
  535. fShaderId: 'fshaderWith256CharacterIdentifier',
  536. fShaderSuccess: true,
  537. linkSuccess: true,
  538. passMsg: 'shader that uses 256 character identifier should succeed',
  539. },
  540. { vShaderId: 'vshader',
  541. vShaderSuccess: true,
  542. fShaderId: 'fshaderWithLongLine',
  543. fShaderSuccess: true,
  544. fShaderPrep: function(str) {
  545. function expand(str, re, replacement, count) {
  546. for (var ii = 0; ii < count; ++ii) {
  547. str = str.replace(re, replacement);
  548. }
  549. return str;
  550. }
  551. str = expand(str, new RegExp(" ", 'g'), " ", 12);
  552. str = expand(str, new RegExp("0", 'g'), "00", 8);
  553. str = expand(str, new RegExp("fooo", 'g'), "fooofooo", 6);
  554. str = expand(str, new RegExp("long", 'g'), "longlong", 6);
  555. //debug("len:" + str.length);
  556. //debug(str);
  557. return str;
  558. },
  559. linkSuccess: true,
  560. passMsg: 'shader that uses long lines should succeed',
  561. },
  562. { vShaderId: 'vshader',
  563. vShaderSuccess: true,
  564. fShaderId: 'fshaderWithErrorDirective',
  565. fShaderSuccess: false,
  566. fShaderTest: (function() {
  567. return wtu.getLastError().indexOf("testing123 testing123") >= 0; }),
  568. linkSuccess: false,
  569. passMsg: "error directive returns error user's error message",
  570. },
  571. { vShaderId: 'vshader',
  572. vShaderSuccess: true,
  573. fShaderId: 'fshaderWithQuotedErrorDirective',
  574. fShaderSuccess: false,
  575. linkSuccess: false,
  576. passMsg: "error directive using quotes fails",
  577. },
  578. { vShaderId: 'vshader',
  579. vShaderSuccess: true,
  580. fShaderId: 'fshaderWithNonASCIIErrorDirective',
  581. fShaderSuccess: false,
  582. linkSuccess: false,
  583. passMsg: "error directive using characters outside of allowed set fails",
  584. }
  585. ];
  586. // Read in all the shader source.
  587. for (var ii = 0; ii < shaderInfo.length; ++ii) {
  588. var si = shaderInfo[ii];
  589. si.vShaderSource = document.getElementById(si.vShaderId).text;
  590. si.fShaderSource = document.getElementById(si.fShaderId).text;
  591. }
  592. // Add more tests from external file
  593. var simpleVertShader = document.getElementById('vshader').text;
  594. var simpleFragShader = document.getElementById('fshader').text;
  595. function addExternalShaders(filename, passMsg) {
  596. var files = wtu.readFileList(filename);
  597. for (var ii = 0; ii < files.length; ++ii) {
  598. var file = files[ii];
  599. var shaderSource = wtu.readFile(file);
  600. var firstLine = shaderSource.split("\n")[0];
  601. var success = undefined;
  602. if (wtu.endsWith(firstLine, " fail") ||
  603. wtu.endsWith(firstLine, " fail.")) {
  604. success = false;
  605. } else if (wtu.endsWith(firstLine, " succeed") ||
  606. wtu.endsWith(firstLine, " succeed.")) {
  607. success = true;
  608. }
  609. if (success === undefined) {
  610. testFailed("bad first line in " + file);
  611. continue;
  612. }
  613. if (!wtu.startsWith(firstLine, "// ")) {
  614. testFailed("bad first line in " + file);
  615. continue;
  616. }
  617. var passMsg = firstLine.substr(3);
  618. if (wtu.endsWith(file, ".vert")) {
  619. shaderInfo.push({
  620. vShaderId: file,
  621. vShaderSource: shaderSource,
  622. vShaderSuccess: success,
  623. fShaderId: 'fshader',
  624. fShaderSource: simpleFragShader,
  625. fShaderSuccess: true,
  626. linkSuccess: success,
  627. passMsg: passMsg,
  628. });
  629. } else if (wtu.endsWith(file, ".frag")) {
  630. shaderInfo.push({
  631. vShaderId: 'vshader',
  632. vShaderSource: simpleVertShader,
  633. vShaderSuccess: true,
  634. fShaderId: file,
  635. fShaderSource: shaderSource,
  636. fShaderSuccess: success,
  637. linkSuccess: success,
  638. passMsg: passMsg,
  639. });
  640. }
  641. }
  642. }
  643. addExternalShaders('shaders/00_shaders.txt');
  644. for (var ii = 0; ii < shaderInfo.length; ++ii) {
  645. var info = shaderInfo[ii];
  646. var passMsg = '[' + info.vShaderId + '/' + info.fShaderId + ']: ' +
  647. info.passMsg
  648. log(passMsg);
  649. //debug(info.fShaderId);
  650. var vSource = info.vShaderPrep ? info.vShaderPrep(info.vShaderSource) :
  651. info.vShaderSource;
  652. var vShader = wtu.loadShader(gl, vSource, gl.VERTEX_SHADER);
  653. if (info.vShaderTest) {
  654. if (!info.vShaderTest(vShader)) {
  655. testFailed(passMsg);
  656. continue;
  657. }
  658. }
  659. if ((vShader != null) != info.vShaderSuccess) {
  660. testFailed(passMsg);
  661. continue;
  662. }
  663. var fSource = info.fShaderPrep ? info.fShaderPrep(info.fShaderSource) :
  664. info.fShaderSource;
  665. var fShader = wtu.loadShader(gl, fSource, gl.FRAGMENT_SHADER);
  666. if (info.fShaderTest) {
  667. if (!info.fShaderTest(fShader)) {
  668. testFailed(passMsg);
  669. continue;
  670. }
  671. }
  672. //debug(fShader == null ? "fail" : "succeed");
  673. if ((fShader != null) != info.fShaderSuccess) {
  674. testFailed(passMsg);
  675. continue;
  676. }
  677. if (vShader && fShader) {
  678. var program = gl.createProgram();
  679. gl.attachShader(program, vShader);
  680. gl.attachShader(program, fShader);
  681. gl.linkProgram(program);
  682. var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
  683. if (!linked) {
  684. var error = gl.getProgramInfoLog(program);
  685. log("*** Error linking program '"+program+"':"+error);
  686. }
  687. if (linked != info.linkSuccess) {
  688. testFailed(passMsg);
  689. continue;
  690. }
  691. } else {
  692. if (info.linkSuccess) {
  693. testFailed(passMsg);
  694. continue;
  695. }
  696. }
  697. testPassed(passMsg);
  698. }
  699. }
  700. debug("");
  701. successfullyParsed = true;
  702. </script>
  703. <script src="../resources/js-test-post.js"></script>
  704. <script>
  705. </script>
  706. </body>
  707. </html>