re-compile-re-link.html (3774B)
1 <!-- 2 Copyright (c) 2019 The Khronos Group Inc. 3 Use of this source code is governed by an MIT-style license that can be 4 found in the LICENSE.txt file. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>WebGL Re-Compile and Re-link Shader conformance test.</title> 12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> 13 <script src="../../../js/js-test-pre.js"></script> 14 <script src="../../../js/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 29 <script id="fshader1" type="x-shader/x-fragment"> 30 precision mediump float; 31 void main() { 32 gl_FragColor = vec4(1,0,0,1); 33 } 34 </script> 35 <script id="fshader2" type="x-shader/x-fragment"> 36 precision mediump float; 37 uniform float foobar; 38 void main() { 39 gl_FragColor = vec4(1,0,foobar,1); 40 } 41 </script> 42 <script id="vshaderB" type="not-js"> 43 attribute vec2 position; 44 varying vec2 v_texCoord; 45 void main() { 46 gl_Position = vec4(position, 0, 1); 47 v_texCoord = vec2(position * 0.5 + 0.5); 48 } 49 </script> 50 <script id="fshaderB" type="not-js"> 51 precision mediump float; 52 varying vec2 v_texCoord; 53 uniform sampler2D tex; 54 void main() { 55 gl_FragColor = texture2D(tex, v_texCoord); 56 } 57 </script> 58 59 <script> 60 "use strict"; 61 description(document.title); 62 var wtu = WebGLTestUtils; 63 var gl = wtu.create3DContext("example"); 64 65 var vsSource = document.getElementById("vshader").text; 66 var fs1Source = document.getElementById("fshader1").text; 67 var fs2Source = document.getElementById("fshader2").text; 68 69 var vsSourceB = document.getElementById("vshaderB").text; 70 var fsSourceB = document.getElementById("fshaderB").text; 71 72 var vShader = gl.createShader(gl.VERTEX_SHADER); 73 var fShader = gl.createShader(gl.FRAGMENT_SHADER); 74 75 var vShaderB = gl.createShader(gl.VERTEX_SHADER); 76 var fShaderB = gl.createShader(gl.FRAGMENT_SHADER); 77 78 var program = gl.createProgram(); 79 var programB = gl.createProgram(); 80 81 gl.attachShader(program, vShader); 82 gl.attachShader(program, fShader); 83 84 gl.attachShader(programB, vShaderB); 85 gl.attachShader(programB, fShaderB); 86 87 var success; 88 var shader; 89 90 function checkShaderStatus(s) { 91 shader = s; 92 shouldBeTrue("success = gl.getShaderParameter(shader, gl.COMPILE_STATUS)"); 93 if (!success) { 94 debug("error: " + gl.getShaderInfoLog(shader)); 95 } 96 } 97 98 var prg; 99 function checkProgramStatus(p) { 100 prg = p; 101 shouldBeTrue("success = gl.getProgramParameter(prg, gl.LINK_STATUS)"); 102 if (!success) { 103 debug("error: " + gl.getProgramInfoLog(prg)); 104 } 105 } 106 107 for (var i = 0; i < 10; ++i) { 108 gl.shaderSource(vShader, vsSource); 109 gl.compileShader(vShader); 110 checkShaderStatus(vShader) 111 gl.shaderSource(fShader, fs1Source); 112 gl.compileShader(fShader); 113 checkShaderStatus(fShader) 114 115 gl.linkProgram(program); 116 checkProgramStatus(program) 117 gl.useProgram(program); 118 119 gl.shaderSource(vShaderB, vsSourceB); 120 gl.compileShader(vShaderB); 121 checkShaderStatus(vShaderB) 122 gl.shaderSource(fShaderB, fsSourceB); 123 gl.compileShader(fShaderB); 124 checkShaderStatus(fShaderB) 125 126 gl.linkProgram(programB); 127 checkProgramStatus(programB) 128 129 gl.useProgram(programB); 130 } 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 138 // And re-link 139 gl.linkProgram(program); 140 checkProgramStatus(program) 141 } 142 143 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors"); 144 145 var successfullyParsed = true; 146 </script> 147 <script src="../../../js/js-test-post.js"></script> 148 149 </body> 150 </html>