1

我正在尝试使用 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>

我可以使用哪种格式?

4

1 回答 1

1

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;
于 2016-03-26T19:15:37.087 回答