Bug 1918529 - fix some subpixel misalignment issues with gfx.webrender.svg-filter...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / textures / misc / gl-pixelstorei.html
blob161a45271b6a7a53a3655c55e7786bb97571d323
1 <!--
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.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
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>
15 </head>
16 <body>
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;
26 void main() {
27 gl_Position = vPosition;
29 </script>
31 <script id="fshader" type="x-shader/x-fragment">
32 void main() {
33 gl_FragColor = vec4(1.0,0.0,0.0,1.0);
35 </script>
37 <script>
38 "use strict";
39 function init() {
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");
43 debug("");
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]);
71 var ctx2d;
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);
84 checkColors();
85 assertMsg(gl.getParameter(gl.PACK_ALIGNMENT) == table[ii],
86 "PACK_ALIGNMENT is " + table[ii]);
90 init();
91 var successfullyParsed = true;
92 </script>
93 <script src="../../../js/js-test-post.js"></script>
95 </body>
96 </html>