PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/content/canvas/test/webgl/conformance/glsl/misc/re-compile-re-link.html

https://bitbucket.org/marfey/releases-mozilla-central
HTML | 151 lines | 122 code | 24 blank | 5 comment | 0 complexity | 59ee1489a2957336a62a2f0b79e73697 MD5 | raw file
Possible License(s): AGPL-1.0, MIT, LGPL-3.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause, GPL-2.0, JSON, Apache-2.0, 0BSD, LGPL-2.1
  1. <!--
  2. Copyright (c) 2012 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>
  7. <html>
  8. <head>
  9. <meta charset="utf-8">
  10. <title>WebGL Re-Compile and Re-link Shader conformance test.</title>
  11. <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
  12. <script src="../../../resources/js-test-pre.js"></script>
  13. <script src="../../resources/webgl-test.js"> </script>
  14. <script src="../../resources/webgl-test-utils.js"> </script>
  15. </head>
  16. <body>
  17. <canvas id="example" width="4" height="4" style="width: 40px; height: 30px;"></canvas>
  18. <div id="description"></div>
  19. <div id="console"></div>
  20. <script id="vshader" type="x-shader/x-vertex">
  21. attribute float column;
  22. attribute float height;
  23. uniform float position;
  24. void main() {
  25. gl_Position = vec4(mod(column - position, 1.0) * 2.0 - 1.0, height, 0, 1);
  26. }
  27. </script>
  28. <script id="fshader1" type="x-shader/x-fragment">
  29. precision mediump float;
  30. void main() {
  31. gl_FragColor = vec4(1,0,0,1);
  32. }
  33. </script>
  34. <script id="fshader2" type="x-shader/x-fragment">
  35. precision mediump float;
  36. uniform float foobar;
  37. void main() {
  38. gl_FragColor = vec4(1,0,foobar,1);
  39. }
  40. </script>
  41. <script id="vshaderB" type="not-js">
  42. attribute vec2 position;
  43. varying vec2 v_texCoord;
  44. void main() {
  45. gl_Position = vec4(position, 0, 1);
  46. v_texCoord = vec2(position * 0.5 + 0.5);
  47. }
  48. </script>
  49. <script id="fshaderB" type="not-js">
  50. precision mediump float;
  51. varying vec2 v_texCoord;
  52. uniform sampler2D tex;
  53. void main() {
  54. gl_FragColor = texture2D(tex, v_texCoord);
  55. }
  56. </script>
  57. <script>
  58. description(document.title);
  59. var wtu = WebGLTestUtils;
  60. var gl = wtu.create3DContext("example");
  61. var vsSource = document.getElementById("vshader").text;
  62. var fs1Source = document.getElementById("fshader1").text;
  63. var fs2Source = document.getElementById("fshader2").text;
  64. var vsSourceB = document.getElementById("vshaderB").text;
  65. var fsSourceB = document.getElementById("fshaderB").text;
  66. var vShader = gl.createShader(gl.VERTEX_SHADER);
  67. var fShader = gl.createShader(gl.FRAGMENT_SHADER);
  68. var vShaderB = gl.createShader(gl.VERTEX_SHADER);
  69. var fShaderB = gl.createShader(gl.FRAGMENT_SHADER);
  70. var program = gl.createProgram();
  71. var programB = gl.createProgram();
  72. gl.attachShader(program, vShader);
  73. gl.attachShader(program, fShader);
  74. gl.attachShader(programB, vShaderB);
  75. gl.attachShader(programB, fShaderB);
  76. var success;
  77. var shader;
  78. function checkShaderStatus(s) {
  79. shader = s;
  80. shouldBeTrue("success = gl.getShaderParameter(shader, gl.COMPILE_STATUS)");
  81. if (!success) {
  82. debug("error: " + gl.getShaderInfoLog());
  83. }
  84. }
  85. var prg;
  86. function checkProgramStatus(p) {
  87. prg = p;
  88. shouldBeTrue("success = gl.getProgramParameter(prg, gl.LINK_STATUS)");
  89. if (!success) {
  90. debug("error: " + gl.getProgramInfoLog(prg));
  91. }
  92. }
  93. for (var i = 0; i < 10; ++i) {
  94. gl.shaderSource(vShader, vsSource);
  95. gl.compileShader(vShader);
  96. checkShaderStatus(vShader)
  97. gl.shaderSource(fShader, fs1Source);
  98. gl.compileShader(fShader);
  99. checkShaderStatus(fShader)
  100. gl.linkProgram(program);
  101. checkProgramStatus(program)
  102. gl.useProgram(program);
  103. gl.shaderSource(vShaderB, vsSourceB);
  104. gl.compileShader(vShaderB);
  105. checkShaderStatus(vShaderB)
  106. gl.shaderSource(fShaderB, fsSourceB);
  107. gl.compileShader(fShaderB);
  108. checkShaderStatus(fShaderB)
  109. gl.linkProgram(programB);
  110. checkProgramStatus(programB)
  111. gl.useProgram(programB);
  112. }
  113. for (var i = 0; i < 10; ++i) {
  114. // Now change the fragment shader
  115. gl.shaderSource(fShader, fs2Source);
  116. gl.compileShader(fShader);
  117. checkShaderStatus(fShader)
  118. // And re-link
  119. gl.linkProgram(program);
  120. checkProgramStatus(program)
  121. }
  122. glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
  123. successfullyParsed = true;
  124. </script>
  125. <script src="../../../resources/js-test-post.js"></script>
  126. </body>
  127. </html>