PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/gabadie/WebGL
HTML | 174 lines | 123 code | 25 blank | 26 comment | 0 complexity | dae62b83bc1bf66aa0e8f4748d51940e MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  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.js"> </script>
  33. <script src="../../resources/webgl-test-utils.js"> </script>
  34. </head>
  35. <body>
  36. <canvas id="example" width="4" height="4" style="width: 40px; height: 30px;"></canvas>
  37. <div id="description"></div>
  38. <div id="console"></div>
  39. <script id="vshader" type="x-shader/x-vertex">
  40. attribute float column;
  41. attribute float height;
  42. uniform float position;
  43. void main() {
  44. gl_Position = vec4(mod(column - position, 1.0) * 2.0 - 1.0, height, 0, 1);
  45. }
  46. </script>
  47. <script id="fshader1" type="x-shader/x-fragment">
  48. precision mediump float;
  49. void main() {
  50. gl_FragColor = vec4(1,0,0,1);
  51. }
  52. </script>
  53. <script id="fshader2" type="x-shader/x-fragment">
  54. precision mediump float;
  55. uniform float foobar;
  56. void main() {
  57. gl_FragColor = vec4(1,0,foobar,1);
  58. }
  59. </script>
  60. <script id="vshaderB" type="not-js">
  61. attribute vec2 position;
  62. varying vec2 v_texCoord;
  63. void main() {
  64. gl_Position = vec4(position, 0, 1);
  65. v_texCoord = vec2(position * 0.5 + 0.5);
  66. }
  67. </script>
  68. <script id="fshaderB" type="not-js">
  69. precision mediump float;
  70. varying vec2 v_texCoord;
  71. uniform sampler2D tex;
  72. void main() {
  73. gl_FragColor = texture2D(tex, v_texCoord);
  74. }
  75. </script>
  76. <script>
  77. "use strict";
  78. description(document.title);
  79. var wtu = WebGLTestUtils;
  80. var gl = wtu.create3DContext("example");
  81. var vsSource = document.getElementById("vshader").text;
  82. var fs1Source = document.getElementById("fshader1").text;
  83. var fs2Source = document.getElementById("fshader2").text;
  84. var vsSourceB = document.getElementById("vshaderB").text;
  85. var fsSourceB = document.getElementById("fshaderB").text;
  86. var vShader = gl.createShader(gl.VERTEX_SHADER);
  87. var fShader = gl.createShader(gl.FRAGMENT_SHADER);
  88. var vShaderB = gl.createShader(gl.VERTEX_SHADER);
  89. var fShaderB = gl.createShader(gl.FRAGMENT_SHADER);
  90. var program = gl.createProgram();
  91. var programB = gl.createProgram();
  92. gl.attachShader(program, vShader);
  93. gl.attachShader(program, fShader);
  94. gl.attachShader(programB, vShaderB);
  95. gl.attachShader(programB, fShaderB);
  96. var success;
  97. var shader;
  98. function checkShaderStatus(s) {
  99. shader = s;
  100. shouldBeTrue("success = gl.getShaderParameter(shader, gl.COMPILE_STATUS)");
  101. if (!success) {
  102. debug("error: " + gl.getShaderInfoLog());
  103. }
  104. }
  105. var prg;
  106. function checkProgramStatus(p) {
  107. prg = p;
  108. shouldBeTrue("success = gl.getProgramParameter(prg, gl.LINK_STATUS)");
  109. if (!success) {
  110. debug("error: " + gl.getProgramInfoLog(prg));
  111. }
  112. }
  113. for (var i = 0; i < 10; ++i) {
  114. gl.shaderSource(vShader, vsSource);
  115. gl.compileShader(vShader);
  116. checkShaderStatus(vShader)
  117. gl.shaderSource(fShader, fs1Source);
  118. gl.compileShader(fShader);
  119. checkShaderStatus(fShader)
  120. gl.linkProgram(program);
  121. checkProgramStatus(program)
  122. gl.useProgram(program);
  123. gl.shaderSource(vShaderB, vsSourceB);
  124. gl.compileShader(vShaderB);
  125. checkShaderStatus(vShaderB)
  126. gl.shaderSource(fShaderB, fsSourceB);
  127. gl.compileShader(fShaderB);
  128. checkShaderStatus(fShaderB)
  129. gl.linkProgram(programB);
  130. checkProgramStatus(programB)
  131. gl.useProgram(programB);
  132. }
  133. for (var i = 0; i < 10; ++i) {
  134. // Now change the fragment shader
  135. gl.shaderSource(fShader, fs2Source);
  136. gl.compileShader(fShader);
  137. checkShaderStatus(fShader)
  138. // And re-link
  139. gl.linkProgram(program);
  140. checkProgramStatus(program)
  141. }
  142. glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
  143. var successfullyParsed = true;
  144. </script>
  145. <script src="../../../resources/js-test-post.js"></script>
  146. </body>
  147. </html>