Reducing texture memory in openGL ES 1.1

Problems with Canvas, OpenGL, etc...

Reducing texture memory in openGL ES 1.1

Postby tenfour » Tue Mar 08, 2011 12:54 am

My scene has a number of large textures, but they are grayscale (I'm using them with GL10.GL_ZERO, GL10.GL_SRC_COLOR) with no alpha. I am just using grayscale PNG files. But my app's using a large amount of RAM.

What I don't know is what format it is in after Android has loaded it as a Bitmap and passed it to GL. Also, I don't know if there can be memory savings by somehow indicating to OpenGL that the image only needs 8bits per pixel instead of 24. or 32, or whatever RGBA_8888 uses.

I tried adding a format field like GL_LUMINANCE to GLUtils.texImage2D(), but ended up with a corrupted image. I assume that is because the Bitmap was already in a different format, but I'm not sure how to change it.

Here's my texture loading code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. gl.glGenTextures(1, mTextureNameWorkspace, 0);
  2. int textureName=mTextureNameWorkspace[0];
  3. t.name=textureName;
  4.                
  5. InputStream is = context.getResources().openRawResource(t.resource);
  6. Bitmap bitmap = null;
  7. Bitmap temp = null;
  8. try {
  9.         temp = BitmapFactory.decodeStream(is);
  10.         bitmap = Bitmap.createBitmap(temp, 0, 0, temp.getWidth(), temp.getHeight(), flipY, false);
  11.         temp.recycle();
  12. } finally {
  13.         try {
  14.                 is.close();
  15.                 is = null;
  16.         } catch (IOException e) {
  17.         }
  18. }
  19.         gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName);
  20.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
  21.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
  22.         GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
  23.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
tenfour
Freshman
Freshman
 
Posts: 7
Joined: Mon Aug 23, 2010 10:55 pm

Top

Re: Reducing texture memory in openGL ES 1.1

Postby tenfour » Wed Mar 09, 2011 1:23 am

I have also found that passing a Bitmap that is in ALPHA_8 format to GLUtils.textImage2d() results in increased memory use!
tenfour
Freshman
Freshman
 
Posts: 7
Joined: Mon Aug 23, 2010 10:55 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 2 guests