Currently, I am combining multiple 2D textures into an Array Texture in WebGL2 (using three.js) to render models with multi draw functionality. These individual textures are frequently updated and utilize mipmaps. Since generating mipmaps for a single layer in an Array Texture is not feasible, I'm interested in creating mipmaps for a 2D target and then transferring the complete mipmap chain to a specific layer within the texture.
Upon investigating the WebGL API, it appears that binding a particular mipmap level from a texture created with texStorage2D
and copying it to a specific mipmap level for a layer in the 3D texture might not be achievable. Although this process occurs within three.js, the following approximate copy commands are executed:
_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
_gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
gl.bindTexture( _gl.TEXTURE_2D, srcTextureHandle, _gl.TEXTURE0 );
gl.copyTexSubImage3D( _gl.TEXTURE_2D_ARRAY, level, dstX, dstY, dstZ, minX, minY, width, height );
While it is possible to specify the target mip level in the parameters of copyTexSubImage3D
, there doesn't seem to be a way to designate the mipmap level for the bound texture to copy.
I have come across the glCopyImageSubData function in the OpenGLES3.2 specification, which allows for specifying both source and target mip levels, but unfortunately, this feature is not available in web browsers. Is it feasible to achieve this in WebGL2?