开发者

loading DXT texture files in android using Java

I am looking to load compressed jpg and png files in android. Loading the raw files is just too slow. The plan is to compress the files ahead of time into DXT files. I tried to use DXTViewer to compress some images and attempt to load them as textures.

Currently I am getting a GL_INVALID_ENUM from gl.glCompressedTexImage2D(...).

Here is the code.

    InputStream is = ESGLTextureUtility.loadFile(iFile, assetManager);
    ByteBuffer bb = this.readToByteBuffer(is);
    textureInfo.source = iFile;
    is.close();

    this.checkError(gl);

    gl.glGenTextures(1, textureInfo.textures, 0);

    g开发者_如何学运维l.glBindTexture(GL10.GL_TEXTURE_2D, textureInfo.textures[0]);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);

    gl.glCompressedTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, 512, 512, 0, (int) this.total, bb);

Like I said, this triggers a GL_INVALID_ENUM.

There seems to be very little documentation or examples on this topic.

Thanks in advance.


Without going into extensive detail (since that would be writing a library that's likely out there somewhere..), at the least you need to be parsing the DDS header from the file, determining the format, and using the proper format code for upload. So if you detect DXT1, your upload should look like:

gl.glCompressedTexImage2D(GL10.GL_TEXTURE_2D, 0, 0x83F1, 512, 512,
                          0, (int) this.total, bb);

The DXT formats aren't part of GLES1 specs, so you'll need to use the hex codes, or make some constants for them. I used the DXT1 format code above. My guess is that using RGBA gave the invalid_enum error.

Note also if your code wants to support loading mipmaps, cubemaps, that is some further effort in parsing, loading, and uploading.

Lastly, you should ensure the device has s3tc/DXT support by looking in the GL extensions string for the s3tc extension.

-d

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜