2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL FramebufferTextureLayer Test
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
19 <canvas id=
"canvas" width=
"2" height=
"2"> </canvas>
23 var wtu
= WebGLTestUtils
;
25 var canvas
= document
.getElementById("canvas");
27 function numLevelsFromSize(size
) {
29 while ((size
>> levels
) > 0) {
35 function checkFramebuffer(expected
) {
36 var actual
= gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
);
37 if (expected
.indexOf(actual
) < 0) {
38 var msg
= "checkFramebufferStatus expects [";
39 for (var index
= 0; index
< expected
.length
; ++index
) {
40 msg
+= wtu
.glEnumToString(gl
, expected
[index
]);
41 if (index
+ 1 < expected
.length
)
44 msg
+= "], was " + wtu
.glEnumToString(gl
, actual
);
47 var msg
= "checkFramebufferStatus got " + wtu
.glEnumToString(gl
, actual
) +
53 function testFramebufferTextureLayer() {
55 debug("Checking FramebufferTextureLayer stuff.");
57 var tex3d
= gl
.createTexture();
58 var fb
= gl
.createFramebuffer();
59 gl
.bindTexture(gl
.TEXTURE_3D
, tex3d
);
60 gl
.texImage3D(gl
.TEXTURE_3D
,
62 gl
.RGBA
, // internalFormat
68 gl
.UNSIGNED_BYTE
, // type
69 new Uint8Array([0xff, 0x00, 0x00, 0x00])); // data
70 gl
.framebufferTextureLayer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, tex3d
, 0, 0);
71 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
72 "attaching a texture to default framebuffer should generate INVALID_OPERATION.");
73 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fb
);
74 gl
.framebufferTextureLayer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, tex3d
, 0, 0);
75 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
76 "attaching a texture to a framebuffer should succeed.");
77 checkFramebuffer([gl
.FRAMEBUFFER_COMPLETE
]);
78 gl
.framebufferTextureLayer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, null, 0, 0);
79 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
80 "detaching a texture from a framebuffer should succeed.");
82 var maxTexSize
= gl
.getParameter(gl
.MAX_3D_TEXTURE_SIZE
);
83 var maxLevels
= numLevelsFromSize(maxTexSize
);
84 gl
.framebufferTextureLayer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, tex3d
, maxLevels
- 1, 0);
85 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
86 "calling framebufferTextureLayer with an appropriate mipmap level should succeed.");
87 checkFramebuffer([gl
.FRAMEBUFFER_INCOMPLETE_ATTACHMENT
]);
88 gl
.framebufferTextureLayer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, tex3d
, maxLevels
, 0);
89 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
,
90 "calling framebufferTextureLayer with a mipmap level out of range should generate INVALID_VALUE.");
92 gl
.framebufferTextureLayer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, tex3d
, 0, -1);
93 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
,
94 "calling framebufferTextureLayer with a negative texture layer should generate INVALID_VALUE.");
95 gl
.framebufferTextureLayer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, tex3d
, 0, maxTexSize
);
96 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
,
97 "calling framebufferTextureLayer with a texture layer out of range should generate INVALID_VALUE.");
99 var tex2d
= gl
.createTexture();
100 gl
.bindTexture(gl
.TEXTURE_2D
, tex2d
);
101 gl
.framebufferTextureLayer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, tex2d
, 0, 0);
102 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
103 "attaching a 2d texture to a framebuffer should generate INVALID_OPERATION.");
105 var texDepthStencil
= gl
.createTexture();
106 gl
.bindTexture(gl
.TEXTURE_2D_ARRAY
, texDepthStencil
);
107 var fbDepthStencil
= gl
.createFramebuffer();
108 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbDepthStencil
);
109 gl
.texImage3D(gl
.TEXTURE_2D_ARRAY
,
111 gl
.DEPTH24_STENCIL8
, // internalFormat
116 gl
.DEPTH_STENCIL
, // format
117 gl
.UNSIGNED_INT_24_8
, // type
118 new Uint32Array([0])); // data
119 gl
.framebufferTextureLayer(gl
.FRAMEBUFFER
, gl
.DEPTH_STENCIL_ATTACHMENT
, texDepthStencil
, 0, 0);
120 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
121 "attaching a depth_stencil texture to a framebuffer should succeed.");
122 checkFramebuffer([gl
.FRAMEBUFFER_COMPLETE
]);
124 var texDepthStencil
= gl
.createTexture();
125 gl
.bindTexture(gl
.TEXTURE_2D_ARRAY
, texDepthStencil
);
127 var texDepthStencilMany
= gl
.createTexture();
128 gl
.bindTexture(gl
.TEXTURE_2D_ARRAY
, texDepthStencilMany
);
129 var fbDepthStencilMany
= gl
.createFramebuffer();
130 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbDepthStencilMany
);
131 gl
.texImage3D(gl
.TEXTURE_2D_ARRAY
,
133 gl
.DEPTH24_STENCIL8
, // internalFormat
138 gl
.DEPTH_STENCIL
, // format
139 gl
.UNSIGNED_INT_24_8
, // type
140 new Uint32Array([0, 1])); // data
142 gl
.framebufferTextureLayer(gl
.FRAMEBUFFER
, gl
.DEPTH_ATTACHMENT
, texDepthStencilMany
, 0, 0);
143 gl
.framebufferTextureLayer(gl
.FRAMEBUFFER
, gl
.STENCIL_ATTACHMENT
, texDepthStencilMany
, 0, 0);
144 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
145 "attaching a depth_stencil 2d array texture level 0 to a framebuffer should succeed.");
146 checkFramebuffer([gl
.FRAMEBUFFER_COMPLETE
]);
147 shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", texDepthStencilMany
);
148 gl
.framebufferTextureLayer(gl
.FRAMEBUFFER
, gl
.STENCIL_ATTACHMENT
, texDepthStencilMany
, 0, 1);
149 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
150 "attaching a 2d array texture level 0 to depth and layer 1 to stencil attachment of a framebuffer should succeed.");
151 // "Depth and stencil attachments, if present, are the same image." If not, then "FRAMEBUFFER_UNSUPPORTED".
152 checkFramebuffer([gl
.FRAMEBUFFER_UNSUPPORTED
]);
153 shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", texDepthStencilMany
);
156 gl
.deleteTexture(tex3d
);
157 gl
.deleteTexture(texDepthStencil
);
158 gl
.deleteTexture(tex2d
);
159 gl
.deleteFramebuffer(fb
);
160 gl
.deleteFramebuffer(fbDepthStencil
);
163 description("This tests framebufferTextureLayer.");
165 shouldBeNonNull("gl = wtu.create3DContext(undefined, undefined, 2)");
167 testFramebufferTextureLayer();
170 var successfullyParsed
= true;
172 <script src=
"../../js/js-test-post.js"></script>