<!--Copyright (c) 2019 The Khronos Group Inc.Use of this source code is governed by an MIT-style license that can befound in the LICENSE.txt file.--><!DOCTYPE html><html><head><metacharset="utf-8"><title>WebGL FramebufferTextureLayer Test</title><linkrel="stylesheet"href="../../resources/js-test-style.css"/><scriptsrc="../../js/js-test-pre.js"></script><scriptsrc="../../js/webgl-test-utils.js"></script></head><body><divid="description"></div><divid="console"></div><canvasid="canvas"width="2"height="2"></canvas><script>"use strict";varwtu=WebGLTestUtils;vargl;varcanvas=document.getElementById("canvas");functionnumLevelsFromSize(size){varlevels=0;while((size>>levels)>0){++levels;}returnlevels;}functioncheckFramebuffer(expected){varactual=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(expected.indexOf(actual)<0){varmsg="checkFramebufferStatus expects [";for(varindex=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{varmsg="checkFramebufferStatus got "+wtu.glEnumToString(gl,actual)+" as expected";testPassed(msg);}}functiontestFramebufferTextureLayer(){debug("");debug("Checking FramebufferTextureLayer stuff.");vartex3d=gl.createTexture();varfb=gl.createFramebuffer();gl.bindTexture(gl.TEXTURE_3D,tex3d);gl.texImage3D(gl.TEXTURE_3D,0,// levelgl.RGBA,// internalFormat1,// width1,// height1,// depth0,// bordergl.RGBA,// formatgl.UNSIGNED_BYTE,// typenewUint8Array([0xff,0x00,0x00,0x00]));// datagl.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.");varmaxTexSize=gl.getParameter(gl.MAX_3D_TEXTURE_SIZE);varmaxLevels=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.");vartex2d=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.");vartexDepthStencil=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D_ARRAY,texDepthStencil);varfbDepthStencil=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,fbDepthStencil);gl.texImage3D(gl.TEXTURE_2D_ARRAY,0,// levelgl.DEPTH24_STENCIL8,// internalFormat1,// width1,// height1,// depth0,// bordergl.DEPTH_STENCIL,// formatgl.UNSIGNED_INT_24_8,// typenewUint32Array([0]));// datagl.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]);vartexDepthStencil=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D_ARRAY,texDepthStencil);vartexDepthStencilMany=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D_ARRAY,texDepthStencilMany);varfbDepthStencilMany=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,fbDepthStencilMany);gl.texImage3D(gl.TEXTURE_2D_ARRAY,0,// levelgl.DEPTH24_STENCIL8,// internalFormat1,// width1,// height2,// depth0,// bordergl.DEPTH_STENCIL,// formatgl.UNSIGNED_INT_24_8,// typenewUint32Array([0,1]));// datagl.framebufferTextureLayer(gl.FRAMEBUFFER,gl.DEPTH_ATTACHMENT,texDepthStencilMany,0,0);gl.framebufferTextureLayer(gl.FRAMEBUFFER,gl.STENCIL_ATTACHMENT,texDepthStencilMany,0,0);wtu.glErrorShouldBe(gl,gl.NO_ERROR,"attaching a depth_stencil 2d array texture level 0 to a framebuffer should succeed.");checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)",texDepthStencilMany);gl.framebufferTextureLayer(gl.FRAMEBUFFER,gl.STENCIL_ATTACHMENT,texDepthStencilMany,0,1);wtu.glErrorShouldBe(gl,gl.NO_ERROR,"attaching a 2d array texture level 0 to depth and layer 1 to stencil attachment of a framebuffer should succeed.");// "Depth and stencil attachments, if present, are the same image." If not, then "FRAMEBUFFER_UNSUPPORTED".checkFramebuffer([gl.FRAMEBUFFER_UNSUPPORTED]);shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)",texDepthStencilMany);// Clean upgl.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("");varsuccessfullyParsed=true;</script><scriptsrc="../../js/js-test-post.js"></script></body></html>