|
1 <!-- |
|
2 Copyright (C) 2011 Apple Computer, Inc. All rights reserved. |
|
3 |
|
4 Redistribution and use in source and binary forms, with or without |
|
5 modification, are permitted provided that the following conditions |
|
6 are met: |
|
7 1. Redistributions of source code must retain the above copyright |
|
8 notice, this list of conditions and the following disclaimer. |
|
9 2. Redistributions in binary form must reproduce the above copyright |
|
10 notice, this list of conditions and the following disclaimer in the |
|
11 documentation and/or other materials provided with the distribution. |
|
12 |
|
13 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
|
14 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
|
17 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
18 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
19 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
20 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
21 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
24 --> |
|
25 <!DOCTYPE html> |
|
26 <html> |
|
27 <head> |
|
28 <meta charset="utf-8"> |
|
29 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
|
30 <script src="../../resources/js-test-pre.js"></script> |
|
31 <script src="../resources/webgl-test.js"></script> |
|
32 </head> |
|
33 <body> |
|
34 <div id="description"></div> |
|
35 <div id="console"></div> |
|
36 |
|
37 <script> |
|
38 description("Test of getActiveAttrib and getActiveUniform"); |
|
39 |
|
40 var context = create3DContext(); |
|
41 var context2 = create3DContext(); |
|
42 var program = loadStandardProgram(context); |
|
43 var program2 = loadProgram(context2, |
|
44 "../resources/intArrayUniformShader.vert", |
|
45 "../resources/noopUniformShader.frag"); |
|
46 |
|
47 glErrorShouldBe(context, context.NO_ERROR); |
|
48 shouldBe("context.getActiveUniform(program, 0).name", "'u_modelViewProjMatrix'"); |
|
49 shouldBe("context.getActiveUniform(program, 0).type", "context.FLOAT_MAT4"); |
|
50 shouldBe("context.getActiveUniform(program, 0).size", "1"); |
|
51 shouldBeNull("context.getActiveUniform(program, 1)"); |
|
52 glErrorShouldBe(context, context.INVALID_VALUE); |
|
53 shouldBeNull("context.getActiveUniform(program, -1)"); |
|
54 glErrorShouldBe(context, context.INVALID_VALUE); |
|
55 shouldBeNull("context.getActiveUniform(null, 0)"); |
|
56 glErrorShouldBe(context, context.INVALID_VALUE); |
|
57 |
|
58 // we don't know the order the attribs will appear. |
|
59 var info = [ |
|
60 context.getActiveAttrib(program, 0), |
|
61 context.getActiveAttrib(program, 1) |
|
62 ]; |
|
63 for (var ii = 0; ii < info.length; ++ii) |
|
64 shouldBeNonNull("info[ii]"); |
|
65 |
|
66 var expected = [ |
|
67 { name: 'a_normal', type: context.FLOAT_VEC3, size: 1 }, |
|
68 { name: 'a_vertex', type: context.FLOAT_VEC4, size: 1 } |
|
69 ]; |
|
70 |
|
71 if (info[0].name != expected[0].name) { |
|
72 t = info[0]; |
|
73 info[0] = info[1]; |
|
74 info[1] = t; |
|
75 } |
|
76 |
|
77 for (var ii = 0; ii < info.length; ++ii) { |
|
78 shouldBe("info[ii].name", "expected[ii].name"); |
|
79 shouldBe("info[ii].type", "expected[ii].type"); |
|
80 shouldBe("info[ii].size", "expected[ii].size"); |
|
81 } |
|
82 |
|
83 // we don't know the order the uniforms will appear. |
|
84 var info2 = [ |
|
85 context2.getActiveUniform(program2, 0), |
|
86 context2.getActiveUniform(program2, 1) |
|
87 ]; |
|
88 for (var ii = 0; ii < info2.length; ++ii) |
|
89 shouldBeNonNull("info2[ii]"); |
|
90 |
|
91 var expected2 = [ |
|
92 { name: 'ival', type: context2.INT, size: 1 }, |
|
93 { name: 'ival2[0]', type: context2.INT, size: 2 } |
|
94 ]; |
|
95 |
|
96 if (info2[0].name != expected2[0].name) { |
|
97 t = info2[0]; |
|
98 info2[0] = info2[1]; |
|
99 info2[1] = t; |
|
100 } |
|
101 |
|
102 for (var ii = 0; ii < info2.length; ++ii) { |
|
103 shouldBe("info2[ii].name", "expected2[ii].name"); |
|
104 shouldBe("info2[ii].type", "expected2[ii].type"); |
|
105 shouldBe("info2[ii].size", "expected2[ii].size"); |
|
106 } |
|
107 |
|
108 shouldBeNull("context.getActiveAttrib(program, 2)"); |
|
109 glErrorShouldBe(context, context.INVALID_VALUE); |
|
110 shouldBeNull("context.getActiveAttrib(program, -1)"); |
|
111 glErrorShouldBe(context, context.INVALID_VALUE); |
|
112 shouldBeNull("context.getActiveAttrib(null, 0)"); |
|
113 glErrorShouldBe(context, context.INVALID_VALUE); |
|
114 |
|
115 glErrorShouldBe(context2, context.NO_ERROR); |
|
116 |
|
117 debug("Check trying to get attribs from different context"); |
|
118 shouldBeNull("context2.getActiveAttrib(program, 0)"); |
|
119 glErrorShouldBe(context2, context2.INVALID_OPERATION); |
|
120 shouldBeNull("context2.getActiveUniform(program, 0)"); |
|
121 glErrorShouldBe(context2, context2.INVALID_OPERATION); |
|
122 |
|
123 debug("Check trying to get attribs from deleted program"); |
|
124 context.deleteProgram(program); |
|
125 shouldBeNull("context.getActiveUniform(program, 0)"); |
|
126 glErrorShouldBe(context, context.INVALID_VALUE); |
|
127 shouldBeNull("context.getActiveAttrib(program, 0)"); |
|
128 glErrorShouldBe(context, context.INVALID_VALUE); |
|
129 |
|
130 successfullyParsed = true; |
|
131 </script> |
|
132 |
|
133 <script>finishTest();</script> |
|
134 </body> |
|
135 </html> |