summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/context/context-size-change.html
blob: 638d7a7099d1a9393371f1736a74db709786324a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>

<script>
"use strict";

// These declarations need to be global for "shouldBe" to see them
var gl;
var pixel = [0, 0, 0, 1];
var canvas;

function init()
{
    description('Verify that changing the size of an antialiased WebGL context does not cause it to stop working.');

    runTest();
}

function getWebGL(canvasWidth, canvasHeight, contextAttribs)
{
    canvas = document.createElement("canvas");
    if (!canvas)
        return null;
    canvas.width = canvasWidth;
    canvas.height = canvasHeight;

    gl = WebGLTestUtils.create3DContext(canvas, contextAttribs);
    if (!gl)
        return null;

    return gl;
}

function runTest()
{
    shouldBeNonNull("gl = getWebGL(1, 1, { alpha: false, antialias: true })");

    // Clear to black.
    gl.clearColor(0.0, 0.0, 0.0, 1.0);
    gl.clear(gl.COLOR_BUFFER_BIT);

    // Check that the pixel's R channel is 0.
    var buf = new Uint8Array(1 * 1 * 4);
    gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
    pixel[0] = buf[0];
    shouldBeTrue("pixel[0] == 0");

    // Change the size of the canvas.
    canvas.width = 3;
    canvas.height = 3;

    // Clear to black.
    gl.clearColor(0.0, 0.0, 0.0, 1.0);
    gl.clear(gl.COLOR_BUFFER_BIT);

    // Clear the top-left pixel to white.
    gl.enable(gl.SCISSOR_TEST);
    gl.scissor(0, 0, 1, 1);
    gl.clearColor(1.0, 1.0, 1.0, 1.0);
    gl.clear(gl.COLOR_BUFFER_BIT);

    // Check that the top-left pixel has R channel 255.
    gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
    pixel[0] = buf[0];
    shouldBeTrue("pixel[0] == 255");

    // Check that the bottom-right pixel has R channel 0.
    gl.readPixels(2, 2, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
    pixel[0] = buf[0];
    shouldBeTrue("pixel[0] == 0");

    finishTest();
}

</script>
</head>
<body onload="init()">
<div id="description"></div>
<div id="console"></div>
</body>
</html>