summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/rendering/rgb-format-support.html
blob: 46712ae68b1b144233de1a32f02a412b28abd6af (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!--
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>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
var wtu = WebGLTestUtils;
description("Verify RGB/RGB8 textures and renderbuffers support");

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

function testRenderbuffer(width, height) {
    var samples = gl.getInternalformatParameter(gl.RENDERBUFFER, gl.RGB8, gl.SAMPLES);
    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors from getInternalformatParameter()");

    if (!samples || samples.length == 0) {
        testFailed("getInternalformatParameter on RGB8 fails to return valid samples");
        return;
    }

    for (var idx = 0; idx < samples.length + 2; ++idx) {
        debug("");
        var renderbuffer = gl.createRenderbuffer();
        gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
        var sampleCount = 0;
        switch (idx) {
          case samples.length:
            sampleCount = 0;
            break;
          case samples.length + 1:
            sampleCount = -1; // non multisampled
            break;
          default:
            sampleCount = samples[idx];
        }

        if (sampleCount < 0) {
            debug("test non-multisampled RGB8 renderbuffer");
            gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGB8, 2, 2);
        } else {
            debug("test RGB8 renderbuffer with " + sampleCount + " samples");
            gl.renderbufferStorageMultisample(gl.RENDERBUFFER, sampleCount, gl.RGB8, width, height);
        }
        wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors from renderbufferStorage{Multisample}");

        var fbo = gl.createFramebuffer();
        gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
        gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, renderbuffer);
        if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
            testFailed("framebuffer with renderbuffer is incomplete");
        } else {
            testPassed("framebuffer with renderbuffer is complete");
        }

        gl.clearColor(1, 0, 1, 1);
        gl.clear(gl.COLOR_BIT);
        wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors from clear()");
    }
}

function testTexture(width, height) {
    var formats = [ "RGB", "RGB8" ];
    for (var idx = 0; idx < formats.length; ++idx) {
        debug("");
        debug("test texture format " + formats[idx]);
        var internalformat = gl[formats[idx]];
        var tex = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, tex);
        gl.texImage2D(gl.TEXTURE_2D, 0, internalformat, width, height, 0, gl.RGB, gl.UNSIGNED_BYTE, null);
        wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors from texture setup");

        var fbo = gl.createFramebuffer();
        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 with texture is incomplete");
        } else {
            testPassed("framebuffer with texture is complete");
        }

        gl.clearColor(1, 0, 1, 1);
        gl.clear(gl.COLOR_BIT);
        wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors from clear()");
    }
}

if (!gl) {
    testFailed('canvas.getContext() failed');
} else {
    testRenderbuffer(2, 2);
    testTexture(2, 2);
}

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