Page 1 of 1
Taking too much time to draw
Posted: Thu Sep 08, 2016 7:05 pm
by pauls313
My code iterates through a tile table every frame to draw it, but it's taking way too long. It's running at 10FPS.
Re: Taking too much time to draw
Posted: Thu Sep 08, 2016 8:44 pm
by raidho36
Well you're rendering 10 000+ objects without using batches or anything of the sort, so pretty much every draw operation translates to at least one GPU render call. And 10k+ draw calls is insane number, GPUs normally deal with few tens at most.
You need to use render batching.
Re: Taking too much time to draw
Posted: Thu Sep 08, 2016 9:13 pm
by KayleMaster
Definitely need to batch those sprites (look up spriteBatch love2d).
I'm using 9 spriteBatches and I am drawing 36864 tiles (32*16) in my game at 512 fps on a low end pc. Basically, the difference is, that it's 1 draw call instead of 10000 and that's what makes it faster. However they can be tricky to implement.
Re: Taking too much time to draw
Posted: Thu Sep 08, 2016 10:29 pm
by pgimeno
Re: Taking too much time to draw
Posted: Thu Sep 08, 2016 11:03 pm
by zorg
I also looked at the code, and apart from not being indented at all, you also redefine love.keywhatever each time love.update is called. That's not how it works, and that's not how you should do it; Define it outside love.update. Or use the isDown function in update.
Re: Taking too much time to draw
Posted: Fri Sep 09, 2016 4:00 am
by bjornbytes
I just made something that might help with this:
glance. You basically wrap your draw operations in glance.render() which will save things to a Canvas if they don't change very much -- it's a tradeoff between draw calls and texture memory. If you're able to use a SpriteBatch though, that would be the best way to do things.
Re: Taking too much time to draw
Posted: Fri Sep 09, 2016 10:11 am
by Karai17
If you're using a tilemap, you shoudl check out
STI and try using
Tiled to make your maps. This is very much a solved problem.