summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/rendering/clear-srgb-color-buffer.html
blob: b88518635e1add784338d0e18792a531ac75672f (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
<!--
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">
<title>Clear sRGB Color Buffer</title>
<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>
</head>
<body>
<canvas id="example" width="8" height="8"></canvas>
<div id="description"></div>
<div id="console"></div>

<script>
"use strict";

var wtu = WebGLTestUtils;
description("This test verifies the functionality of clearing srgb color buffer.");

var gl = wtu.create3DContext("example", undefined, 2);

var tex = gl.createTexture();
var fbo = gl.createFramebuffer();
var size = 8;

if (!gl) {
    testFailed("WebGL context does not exist");
} else {
    testPassed("WebGL context exists");

    // Create a srgb color buffer
    init();

    clear_srgb_color_buffer(0);
    clear_srgb_color_buffer(1);
}

function init() {
    gl.bindTexture(gl.TEXTURE_2D, tex);
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.SRGB8_ALPHA8, size, size, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
    gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
    if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
        testFailed("Framebuffer incomplete.");
        return;
    } else {
        testPassed("framebuffer complete!");
    }
}

function clear_srgb_color_buffer(iter) {
    debug("");
    debug("Clear sRGB color buffer through glClear or glClearBufferfv");

    var color = [0x33, 0x88, 0xbb, 0xff];
    gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);

    if (iter == 0) {
        gl.clearColor(color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255);
        gl.clear(gl.COLOR_BUFFER_BIT);
    } else {
        var data = new Float32Array([color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255]);
        gl.clearBufferfv(gl.COLOR, 0, data);
    }

    var color_ref = wtu.linearToSRGB(color);
    var tolerance = 3;
    var msg = "";
    wtu.checkCanvasRect(gl, 0, 0, size, size, color_ref, msg, tolerance);
}

gl.bindTexture(gl.TEXTURE_2D, null);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.deleteTexture(tex);
gl.deleteFramebuffer(fbo);

var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>

</body>
</html>