Android 使用壓縮紋理( 四 )


CompressedTextureInfo textureInfo = etc1::ParseETC1Texture(input_data);if (!textureInfo.is_valid) {    LogE("LoadTexture: etc1 textureInfo parsed invalid.");}GLuint texture_id = 0;glGenTextures(1, &texture_id);glBindTexture(GL_TEXTURE_2D, texture_id);glCompressedTexImage2D(GL_TEXTURE_2D,                       0,                       textureInfo.internal_format,                       textureInfo.width,                       textureInfo.height,                       0,                       textureInfo.size,                       textureInfo.data);四、總結壓縮紋理的加載,主要是搞清楚如何解析壓縮紋理數據 。一般而言,壓縮紋理加載到內存后,都有一個 Header,通過 Header 可以解析出其寬高等信息,計算出紋理圖像大小 。最后調用glCompressedTexImage2D方法即可渲染 ??梢妷嚎s紋理完全沒有圖像的解碼工作,大大提升加載速度 。
最后 , 介紹幾款紋理壓縮工具:

  • etc2comp:支持生成etc2紋理
  • etc1tool:支持生成etc1紋理,在Android SDK目錄下,Android/sdk/platform-tools/etc1tool
  • ISPCTextureCompressor:支持etc1、astc等
  • astc-encoder:ASTC官方編碼器

推薦閱讀