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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/reading/read-pixels-test.html

Issue 10399113: Roll webgl conformance tests to r17874: part 2, adding r17874 (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 8 years, 7 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
3 /*
4 ** Copyright (c) 2012 The Khronos Group Inc.
5 **
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
16 **
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
24 */
25
26 -->
27
28 <!DOCTYPE html>
29 <html>
30 <head>
31 <meta charset="utf-8">
32 <title>WebGL ReadPixels conformance test.</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/js-test-pre.js"></script>
35 <script src="../resources/webgl-test.js"> </script>
36 <script src="../resources/webgl-test-utils.js"> </script>
37 </head>
38 <body>
39 <canvas id="example" width="200" height="200" style="width: 20px; height: 20px"> </canvas>
40 <div id="description"></div>
41 <div id="console"></div>
42 <script>
43 description("Checks that ReadPixels works as expected.");
44
45 var wtu = WebGLTestUtils;
46 var canvas = document.getElementById("example");
47 var gl = create3DContext(canvas);
48
49 if (window.initNonKhronosFramework) {
50 window.initNonKhronosFramework(true);
51 }
52
53 var actual;
54 var expected;
55 var width = 2;
56 var height = 2;
57 var continueTestFunc = continueTestPart1;
58
59 gl.clearColor(1, 1, 1, 1);
60 gl.clear(gl.COLOR_BUFFER_BIT);
61
62 // Resize the canvas to 2x2. This is an attempt to get stuff in the backbuffer.
63 // that shouldn't be there.
64 canvas.addEventListener("webglcontextlost", function(e) { e.preventDefault(); }, false);
65 canvas.addEventListener("webglcontextrestored", continueTestAfterContextRestored , false);
66 canvas.width = width;
67 canvas.height = height;
68 if (gl.getError() != gl.CONTEXT_LOST_WEBGL) {
69 continueTestPart1();
70 }
71
72 function continueTestAfterContextRestored() {
73 window.gl = create3DContext(canvas);
74 var func = continueTestFunc;
75 window.continueTestFunc = function() { testFailed("should not be here"); };
76 func();
77 }
78
79 function continueTestPart1() {
80 gl.clearColor(0.5, 0.7, 1.0, 1);
81 gl.clear(gl.COLOR_BUFFER_BIT);
82
83 var innerColor = [0.5, 0.7, 1.0, 1];
84 var outerColor = [0, 0, 0, 0];
85
86 var tests = [
87 { msg: 'in range', checkColor: innerColor, x: 0, y: 0,
88 oneColor: innerColor, oneX: 0, oneY: 0},
89 { msg: 'off top left', checkColor: outerColor, x: -1, y: -1,
90 oneColor: innerColor, oneX: 1, oneY: 1},
91 { msg: 'off bottom right', checkColor: outerColor, x: 1, y: 1,
92 oneColor: innerColor, oneX: 0, oneY: 0},
93 { msg: 'completely off top ', checkColor: outerColor, x: 0, y: -2,
94 oneColor: outerColor, oneX: 0, oneY: 0},
95 { msg: 'completely off bottom', checkColor: outerColor, x: 0, y: 2,
96 oneColor: outerColor, oneX: 0, oneY: 0},
97 { msg: 'completely off left', checkColor: outerColor, x: -2, y: 0,
98 oneColor: outerColor, oneX: 0, oneY: 0},
99 { msg: 'completeley off right', checkColor: outerColor, x: 2, y: 0,
100 oneColor: outerColor, oneX: 0, oneY: 0}
101 ];
102
103 for (var tt = 0; tt < tests.length; ++tt) {
104 var test = tests[tt];
105 debug("");
106 debug("checking: " + test.msg);
107 checkBuffer(test.checkColor, test.x, test.y,
108 test.oneColor, test.oneX, test.oneY);
109 }
110
111 glErrorShouldBe(gl, gl.NO_ERROR, "there should be no GL errors");
112
113 function checkBuffer(checkColor, x, y, oneColor, oneX, oneY) {
114 var buf = new Uint8Array(width * height * 4);
115 gl.readPixels(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
116 for (var yy = 0; yy < height; ++yy) {
117 for (var xx = 0; xx < width; ++xx) {
118 var offset = (yy * width + xx) * 4;
119 var expectedColors = (oneX == xx && oneY == yy) ? oneColor : checkColor;
120 for (var cc = 0; cc < 4; ++cc) {
121 var expectedColor = expectedColors[cc] * 255;
122 var color = buf[offset + cc];
123 var diff = Math.abs(expectedColor - color);
124 assertMsg(diff < 3,
125 "color pixel at " + xx + ", " + yy + " should be about " + e xpectedColor);
126 }
127 }
128 }
129 }
130
131 var badFormats = [
132 {
133 format: gl.RGB,
134 type: gl.UNSIGNED_BYTE,
135 dest: new Uint8Array(3),
136 error: gl.INVALID_OPERATION
137 },
138 {
139 format: gl.RGB,
140 type: gl.UNSIGNED_SHORT_5_6_5,
141 dest: new Uint8Array(3),
142 error: gl.INVALID_OPERATION
143 },
144 {
145 format: gl.RGBA,
146 type: gl.UNSIGNED_SHORT_5_5_5_1,
147 dest: new Uint16Array(1),
148 error: gl.INVALID_OPERATION
149 },
150 {
151 format: gl.RGBA,
152 type: gl.UNSIGNED_SHORT_4_4_4_4,
153 dest: new Uint16Array(1),
154 error: gl.INVALID_OPERATION
155 },
156 {
157 format: gl.ALPHA,
158 type: gl.UNSIGNED_BYTE,
159 dest: new Uint8Array(1),
160 error: gl.INVALID_OPERATION
161 },
162 {
163 format: gl.LUMINANCE,
164 type: gl.UNSIGNED_BYTE,
165 dest: new Uint8Array(1),
166 error: gl.INVALID_ENUM
167 },
168 {
169 format: gl.LUMINANCE_ALPHA,
170 type: gl.UNSIGNED_BYTE,
171 dest: new Uint8Array(2),
172 error: gl.INVALID_ENUM
173 }
174 ];
175 debug("");
176 debug("check disallowed formats");
177 for (var tt = 0; tt < badFormats.length; ++ tt) {
178 var info = badFormats[tt]
179 var format = info.format;
180 var type = info.type;
181 var dest = info.dest;
182 var error = info.error;
183 gl.readPixels(0, 0, 1, 1, format, type, dest);
184 // note that the GL error is INVALID_OPERATION if both format and type are i nvalid, but
185 // INVALID_ENUM if only one is.
186 glErrorShouldBe(
187 gl, error,
188 "Should not be able to read as " + wtu.glEnumToString(gl, format) +
189 " / " + wtu.glEnumToString(gl, type));
190 }
191
192 debug("");
193 debug("check reading with lots of drawing");
194 continueTestFunc = continueTestPart2;
195 width = 1024;
196 height = 1024;
197 canvas.width = width;
198 canvas.height = height;
199 if (gl.getError() != gl.CONTEXT_LOST_WEBGL) {
200 continueTestPart2();
201 }
202 }
203
204 function continueTestPart2() {
205 gl.viewport(0, 0, 1024, 1024);
206 var program = wtu.setupTexturedQuad(gl);
207 var loc = gl.getUniformLocation(program, "tex");
208 gl.disable(gl.BLEND);
209 gl.disable(gl.DEPTH_TEST);
210 var colors = [[255, 0, 0, 255], [0, 255, 0, 255], [0, 0, 255, 255]];
211 var textures = [];
212 var results = [];
213 for (var ii = 0; ii < colors.length; ++ii) {
214 gl.activeTexture(gl.TEXTURE0 + ii);
215 var tex = gl.createTexture();
216 wtu.fillTexture(gl, tex, 1, 1, colors[ii]);
217 textures.push(tex);
218 }
219 for (var ii = 0; ii < colors.length; ++ii) {
220 for (var jj = 0; jj < 300 + ii + 1; ++jj) {
221 gl.uniform1i(loc, jj % 3);
222 gl.drawArrays(gl.TRIANGLES, 0, 6);
223 }
224 var buf = new Uint8Array(4);
225 gl.readPixels(512, 512, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
226 results.push(buf);
227 for (var kk = 0; kk < 99; ++kk) {
228 gl.uniform1i(loc, (jj + kk) % 3);
229 gl.drawArrays(gl.TRIANGLES, 0, 6);
230 }
231 }
232 for (var ii = 0; ii < colors.length; ++ii) {
233 var buf = results[ii];
234 var color = colors[ii];
235 actual = [buf[0], buf[1], buf[2], buf[3]];
236 expected = [color[0], color[1], color[2], color[3]];
237 shouldBe("actual", "expected");
238 }
239 glErrorShouldBe(gl, gl.NO_ERROR, "there should be no GL errors");
240
241 debug("");
242 finishTest();
243 }
244 </script>
245 </body>
246 </html>
247
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698