Android : How to manually implement device independent scaling using OpenGL ES?

on Saturday, July 5, 2014


In OpenGL ES 2 for Android, when loading a bitmap as a texture the author explicitly states that he wishes to read the unscaled equivalent of the image. This is done as follows:



/** Returns an unscaled image. Classes should manually dispose the returned bitmap for memory efficiency. **/
public static final Bitmap loadBitmapResource(final Context pContext, final int pBitmapResourceId) {
/* Load image data. */
final BitmapFactory.Options lBitmapFactoryOptions = new BitmapFactory.Options();
/* Disallow automatically scaled image data. */
lBitmapFactoryOptions.inScaled = false;
/* Read the image data. */
final Bitmap lBitmap = BitmapFactory.decodeResource(pContext.getResources(), pBitmapResourceId, lBitmapFactoryOptions);
return lBitmap;
}


Similarly, all images used in each example application is stored in the drawable-nodpi folder.


As OpenGL performance can be maximised through the use of texture sizes that are powers of two (POT), how then do I go about supporting multiple devices in terms of using device-independent scaling?


Is it preferable to programmatically scale each texture at render time, or instead carry multiple POT images for different DIP scaling?


0 comments:

Post a Comment