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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/context/premultiplyalpha-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>Test the WebGL premultipledAlpha context creation flag.</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 <div id="description"></div><div id="console"></div>
40 <script>
41 var wtu = WebGLTestUtils;
42
43 var tests = [
44 // If premultipledAlpha is true then
45 // [texture] [canvas] [dataURL]
46 // 32, 64, 128, 128 -> 64, 128, 255, 128 -> 64, 128, 255, 128
47 { creationAttributes: {},
48 sentColor: [32, 64, 128, 128],
49 expectedColor: [64, 128, 255, 128],
50 errorRange: 2,
51 imageFormat: "image/png"
52 },
53 // If premultipledAlpha is true then
54 // [texture] [canvas] [texture]
55 // 32, 64, 128, 128 -> 64, 128, 255, 128 -> 64, 128, 255, 128
56 { creationAttributes: {},
57 sentColor: [32, 64, 128, 128],
58 expectedColor: [64, 128, 255, 128],
59 errorRange: 2,
60 },
61 // If premultipledAlpha is false then
62 // [texture] [canvas] [dataURL]
63 // 255, 192, 128, 1 -> 255, 192, 128, 1 -> 255, 192, 128, 1
64 { creationAttributes: {premultipliedAlpha: false},
65 sentColor: [255, 192, 128, 1],
66 expectedColor: [255, 192, 128, 1],
67 errorRange: 0,
68 imageFormat: "image/png"
69 },
70 // If premultipledAlpha is false then
71 // [texture] [canvas] [texture]
72 // 255, 192, 128, 1 -> 255, 192, 128, 1 -> 255, 192, 128, 1
73 { creationAttributes: {premultipliedAlpha: false},
74 sentColor: [255, 192, 128, 1],
75 expectedColor: [255, 192, 128, 1],
76 errorRange: 0,
77 },
78 // If premultipledAlpha is false then
79 // [texture] [canvas] [dataURL]
80 // 255, 255, 255, 128 -> 255, 255, 255, 128 -> 128, 128, 128, 255
81 { creationAttributes: {premultipliedAlpha: false},
82 sentColor: [255, 255, 255, 128],
83 expectedColor: [128, 128, 128, 255],
84 errorRange: 2,
85 imageFormat: "image/jpeg"
86 },
87 // If premultipledAlpha is true then
88 // [texture] [canvas] [dataURL]
89 // 128, 128, 128, 128 -> 255, 255, 255, 128 -> 128, 128, 128, 255
90 { creationAttributes: {},
91 sentColor: [128, 128, 128, 128],
92 expectedColor: [128, 128, 128, 255],
93 errorRange: 2,
94 imageFormat: "image/jpeg"
95 }
96 ];
97
98 var g_count = 0;
99 var gl;
100 var canvas;
101 var premultipledAlpha;
102
103 description("Test the WebGL premultipledAlpha context creation flag.");
104 doNextTest();
105 function doNextTest() {
106 if (g_count < tests.length) {
107 var test = tests[g_count++];
108 canvas = document.createElement("canvas");
109 // Need to preserve drawing buffer to load it in a callback
110 test.creationAttributes.preserveDrawingBuffer = true;
111 gl = wtu.create3DContext(canvas, test.creationAttributes);
112 var premultipliedAlpha = test.creationAttributes.premultipliedAlpha != fals e;
113 debug("")
114 debug("testing: premultipliedAlpha: " + premultipliedAlpha + " imageFormat: " + test.imageFormat);
115
116 shouldBe('gl.getContextAttributes().premultipledAlpha', 'premultipledAlpha' );
117 shouldBeTrue('gl.getContextAttributes().preserveDrawingBuffer');
118
119 console.log(gl.getContextAttributes());
120 var program = wtu.setupTexturedQuad(gl);
121
122 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
123 var tex = gl.createTexture();
124 wtu.fillTexture(gl, tex, 2, 2, test.sentColor, 0);
125 var loc = gl.getUniformLocation(program, "tex");
126 gl.uniform1i(loc, 0);
127 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
128 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
129 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
130 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
131
132 wtu.drawQuad(gl);
133 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from drawing.");
134
135 function loadTexture() {
136 var pngTex = gl.createTexture();
137 // not needed as it's the default
138 // gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
139 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, false);
140 gl.bindTexture(gl.TEXTURE_2D, pngTex);
141 if (test.imageFormat) {
142 // create texture from image
143 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, th is);
144 } else {
145 // create texture from canvas
146 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, ca nvas);
147 }
148 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
149 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
150 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
151 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
152 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from creating copy. ");
153 wtu.drawQuad(gl);
154 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from 2nd drawing.") ;
155 wtu.checkCanvas(
156 gl, test.expectedColor,
157 "should draw with " + test.expectedColor, test.errorRange);
158
159 doNextTest();
160 }
161
162 if (test.imageFormat) {
163 // Load canvas into string using toDataURL
164 var imageUrl = canvas.toDataURL(test.imageFormat);
165 if (test.imageFormat != "image/png" &&
166 (imageUrl.indexOf("data:image/png,") == 0 ||
167 imageUrl.indexOf("data:image/png;") == 0)) {
168 debug("Image format " + test.imageFormat + " not supported; skipping") ;
169 setTimeout(doNextTest, 0);
170 } else {
171 // Load string into the texture
172 var input = document.createElement("img");
173 input.onload = loadTexture;
174 input.src = imageUrl;
175 }
176 } else {
177 // Load canvas into the texture asynchronously (to prevent unbounded sta ck consumption)
178 setTimeout(loadTexture, 0);
179 }
180 } else {
181 successfullyParsed = true;
182 finishTest();
183 }
184 }
185
186 </script>
187
188 </body>
189 </html>
190
191
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698