OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2011 The Chromium Authors. 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 are | |
6 met: | |
7 | |
8 * Redistributions of source code must retain the above copyright | |
9 notice, this list of conditions and the following disclaimer. | |
10 * Redistributions in binary form must reproduce the above | |
11 copyright notice, this list of conditions and the following disclaimer | |
12 in the documentation and/or other materials provided with the | |
13 distribution. | |
14 * Neither the name of Google Inc. nor the names of its | |
15 contributors may be used to endorse or promote products derived from | |
16 this software without specific prior written permission. | |
17 | |
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 --> | |
30 <!DOCTYPE html> | |
31 <html> | |
32 <head> | |
33 <meta charset="utf-8"> | |
34 <link rel="stylesheet" href="../../resources/js-test-style.css"/> | |
35 <script src="../../resources/js-test-pre.js"></script> | |
36 <script src="../resources/webgl-test.js"></script> | |
37 </head> | |
38 <body> | |
39 <div id="description"></div> | |
40 <div id="console"></div> | |
41 | |
42 <script> | |
43 description("Tests that index validation verifies the correct number of indices"
); | |
44 | |
45 function sizeInBytes(type) { | |
46 switch (type) { | |
47 case gl.BYTE: | |
48 case gl.UNSIGNED_BYTE: | |
49 return 1; | |
50 case gl.SHORT: | |
51 case gl.UNSIGNED_SHORT: | |
52 return 2; | |
53 case gl.INT: | |
54 case gl.UNSIGNED_INT: | |
55 case gl.FLOAT: | |
56 return 4; | |
57 default: | |
58 throw "unknown type"; | |
59 } | |
60 } | |
61 | |
62 var gl = create3DContext(); | |
63 var program = loadStandardProgram(gl); | |
64 | |
65 // 3 vertices => 1 triangle, interleaved data | |
66 var dataComplete = new Float32Array([0, 0, 0, 1, | |
67 0, 0, 1, | |
68 1, 0, 0, 1, | |
69 0, 0, 1, | |
70 1, 1, 1, 1, | |
71 0, 0, 1]); | |
72 var dataIncomplete = new Float32Array([0, 0, 0, 1, | |
73 0, 0, 1, | |
74 1, 0, 0, 1, | |
75 0, 0, 1, | |
76 1, 1, 1, 1]); | |
77 var indices = new Uint16Array([0, 1, 2]); | |
78 | |
79 debug("Testing with valid indices"); | |
80 | |
81 var bufferComplete = gl.createBuffer(); | |
82 gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete); | |
83 gl.bufferData(gl.ARRAY_BUFFER, dataComplete, gl.STATIC_DRAW); | |
84 var elements = gl.createBuffer(); | |
85 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements); | |
86 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW); | |
87 gl.useProgram(program); | |
88 var vertexLoc = gl.getAttribLocation(program, "a_vertex"); | |
89 var normalLoc = gl.getAttribLocation(program, "a_normal"); | |
90 gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT),
0); | |
91 gl.enableVertexAttribArray(vertexLoc); | |
92 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT),
4 * sizeInBytes(gl.FLOAT)); | |
93 gl.enableVertexAttribArray(normalLoc); | |
94 shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE')
; | |
95 glErrorShouldBe(gl, gl.NO_ERROR); | |
96 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); | |
97 glErrorShouldBe(gl, gl.NO_ERROR); | |
98 | |
99 debug("Testing with out-of-range indices"); | |
100 | |
101 var bufferIncomplete = gl.createBuffer(); | |
102 gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete); | |
103 gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, gl.STATIC_DRAW); | |
104 gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT),
0); | |
105 gl.enableVertexAttribArray(vertexLoc); | |
106 gl.disableVertexAttribArray(normalLoc); | |
107 debug("Enable vertices, valid"); | |
108 glErrorShouldBe(gl, gl.NO_ERROR); | |
109 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); | |
110 glErrorShouldBe(gl, gl.NO_ERROR); | |
111 debug("Enable normals, out-of-range"); | |
112 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT),
4 * sizeInBytes(gl.FLOAT)); | |
113 gl.enableVertexAttribArray(normalLoc); | |
114 glErrorShouldBe(gl, gl.NO_ERROR); | |
115 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); | |
116 glErrorShouldBe(gl, gl.INVALID_OPERATION); | |
117 | |
118 debug("Test with enabled attribute that does not belong to current program"); | |
119 | |
120 gl.disableVertexAttribArray(normalLoc); | |
121 var extraLoc = Math.max(vertexLoc, normalLoc) + 1; | |
122 gl.enableVertexAttribArray(extraLoc); | |
123 debug("Enable an extra attribute with null"); | |
124 glErrorShouldBe(gl, gl.NO_ERROR); | |
125 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); | |
126 glErrorShouldBe(gl, gl.INVALID_OPERATION); | |
127 debug("Enable an extra attribute with insufficient data buffer"); | |
128 gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT),
4 * sizeInBytes(gl.FLOAT)); | |
129 glErrorShouldBe(gl, gl.NO_ERROR); | |
130 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); | |
131 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT),
-2000000000 * sizeInBytes(gl.FLOAT)); | |
132 glErrorShouldBe(gl, gl.NO_ERROR); | |
133 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); | |
134 | |
135 successfullyParsed = true; | |
136 </script> | |
137 | |
138 <script src="../../resources/js-test-post.js"></script> | |
139 </body> | |
140 </html> | |
OLD | NEW |