[英]Which internal format works with compressedTexImage3D?
我正在嘗試使用Firefox 47(每晚)在WebGL2中的TexImage3D中使用紋理壓縮,但找不到有效的格式。 錯誤是:
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>
我可以使用哪種格式?
TEXTURE_ARRAY_2Ds
應該像這樣工作:
let s3tc = gl.getExtension( 'WEBGL_compressed_texture_s3tc' )
let size = 64
let format = s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT
let data = new Uint8Array( size * size * size )
let texture2DArray = gl.createTexture()
gl.bindTexture ( gl.TEXTURE_2D_ARRAY, texture2DArray )
gl.texStorage3D( gl.TEXTURE_2D_ARRAY, 1, format, size, size, size )
gl.compressedTexSubImage3D
( gl.TEXTURE_2D_ARRAY // target
, 0 // level
, 0 // xoffset
, 0 // yoffset
, 0 // zoffset
, size // width
, size // height
, size // depth
, format // format
//, size * size * size // imageSize: omitted in WebGL?
, pixels // data
)
但是此代碼段使Firefox 48.0a1崩潰(每晚)
更新: about:config -> webl.disable-angle: true.
哇!
對應於Firefox WebGLTextureUpload.cpp ,專門針對TEXTURE_3D
排除了以下格式。
// TEXTURE_2D_ARRAY but not TEXTURE_3D:
// D and DS formats
case webgl::EffectiveFormat::DEPTH_COMPONENT16:
case webgl::EffectiveFormat::DEPTH_COMPONENT24:
case webgl::EffectiveFormat::DEPTH_COMPONENT32F:
case webgl::EffectiveFormat::DEPTH24_STENCIL8:
case webgl::EffectiveFormat::DEPTH32F_STENCIL8:
// CompressionFamily::ES3
case webgl::EffectiveFormat::COMPRESSED_R11_EAC:
case webgl::EffectiveFormat::COMPRESSED_SIGNED_R11_EAC:
case webgl::EffectiveFormat::COMPRESSED_RG11_EAC:
case webgl::EffectiveFormat::COMPRESSED_SIGNED_RG11_EAC:
case webgl::EffectiveFormat::COMPRESSED_RGB8_ETC2:
case webgl::EffectiveFormat::COMPRESSED_SRGB8_ETC2:
case webgl::EffectiveFormat::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
case webgl::EffectiveFormat::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
case webgl::EffectiveFormat::COMPRESSED_RGBA8_ETC2_EAC:
case webgl::EffectiveFormat::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
// CompressionFamily::S3TC
case webgl::EffectiveFormat::COMPRESSED_RGB_S3TC_DXT1_EXT:
case webgl::EffectiveFormat::COMPRESSED_RGBA_S3TC_DXT1_EXT:
case webgl::EffectiveFormat::COMPRESSED_RGBA_S3TC_DXT3_EXT:
case webgl::EffectiveFormat::COMPRESSED_RGBA_S3TC_DXT5_EXT:
if (target == LOCAL_GL_TEXTURE_3D) {
webgl->ErrorInvalidOperation("%s: Format %s cannot be used with TEXTURE_3D.",
funcName, format->name);
return false;
}
break;
// No 3D targets:
// CompressionFamily::ATC
case webgl::EffectiveFormat::ATC_RGB_AMD:
case webgl::EffectiveFormat::ATC_RGBA_EXPLICIT_ALPHA_AMD:
case webgl::EffectiveFormat::ATC_RGBA_INTERPOLATED_ALPHA_AMD:
// CompressionFamily::PVRTC
case webgl::EffectiveFormat::COMPRESSED_RGB_PVRTC_4BPPV1:
case webgl::EffectiveFormat::COMPRESSED_RGBA_PVRTC_4BPPV1:
case webgl::EffectiveFormat::COMPRESSED_RGB_PVRTC_2BPPV1:
case webgl::EffectiveFormat::COMPRESSED_RGBA_PVRTC_2BPPV1:
// CompressionFamily::ETC1
case webgl::EffectiveFormat::ETC1_RGB8_OES:
if (target == LOCAL_GL_TEXTURE_3D ||
target == LOCAL_GL_TEXTURE_2D_ARRAY)
{
webgl->ErrorInvalidOperation("%s: Format %s cannot be used with TEXTURE_3D or"
" TEXTURE_2D_ARRAY.",
funcName, format->name);
return false;
}
break;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.