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;
10 gl_Position = vec4(g_Position.x, g_Position.y, g_Position.z,
1.0);
14 <script id=
"fshader" type=
"x-shader/x-fragment">
17 gl_FragColor = vec4(
1.0,
0.0,
0.0,
1.0);
23 <canvas id=
"example" width=
"4px" height=
"4px"></canvas>
24 <div id=
"description"></div>
25 <div id=
"console"></div>
27 description('Verifies that GL viewport does not change when canvas is resized');
29 var gl
= initWebGL("example", "vshader", "fshader", [ "g_Position" ], [ 0, 0, 1, 1 ], 1);
31 var vertices
= new Float32Array([
38 var vbo
= gl
.createBuffer();
39 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vbo
);
40 gl
.bufferData(gl
.ARRAY_BUFFER
, vertices
, gl
.STATIC_DRAW
);
42 gl
.enableVertexAttribArray(0);
43 gl
.vertexAttribPointer(0, 3, gl
.FLOAT
, false, 0, 0);
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);
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
);
59 testFailed("Pixel at (2, 2) should have been (255, 0, 0, 255), " +
60 "was (" + buf
[0] + ", " + buf
[1] + ", " + buf
[2] + ", " + buf
[3] + ")");
65 // Now resize the canvas
66 var canvas
= document
.getElementById("example");
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
75 var buf
= new Uint8Array(1 * 1 * 4);
76 gl
.readPixels(6, 6, 1, 1, gl
.RGBA
, gl
.UNSIGNED_BYTE
, buf
);
82 testFailed("Pixel at (6, 6) should have been (0, 0, 255, 255), " +
83 "was (" + buf
[0] + ", " + buf
[1] + ", " + buf
[2] + ", " + buf
[3] + ")");
89 testPassed("Viewport correctly did not change size during canvas resize");