2016-11-16 134 views
0

我想在Android上传pkm纹理。我能够读取图像并获得其宽度,高度&数据正确,但纹理显示为黑色。PKM纹理与ETC2压缩给黑屏

纹理加载函数:

public static int loadCompressedTexture(final Context context, final int resourceId){ 
     final int[] textures = new int[1]; 
     GLES30.glGenTextures(1, textures, 0); 
     Log.w(TAG, "ETC1 texture support: " + ETC1Util.isETC1Supported()); 
     if (textures[0] != 0) 
     { 
      // Read in the resource 
      InputStream in = context.getResources().openRawResource(R.raw.bodyf1pkm); 
      ETC2Utils.ETC2Texture tex = null; 
      try { 
       tex = ETC2Utils.createTexture(in); 
      } catch (IOException e) { 
       Log.e(TAG,e.toString()); 
      } 
      Log.d(TAG,"tex width: "+tex.getWidth()); 
      Log.d(TAG,"tex height: "+tex.getHeight()); 

      // Bind to the texture in OpenGL 
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textures[0]); 

      // Set filtering 
      GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST); 
      GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR); 
      GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT); 
      GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT); 
      // Load texture. 
      GLES30.glCompressedTexImage2D(GLES30.GL_TEXTURE_2D,0,tex.getCompressionFormat(),tex.getWidth(),tex.getHeight(),0,tex.getDataSize(),tex.getData()); 


     } 
     return textures[0]; 
    } 

我使用的是同级拉贾瓦利的ETC2Util类(https://github.com/Rajawali/Rajawali/blob/master/rajawali/src/main/java/org/rajawali3d/materials/textures/utils/ETC2Util.java)的加载数据。 数据正在正确加载,但纹理变黑。谁能帮忙?

回答

0

我终于解决了。事实证明,我正在使用的压缩格式(GL_COMPRESSED_RGBA8_ETC2_EAC)是每像素16位,我正在计算每像素8位的图像大小,这对GL_COMPRESSED_RGB8_ETC2有效