Sign in to follow this  
Windhawk

SDL_CreateRGBSurface *masks and blitting

Recommended Posts

I have a tile surface that gets blitted to the screen every turn. The speed of this blit seems to depend a huge amount on the way I create the surface. If I initialise the tile surface like this:
tiles = SDL_CreateRGBSurface(SDL_SWSURFACE, lvlWid*TILEWID,lvlHgt*TILEHGT, 32, rmask, gmask, bmask, amask);
where the masks are given by:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    const Uint32 rmask = 0xff000000;
    const Uint32 gmask = 0x00ff0000;
    const Uint32 bmask = 0x0000ff00;
    const Uint32 amask = 0x000000ff;
#else
    const Uint32 rmask = 0x000000ff;
    const Uint32 gmask = 0x0000ff00;
    const Uint32 bmask = 0x00ff0000;
    const Uint32 amask = 0xff000000;
#endif
... it's a huge amount slower when I then blit the surface each frame than just initializing the surface like so:
tiles = SDL_CreateRGBSurface(SDL_SWSURFACE, lvlWid*TILEWID,lvlHgt*TILEHGT, 32, 0, 0, 0, 0);
which is technically wrong? This is rather confusing... is there any reason I'd want to use the correct version?

Share this post


Link to post
Share on other sites
Looking at the SDL source, if the RMask and Gmask and Bmask are all unspecified and the bpp as 32, you get a 24 bit surface with the following masks:

format->Rmask = 0xFF0000
format->Gmask = 0xFF00
format->Bmask = 0xFF

I may be wrong though, im a bit rusty with my bitwise operations.

Share this post


Link to post
Share on other sites
Ok, so that would mean no alpha in the pixel info? though presumably I can still use SDL_SetColorKey? Is there a way to speed up blitting doing it with the masks?

Share this post


Link to post
Share on other sites
Quote:
Original post by Windhawk
Ok, so that would mean no alpha in the pixel info? though presumably I can still use SDL_SetColorKey? Is there a way to speed up blitting doing it with the masks?


No alpha, thats right as far as I can see.

SDL_SetColorKey should work.

Speed up with masks? I have no idea, I think thats what SDL_DisplayFormat is for, optimising a surface for blitting to the display format.

Share this post


Link to post
Share on other sites
If you're looking for a way to speed up your alpha-channel blits, you could look into using an OpenGL-based wrapper like hxRender to do the alpha-blitting for you using hardware-acceleration. It's about 15% faster than SDL's alpha-channel blitting. And the best part about it is that, by setting up your OpenGL context with SDL, you can still use SDL_mixer and SDL_image and all of your other favorite SDL libraries with it.

Share this post


Link to post
Share on other sites
Thanks, rip-off, the colorkey will do for me for now, so I'll probably just carry on using the 24 bit surface. Presumably I can define 24 bit "*mask" variables, and just use 0 for the amask to create a 24 bit surface properly? so...


#if SDL_BYTEORDER == SDL_BIGENDIAN
const Uint32 rmask = 0xff0000
const Uint32 gmask = 0x00ff00
const Uint32 bmask = 0x0000ff
#else
const Uint32 rmask = 0x0000ff
const Uint32 gmask = 0x00ff00
const Uint32 bmask = 0xff0000
#endif


Quote:
Original post by samuraicrow
If you're looking for a way to speed up your alpha-channel blits, you could look into using an OpenGL-based wrapper like hxRender to do the alpha-blitting for you using hardware-acceleration. It's about 15% faster than SDL's alpha-channel blitting. And the best part about it is that, by setting up your OpenGL context with SDL, you can still use SDL_mixer and SDL_image and all of your other favorite SDL libraries with it.


Thanks, samuraicrow, it's not too vital for me at the moment, since I don't really need the alpha channel, and the colorkey will do fine for what I'm doing, but I'll look into that.

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