Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » General questions about Allegro mechanics

This thread is locked; no one can reply to it. rss feed Print
General questions about Allegro mechanics
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Hi guys!

I've got a couple questions about how allegro operates internally.

Basic info about my program - I have a multi-window application, with one allegro display to capture input using the RawInput API from win32, one to display logging output using allegro, and one display for each mouse cursor I create on the screen corresponding to each hardware mouse connected to the computer.

As I understand it, allegro creates a new thread for each display it creates to run the window process on (using Windows here for the moment).

Question 1) A single thread can have multiple displays created on it, correct? And each thread has a current display, correct? Is this part of the thread local storage I've heard of? How does that work exactly?

Quoting from al_set_target_bitmap :

Quote:

Each video bitmap is tied to a display. When a video bitmap is set to as the target bitmap, the display that the bitmap belongs to is automatically made "current" for the calling thread (if it is not current already). Then drawing other bitmaps which are tied to the same display can be hardware accelerated.

A single display cannot be current for multiple threads simultaneously. If you need to release a display, so it is not current for the calling thread, call al_set_target_bitmap(NULL);

Question 2) Every bitmap has a display it is attached to, correct? Is this true for memory bitmaps too?

*Question 3) How does drawing work with multiple display threads running in parallel?

Question 4) Is there a way to detect the current display?

These questions are because of my other thread here :
https://www.allegro.cc/forums/thread/615871

My program crashes intermittently in al_set_target_bitmap. Sometimes it does, sometimes it doesn't. But it always crashes in the same place when it does.

Elias
Member #358
May 2000

1) Yes. Yes. "thread local storage" means the same as "global variable" - except each thread has a copy of that variable. So if there's a global variable "ALLEGRO_DISPLAY *current", then if there's two threads there will be two values for "current", one for each thread.

2) Only display bitmaps.

3) For example with OpenGL, each display also will have a separate OpenGL context. So if two threads call "al_draw_bitmap" at the same time, they will use different textures and draw into different framebuffers - so there is no risk of anything going wrong.

4) al_get_current_display

Now, multiple displays are probably not tested much at all as it's not something usually done in a game. And often enough something works with OpenGL only or DirectX only because it was only properly tested with one driver when first implemented. So yes, you may very well be hitting a bug in A5.

--
"Either help out or stop whining" - Evert

Go to: