Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Timbertoes

Pages: [1]
1
Support / Update texture at run-time without calling GC?
« on: May 18, 2011, 12:28:27 am »
Greetings!

Here's what I'm trying to accomplish:
  I accept user input in the form of a String and would like to update a Texture during run-time to display the string whenever it's modified.

I've tried the ITextureEffect approach as well as just unloading the texture and replacing it with the new one. My current problem is that both methods seem to call the android garbage collector.

Here's my current implementation using the replaceTexture() function:
Code: [Select]
Bitmap texture_bmp = Bitmap.createBitmap(imageWidth, imageHeight, DEFAULT_BITMAP_CONFIG);

// ... Code to draw text onto texture_bmp ...

TextureManager.getInstance().unloadTexture(frameBuffer, old_texture);

old_texture = new Texture(texture_bmp, true);

TextureManager.getInstance().replaceTexture(texture_name, texture);

texture_bmp.recycle();
texture = null;

This makes sense why the GC is being called since I'm allocating a new Texture object. If I comment out the lines that allocate the new Texture, the GC is not called.

Because I want to avoid the GC, I thought I'd try and figure out how to use the ITextureEffect. I read about ways to implement it here, and here and it seemed easy enough.

However, once I had it implemented, the GC still seemed to be called each frame as long as the code that called setEffect and applyEffect were there. I did read that the ITextureEffect says: "The affected texture has to be converted and uploaded to the GPU every time the effect will be applied." My question: During this 'conversion' is a new texture being allocated and possibly triggering the GC?

I checked my memory usage and I'm only using about half of my 13MB heap while this GC is happening. The logcat output says 'GC_FOR_MALLOC' which I believe happens when a new allocation is made.

I'm aware of how delicate most operations must be, especially after reading the article on Performance tips for Android.

Allocating the new Bitmap does not seem to trigger the GC at all if I comment out the 'new Texture()' or ITextureEffect code. And as for my ITextureEffect code, it is just a blank class for now. If you need any additional code, let me know and I'll post what I can.

If anyone that is more familiar with jPCT-AE can help me out here, I would greatly appreciate it. There's always the chance that I am approaching the problem the wrong way and might need a new strategy.

Thanks!

Pages: [1]