WEBGL_compressed_texture_astc 擴充套件

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流瀏覽器均已支援。

WEBGL_compressed_texture_astc 擴充套件是 WebGL API 的一部分,它將 自適應可伸縮紋理壓縮 (ASTC) 壓縮紋理格式暴露給 WebGL。

有關更多資訊,請參閱 NVIDIA 的文章 使用 ASTC 紋理壓縮來處理遊戲資源

可以使用 WebGLRenderingContext.getExtension() 方法來訪問 WebGL 擴充套件。有關更多資訊,請參閱 WebGL 教程中的 使用擴充套件

注意: ASTC 壓縮通常在 Mali ARM GPU、Intel GPU 和 NVIDIA Tegra 晶片上可用。

此擴充套件同時適用於 WebGL1WebGL2 上下文。

例項方法

此擴充套件公開了一個新方法。

ext.getSupportedProfiles()

返回一個字串陣列,其中包含實現所支援的 ASTC 配置檔名稱。

常量

壓縮紋理格式透過 28 個常量公開,並可用於兩個函式:compressedTexImage2D()compressedTexSubImage2D()

常量 每畫素位數 ArrayBuffer byteLength 如果寬度和高度為 512,則為位元組數
ext.COMPRESSED_RGBA_ASTC_4x4_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
4x4 8.00 floor((width + 3) / 4) * floor((height + 3) / 4) * 16 262144
ext.COMPRESSED_RGBA_ASTC_5x4_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
5x4 6.40 floor((width + 4) / 5) * floor((height + 3) / 4) * 16 210944
ext.COMPRESSED_RGBA_ASTC_5x5_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
5x5 5.12 floor((width + 4) / 5) * floor((height + 4) / 5) * 16 169744
ext.COMPRESSED_RGBA_ASTC_6x5_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
6x5 4.27 floor((width + 5) / 6) * floor((height + 4) / 5) * 16 141728
ext.COMPRESSED_RGBA_ASTC_6x6_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
6x6 3.56 floor((width + 5) / 6) * floor((height + 5) / 6) * 16 118336
ext.COMPRESSED_RGBA_ASTC_8x5_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
8x5 3.20 floor((width + 7) / 8) * floor((height + 4) / 5) * 16 105472
ext.COMPRESSED_RGBA_ASTC_8x6_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
8x6 2.67 floor((width + 7) / 8) * floor((height + 5) / 6) * 16 88064
ext.COMPRESSED_RGBA_ASTC_8x8_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
8x8 2.00 floor((width + 7) / 8) * floor((height + 7) / 8) * 16 65536
ext.COMPRESSED_RGBA_ASTC_10x5_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
10x5 2.56 floor((width + 9) / 10) * floor((height + 4) / 5) * 16 85696
ext.COMPRESSED_RGBA_ASTC_10x6_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
10x6 2.13 floor((width + 9) / 10) * floor((height + 5) / 6) * 16 71552
ext.COMPRESSED_RGBA_ASTC_10x8_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
10x8 1.60 floor((width + 9) / 10) * floor((height + 7) / 8) * 16 53248
ext.COMPRESSED_RGBA_ASTC_10x10_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
10x10 1.28 floor((width + 9) / 10) * floor((height + 9) / 10) * 16 43264
ext.COMPRESSED_RGBA_ASTC_12x10_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
12x10 1.07 floor((width + 11) / 12) * floor((height + 9) / 10) * 16 35776
ext.COMPRESSED_RGBA_ASTC_12x12_KHR
ext.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
12x12 0.89 floor((width + 11) / 12) * floor((height + 11) / 12) * 16 29584

示例

js
const ext = gl.getExtension("WEBGL_compressed_texture_astc");

const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);

gl.compressedTexImage2D(
  gl.TEXTURE_2D,
  0,
  ext.COMPRESSED_RGBA_ASTC_12x12_KHR,
  512,
  512,
  0,
  textureData,
);

規範

規範
WebGL WEBGL_compressed_texture_astc 擴充套件規範

瀏覽器相容性

另見