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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/canvas/drawingbuffer-static-canvas-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 Canvas Conformance Tests</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>
40 <div id="console"></div>
41 <canvas id="canvas" width="50" height="50"> </canvas>
42
43 <script id="vshader" type="x-shader/x-vertex">
44 attribute vec4 vPosition;
45 void main()
46 {
47 gl_Position = vPosition;
48 }
49 </script>
50
51 <script id="fshader" type="x-shader/x-fragment">
52 void main()
53 {
54 gl_FragColor = vec4(1.0,0.0,0.0,1.0);
55 }
56 </script>
57
58 <script>
59 function fail(x,y, buf, shouldBe)
60 {
61 var i = (y*50+x) * 4;
62 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+", "+buf[i+3]+"), should be "+shouldBe;
63 testFailed(reason);
64 }
65
66 function pass()
67 {
68 testPassed("drawing is correct");
69 }
70
71 function drawTriangleTest(gl)
72 {
73 gl.viewport(0, 0, 50, 50);
74 var vertexObject = gl.createBuffer();
75 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
76 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0 .5,0 ]), gl.STATIC_DRAW);
77 gl.enableVertexAttribArray(0);
78 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
79
80 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
81 gl.drawArrays(gl.TRIANGLES, 0, 3);
82
83 var buf = new Uint8Array(50 * 50 * 4);
84 gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf);
85
86 // Test several locations
87 // First line should be all black
88 for (var i = 0; i < 50; ++i) {
89 if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i*4+3] != 255 ) {
90 fail(i, 0, buf, "(0,0,0,255)");
91 return;
92 }
93 }
94 // Line 15 should be red for at least 10 red pixels starting 20 pixels in
95 var offset = (15*50+20) * 4;
96 for (var i = 0; i < 10; ++i) {
97 if (buf[offset+i*4] != 255 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) {
98 fail(20 + i, 15, buf, "(255,0,0,255)");
99 return;
100 }
101 }
102 // Last line should be all black
103 offset = (49*50) * 4;
104 for (var i = 0; i < 50; ++i) {
105 if (buf[offset+i*4] != 0 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) {
106 fail(i, 49, buf, "(0,0,0,255)");
107 return;
108 }
109 }
110 }
111
112 description("This test ensures WebGL implementations correctly implement drawing bufferWidth/Height with compositing.");
113
114 debug("");
115
116 var wtu = WebGLTestUtils;
117 var err;
118 var maxSize;
119 var gl = wtu.create3DContext("canvas");
120 if (!gl) {
121 testFailed("context does not exist");
122 } else {
123 testPassed("context exists");
124
125 program = createProgram(gl, "vshader", "fshader", ["vPosition"]);
126 shouldBeNonNull("program");
127 gl.useProgram(program);
128 gl.enable(gl.DEPTH_TEST);
129 gl.disable(gl.BLEND);
130 gl.clearColor(0, 0, 0, 1);
131 gl.clearDepth(1);
132 shouldBe('gl.getError()', 'gl.NO_ERROR');
133
134 debug("");
135 debug("Checking drawingBufferWidth/drawingBufferHeight");
136
137 // Check that a canvas with no width or height is 300x150 pixels
138 shouldBe('gl.drawingBufferWidth', 'gl.canvas.width');
139 shouldBe('gl.drawingBufferHeight', 'gl.canvas.height');
140
141 // Check that changing the canvas size to something too large falls back to re asonable values.
142 maxSize = gl.getParameter(gl.MAX_VIEWPORT_DIMS);
143 shouldBeTrue('maxSize[0] > 0');
144 shouldBeTrue('maxSize[1] > 0');
145
146 // debug("MAX_VIEWPORT_DIMS = " + maxSize[0] + "x" + maxSize[1]);
147 gl.canvas.width = maxSize[0] * 4;
148 gl.canvas.height = maxSize[1] * 4;
149 shouldBeTrue('gl.drawingBufferWidth > 0');
150 shouldBeTrue('gl.drawingBufferHeight > 0');
151 shouldBeTrue('gl.drawingBufferWidth <= maxSize[0]');
152 shouldBeTrue('gl.drawingBufferHeight <= maxSize[1]');
153 shouldBe('gl.getError()', 'gl.NO_ERROR');
154
155 debug("");
156 debug("Checking scaling up then back down to 50/50, drawing still works.");
157 gl.canvas.width = 50;
158 gl.canvas.height = 50;
159 shouldBeTrue('gl.drawingBufferWidth == 50');
160 shouldBeTrue('gl.drawingBufferHeight == 50');
161 shouldBe('gl.getError()', 'gl.NO_ERROR');
162 drawTriangleTest(gl);
163 shouldBe('gl.getError()', 'gl.NO_ERROR');
164 }
165 debug("")
166 successfullyParsed = true;
167 </script>
168 <script src="../../resources/js-test-post.js"></script>
169 </body>
170 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698