2016-03-05 77 views
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>

我可以使用哪種格式?

回答

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.cppTEXTURE_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; 
相關問題