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 vertexAttribIPointer 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 vertexAttribIPointer behaviors in WebGL 2.");
25 debug("Canvas.getContext");
27 var wtu
= WebGLTestUtils
;
28 var gl
= wtu
.create3DContext("canvas", undefined, 2);
30 testFailed("context does not exist");
32 testPassed("context exists");
35 debug("Checking gl.vertexAttribIPointer.");
37 gl
.vertexAttribIPointer(0, 3, gl
.INT
, 0, 0);
38 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
39 "vertexAttribIPointer should succeed if no buffer is bound and offset is zero");
41 gl
.vertexAttribIPointer(0, 3, gl
.INT
, 0, 12);
42 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
43 "vertexAttribIPointer should fail if no buffer is bound and offset is non-zero");
45 var vertexObject
= gl
.createBuffer();
46 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
47 gl
.bufferData(gl
.ARRAY_BUFFER
, new Int32Array(0), gl
.STATIC_DRAW
);
49 gl
.vertexAttribIPointer(0, 1, gl
.FLOAT
, 0, 0);
50 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
51 "vertexAttribIPointer should not support FLOAT");
53 var checkVertexAttribIPointer = function(
54 gl
, err
, reason
, size
, type
, stride
, offset
) {
55 gl
.vertexAttribIPointer(0, size
, type
, stride
, offset
);
56 wtu
.glErrorShouldBe(gl
, err
,
57 "gl.vertexAttribIPointer(0, " + size
+
58 ", gl." + wtu
.glEnumToString(gl
, type
) +
61 ") should " + (err
== gl
.NO_ERROR
? "succeed " : "fail ") + reason
);
65 { type
:gl
.BYTE
, bytesPerComponent
: 1 },
66 { type
:gl
.UNSIGNED_BYTE
, bytesPerComponent
: 1 },
67 { type
:gl
.SHORT
, bytesPerComponent
: 2 },
68 { type
:gl
.UNSIGNED_SHORT
, bytesPerComponent
: 2 },
69 { type
:gl
.INT
, bytesPerComponent
: 4 },
70 { type
:gl
.UNSIGNED_INT
, bytesPerComponent
: 4 },
73 for (var ii
= 0; ii
< types
.length
; ++ii
) {
76 for (var size
= 1; size
<= 4; ++size
) {
78 debug("checking: " + wtu
.glEnumToString(gl
, info
.type
) + " with size " + size
);
79 var bytesPerElement
= size
* info
.bytesPerComponent
;
83 info
.bytesPerComponent
- 1,
84 info
.bytesPerComponent
,
85 info
.bytesPerComponent
+ 1,
86 info
.bytesPerComponent
* 2];
87 for (var jj
= 0; jj
< offsetSet
.length
; ++jj
) {
88 var offset
= offsetSet
[jj
];
89 for (var kk
= 0; kk
< offsetSet
.length
; ++kk
) {
90 var stride
= offsetSet
[kk
];
91 var err
= gl
.NO_ERROR
;
93 if (offset
% info
.bytesPerComponent
!= 0) {
94 reason
= "because offset is bad";
95 err
= gl
.INVALID_OPERATION
;
97 if (stride
% info
.bytesPerComponent
!= 0) {
98 reason
= "because stride is bad";
99 err
= gl
.INVALID_OPERATION
;
101 checkVertexAttribIPointer(
102 gl
, err
, reason
, size
, info
.type
, stride
, offset
);
104 var stride
= Math
.floor(255 / info
.bytesPerComponent
) * info
.bytesPerComponent
;
107 checkVertexAttribIPointer(
108 gl
, gl
.NO_ERROR
, "at stride limit",
109 size
, info
.type
, stride
, offset
);
110 checkVertexAttribIPointer(
111 gl
, gl
.INVALID_VALUE
, "over stride limit",
112 size
, info
.type
, stride
+ info
.bytesPerComponent
, offset
);
120 var successfullyParsed
= true;
123 <script src=
"../../js/js-test-post.js"></script>