Author Topic: itexture apply effect causing GC compaction on overlay  (Read 2998 times)

Offline davec64

  • byte
  • *
  • Posts: 31
    • View Profile
itexture apply effect causing GC compaction on overlay
« on: December 16, 2013, 12:26:37 pm »
I am using overlays to place some text on the 3d view .if I do not apply the effect GC is firing about 1 time in 25 seconds. I normally call apply 1 time per second. And GC is firing almost every second causing a pause of 100 ms which even pauses my async tasks as well.
I am running at 25 fps with plenty of spare CPU. It frees around 8000k in 100ms.
Any ideas how to stop the memory being allocated and deallocated.
Dave

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: itexture apply effect causing GC compaction on overlay
« Reply #1 on: December 16, 2013, 09:53:37 pm »
Applying an ITextureEffect is costly, because it requires a new texture upload which needs some memory. If it's used as an overlay, chances are that you don't need mipmaps. You can disable them by setting this to false: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Texture.html#setMipmap(boolean)

Another thing worth trying is to use the latest beta jar: http://jpct.de/download/beta/jpct_ae.jar. It includes some changes to reuse buffers if possible when uploading textures.

Offline davec64

  • byte
  • *
  • Posts: 31
    • View Profile
Re: itexture apply effect causing GC compaction on overlay
« Reply #2 on: December 16, 2013, 11:02:49 pm »
Hi Egon 
The logcat is being spammed with creating 32768 texture buffer in this version.

I am not seeing any benefits in the GC department I Have turned off mipmap as well.

Code: [Select]
if (overlayBitmap == null) {
      // get a canvas to paint over the overlayBitmap
      overlayBitmap = Bitmap.createBitmap(nextPow2(280), nextPow2(64), Bitmap.Config.ARGB_8888);
      overlayBitmap.eraseColor(0);
      overlayCanvas = new Canvas(overlayBitmap);
      overlay = new Texture(Bitmap.createBitmap(overlayBitmap));
      overlay.setMipmap(false);
      overlay.setEffect(new ITextureEffect() {

        @Override
        public void init(Texture arg0) {
        }

        @Override
        public boolean containsAlpha() {
          return true;
        }

        @Override
        public void apply(int[] dest, int[] src) {
          overlayBitmap.getPixels(dest, 0, overlay.getWidth(), 0, 0, overlay.getWidth(),
              overlay.getHeight());
        }
      });
    }

Offline davec64

  • byte
  • *
  • Posts: 31
    • View Profile
Re: itexture apply effect causing GC compaction on overlay
« Reply #3 on: December 17, 2013, 12:16:12 am »
Is there any other way to create a lets call it a text character layer over the 3d view. When I designed an Arcade Board in an Asic I created an 8*8 character map that was the first layer ( hi score points player level info etc) then 2 * 16*16 background layers. I just pointed the index (texture pointer) in the map to the correct character to display.
So if you like a plane with a custom character texture of say 64 characters . The same as I have done for my depth plane. but with alphanumeric's rather than textures. It would have to support transparency.
Before the days of 3D rendering chips. :-)

This would resolve all the memory re use issues in my case and it would be incredibly quick and would not require any bitmap and canvas draw rubbish.

Dave

 

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: itexture apply effect causing GC compaction on overlay
« Reply #4 on: December 17, 2013, 09:11:46 am »
The logcat is being spammed with creating 32768 texture buffer in this version.
Thanks for pointing that out. I forgot to limit this particular message to debug mode. Too bad that it didn't help though.

Edit: i just remembered that you have enable that feature by setting Config.reuseTextureBuffers=true;...
« Last Edit: December 17, 2013, 09:31:57 am by EgonOlsen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: itexture apply effect causing GC compaction on overlay
« Reply #5 on: December 17, 2013, 09:14:24 am »
So if you like a plane with a custom character texture of say 64 characters . The same as I have done for my depth plane. but with alphanumeric's rather than textures. It would have to support transparency.
So this is all about text rendering? In that case, using an ITextureEffect is pretty inefficient (as you have noticed) and not really needed anyway. You can use a texture with all the characters in it and blit parts of if to render the text. That's much more efficient than rendering into a bitmap which will then be converted to a texture. Or, to ease things, use this: http://www.jpct.net/forum2/index.php/topic,1563.0.html

Offline davec64

  • byte
  • *
  • Posts: 31
    • View Profile
Re: itexture apply effect causing GC compaction on overlay
« Reply #6 on: December 17, 2013, 12:14:33 pm »
I will try that in the morning

Offline davec64

  • byte
  • *
  • Posts: 31
    • View Profile
Re: itexture apply effect causing GC compaction on overlay
« Reply #7 on: December 18, 2013, 06:44:12 am »
Works a treat. I think I looked at that thread initially but was not sure of the implementation. the apk file was a nice touch to ensure it was what I wanted.
Dave