1
我試圖在WebGL2中使用Firefox 47(夜間)使用TexImage3D進行紋理壓縮,但找不到有效的格式。錯誤是:哪種內部格式適用於compressedTexImage3D?
Error: WebGL: compressedTexImage3D: Format COMPRESSED_RGB_S3TC_DXT1_EXT cannot be used with TEXTURE_3D.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script>
function compressedTexImage3D()
{
let canvas = document.createElement('canvas')
let gl = canvas.getContext('webgl2')
if(gl == null) { alert('requires Firefox 47') }
let etc = gl.getExtension('WEBGL_compressed_texture_etc1' )
let s3tc = gl.getExtension('WEBGL_compressed_texture_s3tc' )
// let atc = gl.getExtension('WEBGL_compressed_texture_atc' )
// let es3 = gl.getExtension('WEBGL_compressed_texture_es3' )
// let pvrtc = gl.getExtension('WEBGL_compressed_texture_pvrtc')
let size = 64
let data = new Uint8Array(size * size * size)
let texture3D = gl.createTexture()
gl.bindTexture(gl.TEXTURE_3D, texture3D)
let formatsTexture3D =
[ etc .COMPRESSED_RGB_ETC1_WEBGL
, s3tc.COMPRESSED_RGB_S3TC_DXT1_EXT
, s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT
, s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT
, s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT
]
formatsTexture3D.forEach(function(format)
{
gl.compressedTexImage3D
(gl.TEXTURE_3D // target
, 0 // level
, format // internal format
, size // width
, size // height
, size // depth
, 0 // border
, data // data
)
})
let texture2DArray = gl.createTexture()
gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture2DArray)
let formatsTexture2DArray =
[ [etc .COMPRESSED_RGB_ETC1_WEBGL , new Uint8Array(size * size * size )]
//, [s3tc.COMPRESSED_RGB_S3TC_DXT1_EXT , new Uint8Array(size * size * size/2)] // crash
//, [s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT, new Uint8Array(size * size * size/2)] // crash
//, [s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT, new Uint8Array(size * size * size/2)] // crash
//, [s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT, new Uint8Array(size * size * size )] // crash
]
formatsTexture2DArray.forEach(function(formatData)
{
let format = formatData[0]
let data = formatData[1]
gl.compressedTexImage3D
(gl.TEXTURE_2D_ARRAY // target
, 0 // level
, format // internal format
, size // width
, size // height
, size // depth
, 0 // border
, data // data
)
})
}
</script>
</head>
<body onload="compressedTexImage3D()">
</body>
</html>
我可以使用哪種格式?