itexture apply effect causing GC compaction on overlay

Started by davec64, December 16, 2013, 12:26:37 PM

Previous topic - Next topic

davec64

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

EgonOlsen

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.

davec64

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.


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());
        }
      });
    }

davec64

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


EgonOlsen

#4
Quote from: davec64 on December 16, 2013, 11:02:49 PM
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;...

EgonOlsen

Quote from: davec64 on December 17, 2013, 12:16:12 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


davec64

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