OLD | NEW |
| (Empty) |
1 <html> | |
2 <head> | |
3 <script src="../../../resources/js-test.js"></script> | |
4 <script src="resources/webgl-test.js"></script> | |
5 <script id="vshader" type="x-shader/x-vertex"> | |
6 attribute vec3 g_Position; | |
7 | |
8 void main() | |
9 { | |
10 gl_Position = vec4(g_Position.x, g_Position.y, g_Position.z, 1.0); | |
11 } | |
12 </script> | |
13 | |
14 <script id="fshader" type="x-shader/x-fragment"> | |
15 void main() | |
16 { | |
17 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); | |
18 } | |
19 </script> | |
20 | |
21 </head> | |
22 <body> | |
23 <canvas id="example" width="4px" height="4px"></canvas> | |
24 <div id="description"></div> | |
25 <div id="console"></div> | |
26 <script> | |
27 description('Verifies that GL viewport does not change when canvas is resized'); | |
28 | |
29 var gl = initWebGL("example", "vshader", "fshader", [ "g_Position" ], [ 0, 0, 1,
1 ], 1); | |
30 | |
31 var vertices = new Float32Array([ | |
32 1.0, 1.0, 0.0, | |
33 -1.0, 1.0, 0.0, | |
34 -1.0, -1.0, 0.0, | |
35 1.0, 1.0, 0.0, | |
36 -1.0, -1.0, 0.0, | |
37 1.0, -1.0, 0.0]); | |
38 var vbo = gl.createBuffer(); | |
39 gl.bindBuffer(gl.ARRAY_BUFFER, vbo); | |
40 gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); | |
41 | |
42 gl.enableVertexAttribArray(0); | |
43 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); | |
44 | |
45 // Clear and set up | |
46 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
47 gl.useProgram(gl.program); | |
48 // Draw the triangle pair to the frame buffer | |
49 gl.drawArrays(gl.TRIANGLES, 0, 6); | |
50 | |
51 // Ensure that the frame buffer is red at the sampled pixel | |
52 var buf = new Uint8Array(1 * 1 * 4); | |
53 gl.readPixels(2, 2, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf); | |
54 var passed = true; | |
55 if (buf[0] != 255 || | |
56 buf[1] != 0 || | |
57 buf[2] != 0 || | |
58 buf[3] != 255) { | |
59 testFailed("Pixel at (2, 2) should have been (255, 0, 0, 255), " + | |
60 "was (" + buf[0] + ", " + buf[1] + ", " + buf[2] + ", " + buf[3] +
")"); | |
61 passed = false; | |
62 } | |
63 | |
64 if (passed) { | |
65 // Now resize the canvas | |
66 var canvas = document.getElementById("example"); | |
67 canvas.width = 8; | |
68 canvas.height = 8; | |
69 // Do another render | |
70 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
71 gl.drawArrays(gl.TRIANGLES, 0, 6); | |
72 // This time, because we did not change the viewport, it should | |
73 // still be (0, 0, 4, 4), so only the lower-left quadrant should | |
74 // have been filled. | |
75 var buf = new Uint8Array(1 * 1 * 4); | |
76 gl.readPixels(6, 6, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf); | |
77 var passed = true; | |
78 if (buf[0] != 0 || | |
79 buf[1] != 0 || | |
80 buf[2] != 255 || | |
81 buf[3] != 255) { | |
82 testFailed("Pixel at (6, 6) should have been (0, 0, 255, 255), " + | |
83 "was (" + buf[0] + ", " + buf[1] + ", " + buf[2] + ", " + buf[3]
+ ")"); | |
84 passed = false; | |
85 } | |
86 } | |
87 | |
88 if (passed) | |
89 testPassed("Viewport correctly did not change size during canvas resize"); | |
90 </script> | |
91 </body> | |
92 </html> | |
OLD | NEW |