summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/renderbuffers/framebuffer-texture-layer.html
blob: 0e435d6a2e2902c4b33d550661140111a3475bbf (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!--
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>WebGL FramebufferTextureLayer Test</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>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>

<script>
"use strict";
var wtu = WebGLTestUtils;
var gl;
var canvas = document.getElementById("canvas");

function numLevelsFromSize(size) {
    var levels = 0;
    while ((size >> levels) > 0) {
        ++levels;
    }
    return levels;
}

function checkFramebuffer(expected) {
    var actual = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
    if (expected.indexOf(actual) < 0) {
        var msg = "checkFramebufferStatus expects [";
        for (var index = 0; index < expected.length; ++index) {
            msg += wtu.glEnumToString(gl, expected[index]);
            if (index + 1 < expected.length)
                msg += ", ";
        }
        msg += "], was " + wtu.glEnumToString(gl, actual);
        testFailed(msg);
    } else {
        var msg = "checkFramebufferStatus got " + wtu.glEnumToString(gl, actual) +
                  " as expected";
        testPassed(msg);
    }
}

function testFramebufferTextureLayer() {
    debug("");
    debug("Checking FramebufferTextureLayer stuff.");

    var tex3d = gl.createTexture();
    var fb = gl.createFramebuffer();
    gl.bindTexture(gl.TEXTURE_3D, tex3d);
    gl.texImage3D(gl.TEXTURE_3D,
                  0,                                          // level
                  gl.RGBA,                                    // internalFormat
                  1,                                          // width
                  1,                                          // height
                  1,                                          // depth
                  0,                                          // border
                  gl.RGBA,                                    // format
                  gl.UNSIGNED_BYTE,                           // type
                  new Uint8Array([0xff, 0x00, 0x00, 0x00]));  // data
    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, 0, 0);
    wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
        "attaching a texture to default framebuffer should generate INVALID_OPERATION.");
    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, 0, 0);
    wtu.glErrorShouldBe(gl, gl.NO_ERROR,
        "attaching a texture to a framebuffer should succeed.");
    checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, null, 0, 0);
    wtu.glErrorShouldBe(gl, gl.NO_ERROR,
        "detaching a texture from a framebuffer should succeed.");

    var maxTexSize = gl.getParameter(gl.MAX_3D_TEXTURE_SIZE);
    var maxLevels = numLevelsFromSize(maxTexSize);
    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, maxLevels - 1, 0);
    wtu.glErrorShouldBe(gl, gl.NO_ERROR,
        "calling framebufferTextureLayer with an appropriate mipmap level should succeed.");
    checkFramebuffer([gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT]);
    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, maxLevels, 0);
    wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
        "calling framebufferTextureLayer with a mipmap level out of range should generate INVALID_VALUE.");

    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, 0, -1);
    wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
        "calling framebufferTextureLayer with a negative texture layer should generate INVALID_VALUE.");
    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, 0, maxTexSize);
    wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
        "calling framebufferTextureLayer with a texture layer out of range should generate INVALID_VALUE.");

    var tex2d = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D, tex2d);
    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex2d, 0, 0);
    wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
        "attaching a 2d texture to a framebuffer should generate INVALID_OPERATION.");

    var texDepthStencil = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D_ARRAY, texDepthStencil);
    var fbDepthStencil = gl.createFramebuffer();
    gl.bindFramebuffer(gl.FRAMEBUFFER, fbDepthStencil);
    gl.texImage3D(gl.TEXTURE_2D_ARRAY,
                  0,                                          // level
                  gl.DEPTH24_STENCIL8,                        // internalFormat
                  1,                                          // width
                  1,                                          // height
                  1,                                          // depth
                  0,                                          // border
                  gl.DEPTH_STENCIL,                           // format
                  gl.UNSIGNED_INT_24_8,                       // type
                  new Uint32Array([0]));                      // data
    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, texDepthStencil, 0, 0);
    wtu.glErrorShouldBe(gl, gl.NO_ERROR,
        "attaching a depth_stencil texture to a framebuffer should succeed.");
    checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);

    // Clean up
    gl.deleteTexture(tex3d);
    gl.deleteTexture(texDepthStencil);
    gl.deleteTexture(tex2d);
    gl.deleteFramebuffer(fb);
    gl.deleteFramebuffer(fbDepthStencil);
}

description("This tests framebufferTextureLayer.");

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

testFramebufferTextureLayer();

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

</body>
</html>