speeding up mandelbrot fractal creation

I am using Allegro 5 on Ubuntu 14.04. I am creating the Mandelbrot fractal on a 1333 x 1000 display, and a bitmap of the same size. I lock the bitmap, issue 273248 calls to al_put_pixel with color black (background is white), unlock the bitmap, and flip the display. The resulting display is fine, but the timing is not so good compared to SDL2:

time on Allegro 5: 3.8 seconds
time on SDL2 : 0.15 seconds

I would appreciate advice on how to speed up the Allegro version, and also can Allegro take advantage of my Nvidia Fermi architecture graphics card?


Edgar Reynaldo

There are several techniques that allow you to speed up allegro drawing.

1. Lock your target bitmap before drawing to it, and unlock it when done.
A. Lock only the region you need. The smaller the better.
B. Lock it write only if you can. This prevents the download of the texture from the gpu

2. Draw using the primitives addon. Depends on what you're doing, but batch drawing helps speed things up for example if you have an ALLEGRO_PRIM_POINT_LIST.

3. Hold your bitmap drawing. This is useful when all graphics being drawn are on the same texture in the gpu.


Thanks for the reply. I am using al_lock_bitmap, and will try the other suggestions soon.


mandelbrot is computed per-pixel, thus a shader would probably be the fastest way.


Edgar Reynaldo

There are two ways to do it using al_lock_bitmap as well.

1. Lock bitmap in desired format

2. Option A. Let allegro draw using al_put_pixel or al_draw_pixel.

2. Option B. Draw directly to the locked bitmap using memory access through locked_region->data. See ALLEGRO_LOCKED_REGION and ALLEGRO_PIXEL_FORMAT.

3. Unlock bitmap

Bruce Pascoe

al_draw_pixel() is generally the faster of the two, I've found.

al_draw_prim() is the best option here though. This lets you build up the points in memory and send them to the GPU all at once so the whole thing is blazing fast.

Directly working with the screen at the pixel level is a thing of the past. You need different techniques with modern hardware. :)

Thread #615551. Printed from Allegro.cc