1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
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>
13 <div id=
"description"></div>
14 <div id=
"console"></div>
15 <canvas id=
"canvas" width=
"2" height=
"2"> </canvas>
17 description("This test checks vertexAttribPointer behaviors in WebGL.");
20 debug("Canvas.getContext");
23 window
.internals
.settings
.setWebGLErrorsToConsoleEnabled(false);
25 var wtu
= WebGLTestUtils
;
26 var gl
= create3DContext(document
.getElementById("canvas"));
28 testFailed("context does not exist");
30 testPassed("context exists");
33 debug("Checking gl.vertexAttribPointer.");
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");
43 var vertexObject
= gl
.createBuffer();
44 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
45 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array(0), gl
.STATIC_DRAW
);
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");
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
) +
66 ") should " + (err
== gl
.NO_ERROR
? "succeed " : "fail ") + reason
);
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 },
77 for (var ii
= 0; ii
< types
.length
; ++ii
) {
80 for (var size
= 1; size
<= 4; ++size
) {
82 debug("checking: " + wtu
.glEnumToString(gl
, info
.type
) + " with size " + size
);
83 var bytesPerElement
= size
* info
.bytesPerComponent
;
85 if (info
.bytesPerComponent
> 1)
86 offsetSet
= [0, info
.bytesPerComponent
- 1];
89 for (var jj
= 0; jj
< offsetSet
.length
; ++jj
) {
90 var offset
= offsetSet
[jj
];
92 if (bytesPerElement
> 1)
93 strideSet
= [0, bytesPerElement
- 1, bytesPerElement
];
95 strideSet
= [0, bytesPerElement
];
96 for (var kk
= 0; kk
< strideSet
.length
; ++kk
) {
97 var stride
= strideSet
[kk
];
98 var err
= gl
.NO_ERROR
;
101 reason
= "because offset is bad";
102 err
= gl
.INVALID_OPERATION
;
104 if (stride
% info
.bytesPerComponent
!= 0) {
105 reason
= "because stride is bad";
106 err
= gl
.INVALID_OPERATION
;
108 checkVertexAttribPointer(
109 gl
, err
, reason
, size
, info
.type
, false, stride
, offset
);
111 var stride
= Math
.floor(255 / info
.bytesPerComponent
) * info
.bytesPerComponent
;
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
);