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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/context/context-attributes-alpha-depth-stencil-antialias.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 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
33 <script src="../../resources/js-test-pre.js"></script>
34 <script src="../resources/webgl-test.js"></script>
35 <script id="vshader" type="x-shader/x-vertex">
36 attribute vec3 pos;
37 attribute vec4 colorIn;
38 varying vec4 color;
39
40 void main()
41 {
42 color = colorIn;
43 gl_Position = vec4(pos.xyz, 1.0);
44 }
45 </script>
46
47 <script id="fshader" type="x-shader/x-fragment">
48 precision mediump float;
49
50 varying vec4 color;
51
52 void main()
53 {
54 gl_FragColor = color;
55 }
56 </script>
57
58 <script>
59 var successfullyParsed = false;
60
61 // These four declarations need to be global for "shouldBe" to see them
62 var webGL = null;
63 var contextAttribs = null;
64 var pixel = [0, 0, 0, 1];
65 var correctColor = null;
66
67 function init()
68 {
69 if (window.initNonKhronosFramework) {
70 window.initNonKhronosFramework(true);
71 }
72
73 description('Verify WebGLContextAttributes are working as specified, includi ng alpha, depth, stencil, antialias, but not premultipliedAlpha');
74
75 runTest();
76 }
77
78 function getWebGL(canvasWidth, canvasHeight, contextAttribs, clearColor, clearDe pth, clearStencil)
79 {
80 var canvas = document.createElement("canvas");
81 if (!canvas)
82 return null;
83 canvas.width = canvasWidth;
84 canvas.height = canvasHeight;
85
86 var context = create3DContext(canvas, contextAttribs);
87 if (!context)
88 return null;
89
90 context.program = createProgram(context, "vshader", "fshader", ["pos", "colo rIn"]);
91 if (!context.program)
92 return null;
93
94 context.useProgram(context.program);
95
96 context.enable(context.DEPTH_TEST);
97 context.enable(context.STENCIL_TEST);
98 context.disable(context.BLEND);
99
100 context.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3 ]);
101 context.clearDepth(clearDepth);
102 context.clearStencil(clearStencil);
103 context.clear(context.COLOR_BUFFER_BIT | context.DEPTH_BUFFER_BIT | context. STENCIL_BUFFER_BIT);
104
105 return context;
106 }
107
108 function drawAndReadPixel(gl, vertices, colors, x, y)
109 {
110 var colorOffset = vertices.byteLength;
111
112 var vbo = gl.createBuffer();
113 gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
114 gl.bufferData(gl.ARRAY_BUFFER, colorOffset + colors.byteLength, gl.STATIC_DR AW);
115 gl.bufferSubData(gl.ARRAY_BUFFER, 0, vertices);
116 gl.bufferSubData(gl.ARRAY_BUFFER, colorOffset, colors);
117
118 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
119 gl.enableVertexAttribArray(0);
120 gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 0, colorOffset);
121 gl.enableVertexAttribArray(1);
122
123 gl.drawArrays(gl.TRIANGLES, 0, vertices.length / 3);
124
125 var buf = new Uint8Array(1 * 1 * 4);
126 gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
127 return buf;
128 }
129
130 function testAlpha(alpha)
131 {
132 debug("Testing alpha = " + alpha);
133 if (alpha)
134 shouldBeNonNull("webGL = getWebGL(1, 1, { alpha: true, depth: false, ste ncil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0)");
135 else
136 shouldBeNonNull("webGL = getWebGL(1, 1, { alpha: false, depth: false, st encil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0)");
137 shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
138 shouldBeTrue("contextAttribs.alpha == " + alpha);
139
140 var buf = new Uint8Array(1 * 1 * 4);
141 webGL.readPixels(0, 0, 1, 1, webGL.RGBA, webGL.UNSIGNED_BYTE, buf);
142 pixel[0] = buf[0];
143 pixel[1] = buf[1];
144 pixel[2] = buf[2];
145 pixel[3] = buf[3];
146 correctColor = (contextAttribs.alpha ? [0, 0, 0, 0] : [0, 0, 0, 255]);
147 shouldBe("pixel", "correctColor");
148 }
149
150 function testDepth(depth)
151 {
152 debug("Testing depth = " + depth);
153 if (depth)
154 shouldBeNonNull("webGL = getWebGL(1, 1, { stencil: false, antialias: fal se }, [ 0, 0, 0, 1 ], 1, 0)");
155 else
156 shouldBeNonNull("webGL = getWebGL(1, 1, { depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
157 shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
158
159 webGL.depthFunc(webGL.NEVER);
160
161 var vertices = new Float32Array([
162 1.0, 1.0, 0.0,
163 -1.0, 1.0, 0.0,
164 -1.0, -1.0, 0.0,
165 1.0, 1.0, 0.0,
166 -1.0, -1.0, 0.0,
167 1.0, -1.0, 0.0]);
168 var colors = new Uint8Array([
169 255, 0, 0, 255,
170 255, 0, 0, 255,
171 255, 0, 0, 255,
172 255, 0, 0, 255,
173 255, 0, 0, 255,
174 255, 0, 0, 255]);
175
176 var buf = drawAndReadPixel(webGL, vertices, colors, 0, 0);
177 pixel[0] = buf[0];
178 pixel[1] = buf[1];
179 pixel[2] = buf[2];
180 pixel[3] = buf[3];
181 correctColor = (contextAttribs.depth ? [0, 0, 0, 255] : [255, 0, 0, 255]);
182 shouldBe("pixel", "correctColor");
183 }
184
185 function testStencilAndDepth(stencil, depth)
186 {
187 debug("Testing stencil = " + stencil + ", depth = " + depth);
188 var creationString =
189 "webGL = getWebGL(1, 1, { depth: " + depth + ", stencil: " + stencil + " , antialias: false }, [ 0, 0, 0, 1 ], 1, 0)";
190 shouldBeNonNull(creationString);
191 shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
192 if (!stencil && contextAttribs.stencil) {
193 testFailed("WebGL implementation provided a stencil buffer when it shoul d not have");
194 }
195 if (!contextAttribs.stencil)
196 stencil = false;
197
198 webGL.depthFunc(webGL.ALWAYS);
199
200 webGL.stencilFunc(webGL.NEVER, 1, 1);
201 webGL.stencilOp(webGL.KEEP, webGL.KEEP, webGL.KEEP);
202
203 var vertices = new Float32Array([
204 1.0, 1.0, 0.0,
205 -1.0, 1.0, 0.0,
206 -1.0, -1.0, 0.0,
207 1.0, 1.0, 0.0,
208 -1.0, -1.0, 0.0,
209 1.0, -1.0, 0.0]);
210 var colors = new Uint8Array([
211 255, 0, 0, 255,
212 255, 0, 0, 255,
213 255, 0, 0, 255,
214 255, 0, 0, 255,
215 255, 0, 0, 255,
216 255, 0, 0, 255]);
217
218 var buf = drawAndReadPixel(webGL, vertices, colors, 0, 0);
219 pixel[0] = buf[0];
220 pixel[1] = buf[1];
221 pixel[2] = buf[2];
222 pixel[3] = buf[3];
223 correctColor = (stencil ? [0, 0, 0, 255] : [255, 0, 0, 255]);
224 shouldBe("pixel", "correctColor");
225 }
226
227 function testAntialias(antialias)
228 {
229 debug("Testing antialias = " + antialias);
230 if (antialias)
231 shouldBeNonNull("webGL = getWebGL(2, 2, { depth: false, stencil: false, alpha: false, antialias: true }, [ 0, 0, 0, 1 ], 1, 0)");
232 else
233 shouldBeNonNull("webGL = getWebGL(2, 2, { depth: false, stencil: false, alpha: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
234 shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
235
236 var vertices = new Float32Array([
237 1.0, 1.0, 0.0,
238 -1.0, 1.0, 0.0,
239 -1.0, -1.0, 0.0]);
240 var colors = new Uint8Array([
241 255, 0, 0, 255,
242 255, 0, 0, 255,
243 255, 0, 0, 255]);
244 var buf = drawAndReadPixel(webGL, vertices, colors, 0, 0);
245 pixel[0] = buf[0];
246 shouldBe("pixel[0] != 255 && pixel[0] != 0", "contextAttribs.antialias");
247 }
248
249 function runTest()
250 {
251
252 testAlpha(true);
253 testAlpha(false);
254 testDepth(true);
255 testDepth(false);
256 testStencilAndDepth(true, false);
257 testStencilAndDepth(false, false);
258 testStencilAndDepth(true, true);
259 testStencilAndDepth(false, true);
260 testAntialias(true);
261 testAntialias(false);
262
263 finishTest();
264 }
265
266 </script>
267 </head>
268 <body onload="init()">
269 <div id="description"></div>
270 <div id="console"></div>
271 </body>
272 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698