Batching?

Monkey Forums/Monkey Programming/Batching?

dom(Posted 2011) [#1]
Hi!

I got a little performance problem with displaying a bit gui and text (using angelfont) already (all platforms at least -50% FPS with gui enabled).

After browsing the forum I am wondering:
1) Are e.g. DrawImage calls somehow batched if they use the same texture or would I have to implement this myself?

2) Should I maybe even go so far, and merge the static quads to a single mesh or triangle strips?

Anybody got some experience?
I'd be glad for any tips as I really like the idea of the engine...but having to go so low level might be a killer :/


slenkar(Posted 2011) [#2]
do you have a lot of empty space in the images?


Dima(Posted 2011) [#3]
it might give you a boost, havent looked deep into target sources, unsure what the current implementation is. for my current mobile game i prerender static texts into textures and display portions for scrolling. this way effects like dropshadows can be baked in. takes a lot more memory, so best to load these textures on demand and unload unused ones.


dom(Posted 2011) [#4]
@Slenkar: I disabled blending, no noteable difference.


The whole situation made me curious and I took a look at the mojo native implementation for android.

It appears, that if you call e.g. DrawImage with the same texture, it should get batched.

I assume the following: using diddy-gui, I draw the labels with background (color -> DrawRect) and text per component.
Meaning no batching can happen, as it (mojo) flushes as soon as something changes (any tags for code formatting?):

void Begin( int type,int count,gxtkSurface surf ){
if( type!=rtype || surf!=rsurf || rcount+count>MAX_VERTICES ){
Flush();
rtype=type;
rsurf=surf;
}
rcount+=count;
}

So I guess in order to take advantage of batching, I'd need so some how sort the DrawImage/DrawRect calls by material myself...or simply assign all labels etc. the same texture.
And draw all text in a separate (batched) pass (don't know if pass is the correct term here).

I'll try to verify this with perfHud and keep you posted =)


anawiki(Posted 2011) [#5]
Take a look at my post in iOS section called "Why AngelFont is so slow". To make the story short, I accidentally loaded to many fonts into memory and it slowed the game from 60 to 30 FPS. Maybe it's the same case in your situation.


dom(Posted 2011) [#6]
Hi,

thanks for pointing it out!
I have read the thread before posting and changed it already though =)

Didn't have any success with perfHUD yet, but I currently really think this is because of the draw calls and state changes:
(FPS on Desire)
No gui: ~45 FPS
With gui (no text meaning text set to ""): ~35 FPS
With gui and text: 8 FPS

The frame drop vom 45 to 35 is already quite big for a few labels (30-40 piece)...and since it renders label1 background, label1 text, label2 bg, label2 text, etc. this could be the answer =)

I also see that there is a lot of Push and Pop-Matrix going on...which actually shouldn't be needed for static gui if one pre-bakes the transformaiton and so.

I'll post my results asap.