Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / reading / fbo-remains-unchanged-after-read-pixels.html
blob00e8dcd9a03da1af414c07856370845c4aa861c7
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 <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 </head>
15 <body>
16 <div id="description"></div>
17 <div id="console"></div>
18 <canvas id="canvas" width="4" height="4"></canvas>
19 <script id="vshader" type="x-shader/x-vertex">
20 attribute vec3 a_pos;
21 attribute vec4 a_color;
22 varying vec4 v_color;
24 void main()
26 v_color = a_color;
27 gl_Position = vec4(a_pos.xyz, 1.0);
29 </script>
31 <script id="fshader" type="x-shader/x-fragment">
32 precision mediump float;
34 varying vec4 v_color;
36 void main()
38 gl_FragColor = v_color;
40 </script>
42 <script>
43 "use strict";
45 description("when antialias is enabled, verify default fbo pixels would not be changed between two readPixels without drawing operations");
46 var wtu = WebGLTestUtils;
47 var N = 4;
49 var vertices = new Float32Array([
50 1.0, 1.0, 0.0,
51 -1.0, -1.0, 0.0]);
52 var colors = new Uint8Array([
53 255, 0, 0, 255,
54 255, 0, 0, 255]);
56 var canvas = document.getElementById('canvas');
57 var gl = wtu.create3DContext(canvas, {antialias: true});
59 if (!gl) {
60 testFailed("context does not exist");
61 } else {
62 testPassed("context exists");
64 var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["a_pos", "a_color"]);
65 gl.clearColor(0, 0, 0, 1);
66 gl.clear(gl.COLOR_BUFFER_BIT);
68 var colorOffset = vertices.byteLength;
69 var vbo = gl.createBuffer();
70 gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
71 gl.bufferData(gl.ARRAY_BUFFER, colorOffset + colors.byteLength, gl.STATIC_DRAW);
72 gl.bufferSubData(gl.ARRAY_BUFFER, 0, vertices);
73 gl.bufferSubData(gl.ARRAY_BUFFER, colorOffset, colors);
75 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
76 gl.enableVertexAttribArray(0);
77 gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 0, colorOffset);
78 gl.enableVertexAttribArray(1);
79 gl.drawArrays(gl.LINES, 0, vertices.length / 3);
81 var result_1 = new Uint8Array(N * N * 4);
82 var result_2 = new Uint8Array(N * N * 4);
83 gl.readPixels(0, 0, N, N, gl.RGBA, gl.UNSIGNED_BYTE, result_1);
84 gl.readPixels(0, 0, N, N, gl.RGBA, gl.UNSIGNED_BYTE, result_2);
85 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
87 var tolerance = 0;
88 var diff = new Uint8Array(N * N * 4);
89 var failed = wtu.comparePixels(result_1, result_2, tolerance, diff);
91 if (failed) {
92 testFailed("default fbo pixels had be changed between two readPixels without drawing operations");
93 } else {
94 testPassed("default fbo pixels had not be changed between two readPixels without drawing operations.");
97 gl.bindBuffer(gl.ARRAY_BUFFER, null);
98 gl.deleteBuffer(vbo);
101 var successfullyParsed = true;
102 </script>
103 <script src="../../js/js-test-post.js"></script>
104 </body>
105 </html>