Low framerate on android using immediateLayer (and weird playn log message)

StackOverflow https://stackoverflow.com/questions/11779919

  •  24-06-2021
  •  | 
  •  

Question

I am trying to get my game running smoothly on android using PlayN, everything works as expected but I have a verry low framerate. I think i might be doing it the wrong way so it'd be great if someone could give me some help :D.

So I'm currently creating an ImmediateLayer and cleaning it and drawing every objet at every frame, images are loaded once using graphics.getImage(...). I get around 10 fps on a HTC Desire (connected in debug mode) while drawing around 100 images. It gets slower as I add objetcs. What makes me think I am doing something really wrong is that PlayN is spamming the log (I use DDMS to check the log) with these messages.

X Textures remaining

Y Textures created

It appears around 20 times per second.

So basically i am doing something like this:

public void draw(Surface s){
for (Drawable d : toDraw) {
        surface.drawImage(d.getImage(), d.x, d.y, d.w, d.h); }}

Where draw is called in the renderer of an immediateLayer.

thank you for your time!

Lucas

Edit: I found a possible answer reading that thread on playn mailing list. https://groups.google.com/forum/?fromgroups#!topic/playn/XJTlBgmfzaQ

especially that message

Most of the tiles share the same image, but different parts of it (atteined by subImage, which to my knowledge doesn't copy but rather only creates a reference to a sub part to the image?). Would different sub parts cause a texture change?

Sub-images will share the same texture, but you have to be sure to render all the images that share the same texture together. If you have a bunch of sub images from image A and a bunch from image B and you render A, B, A, B, A, B, A, B, you are getting same performance as if you rendered eight different images. You need to render A, A, A, A, B, B, B, B.

It seems I am in a worst case scenario.

I have many different textures (say 50), They're all part of a different image and all rendered randomly. I may end up with something close to N texture switch where N is the number of objet i render.

I'll update this when i get something to work :).

Edit 2:

I am now rendering 100 objet pointing to the same Image (so no texture swap?). I still get about 10 fps on android and the debug log is still saying in each frame:

1 textures remain 2 textures created

I feel like i'm missing something important... help :).

Was it helpful?

Solution

After some deeper testing I found that :

1) The htc desire cannot be expected to get 60 fps drawing hundreds of objects even sharing the same image.

2) imageLayer attached to a group layer seems to provide better performance on android

3) Calling surface.clear() at the beginning of the renderer callback (using immediate layer) greatly improved the performance of the draw and removed the "textures created" debug log.

4) Finally sorting the object by texture and reducing the number of texture swap (drawing A A A A B B B istead of A B A B A B) gave me better results.

The app is now runnig at 30 fps on the desire and 60 fps on a galaxy S2 drawing around 500 object on screen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top