Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | <!-- |
michael@0 | 2 | Copyright (c) 2011 The Chromium Authors. All rights reserved. |
michael@0 | 3 | Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | found in the LICENSE file. |
michael@0 | 5 | --> |
michael@0 | 6 | <!DOCTYPE html> |
michael@0 | 7 | <html> |
michael@0 | 8 | <head> |
michael@0 | 9 | <meta charset="utf-8"> |
michael@0 | 10 | <title>WebGL pixelStorei Test</title> |
michael@0 | 11 | <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
michael@0 | 12 | <script src="../../resources/js-test-pre.js"></script> |
michael@0 | 13 | <script src="../resources/webgl-test.js"> </script> |
michael@0 | 14 | <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></script> |
michael@0 | 15 | </head> |
michael@0 | 16 | <body> |
michael@0 | 17 | <canvas id="example" width="50" height="50"></canvas> |
michael@0 | 18 | <canvas id="2d00" width="50" height="50"></canvas> |
michael@0 | 19 | <canvas id="2d01" width="50" height="50"></canvas> |
michael@0 | 20 | <canvas id="2d02" width="50" height="50"></canvas> |
michael@0 | 21 | <canvas id="2d03" width="50" height="50"></canvas> |
michael@0 | 22 | <div id="description"></div> |
michael@0 | 23 | <div id="console"></div> |
michael@0 | 24 | <script id="vshader" type="x-shader/x-vertex"> |
michael@0 | 25 | attribute vec4 vPosition; |
michael@0 | 26 | void main() { |
michael@0 | 27 | gl_Position = vPosition; |
michael@0 | 28 | } |
michael@0 | 29 | </script> |
michael@0 | 30 | |
michael@0 | 31 | <script id="fshader" type="x-shader/x-fragment"> |
michael@0 | 32 | void main() { |
michael@0 | 33 | gl_FragColor = vec4(1.0,0.0,0.0,1.0); |
michael@0 | 34 | } |
michael@0 | 35 | </script> |
michael@0 | 36 | |
michael@0 | 37 | <script> |
michael@0 | 38 | function fail(x,y, name, buf, shouldBe) { |
michael@0 | 39 | var i = (y*50+x) * 4; |
michael@0 | 40 | var reason = "pixel in "+name+" at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe; |
michael@0 | 41 | testFailed(reason); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function pass(name) { |
michael@0 | 45 | testPassed("drawing is correct in " + name); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function init() { |
michael@0 | 49 | description("This test checks that drawImage and readPixels are not effected by gl.Pixelstorei(gl.PACK_ALIGNMENT) and visa versa"); |
michael@0 | 50 | |
michael@0 | 51 | debug("There should be 5 red triangles on 5 black squares above"); |
michael@0 | 52 | debug(""); |
michael@0 | 53 | |
michael@0 | 54 | var canvas3d = document.getElementById("example"); |
michael@0 | 55 | gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1); |
michael@0 | 56 | |
michael@0 | 57 | var vertexObject = gl.createBuffer(); |
michael@0 | 58 | gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
michael@0 | 59 | gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW); |
michael@0 | 60 | gl.enableVertexAttribArray(0); |
michael@0 | 61 | gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); |
michael@0 | 62 | |
michael@0 | 63 | gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
michael@0 | 64 | gl.drawArrays(gl.TRIANGLES, 0, 3); |
michael@0 | 65 | |
michael@0 | 66 | |
michael@0 | 67 | function checkData(buf, name) { |
michael@0 | 68 | // Test several locations |
michael@0 | 69 | // First line should be all black |
michael@0 | 70 | for (var i = 0; i < 50; ++i) { |
michael@0 | 71 | if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i*4+3] != 255) { |
michael@0 | 72 | fail(i, 0, name, buf, "(0,0,0,255)"); |
michael@0 | 73 | return; |
michael@0 | 74 | } |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | // Line 25 should be red for at least 6 red pixels starting 22 pixels in |
michael@0 | 78 | var offset = (25*50+22) * 4; |
michael@0 | 79 | for (var i = 0; i < 6; ++i) { |
michael@0 | 80 | if (buf[offset+i*4] != 255 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) { |
michael@0 | 81 | fail(22 + i, 25, name, buf, "(255,0,0,255)"); |
michael@0 | 82 | return; |
michael@0 | 83 | } |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | // Last line should be all black |
michael@0 | 87 | offset = (49*50) * 4; |
michael@0 | 88 | for (var i = 0; i < 50; ++i) { |
michael@0 | 89 | if (buf[offset+i*4] != 0 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) { |
michael@0 | 90 | fail(i, 49, name, buf, "(0,0,0,255)"); |
michael@0 | 91 | return; |
michael@0 | 92 | } |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | pass(name); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | function checkColors() { |
michael@0 | 99 | var buf = new Uint8Array(50 * 50 * 4); |
michael@0 | 100 | gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
michael@0 | 101 | checkData(buf, "3d context"); |
michael@0 | 102 | var imgData = ctx2d.getImageData(0, 0, 50, 50); |
michael@0 | 103 | checkData(imgData.data, "2d context"); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | var table = [1, 2, 4, 8]; |
michael@0 | 107 | for (var ii = 0; ii < table.length; ++ii) { |
michael@0 | 108 | gl.pixelStorei(gl.PACK_ALIGNMENT, table[ii]); |
michael@0 | 109 | ctx2d = document.getElementById("2d0" + ii).getContext("2d"); |
michael@0 | 110 | ctx2d.globalCompositeOperation = 'copy'; |
michael@0 | 111 | ctx2d.drawImage(canvas3d, 0, 0); |
michael@0 | 112 | checkColors(); |
michael@0 | 113 | assertMsg(gl.getParameter(gl.PACK_ALIGNMENT) == table[ii], |
michael@0 | 114 | "PACK_ALIGNMENT is " + table[ii]); |
michael@0 | 115 | } |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | init(); |
michael@0 | 119 | successfullyParsed = true; |
michael@0 | 120 | </script> |
michael@0 | 121 | <script>finishTest();</script> |
michael@0 | 122 | |
michael@0 | 123 | </body> |
michael@0 | 124 | </html> |