fbo-remains-unchanged-after-read-pixels.html (2926B)
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 --> 6 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; 23 24 void main() 25 { 26 v_color = a_color; 27 gl_Position = vec4(a_pos.xyz, 1.0); 28 } 29 </script> 30 31 <script id="fshader" type="x-shader/x-fragment"> 32 precision mediump float; 33 34 varying vec4 v_color; 35 36 void main() 37 { 38 gl_FragColor = v_color; 39 } 40 </script> 41 42 <script> 43 "use strict"; 44 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; 48 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]); 55 56 var canvas = document.getElementById('canvas'); 57 var gl = wtu.create3DContext(canvas, {antialias: true}); 58 59 if (!gl) { 60 testFailed("context does not exist"); 61 } else { 62 testPassed("context exists"); 63 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); 67 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); 74 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); 80 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); 86 87 var tolerance = 0; 88 var diff = new Uint8Array(N * N * 4); 89 var failed = wtu.comparePixels(result_1, result_2, tolerance, diff); 90 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."); 95 } 96 97 gl.bindBuffer(gl.ARRAY_BUFFER, null); 98 gl.deleteBuffer(vbo); 99 } 100 101 var successfullyParsed = true; 102 </script> 103 <script src="../../js/js-test-post.js"></script> 104 </body> 105 </html>