Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: third_party/webgl/sdk/tests/conformance/programs/program-test.html

Issue 10399113: Roll webgl conformance tests to r17874: part 2, adding r17874 (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 <!--
2
3 /*
4 ** Copyright (c) 2012 The Khronos Group Inc.
5 **
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
16 **
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
24 */
25
26 -->
27 <!DOCTYPE html>
28 <html>
29 <head>
30 <meta charset="utf-8">
31 <title>WebGL Program Compiling/Linking Conformance Test</title>
32 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
33 <script src="../../resources/js-test-pre.js" type="text/javascript"></script>
34 <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></s cript>
35 <script src="../resources/webgl-test.js" type="text/javascript"></script>
36 </head>
37 <body>
38 <div id="description"></div>
39 <div id="console"></div>
40 <canvas id="canvas" width="2" height="2"> </canvas>
41 <script type="text/javascript">
42 function go() {
43 description("Tests that program compiling/linking/using works correctly.");
44
45 debug("");
46 debug("Canvas.getContext");
47
48 var gl = create3DContext(document.getElementById("canvas"));
49 if (!gl) {
50 testFailed("context does not exist");
51 return;
52 }
53
54 testPassed("context exists");
55
56 gl.clearColor(0.0, 0.0, 0.0, 0.0);
57 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
58
59 function doArraysHaveSameContents(a, b) {
60 var flags = [];
61 function hasUnusedValue(a, value) {
62 for (var ii = 0; ii < a.length; ++ii) {
63 if (a[ii] === value && !flags[ii]) {
64 flags[ii] = true;
65 return true;
66 }
67 }
68 return false;
69 }
70
71 try {
72 if (a.length !== b.length) {
73 return false;
74 }
75 for (var ii = 0; ii < a.length; ii++) {
76 if (!hasUnusedValue(b, a[ii])) {
77 return false;
78 }
79 }
80 } catch (ex) {
81 return false;
82 }
83 return true;
84 }
85
86 /////// Check compileShader() /////////////////////////////
87
88 var vs = gl.createShader(gl.VERTEX_SHADER);
89 gl.shaderSource(vs, "attribute vec4 aVertex; attribute vec4 aColor; varying vec4 vColor; void main() { vColor = aColor; gl_Position = aVertex; }");
90 gl.compileShader(vs);
91
92 assertMsg(gl.getShaderParameter(vs, gl.COMPILE_STATUS) == true,
93 "good vertex shader should compile");
94
95 // Verify that constants removed from the WebGL spec generate INVALID_ENUM e rrors
96 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors at this point");
97 assertMsg(gl.getShaderParameter(vs, desktopGL['INFO_LOG_LENGTH']) === null, "invalid call to getShaderParameter should return null");
98 glErrorShouldBe(gl, gl.INVALID_ENUM, "INFO_LOG_LENGTH is not a valid argumen t to getShaderParameter in WebGL");
99 assertMsg(gl.getShaderParameter(vs, desktopGL['SHADER_SOURCE_LENGTH']) === n ull, "invalid call to getShaderParameter should return null");
100 glErrorShouldBe(gl, gl.INVALID_ENUM, "SHADER_SOURCE_LENGTH is not a valid ar gument to getShaderParameter in WebGL");
101
102 var vs2 = gl.createShader(gl.VERTEX_SHADER);
103 gl.shaderSource(vs2, "attribute vec4 aVertex; attribute vec4 aColor; varying vec4 vColor; void main() { vColor = aColor; gl_Position = aVertex * 0.5; }");
104 gl.compileShader(vs2);
105
106 assertMsg(gl.getShaderParameter(vs2, gl.COMPILE_STATUS) == true,
107 "good vertex shader #2 should compile");
108
109 var vsBad = gl.createShader(gl.VERTEX_SHADER);
110 gl.shaderSource(vsBad, "WILL NOT COMPILE;");
111 gl.compileShader(vsBad);
112
113 // GLSL 1.0.17 section 10.27. compile shader does not have to return failure .
114 //assertMsg(gl.getShaderParameter(vsBad, gl.COMPILE_STATUS) == false,
115 // "bad vertex shader should fail to compile");
116
117 var fs = gl.createShader(gl.FRAGMENT_SHADER);
118 gl.shaderSource(fs, "precision mediump float; varying vec4 vColor; void main () { gl_FragColor = vColor; }");
119 gl.compileShader(fs);
120
121 assertMsg(gl.getShaderParameter(fs, gl.COMPILE_STATUS) == true,
122 "good fragment shader should compile");
123
124 var fs2 = gl.createShader(gl.FRAGMENT_SHADER);
125 gl.shaderSource(fs2, "precision mediump float; varying vec4 vColor; void mai n() { gl_FragColor = vColor * 0.5; }");
126 gl.compileShader(fs2);
127
128 assertMsg(gl.getShaderParameter(fs2, gl.COMPILE_STATUS) == true,
129 "good fragment shader #2 should compile");
130
131 var fsBad = gl.createShader(gl.FRAGMENT_SHADER);
132 gl.shaderSource(fsBad, "WILL NOT COMPILE;");
133 gl.compileShader(fsBad);
134
135 // GLSL 1.0.17 section 10.27. compile shader does not have to return failure .
136 //assertMsg(gl.getShaderParameter(fsBad, gl.COMPILE_STATUS) == false,
137 // "bad fragment shader should fail to compile");
138
139 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors at this point");
140
141 /////// Check attachShader() /////////////////////////////
142
143 function checkAttachShader(already_attached_shaders, shader, expected_error_ code, errmsg) {
144 var prog = gl.createProgram();
145 for (var i = 0; i < already_attached_shaders.length; ++i)
146 gl.attachShader(prog, already_attached_shaders[i]);
147 if(gl.getError() != gl.NO_ERROR)
148 assertMsg(false, "unexpected error in attachShader()");
149 gl.attachShader(prog, shader);
150 glErrorShouldBe(gl, expected_error_code, errmsg);
151 }
152
153 checkAttachShader([], vs, gl.NO_ERROR, "attaching a vertex shader should suc ceed");
154 checkAttachShader([vs], vs, gl.INVALID_OPERATION,
155 "attaching an already attached vertex shader should genera te INVALID_OPERATION");
156 checkAttachShader([], fs, gl.NO_ERROR, "attaching a fragment shader should s ucceed");
157 checkAttachShader([fs], fs, gl.INVALID_OPERATION,
158 "attaching an already attached fragment shader should gene rate INVALID_OPERATION");
159 checkAttachShader([vs], vs2, gl.INVALID_OPERATION,
160 "attaching shaders of the same type to a program should ge nerate INVALID_OPERATION");
161 checkAttachShader([fs], fs2, gl.INVALID_OPERATION,
162 "attaching shaders of the same type to a program should ge nerate INVALID_OPERATION");
163
164 /////// Check detachShader() /////////////////////////////
165
166 function checkDetachShader(already_attached_shaders, shader, expected_error_ code, errmsg) {
167 var prog = gl.createProgram();
168 for (var i = 0; i < already_attached_shaders.length; ++i)
169 gl.attachShader(prog, already_attached_shaders[i]);
170 if(gl.getError() != gl.NO_ERROR)
171 assertMsg(false, "unexpected error in attachShader()");
172 gl.detachShader(prog, shader);
173 glErrorShouldBe(gl, expected_error_code, errmsg);
174 }
175
176 checkDetachShader([vs], vs, gl.NO_ERROR, "detaching a vertex shader should s ucceed");
177 checkDetachShader([fs], vs, gl.INVALID_OPERATION,
178 "detaching a not already attached vertex shader should gen erate INVALID_OPERATION");
179 checkDetachShader([fs], fs, gl.NO_ERROR, "detaching a fragment shader should succeed");
180 checkDetachShader([vs], fs, gl.INVALID_OPERATION,
181 "detaching a not already attached fragment shader should g enerate INVALID_OPERATION");
182
183 /////// Check getAttachedShaders() /////////////////////////////
184
185 function checkGetAttachedShaders(shaders_to_attach, shaders_to_detach, expec ted_shaders, errmsg) {
186 var prog = gl.createProgram();
187 for (var i = 0; i < shaders_to_attach.length; ++i)
188 gl.attachShader(prog, shaders_to_attach[i]);
189 if(gl.getError() != gl.NO_ERROR)
190 assertMsg(false, "unexpected error in attachShader()");
191 for (var i = 0; i < shaders_to_detach.length; ++i)
192 gl.detachShader(prog, shaders_to_detach[i]);
193 if(gl.getError() != gl.NO_ERROR)
194 assertMsg(false, "unexpected error in detachShader()");
195 assertMsg(doArraysHaveSameContents(gl.getAttachedShaders(prog), expected _shaders), errmsg);
196 }
197 checkGetAttachedShaders([], [], [], "getAttachedShaders should return an emp ty list by default");
198 checkGetAttachedShaders([fs], [], [fs], "attaching a single shader should gi ve the expected list");
199 checkGetAttachedShaders([fs, vs], [], [fs, vs],
200 "attaching some shaders should give the expected list");
201 checkGetAttachedShaders([fs], [fs], [], "attaching a shader and detaching it shoud leave an empty list");
202 checkGetAttachedShaders([fs, vs], [fs, vs], [],
203 "attaching some shaders and detaching them in same order shoud leave an empty list");
204 checkGetAttachedShaders([fs, vs], [vs, fs], [],
205 "attaching some shaders and detaching them in random order shoud leave a n empty list");
206 checkGetAttachedShaders([fs, vs], [vs], [fs],
207 "attaching and detaching some shaders should leave the difference list") ;
208 checkGetAttachedShaders([fs, vs], [fs], [vs],
209 "attaching and detaching some shaders should leave the difference list") ;
210 checkGetAttachedShaders([fsBad], [], [fsBad],
211 "attaching a shader that failed to compile should still show it in the l ist");
212 checkGetAttachedShaders([fs, vsBad], [], [fs, vsBad],
213 "attaching shaders, including one that failed to compile, should still s how the it in the list");
214
215 /////// Check linkProgram() and useProgram /////////////////////////////
216
217 function checkLinkAndUse(shaders, deleteShaderAfterAttach, expected_status, testInvalidEnums, errmsg) {
218 var prog = gl.createProgram();
219 for (var i = 0; i < shaders.length; ++i) {
220 gl.attachShader(prog, shaders[i]);
221 if (deleteShaderAfterAttach)
222 gl.deleteShader(shaders[i]);
223 }
224 gl.bindAttribLocation(prog, 0, "aVertex");
225 gl.bindAttribLocation(prog, 1, "aColor");
226 gl.linkProgram(prog);
227 if (gl.getError() != gl.NO_ERROR)
228 assertMsg(false, "unexpected error in linkProgram()");
229 assertMsg(gl.getProgramParameter(prog, gl.LINK_STATUS) == expected_statu s, errmsg);
230 var infolog = gl.getProgramInfoLog(prog);
231 if (gl.getError() != gl.NO_ERROR)
232 assertMsg(false, "unexpected error in getProgramInfoLog()");
233 if (typeof(infolog) != "string")
234 assertMsg(false, "getProgramInfoLog() did not return a string");
235 if (expected_status == true && gl.getProgramParameter(prog, gl.LINK_STAT US) == false)
236 debug(infolog);
237 if (gl.getError() != gl.NO_ERROR)
238 assertMsg(false, "unexpected error in getProgramParameter()");
239
240 if (testInvalidEnums) {
241 // Verify that constants removed from the WebGL spec generate INVALI D_ENUM errors
242 assertMsg(gl.getProgramParameter(prog, desktopGL['INFO_LOG_LENGTH']) === null, "invalid call to getProgramParameter should return null");
243 glErrorShouldBe(gl, gl.INVALID_ENUM, "INFO_LOG_LENGTH is not a valid argument to getProgramParameter in WebGL");
244 assertMsg(gl.getProgramParameter(prog, desktopGL['ACTIVE_ATTRIBUTE_M AX_LENGTH']) === null, "invalid call to getProgramParameter should return null") ;
245 glErrorShouldBe(gl, gl.INVALID_ENUM, "ACTIVE_ATTRIBUTE_MAX_LENGTH is not a valid argument to getProgramParameter in WebGL");
246 assertMsg(gl.getProgramParameter(prog, desktopGL['ACTIVE_UNIFORM_MAX _LENGTH']) === null, "invalid call to getProgramParameter should return null");
247 glErrorShouldBe(gl, gl.INVALID_ENUM, "ACTIVE_UNIFORM_MAX_LENGTH is n ot a valid argument to getProgramParameter in WebGL");
248 }
249
250 gl.useProgram(prog);
251 if (expected_status == true)
252 glErrorShouldBe(gl, gl.NO_ERROR, "using a valid program should succe ed");
253 if (expected_status == false)
254 glErrorShouldBe(gl, gl.INVALID_OPERATION, "using an invalid program should generate INVALID_OPERATION");
255 return prog;
256 }
257
258 var progGood1 = checkLinkAndUse([vs, fs], false, true, true, "valid program should link");
259 var progGood2 = checkLinkAndUse([vs, fs2], false, true, false, "valid progra m #2 should link");
260 var progBad1 = checkLinkAndUse([vs], false, false, false, "program with no f ragment shader should fail to link");
261 var progBad2 = checkLinkAndUse([fs], false, false, false, "program with no v ertex shader should fail to link");
262 var progBad3 = checkLinkAndUse([vsBad, fs], false, false, false, "program wi th bad vertex shader should fail to link");
263 var progBad4 = checkLinkAndUse([vs, fsBad], false, false, false, "program wi th bad fragment shader should fail to link");
264 var progBad5 = checkLinkAndUse([vsBad, fsBad], false, false, false, "program with bad shaders should fail to link");
265
266 gl.useProgram(progGood1);
267 glErrorShouldBe(gl, gl.NO_ERROR, "using a valid program shouldn't generate a GL error");
268
269 var vbuf = gl.createBuffer();
270 gl.bindBuffer(gl.ARRAY_BUFFER, vbuf);
271 gl.bufferData(gl.ARRAY_BUFFER,
272 new Float32Array([
273 0.0, 0.0, 0.0, 1.0,
274 1.0, 0.0, 0.0, 1.0,
275 1.0, 1.0, 0.0, 1.0,
276 0.0, 1.0, 0.0, 1.0]),
277 gl.STATIC_DRAW);
278 gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0);
279 gl.enableVertexAttribArray(0);
280 gl.vertexAttrib3f(1, 1.0, 0.0, 0.0);
281
282 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors at this point #2");
283
284 gl.useProgram(progGood1);
285 gl.drawArrays(gl.TRIANGLES, 0, 3);
286 glErrorShouldBe(gl, gl.NO_ERROR, "drawing with a valid program shouldn't gen erate a GL error");
287
288 gl.useProgram(progBad1);
289 glErrorShouldBe(gl, gl.INVALID_OPERATION, "using an invalid program should g enerate INVALID_OPERATION");
290 gl.drawArrays(gl.TRIANGLES, 0, 3);
291 glErrorShouldBe(gl, gl.NO_ERROR, "Try to use an invalid program should not c hange the current rendering state");
292
293 gl.useProgram(progGood2);
294 gl.drawArrays(gl.TRIANGLES, 0, 3);
295 glErrorShouldBe(gl, gl.NO_ERROR, "drawing with a valid program shouldn't gen erate a GL error");
296 gl.detachShader(progGood2, fs2);
297 gl.attachShader(progGood2, fsBad);
298 gl.linkProgram(progGood2);
299 assertMsg(gl.getProgramParameter(progGood2, gl.LINK_STATUS) == false,
300 "linking should fail with in-use formerly good program, with new b ad shader attached");
301
302 // Invalid link leaves previous valid program intact.
303 gl.drawArrays(gl.TRIANGLES, 0, 3);
304 glErrorShouldBe(gl, gl.NO_ERROR, "drawing with a valid program shouldn't gen erate a GL error");
305
306 gl.useProgram(progGood1);
307 gl.drawArrays(gl.TRIANGLES, 0, 4);
308 glErrorShouldBe(gl, gl.NO_ERROR, "drawing with a valid when last used progra m shouldn't generate a GL error");
309
310 var progGood1 = checkLinkAndUse([vs, fs], true, true, false, "delete shaders after attaching them and before linking program should not affect linkProgram") ;
311 gl.useProgram(progGood1);
312 gl.drawArrays(gl.TRIANGLES, 0, 4);
313 glErrorShouldBe(gl, gl.NO_ERROR, "drawing with a valid when last used progra m shouldn't generate a GL error");
314
315 /////// Check deleteProgram() and deleteShader() /////////////////////////////
316
317 gl.useProgram(progGood1);
318 gl.deleteProgram(progGood1);
319 gl.drawArrays(gl.TRIANGLES, 0, 4);
320 glErrorShouldBe(gl, gl.NO_ERROR, "delete the current program shouldn't chang e the current rendering state");
321
322 gl.linkProgram(progGood1);
323 glErrorShouldBe(gl, gl.NO_ERROR, "The current program shouldn't be deleted") ;
324
325 var fs3 = gl.createShader(gl.FRAGMENT_SHADER);
326 gl.shaderSource(fs3, "precision mediump float; varying vec4 vColor; void mai n() { gl_FragColor = vColor; }");
327 gl.compileShader(fs3);
328
329 assertMsg(gl.getShaderParameter(fs3, gl.COMPILE_STATUS) == true,
330 "good fragment shader should compile");
331
332 gl.deleteShader(fs3);
333 gl.compileShader(fs3);
334 glErrorShouldBe(gl, gl.INVALID_VALUE, "an unattached shader should be delete d immediately");
335
336 fs3 = gl.createShader(gl.FRAGMENT_SHADER);
337 gl.shaderSource(fs3, "precision mediump float; varying vec4 vColor; void mai n() { gl_FragColor = vColor; }");
338 gl.compileShader(fs3);
339
340 assertMsg(gl.getShaderParameter(fs3, gl.COMPILE_STATUS) == true,
341 "good fragment shader should compile");
342
343 gl.detachShader(progGood1, fs);
344 gl.attachShader(progGood1, fs3);
345
346 gl.deleteShader(fs3);
347 gl.compileShader(fs3);
348 assertMsg(gl.getShaderParameter(fs3, gl.COMPILE_STATUS) == true,
349 "an attached shader shouldn't be deleted");
350
351 gl.useProgram(null);
352 gl.linkProgram(progGood1);
353 glErrorShouldBe(gl, gl.INVALID_VALUE, "a delete-marked program should be del eted once it's no longer the current program");
354
355 gl.compileShader(fs3);
356 glErrorShouldBe(gl, gl.INVALID_VALUE, "a delete-marked shader should be dele ted once all its attachments are removed");
357 }
358
359 debug("");
360 go();
361
362 successfullyParsed = true;
363 </script>
364 <script src="../../resources/js-test-post.js"></script>
365
366 </body>
367 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698