Is there a fast way to copy memory to bitmap?

This relates to the map in the game. The map consists of 32X32 segments, each of them are updated and stored in an 32X32 array of four bytes (rgba).

When any of the segment is changed or created, it needs to create it's video sprite and setup it's contents based on the array of data, so it can be actually drawn when the map is displayed. This tasks is quite slow, and the best improvement I have done (long time ago), was to find biggest set of squares and draw to the bitmap these instead of drawing pixel by pixel.

I'm looking for a way, to directly copy the raw sprite data to the allegro structures, so they are updated in one operation, which would most probably fasten the process a lot.

Thank you for any advice.


Don't know exactly what you're looking for, but I think bitmap locking and accessing data via ALLEGRO_LOCKED_REGION is the fastest way. Be sure to pass ALLEGRO_LOCK_WRITEONLY to al_lock_bitmap, so as to avoid reading texture data.


The slow part is not copying from your structure to the Allegro structure, it is fetching the video bitmap from the graphics card and putting it into main memory for manipulation, then sending back your changes to the graphics card. This was not a problem in the old days of software rendering, but it is in hardware rendering.

If it is possible, you will see significant speed increase from using a fragment shader to manipulate the bitmap. This avoids the travel cost.

Chris Katko

Assuming he's talking about Factorio:

You have this game world, split into large chunks:


You press the map button and it looks like this:


Note the square edges. Those are chunks.

But without seeing the rendering pipeline, I agree with the two answers provided. It's most likely an issue copying to system RAM. You should definitely try to avoid system bitmaps for live updates at all cost. Shaders are insanely fast.

You'd want to look into tutorials regarding "Shader Rendering to Texture".

Someone built "the Game of Life" into a texture (using every pixel!) and rendered it to a torus.


And that's about as per-pixel as you can get.

One more possibility. Thinking about this from the time axis. Assuming you're talking about that map and scanning every piece on a chunk. How much of that map needs to be updated in real-time? Can a particular chuck update be "deferred" across multiple frames? I can't remember, does the map show live movement of "alien attacks"? If not, a "chunk parse" could certainly cross a few frames and still "appear" instant to a user if that one piece is dragging the FPS down.

Thread #616107. Printed from