|
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 |
|
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 description(document.title); |
|
61 var wtu = WebGLTestUtils; |
|
62 var gl = wtu.create3DContext("example"); |
|
63 |
|
64 var vsSource = document.getElementById("vshader").text; |
|
65 var fs1Source = document.getElementById("fshader1").text; |
|
66 var fs2Source = document.getElementById("fshader2").text; |
|
67 |
|
68 var vsSourceB = document.getElementById("vshaderB").text; |
|
69 var fsSourceB = document.getElementById("fshaderB").text; |
|
70 |
|
71 var vShader = gl.createShader(gl.VERTEX_SHADER); |
|
72 var fShader = gl.createShader(gl.FRAGMENT_SHADER); |
|
73 |
|
74 var vShaderB = gl.createShader(gl.VERTEX_SHADER); |
|
75 var fShaderB = gl.createShader(gl.FRAGMENT_SHADER); |
|
76 |
|
77 var program = gl.createProgram(); |
|
78 var programB = gl.createProgram(); |
|
79 |
|
80 gl.attachShader(program, vShader); |
|
81 gl.attachShader(program, fShader); |
|
82 |
|
83 gl.attachShader(programB, vShaderB); |
|
84 gl.attachShader(programB, fShaderB); |
|
85 |
|
86 var success; |
|
87 var shader; |
|
88 |
|
89 function checkShaderStatus(s) { |
|
90 shader = s; |
|
91 shouldBeTrue("success = gl.getShaderParameter(shader, gl.COMPILE_STATUS)"); |
|
92 if (!success) { |
|
93 debug("error: " + gl.getShaderInfoLog()); |
|
94 } |
|
95 } |
|
96 |
|
97 var prg; |
|
98 function checkProgramStatus(p) { |
|
99 prg = p; |
|
100 shouldBeTrue("success = gl.getProgramParameter(prg, gl.LINK_STATUS)"); |
|
101 if (!success) { |
|
102 debug("error: " + gl.getProgramInfoLog(prg)); |
|
103 } |
|
104 } |
|
105 |
|
106 for (var i = 0; i < 10; ++i) { |
|
107 gl.shaderSource(vShader, vsSource); |
|
108 gl.compileShader(vShader); |
|
109 checkShaderStatus(vShader) |
|
110 gl.shaderSource(fShader, fs1Source); |
|
111 gl.compileShader(fShader); |
|
112 checkShaderStatus(fShader) |
|
113 |
|
114 gl.linkProgram(program); |
|
115 checkProgramStatus(program) |
|
116 gl.useProgram(program); |
|
117 |
|
118 gl.shaderSource(vShaderB, vsSourceB); |
|
119 gl.compileShader(vShaderB); |
|
120 checkShaderStatus(vShaderB) |
|
121 gl.shaderSource(fShaderB, fsSourceB); |
|
122 gl.compileShader(fShaderB); |
|
123 checkShaderStatus(fShaderB) |
|
124 |
|
125 gl.linkProgram(programB); |
|
126 checkProgramStatus(programB) |
|
127 |
|
128 gl.useProgram(programB); |
|
129 } |
|
130 |
|
131 for (var i = 0; i < 10; ++i) { |
|
132 // Now change the fragment shader |
|
133 gl.shaderSource(fShader, fs2Source); |
|
134 gl.compileShader(fShader); |
|
135 checkShaderStatus(fShader) |
|
136 |
|
137 // And re-link |
|
138 gl.linkProgram(program); |
|
139 checkProgramStatus(program) |
|
140 } |
|
141 |
|
142 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors"); |
|
143 |
|
144 successfullyParsed = true; |
|
145 </script> |
|
146 <script>finishTest();</script> |
|
147 |
|
148 </body> |
|
149 </html> |
|
150 |
|
151 |