Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: third_party/webgl/sdk/tests/conformance/textures/gl-pixelstorei.html

Issue 9373009: Check in webgl conformance tests r16844 from khronos. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 <!--
2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file.
5 -->
6 <!DOCTYPE html>
7 <html>
8 <head>
9 <meta charset="utf-8">
10 <title>WebGL pixelStorei Test</title>
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
12 <script src="../../resources/js-test-pre.js"></script>
13 <script src="../resources/webgl-test.js"> </script>
14 <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></s cript>
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;
28 }
29 </script>
30
31 <script id="fshader" type="x-shader/x-fragment">
32 void main() {
33 gl_FragColor = vec4(1.0,0.0,0.0,1.0);
34 }
35 </script>
36
37 <script>
38 function fail(x,y, name, buf, shouldBe) {
39 var i = (y*50+x) * 4;
40 var reason = "pixel in "+name+" at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+"," +buf[i+2]+","+buf[i+3]+"), should be "+shouldBe;
41 testFailed(reason);
42 }
43
44 function pass(name) {
45 testPassed("drawing is correct in " + name);
46 }
47
48 function init() {
49 description("This test checks that drawImage and readPixels are not effected b y gl.Pixelstorei(gl.PACK_ALIGNMENT) and visa versa");
50
51 debug("There should be 5 red triangles on 5 black squares above");
52 debug("");
53
54 var canvas3d = document.getElementById("example");
55 gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ] , 1);
56
57 var vertexObject = gl.createBuffer();
58 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
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);
60 gl.enableVertexAttribArray(0);
61 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
62
63 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
64 gl.drawArrays(gl.TRIANGLES, 0, 3);
65
66
67 function checkData(buf, name) {
68 // Test several locations
69 // First line should be all black
70 for (var i = 0; i < 50; ++i) {
71 if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i*4+3] != 2 55) {
72 fail(i, 0, name, buf, "(0,0,0,255)");
73 return;
74 }
75 }
76
77 // Line 25 should be red for at least 6 red pixels starting 22 pixels in
78 var offset = (25*50+22) * 4;
79 for (var i = 0; i < 6; ++i) {
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) {
81 fail(22 + i, 25, name, buf, "(255,0,0,255)");
82 return;
83 }
84 }
85
86 // Last line should be all black
87 offset = (49*50) * 4;
88 for (var i = 0; i < 50; ++i) {
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) {
90 fail(i, 49, name, buf, "(0,0,0,255)");
91 return;
92 }
93 }
94
95 pass(name);
96 }
97
98 function checkColors() {
99 var buf = new Uint8Array(50 * 50 * 4);
100 gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf);
101 checkData(buf, "3d context");
102 var imgData = ctx2d.getImageData(0, 0, 50, 50);
103 checkData(imgData.data, "2d context");
104 }
105
106 var table = [1, 2, 4, 8];
107 for (var ii = 0; ii < table.length; ++ii) {
108 gl.pixelStorei(gl.PACK_ALIGNMENT, table[ii]);
109 ctx2d = document.getElementById("2d0" + ii).getContext("2d");
110 ctx2d.globalCompositeOperation = 'copy';
111 ctx2d.drawImage(canvas3d, 0, 0);
112 checkColors();
113 assertMsg(gl.getParameter(gl.PACK_ALIGNMENT) == table[ii],
114 "PACK_ALIGNMENT is " + table[ii]);
115 }
116 }
117
118 init();
119 successfullyParsed = true;
120 </script>
121 <script src="../../resources/js-test-post.js"></script>
122
123 </body>
124 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698