Will SDL_SetAlpha move a surface from Video Mem ory to System Memory?

Will SDL_SetAlpha will move a surface from Video memory to System memory? I
think this should be made explicit because the documentation for
SDL_CreateSurface makes several mentions of calling SDL_SetAlpha+SDL_SRCALPHA
after a SDL_Surface is created.

Take the following example when the hardware does not support support hardware-
accelerated alpha-blending blits:

Calling SDL_CreateSurface+SDL_HWSURFACE+SDL_SRCALPHA will return a software
surface.

If only SDL_CreateSurface+SDL_HWSURFACE is called, a hardware surface is
returned. Calling SDL_SetAlpha+SDL_SRCALPHA on this hardware surface will,
what? Enable alpha blending on the hardware surface, or move the surface from
video memory to system memory?

  • Luke

SDL_SetAlpha does not mess with your surface in any serious way. It is just an interface to surface->format->alpha and the SDL_SRCALPHA flag in surface->flags. The give-away to this functionality is that SDL always makes a copy of a surface and hands it to you when it does conversions. This is necessary so you aren’t forced into overhead like freeing memory. I’m not certain that creating a SDL_HWSURFACE | SDL_SRCALPHA surface will return a software surface. This might be due to your system. Setting SDL_SRCALPHA on a hardware surface will not move the surface anywhere (that’d be quite the computation whenever you call it). As has been said plenty of times, reading from video memory is very slow, so if you’re going to be doing some alpha-blending, it should be done in software.

I wrote up a chart that I think displays the colorkey/alpha-blending capabilities of SDL better than the documentation:
http://pubpages.unh.edu/~jmb97/tutorials/blending.html

I hope that helps,
Jonny D> To: sdl at libsdl.org

From: luke at balooga.com
Date: Sun, 10 Aug 2008 02:42:33 +0000
Subject: [SDL] Will SDL_SetAlpha move a surface from Video Memory to System Memory?

Will SDL_SetAlpha will move a surface from Video memory to System memory? I
think this should be made explicit because the documentation for
SDL_CreateSurface makes several mentions of calling SDL_SetAlpha+SDL_SRCALPHA
after a SDL_Surface is created.

Take the following example when the hardware does not support support hardware-
accelerated alpha-blending blits:

Calling SDL_CreateSurface+SDL_HWSURFACE+SDL_SRCALPHA will return a software
surface.

If only SDL_CreateSurface+SDL_HWSURFACE is called, a hardware surface is
returned. Calling SDL_SetAlpha+SDL_SRCALPHA on this hardware surface will,
what? Enable alpha blending on the hardware surface, or move the surface from
video memory to system memory?

  • Luke

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Jonathan Dearborn <grimfang4 hotmail.com> writes:

Thank you for the feedback. Additional comments below.

SDL_SetAlpha does not mess with your surface in any serious way.?
I’m not certain that creating a SDL_HWSURFACE | SDL_SRCALPHA surface
will return a software surface.? This might be due to your system.?

On my system, probably not. I’m just thinking edge cases.

There seems to be no way to get SDL to create a RGBA surface in video memory if
the hardware does not support accelerated alpha-blending blits. SDL will always
set SDL_SRCALPHA if the alpha mask is not 0. You can turn SDL_SRCALPHA off on a
subsequent call to SDL_SetAlpha, but then you have a software surface.

As has been said plenty of times, reading from video memory is very slow,
so if you’re going to be doing some alpha-blending, it should be done
in software.

Unless the hardware supports accelerated alpha-blending blits, correct? I
thought this was the point of passing SDL_HWSURFACE | SDL_SRCALPHA to
SDL_Create_Surface.

I wrote up a chart that I think displays the
colorkey/alpha-blending capabilities of SDL better than the
documentation:
http://pubpages.unh.edu/~jmb97/tutorials/blending.html

I like that chart. Just a couple of comments.

#1 - I think you need to mention that SDL_SRCALPHA and SDL_SRCCOLORKEY must be
set on the ‘source’ surface. The chart does not make this clear.

#2 - See your sentence, “Notice that when performing alpha-blending in SDL,
there is no way to blend the destination alpha (see Sprig).” I don’t see this
in the chart which is what ‘Notice’ implies. I think you pobably mean “Note:
When performing alpha-blending in SDL, there is no way to blend the destination
alpha (see Sprig).”