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 pixelStorei Test
</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 <canvas id=
"example" width=
"50" height=
"50"></canvas>
18 <canvas id=
"2d00" width=
"50" height=
"50"></canvas>
19 <canvas id=
"2d01" width=
"50" height=
"50"></canvas>
20 <canvas id=
"2d02" width=
"50" height=
"50"></canvas>
21 <canvas id=
"2d03" width=
"50" height=
"50"></canvas>
22 <div id=
"description"></div>
23 <div id=
"console"></div>
24 <script id=
"vshader" type=
"x-shader/x-vertex">
25 attribute vec4 vPosition;
27 gl_Position = vPosition;
31 <script id=
"fshader" type=
"x-shader/x-fragment">
33 gl_FragColor = vec4(
1.0,
0.0,
0.0,
1.0);
40 description("This test checks that drawImage and readPixels are not effected by gl.Pixelstorei(gl.PACK_ALIGNMENT) and visa versa");
42 debug("There should be 5 red triangles on 5 black squares above");
45 var wtu
= WebGLTestUtils
;
46 var canvas3d
= document
.getElementById("example");
47 var gl
= wtu
.create3DContext("example");
48 var program
= wtu
.setupProgram(gl
, ["vshader", "fshader"], ["vPosition"]);
50 var vertexObject
= gl
.createBuffer();
51 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
52 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl
.STATIC_DRAW
);
53 gl
.enableVertexAttribArray(0);
54 gl
.vertexAttribPointer(0, 3, gl
.FLOAT
, false, 0, 0);
56 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
57 gl
.drawArrays(gl
.TRIANGLES
, 0, 3);
59 function checkData(ctx
, name
) {
60 // Test several locations
61 // First line should be all black
62 wtu
.checkCanvasRect(ctx
, 0, 0, 50, 1, [0, 0, 0, 0]);
64 // Line 25 should be red for at least 6 red pixels starting 22 pixels in
65 wtu
.checkCanvasRect(ctx
, 22, 25, 6, 1, [255, 0, 0, 255]);
67 // Last line should be all black
68 wtu
.checkCanvasRect(ctx
, 0, 49, 50, 1, [0, 0, 0, 0]);
73 function checkColors() {
74 checkData(gl
, "3d context");
75 checkData(ctx2d
, "2d context");
78 var table
= [1, 2, 4, 8];
79 for (var ii
= 0; ii
< table
.length
; ++ii
) {
80 gl
.pixelStorei(gl
.PACK_ALIGNMENT
, table
[ii
]);
81 ctx2d
= document
.getElementById("2d0" + ii
).getContext("2d");
82 ctx2d
.globalCompositeOperation
= 'copy';
83 ctx2d
.drawImage(canvas3d
, 0, 0);
85 assertMsg(gl
.getParameter(gl
.PACK_ALIGNMENT
) == table
[ii
],
86 "PACK_ALIGNMENT is " + table
[ii
]);
91 var successfullyParsed
= true;
93 <script src=
"../../../js/js-test-post.js"></script>