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 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
12 <script src=
"../../js/js-test-pre.js"></script>
13 <script src=
"../../js/webgl-test-utils.js"></script>
14 <script id='vshader' type='x-shader/x-vertex'
>#version
300 es
15 layout(location=
0) in ivec2 p;
16 layout(location=
1) in ivec4 a;
19 gl_Position = vec4(p.x + a.x + a.y + a.z + a.w, p.y,
0.0,
10.0);
22 <script id='vshader_unsigned' type='x-shader/x-vertex'
>#version
300 es
23 layout(location=
0) in ivec2 p;
24 layout(location=
1) in uvec4 a;
27 gl_Position = vec4(p.x + int(a.x + a.y + a.z + a.w), p.y,
0.0,
10.0);
30 <script id='fshader' type='x-shader/x-fragment'
>#version
300 es
31 precision mediump float;
32 layout(location=
0) out vec4 oColor;
35 oColor = vec4(
1.0,
0.0,
0.0,
1.0);
40 function checkRedPortion(gl
, w
, low
, high
) {
41 var buf
= new Uint8Array(w
* w
* 4);
42 gl
.readPixels(0, 0, w
, w
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, buf
);
45 if (buf
[i
* 4 + 0] == 255 && buf
[i
* 4 + 1] == 0 && buf
[i
* 4 + 2] == 0 && buf
[i
* 4 + 3] == 255) {
49 return low
<= i
&& i
<= high
;
53 var wtu
= WebGLTestUtils
;
54 var gl
= wtu
.create3DContext('testbed', { preserveDrawingBuffer
: true }, 2);
56 testFailed('could not create context');
59 var program
= wtu
.setupProgram(gl
, ['vshader', 'fshader']);
60 var program_unsigned
= wtu
.setupProgram(gl
, ['vshader_unsigned', 'fshader']);
62 gl
.enableVertexAttribArray(0);
63 var pos
= gl
.createBuffer();
64 gl
.bindBuffer(gl
.ARRAY_BUFFER
, pos
);
65 gl
.bufferData(gl
.ARRAY_BUFFER
, new Int32Array([-10, -10, 10, -10, -10, 10, 10, 10]), gl
.STATIC_DRAW
);
67 gl
.vertexAttribIPointer(0, 2, gl
.INT
, 4 * 2, 0);
69 debug('Test vertexAttribI4[ui][v] by setting different combinations that add up to 15 and use that when rendering.');
70 var vals
= [[2, -3, 6, 10], [1, 3, 1, 10], [-10, 3, 2, 20], [5, 6, 2, 2]];
71 var tests
= ['vertexAttribI4i', 'vertexAttribI4ui', 'vertexAttribI4iv', 'vertexAttribI4uiv'];
73 for (var ii
= 0; ii
< 4; ++ii
) {
75 gl
.useProgram(program
);
77 gl
.useProgram(program_unsigned
);
79 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
81 gl
[tests
[ii
]](1, vals
[ii
][0], vals
[ii
][1], vals
[ii
][2], vals
[ii
][3]);
83 gl
[tests
[ii
]](1, vals
[ii
]);
85 gl
.drawArrays(gl
.TRIANGLE_STRIP
, 0, 4);
87 if (checkRedPortion(gl
, 50, 50 * 0.7, 50 * 0.8)) {
88 testPassed('Attribute of ' + tests
[ii
] + ' was set correctly');
90 testFailed('Attribute of ' + tests
[ii
] + ' was not set correctly');
97 <canvas id=
"testbed" width=
"50" height=
"50"></canvas>
98 <div id=
"description"></div>
99 <div id=
"console"></div>
102 description('Verify that using constant attributes for vertexAttribI* works.');
104 var successfullyParsed
= true;
106 <script src=
"../../js/js-test-post.js"></script>