OLD | NEW |
| (Empty) |
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
2 "http://www.w3.org/TR/html4/loose.dtd"> | |
3 <html> | |
4 <head> | |
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
6 <title>WebGL vertexAttribPointer Conformance Tests</title> | |
7 <script src="resources/desktop-gl-constants.js" type="text/javascript"></script> | |
8 <script src="../../../resources/js-test.js"></script> | |
9 <script src="resources/webgl-test.js"></script> | |
10 <script src="resources/webgl-test-utils.js"></script> | |
11 </head> | |
12 <body> | |
13 <div id="description"></div> | |
14 <div id="console"></div> | |
15 <canvas id="canvas" width="2" height="2"> </canvas> | |
16 <script> | |
17 description("This test checks vertexAttribPointer behaviors in WebGL."); | |
18 | |
19 debug(""); | |
20 debug("Canvas.getContext"); | |
21 | |
22 if (window.internals) | |
23 window.internals.settings.setWebGLErrorsToConsoleEnabled(false); | |
24 | |
25 var wtu = WebGLTestUtils; | |
26 var gl = create3DContext(document.getElementById("canvas")); | |
27 if (!gl) { | |
28 testFailed("context does not exist"); | |
29 } else { | |
30 testPassed("context exists"); | |
31 | |
32 debug(""); | |
33 debug("Checking gl.vertexAttribPointer."); | |
34 | |
35 if (!gl.FIXED) { | |
36 gl.FIXED = 0x140C; | |
37 } | |
38 | |
39 gl.vertexAttribPointer(0, 3, gl.FLOAT, 0, 0, 12); | |
40 glErrorShouldBe(gl, gl.INVALID_OPERATION, | |
41 "vertexAttribPointer should fail if no buffer is bound"); | |
42 | |
43 var vertexObject = gl.createBuffer(); | |
44 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
45 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(0), gl.STATIC_DRAW); | |
46 | |
47 gl.vertexAttribPointer(0, 1, gl.INT, 0, 0, 0); | |
48 glErrorShouldBe(gl, gl.INVALID_ENUM, | |
49 "vertexAttribPointer should not support INT"); | |
50 gl.vertexAttribPointer(0, 1, gl.UNSIGNED_INT, 0, 0, 0); | |
51 glErrorShouldBe(gl, gl.INVALID_ENUM, | |
52 "vertexAttribPointer should not support UNSIGNED_INT"); | |
53 gl.vertexAttribPointer(0, 1, gl.FIXED, 0, 0, 0); | |
54 glErrorShouldBe(gl, gl.INVALID_ENUM, | |
55 "vertexAttribPointer should not support FIXED"); | |
56 | |
57 function checkVertexAttribPointer( | |
58 gl, err, reason, size, type, normalize, stride, offset) { | |
59 gl.vertexAttribPointer(0, size, type, normalize, stride, offset); | |
60 glErrorShouldBe(gl, err, | |
61 "gl.vertexAttribPointer(0, " + size + | |
62 ", gl." + wtu.glEnumToString(gl, type) + | |
63 ", " + normalize + | |
64 ", " + stride + | |
65 ", " + offset + | |
66 ") should " + (err == gl.NO_ERROR ? "succeed " : "fail ") + reason); | |
67 } | |
68 | |
69 var types = [ | |
70 { type:gl.BYTE, bytesPerComponent: 1 }, | |
71 { type:gl.UNSIGNED_BYTE, bytesPerComponent: 1 }, | |
72 { type:gl.SHORT, bytesPerComponent: 2 }, | |
73 { type:gl.UNSIGNED_SHORT, bytesPerComponent: 2 }, | |
74 { type:gl.FLOAT, bytesPerComponent: 4 }, | |
75 ]; | |
76 | |
77 for (var ii = 0; ii < types.length; ++ii) { | |
78 var info = types[ii]; | |
79 debug(""); | |
80 for (var size = 1; size <= 4; ++size) { | |
81 debug(""); | |
82 debug("checking: " + wtu.glEnumToString(gl, info.type) + " with size " + s
ize); | |
83 var bytesPerElement = size * info.bytesPerComponent; | |
84 var offsetSet; | |
85 if (info.bytesPerComponent > 1) | |
86 offsetSet = [0, info.bytesPerComponent - 1]; | |
87 else | |
88 offsetSet = [0]; | |
89 for (var jj = 0; jj < offsetSet.length; ++jj) { | |
90 var offset = offsetSet[jj]; | |
91 var strideSet; | |
92 if (bytesPerElement > 1) | |
93 strideSet = [0, bytesPerElement - 1, bytesPerElement]; | |
94 else | |
95 strideSet = [0, bytesPerElement]; | |
96 for (var kk = 0; kk < strideSet.length; ++kk) { | |
97 var stride = strideSet[kk]; | |
98 var err = gl.NO_ERROR; | |
99 var reason = "" | |
100 if (offset != 0) { | |
101 reason = "because offset is bad"; | |
102 err = gl.INVALID_OPERATION; | |
103 } | |
104 if (stride % info.bytesPerComponent != 0) { | |
105 reason = "because stride is bad"; | |
106 err = gl.INVALID_OPERATION; | |
107 } | |
108 checkVertexAttribPointer( | |
109 gl, err, reason, size, info.type, false, stride, offset); | |
110 } | |
111 var stride = Math.floor(255 / info.bytesPerComponent) * info.bytesPerCom
ponent; | |
112 | |
113 if (offset == 0) { | |
114 checkVertexAttribPointer( | |
115 gl, gl.NO_ERROR, "at stride limit", | |
116 size, info.type, false, stride, offset); | |
117 checkVertexAttribPointer( | |
118 gl, gl.INVALID_VALUE, "over stride limit", | |
119 size, info.type, false, | |
120 stride + info.bytesPerComponent, offset); | |
121 } | |
122 } | |
123 } | |
124 } | |
125 } | |
126 | |
127 debug(""); | |
128 | |
129 </script> | |
130 | |
131 <script> | |
132 </script> | |
133 | |
134 </body> | |
135 </html> | |
OLD | NEW |