4 ** Copyright (c) 2012 The Khronos Group Inc.
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:
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
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.
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-utils.js"></script>
38 <div id="description"></div>
39 <div id="console"></div>
40 <canvas id="canvas" width="50" height="50"> </canvas>
42 <script id="vshader" type="x-shader/x-vertex">
43 attribute vec4 vPosition;
46 gl_Position = vPosition;
50 <script id="fshader" type="x-shader/x-fragment">
53 gl_FragColor = vec4(1.0,0.0,0.0,1.0);
60 function drawTriangleTest(gl)
64 gl.viewport(0, 0, width, height);
65 var vertexObject = gl.createBuffer();
66 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
67 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
68 gl.enableVertexAttribArray(0);
69 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
71 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
72 gl.drawArrays(gl.TRIANGLES, 0, 3);
74 // Test several locations
75 wtu.checkCanvasRect(gl, 0, 0, width, 1, [0, 0, 0, 255],
76 'First line should be all black');
77 wtu.checkCanvasRect(gl, 20, 15, 10, 1, [255, 0, 0, 255],
78 'Line 15 should be red for at least 10 red pixels starting 20 pixels in');
79 wtu.checkCanvasRect(gl, 0, height - 1, width, 1, [0, 0, 0, 255],
80 'Last line should be all black');
83 description("This test ensures WebGL implementations correctly implement drawingbufferWidth/Height with compositing.");
87 var wtu = WebGLTestUtils;
90 var gl = wtu.create3DContext("canvas");
92 testFailed("context does not exist");
94 testPassed("context exists");
96 var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]);
97 shouldBeNonNull("program");
98 gl.enable(gl.DEPTH_TEST);
99 gl.clearColor(0, 0, 0, 1);
100 shouldBe('gl.getError()', 'gl.NO_ERROR');
103 debug("Checking drawingBufferWidth/drawingBufferHeight");
105 shouldBe('gl.drawingBufferWidth', 'gl.canvas.width');
106 shouldBe('gl.drawingBufferHeight', 'gl.canvas.height');
108 // Check that changing the canvas size to something too large falls back to reasonable values.
109 maxSize = gl.getParameter(gl.MAX_VIEWPORT_DIMS);
110 shouldBeTrue('maxSize[0] > 0');
111 shouldBeTrue('maxSize[1] > 0');
113 // debug("MAX_VIEWPORT_DIMS = " + maxSize[0] + "x" + maxSize[1]);
114 gl.canvas.width = maxSize[0] * 4;
115 gl.canvas.height = maxSize[1] * 4;
116 shouldBeTrue('gl.drawingBufferWidth > 0');
117 shouldBeTrue('gl.drawingBufferHeight > 0');
118 shouldBeTrue('gl.drawingBufferWidth <= maxSize[0]');
119 shouldBeTrue('gl.drawingBufferHeight <= maxSize[1]');
120 shouldBe('gl.getError()', 'gl.NO_ERROR');
123 debug("Checking scaling up then back down to 50/50, drawing still works.");
124 gl.canvas.width = 50;
125 gl.canvas.height = 50;
126 shouldBeTrue('gl.drawingBufferWidth == 50');
127 shouldBeTrue('gl.drawingBufferHeight == 50');
128 shouldBe('gl.getError()', 'gl.NO_ERROR');
129 drawTriangleTest(gl);
130 shouldBe('gl.getError()', 'gl.NO_ERROR');
133 var successfullyParsed = true;
135 <script src="../../resources/js-test-post.js"></script>