C API - is drawing to a bitmap faster than drawing to screen?

I am trying to implement a tilemap like the one in the Lua SDK but for C. Aside from this question if anyone knows how that's actually implemented in C that would be a huge help. I started by just drawing every tile as a bitmap to the screen one at a time (only for the tiles within the dirty rectangle). I decided to try drawing them all to a bitmap instead using playdate->graphics->pushContext and then drawing that to the screen instead (lots of draws to the bitmap but only one to screen). This actually seemed to improve the performance but I'm not sure why. Is there some overhead involved when drawing a bitmap directly to the screen vs drawing it to another bitmap? I am doing all of the draw calls in the function I gave the sprite with playdate->sprite->setDrawFunction if that changes anything.

I'm new to PlayDate, but have 38 years of professional game development behind me, so if I had to guess it is because of the way the Sharp display works that is causing it to be slower with lots of writes to it. My gut tells me it is better to have a draw buffer and write to that then do the whole thing in one hit to the Sharp hardware at the end of your game update loop, even better, if you can keep a list of rows that have changed and only update those on the Sharp hardware you should get a better bang for your buck.
This is why it would be better to have your games info UI along the top or bottom as that would be updated far less than the actual play area, meaning you could make some optimisations there.

1 Like

The display driver already tracks changed rows and only sends those to the screen, fyi. In general you shouldn't have to worry about implementation details like this.. But I don't know why it'd be faster to draw to an image buffer than directly to the screen. I'd expect it to be the other way around since the screen's framebuffer is in internal memory while the image's storage is out in the external PSRAM. If you want to put together a small demo I'd be happy to look into this, but without code to test I can only guess.