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

Powered by Google App Engine
This is Rietveld 408576698