Sign in to follow this  
Mhondoz

SDL_MUSTLOCK needed for software surfaces?

Recommended Posts

I am using software surfaces in SDL:
_screen = SDL_SetVideoMode( width, height, 8, SDL_SWSURFACE );
_backscreen = SDL_CreateRGBSurface( SDL_SWSURFACE, width, height, 8, 0, 0, 0, 0 );
Inspecting the SDL_MUSTLOCK macro it looks like you should lock your surface if you are using SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_RLEACCEL, or surface->offset != 0. My question is, what is the surface->offset used for? The reason for questioning this is that I am not using any of the flags that will require locking, and if I could know for certain that the offset will not change from 0, I could use the surface without checking if it need to be locked. Btw. I am on Windows XP, and using the _screen in both windowed and fullscreen mode. [Edited by - Mhondoz on June 29, 2005 8:12:47 AM]

Share this post


Link to post
Share on other sites
The offset is there because some drivers will pad surfaces that do not align on certain word boundaries as an optimization. So the surface block may begin at address x in memory, but the actual image data may begin at address x+offset. You should just use the macro. Just because you request a hardware surface or system memory surface or a surface with some other flags does not mean you will always get exactly what you requested. Many times the driver will decide where and how the surface actually gets allocated. The lock macro will resolve this for you and make sure you are getting a pointer to actual image data. There is very little overhead for using the macro, the overhead is in the actual lock itself if it becomes neccessary. I would recommend just using the macro and save yourself potential head aches.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this