我正在尝试在Android上传pkm纹理。我能够读取图像并获得其宽度,高度和宽度。数据正常但纹理显示为黑色。
纹理加载函数:
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];
}
我正在使用类似的Rajawali的ETC2Util类(https://github.com/Rajawali/Rajawali/blob/master/rajawali/src/main/java/org/rajawali3d/materials/textures/utils/ETC2Util.java)来加载数据。 数据正在正确加载,但纹理变黑。有人可以帮忙吗?
答案 0 :(得分:0)
我终于解决了它。事实证明我正在使用的压缩格式(GL_COMPRESSED_RGBA8_ETC2_EAC)是每像素16位,因为我计算每像素8位的图像大小,这对GL_COMPRESSED_RGB8_ETC2有效