PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/sdk/tests/conformance/glsl/misc/re-compile-re-link.html

https://github.com/JunJiang/WebGL
HTML | 173 lines | 122 code | 25 blank | 26 comment | 0 complexity | 6bd3debdfaffeb5d7061f486ffd8ac16 MD5 | raw file
  1. <!--
  2. /*
  3. ** Copyright (c) 2012 The Khronos Group Inc.
  4. **
  5. ** Permission is hereby granted, free of charge, to any person obtaining a
  6. ** copy of this software and/or associated documentation files (the
  7. ** "Materials"), to deal in the Materials without restriction, including
  8. ** without limitation the rights to use, copy, modify, merge, publish,
  9. ** distribute, sublicense, and/or sell copies of the Materials, and to
  10. ** permit persons to whom the Materials are furnished to do so, subject to
  11. ** the following conditions:
  12. **
  13. ** The above copyright notice and this permission notice shall be included
  14. ** in all copies or substantial portions of the Materials.
  15. **
  16. ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19. ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  20. ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  21. ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  22. ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
  23. */
  24. -->
  25. <!DOCTYPE html>
  26. <html>
  27. <head>
  28. <meta charset="utf-8">
  29. <title>WebGL Re-Compile and Re-link Shader conformance test.</title>
  30. <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
  31. <script src="../../../resources/js-test-pre.js"></script>
  32. <script src="../../resources/webgl-test-utils.js"> </script>
  33. </head>
  34. <body>
  35. <canvas id="example" width="4" height="4" style="width: 40px; height: 30px;"></canvas>
  36. <div id="description"></div>
  37. <div id="console"></div>
  38. <script id="vshader" type="x-shader/x-vertex">
  39. attribute float column;
  40. attribute float height;
  41. uniform float position;
  42. void main() {
  43. gl_Position = vec4(mod(column - position, 1.0) * 2.0 - 1.0, height, 0, 1);
  44. }
  45. </script>
  46. <script id="fshader1" type="x-shader/x-fragment">
  47. precision mediump float;
  48. void main() {
  49. gl_FragColor = vec4(1,0,0,1);
  50. }
  51. </script>
  52. <script id="fshader2" type="x-shader/x-fragment">
  53. precision mediump float;
  54. uniform float foobar;
  55. void main() {
  56. gl_FragColor = vec4(1,0,foobar,1);
  57. }
  58. </script>
  59. <script id="vshaderB" type="not-js">
  60. attribute vec2 position;
  61. varying vec2 v_texCoord;
  62. void main() {
  63. gl_Position = vec4(position, 0, 1);
  64. v_texCoord = vec2(position * 0.5 + 0.5);
  65. }
  66. </script>
  67. <script id="fshaderB" type="not-js">
  68. precision mediump float;
  69. varying vec2 v_texCoord;
  70. uniform sampler2D tex;
  71. void main() {
  72. gl_FragColor = texture2D(tex, v_texCoord);
  73. }
  74. </script>
  75. <script>
  76. "use strict";
  77. description(document.title);
  78. var wtu = WebGLTestUtils;
  79. var gl = wtu.create3DContext("example");
  80. var vsSource = document.getElementById("vshader").text;
  81. var fs1Source = document.getElementById("fshader1").text;
  82. var fs2Source = document.getElementById("fshader2").text;
  83. var vsSourceB = document.getElementById("vshaderB").text;
  84. var fsSourceB = document.getElementById("fshaderB").text;
  85. var vShader = gl.createShader(gl.VERTEX_SHADER);
  86. var fShader = gl.createShader(gl.FRAGMENT_SHADER);
  87. var vShaderB = gl.createShader(gl.VERTEX_SHADER);
  88. var fShaderB = gl.createShader(gl.FRAGMENT_SHADER);
  89. var program = gl.createProgram();
  90. var programB = gl.createProgram();
  91. gl.attachShader(program, vShader);
  92. gl.attachShader(program, fShader);
  93. gl.attachShader(programB, vShaderB);
  94. gl.attachShader(programB, fShaderB);
  95. var success;
  96. var shader;
  97. function checkShaderStatus(s) {
  98. shader = s;
  99. shouldBeTrue("success = gl.getShaderParameter(shader, gl.COMPILE_STATUS)");
  100. if (!success) {
  101. debug("error: " + gl.getShaderInfoLog());
  102. }
  103. }
  104. var prg;
  105. function checkProgramStatus(p) {
  106. prg = p;
  107. shouldBeTrue("success = gl.getProgramParameter(prg, gl.LINK_STATUS)");
  108. if (!success) {
  109. debug("error: " + gl.getProgramInfoLog(prg));
  110. }
  111. }
  112. for (var i = 0; i < 10; ++i) {
  113. gl.shaderSource(vShader, vsSource);
  114. gl.compileShader(vShader);
  115. checkShaderStatus(vShader)
  116. gl.shaderSource(fShader, fs1Source);
  117. gl.compileShader(fShader);
  118. checkShaderStatus(fShader)
  119. gl.linkProgram(program);
  120. checkProgramStatus(program)
  121. gl.useProgram(program);
  122. gl.shaderSource(vShaderB, vsSourceB);
  123. gl.compileShader(vShaderB);
  124. checkShaderStatus(vShaderB)
  125. gl.shaderSource(fShaderB, fsSourceB);
  126. gl.compileShader(fShaderB);
  127. checkShaderStatus(fShaderB)
  128. gl.linkProgram(programB);
  129. checkProgramStatus(programB)
  130. gl.useProgram(programB);
  131. }
  132. for (var i = 0; i < 10; ++i) {
  133. // Now change the fragment shader
  134. gl.shaderSource(fShader, fs2Source);
  135. gl.compileShader(fShader);
  136. checkShaderStatus(fShader)
  137. // And re-link
  138. gl.linkProgram(program);
  139. checkProgramStatus(program)
  140. }
  141. wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
  142. var successfullyParsed = true;
  143. </script>
  144. <script src="../../../resources/js-test-post.js"></script>
  145. </body>
  146. </html>