OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 Use of this source code is governed by a BSD-style license that can be | |
4 found in the LICENSE file. | |
5 --> | |
6 <!DOCTYPE html> | |
7 <html> | |
8 <head> | |
9 <meta charset="utf-8"> | |
10 <title>WebGL Canvas Conformance Tests</title> | |
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/> | |
12 <script src="../../resources/js-test-pre.js"></script> | |
13 <script src="../resources/webgl-test.js"></script> | |
14 <script src="../resources/webgl-test-utils.js"></script> | |
15 </head> | |
16 <body> | |
17 <div id="description"></div> | |
18 <div id="console"></div> | |
19 <canvas id="canvas" width="50" height="50"> </canvas> | |
20 | |
21 <script id="vshader" type="x-shader/x-vertex"> | |
22 attribute vec4 vPosition; | |
23 void main() | |
24 { | |
25 gl_Position = vPosition; | |
26 } | |
27 </script> | |
28 | |
29 <script id="fshader" type="x-shader/x-fragment"> | |
30 void main() | |
31 { | |
32 gl_FragColor = vec4(1.0,0.0,0.0,1.0); | |
33 } | |
34 </script> | |
35 | |
36 <script> | |
37 function fail(x,y, buf, shouldBe) | |
38 { | |
39 var i = (y*50+x) * 4; | |
40 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+",
"+buf[i+3]+"), should be "+shouldBe; | |
41 testFailed(reason); | |
42 } | |
43 | |
44 function pass() | |
45 { | |
46 testPassed("drawing is correct"); | |
47 } | |
48 | |
49 function drawTriangleTest(gl) | |
50 { | |
51 gl.viewport(0, 0, 50, 50); | |
52 var vertexObject = gl.createBuffer(); | |
53 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
54 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0
.5,0 ]), gl.STATIC_DRAW); | |
55 gl.enableVertexAttribArray(0); | |
56 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); | |
57 | |
58 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
59 gl.drawArrays(gl.TRIANGLES, 0, 3); | |
60 | |
61 var buf = new Uint8Array(50 * 50 * 4); | |
62 gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf); | |
63 | |
64 // Test several locations | |
65 // First line should be all black | |
66 for (var i = 0; i < 50; ++i) { | |
67 if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i*4+3] != 255
) { | |
68 fail(i, 0, buf, "(0,0,0,255)"); | |
69 return; | |
70 } | |
71 } | |
72 // Line 15 should be red for at least 10 red pixels starting 20 pixels in | |
73 var offset = (15*50+20) * 4; | |
74 for (var i = 0; i < 10; ++i) { | |
75 if (buf[offset+i*4] != 255 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] !=
0 || buf[offset+i*4+3] != 255) { | |
76 fail(20 + i, 15, buf, "(255,0,0,255)"); | |
77 return; | |
78 } | |
79 } | |
80 // Last line should be all black | |
81 offset = (49*50) * 4; | |
82 for (var i = 0; i < 50; ++i) { | |
83 if (buf[offset+i*4] != 0 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0
|| buf[offset+i*4+3] != 255) { | |
84 fail(i, 49, buf, "(0,0,0,255)"); | |
85 return; | |
86 } | |
87 } | |
88 } | |
89 | |
90 description("This test ensures WebGL implementations correctly implement drawing
bufferWidth/Height with compositing."); | |
91 | |
92 debug(""); | |
93 | |
94 var wtu = WebGLTestUtils; | |
95 var err; | |
96 var maxSize; | |
97 var canvas = document.getElementById("canvas"); | |
98 var gl = wtu.create3DContext(canvas); | |
99 if (!gl) { | |
100 testFailed("context does not exist"); | |
101 } else { | |
102 testPassed("context exists"); | |
103 | |
104 gl.program = createProgram(gl, "vshader", "fshader", ["vPosition"]); | |
105 shouldBeNonNull(gl.program); | |
106 gl.useProgram(gl.program); | |
107 gl.enable(gl.DEPTH_TEST); | |
108 gl.disable(gl.BLEND); | |
109 gl.clearColor(0, 0, 0, 1); | |
110 gl.clearDepth(1); | |
111 shouldBe('gl.getError()', 'gl.NO_ERROR'); | |
112 | |
113 debug(""); | |
114 debug("Checking drawingBufferWidth/drawingBufferHeight"); | |
115 | |
116 // Check that a canvas with no width or height is 300x150 pixels | |
117 shouldBe('gl.drawingBufferWidth', 'canvas.width'); | |
118 shouldBe('gl.drawingBufferHeight', 'canvas.height'); | |
119 | |
120 // Check that changing the canvas size to something too large falls back to re
asonable values. | |
121 maxSize = gl.getParameter(gl.MAX_VIEWPORT_DIMS); | |
122 shouldBeTrue('maxSize[0] > 0'); | |
123 shouldBeTrue('maxSize[1] > 0'); | |
124 | |
125 // debug("MAX_VIEWPORT_DIMS = " + maxSize[0] + "x" + maxSize[1]); | |
126 canvas.width = maxSize[0] * 4; | |
127 canvas.height = maxSize[1] * 4; | |
128 shouldBeTrue('gl.drawingBufferWidth > 0'); | |
129 shouldBeTrue('gl.drawingBufferHeight > 0'); | |
130 shouldBeTrue('gl.drawingBufferWidth <= maxSize[0]'); | |
131 shouldBeTrue('gl.drawingBufferHeight <= maxSize[1]'); | |
132 shouldBe('gl.getError()', 'gl.NO_ERROR'); | |
133 | |
134 debug(""); | |
135 debug("Checking scaling up then back down to 50/50, drawing still works."); | |
136 canvas.width = 50; | |
137 canvas.height = 50; | |
138 shouldBeTrue('gl.drawingBufferWidth == 50'); | |
139 shouldBeTrue('gl.drawingBufferHeight == 50'); | |
140 shouldBe('gl.getError()', 'gl.NO_ERROR'); | |
141 drawTriangleTest(gl); | |
142 shouldBe('gl.getError()', 'gl.NO_ERROR'); | |
143 } | |
144 debug("") | |
145 successfullyParsed = true; | |
146 </script> | |
147 <script src="../../resources/js-test-post.js"></script> | |
148 </body> | |
149 </html> | |
OLD | NEW |