2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL vertexAttribPointer Conformance Tests
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
19 <canvas id=
"canvas" width=
"2" height=
"2"> </canvas>
22 description("This test checks vertexAttribPointer behaviors in WebGL.");
25 debug("Canvas.getContext");
27 var wtu
= WebGLTestUtils
;
28 var gl
= wtu
.create3DContext("canvas");
30 testFailed("context does not exist");
32 testPassed("context exists");
35 debug("Checking gl.vertexAttribPointer.");
41 var vertexObject
= gl
.createBuffer();
42 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
43 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array(0), gl
.STATIC_DRAW
);
46 gl
.bindBuffer(gl
.ARRAY_BUFFER
, null);
47 gl
.vertexAttribPointer(0, 1, gl
.FLOAT
, false, 0, 4);
48 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
49 "vertexAttribPointer should fail if no buffer is bound and `offset` is non-zero.");
51 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
52 gl
.vertexAttribPointer(0, 1, gl
.FLOAT
, false, 0, 0);
53 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
);
55 gl
.bindBuffer(gl
.ARRAY_BUFFER
, null);
56 gl
.vertexAttribPointer(0, 1, gl
.FLOAT
, false, 0, 0);
57 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
58 "vertexAttribPointer should succeed if no buffer is bound and `offset` is zero.");
60 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
63 if (wtu
.getDefault3DContextVersion() < 2) {
64 gl
.vertexAttribPointer(0, 1, gl
.INT
, 0, 0, 0);
65 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
66 "vertexAttribPointer should not support INT");
67 gl
.vertexAttribPointer(0, 1, gl
.UNSIGNED_INT
, 0, 0, 0);
68 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
69 "vertexAttribPointer should not support UNSIGNED_INT");
71 gl
.vertexAttribPointer(0, 1, gl
.FIXED
, 0, 0, 0);
72 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
73 "vertexAttribPointer should not support FIXED");
75 var checkVertexAttribPointer = function(
76 gl
, err
, reason
, size
, type
, normalize
, stride
, offset
) {
77 gl
.vertexAttribPointer(0, size
, type
, normalize
, stride
, offset
);
78 var succeeded
= (err
== gl
.NO_ERROR
);
79 wtu
.glErrorShouldBe(gl
, err
,
80 "gl.vertexAttribPointer(0, " + size
+
81 ", gl." + wtu
.glEnumToString(gl
, type
) +
85 ") should " + (succeeded
? "succeed " : "fail ") + reason
);
87 shouldBe('gl.getVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_SIZE)', size
.toString());
88 shouldBe('gl.getVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_TYPE)', 'gl.' + wtu
.glEnumToString(gl
, type
));
89 shouldBe('gl.getVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED)', normalize
.toString());
90 shouldBe('gl.getVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_STRIDE)', stride
.toString());
91 shouldBe('gl.getVertexAttribOffset(0, gl.VERTEX_ATTRIB_ARRAY_POINTER)', offset
.toString());
96 { type
:gl
.BYTE
, bytesPerComponent
: 1 },
97 { type
:gl
.UNSIGNED_BYTE
, bytesPerComponent
: 1 },
98 { type
:gl
.SHORT
, bytesPerComponent
: 2 },
99 { type
:gl
.UNSIGNED_SHORT
, bytesPerComponent
: 2 },
100 { type
:gl
.FLOAT
, bytesPerComponent
: 4 },
103 if (wtu
.getDefault3DContextVersion() >= 2) {
105 { type
:gl
.INT
, bytesPerComponent
: 4 },
106 { type
:gl
.UNSIGNED_INT
, bytesPerComponent
: 4 },
107 { type
:gl
.HALF_FLOAT
, bytesPerComponent
: 2 },
108 { type
:gl
.INT_2_10_10_10_REV
, bytesPerComponent
: 4, minSize
: 4 },
109 { type
:gl
.UNSIGNED_INT_2_10_10_10_REV
, bytesPerComponent
: 4, minSize
: 4 },
113 for (var ii
= 0; ii
< types
.length
; ++ii
) {
114 var info
= types
[ii
];
116 for (var size
= 1; size
<= 4; ++size
) {
118 debug("checking: " + wtu
.glEnumToString(gl
, info
.type
) + " with size " + size
);
119 var bytesPerElement
= size
* info
.bytesPerComponent
;
123 info
.bytesPerComponent
- 1,
124 info
.bytesPerComponent
,
125 info
.bytesPerComponent
+ 1,
126 info
.bytesPerComponent
* 2];
127 for (var jj
= 0; jj
< offsetSet
.length
; ++jj
) {
128 var offset
= offsetSet
[jj
];
129 for (var kk
= 0; kk
< offsetSet
.length
; ++kk
) {
130 var stride
= offsetSet
[kk
];
131 var err
= gl
.NO_ERROR
;
133 if (offset
% info
.bytesPerComponent
!= 0) {
134 reason
= "because offset is bad";
135 err
= gl
.INVALID_OPERATION
;
137 if (stride
% info
.bytesPerComponent
!= 0) {
138 reason
= "because stride is bad";
139 err
= gl
.INVALID_OPERATION
;
141 if (size
< info
.minSize
) {
142 reason
= "because size < minSize";
143 err
= gl
.INVALID_OPERATION
;
145 checkVertexAttribPointer(
146 gl
, err
, reason
, size
, info
.type
, false, stride
, offset
);
148 var stride
= Math
.floor(255 / info
.bytesPerComponent
) * info
.bytesPerComponent
;
151 checkVertexAttribPointer(
152 gl
, size
< info
.minSize
? gl
.INVALID_OPERATION
: gl
.NO_ERROR
, "at stride limit",
153 size
, info
.type
, false, stride
, offset
);
154 checkVertexAttribPointer(
155 gl
, size
< info
.minSize
? [gl
.INVALID_OPERATION
, gl
.INVALID_VALUE
] : gl
.INVALID_VALUE
, "over stride limit",
156 size
, info
.type
, false,
157 stride
+ info
.bytesPerComponent
, offset
);
165 var successfullyParsed
= true;
168 <script src=
"../../js/js-test-post.js"></script>