Archives

Tuesday, June 21, 2011

Texture compression tips for Sony Ericsson’s Xperia™ phones

Are you unsure about which texture format is supported by your Xperia™ smartphone? Are you also wondering which texture compression should you use? We’ve got some helpful texture compression tips from Jonas Gustavsson, a Senior Graphics Expert for the Sony Ericsson Research and Technology group.
Texture compression is a specialized form of image compression designed for storing texture maps in 3D computer graphics rendering systems. Unlike conventional image compression algorithms, texture compression algorithms are optimized for random access. The issue with texture compression is that different graphics processor vendors support different texture formats, unfortunately these formats are not compatible. The good news is, all OpenGL ES 2.0 devices support a common format called ETC1. ETC1 isn’t the best texture format (for example, it lacks support for RGBA, textures with alpha channels), but it’s the most common format supported. On current Sony Ericsson Android™ phones such as the Xperia™ X10 or Xperia™ PLAY, we have support for Uncompressed, ETC1, and ATITC through the Qualcomm Adreno 200 and 205.
Note: The Android SDK provides a compressor utility (see sdk/tools/etc1tool) and runtime tools for this format.
Deciding which texture compression to use is a fairly subjective question but Sony Ericsson has the following suggestions:
For the least amount of device restrictions, use uncompressed textures.
For devices with OpenGL ES 2.0, use ETC1 on RGB and uncompressed on RGBA.
Alternatively provide variations including ETC1 + uncompressed, ATITC, PVRTC, DXT1, DXT3 and DXT5.
An alternative to TC support with Alpha is to use 2 discreet textures using ETC1. To do that, you split the RGBA texture into an RGB-texture and an alpha-texture, which is an RGB-texture with Alpha in G-channel, and R- and B-channels unused. Then you create a custom shader where the simple texture fetch is replaced by two; one to the first texture for RGB, and one to the second for A.
The following table explains the supported texture compression according to vendor:
Mobile GPU TC Support Without Alpha TC Support With Alpha
NVIDIA Tegra ETC1 DXT1, DXT3 and DXT5
Qualcomm Adreno ETC1 ATITC
Imagination PowerVR ETC1 PVRTC
To check what the current device supports, query GL_EXTENSIONS then provide the different variants you support in the APK, use the Multiple APK coming to Android Market, or simply download variants off the web over http.
An example of a GL_EXTENSIONS script (by Chris Pruett ) is provided below:
String extensions = " " + gl.glGetString(GL10.GL_EXTENSIONS) + " ";
String version = gl.glGetString(GL10.GL_VERSION);
String renderer = gl.glGetString(GL10.GL_RENDERER);
boolean isSoftwareRenderer = renderer.contains("PixelFlinger");
// On 1.6 and newer, we could use ActivityManager.getDeviceConfigurationInfo() to get the GL version.
// To include 1.5, I'll use the GL version string.
boolean isOpenGL10 = version.contains("1.0");
boolean supportsDrawTexture = extensions.contains("GL_OES_draw_texture"); // draw_texture extension
boolean supportsETC1 = extensions.contains("GL_OES_compressed_ETC1_RGB8_texture"); // standard ETC1 support extension
// VBOs are guaranteed in GLES1.1, but they were an extension under 1.0.
// There's no point in using VBOs when using the software renderer (though they are supported).
boolean supportsVBOs = !isSoftwareRenderer && (!isOpenGL10 || extensions.contains("vertex_buffer_object"));

No comments:

Post a Comment