![]() |
|
[A5] Bitmap locking |
SimonN
Member #8,272
January 2007
![]() |
Hey folks, I have these questions about Allegro 5's al_lock_bitmap and al_unlock_bitmap, which I couldn't answer by reading the manual and wiki. 1. Does locking in a readable mode simply mean to copy a bitmap into RAM, or is there more to it? (Unlocking will do different things, based on whether the lock was read-only.) If so, does locking/unlocking a memory bitmap do anything at all? 2. Assume I have a video bitmap, onto which I wish to blit several other video bitmaps. I won't use any drawing primitives here. Which of these bitmaps should I lock for best performance? 3. If I lock the same bitmap several times (might happen write-only or readwrite), is that hazardous or taxing on performance? What will happen if I unlock it too many times? These questions arise as I'm porting my game from A4 to A5. I was only using memory bitmaps in A4, which likely hasn't ever been a great idea, and I wish to do a cleaner job in A5. -- Simon |
Elias
Member #358
May 2000
|
1. Yes. Locking a memory bitmap does nothing. 2. You should lock none of them. 3. You cannot lock a locked bitmap again if that's what you meant. And both locking (for reading) and un-locking (for writing) will be extremely slow. Basically, locking is required to copy data from memory to a video bitmap, so is used internally by e.g. al_load_bitmap (with OpenGL, it will translate to e.g. glTexImage2d). Other than that you should mostly avoid it. Taking a screenshot would require locking the screen (translates to e.g. glReadPixels with OpenGL). Also for things like streaming a video you may have to lock a bitmap for writing. But in any other cases where you think you need locking it's likely much faster to not use it. Especially for per-pixel manipulations you should use shaders. -- |
SimonN
Member #8,272
January 2007
![]() |
Thanks, this has helped to think about its benefits and pitfalls. Yes, for #3, I meant locking an already locked bitmap. I'll continue to play around, and think about shader usage where appropriate. -- Simon |
|