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'
>
18 gl_Position = vec4(p.x + a.x + a.y + a.z + a.w, p.y,
0.0,
1.0);
21 <script id='fshader' type='x-shader'
>
22 precision mediump float;
24 gl_FragColor = vec4(
1.0,
0.0,
0.0,
1.0);
29 function checkRedPortion(gl
, w
, low
, high
) {
30 var buf
= new Uint8Array(w
* w
* 4);
31 gl
.readPixels(0, 0, w
, w
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, buf
);
34 if (buf
[i
* 4 + 0] == 255 && buf
[i
* 4 + 1] == 0 && buf
[i
* 4 + 2] == 0 && buf
[i
* 4 + 3] == 255) {
38 return low
<= i
&& i
<= high
;
42 var wtu
= WebGLTestUtils
;
43 var gl
= wtu
.create3DContext('testbed', { preserveDrawingBuffer
: true });
45 testFailed('could not create context');
48 var program
= wtu
.setupProgram(gl
, ['vshader', 'fshader'], ['p', 'a'])
50 gl
.enableVertexAttribArray(gl
.p
);
51 var pos
= gl
.createBuffer();
55 gl
.bindBuffer(gl
.ARRAY_BUFFER
, pos
);
56 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl
.STATIC_DRAW
);
58 gl
.vertexAttribPointer(0, pos
.size
, pos
.type
, false, 0, 0);
60 debug('Test vertexAttrib[1..4]fv by setting different combinations that add up to 1.5 and use that when rendering.');
61 var vals
= [[0.5], [0.1,0.4], [0.2,-0.2,0.5], [-1.0,0.3,0.2,2.0]];
63 for (var j
= 0; j
< 4; ++j
) {
64 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
65 gl
['vertexAttrib' + (j
+1) + 'fv'](1, vals
[j
]);
66 gl
.drawArrays(gl
.TRIANGLE_STRIP
, 0, pos
.num
);
68 if (checkRedPortion(gl
, 50, 50 * 0.7, 50 * 0.8)) {
69 testPassed('Attribute of size ' + (j
+1) + ' was set correctly');
71 testFailed('Attribute of size ' + (j
+1) + ' was not set correctly');
78 <canvas id=
"testbed" width=
"50" height=
"50"></canvas>
79 <div id=
"description"></div>
80 <div id=
"console"></div>
83 description('Verify that using constant attributes works.');
85 var successfullyParsed
= true;
87 <script src=
"../../js/js-test-post.js"></script>