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