[SDL] Bad performence problems

darkplastic darkeninghorizons at hotmail.com
Fri Aug 11 12:19:17 PDT 2006




David Olofson wrote:
> 
> On Friday 11 August 2006 03:05, darkplastic wrote:
>> 
>> I have been working on this one algorithm for days to try and make
>> it work at a reasonable speed but to no avail...was hoping meyb u
>> guys could help! :)....firstly my coputer specs: athlon 2100xp 1gig
>> ram r9800pro gfx card.....
>>                At the moment i am writing a top down shooter, and i
>> am  trying to write an algorithm that darkens the whole screen apart
>> from a circular area around the player using the folliwng algorithm
>> that i made:
> [...]
> 
> I'm doing this, although not to this extreme extent, in Kobo Deluxe. 
> Though there is (of course) a frame rate hit, it's pretty much 
> insignificant on anything better than a Pentium II. (And even so, it 
> can be turned off, if you really need to.)
> 
> My solution is very simple: A black overlay (actually includes some 
> framework graphics, but that's not really relevant to this 
> discussion) with an alpha channel that creates a smooth "shadow" 
> inside the frame of the playfield.
> 
> When using SDL 2D rendering, I just SDL_DisplayFormatAlpha() this 
> overlay surface with RLE acceleration, along with all other graphics. 
> On platforms that can provide a double buffered hardware screen, 
> "SemiTriple" buffering is used, which means the changes for each 
> frame are rendered into an off-screen software surface and blitted 
> from there to the display surface, and then a flip is performed. On 
> platforms that will only provide a "single" buffered software display 
> (like most Un*x systems running X11 or similar), rendering is done 
> "directly" into the display surface - no special tricks needed.
> 
> When using OpenGL (through the old glSDL wrapper), I make use of 
> normal OpenGL source alpha blending. (Since it's hardware 
> accelerated, the CPU/VRAM issue is avoided, so no strange hacks 
> needed for performance here.)
> 
> 
> If you're stuck with software rendering (which you are, unless you're 
> using OpenGL directly or via some version of glSDL), there are two 
> important things to keep in mind:
> 
> 	1) Alpha blending is a read-modify-write operation, and
> 	   reading from VRAM is usually very, very expensive on
> 	   modern PC hardware. Thus, when doing significant
> 	   amounts of alpha blending, doing all rendering into
> 	   a software surface, and then blitting that to the
> 	   display surface is often much faster than working
> 	   directly in a hardware display surface.
> 
> 	2) Alpha blending is rather expensive per pixel, compared
> 	   to plain opaque blitting. However, when using SDL's
> 	   RLE acceleration this impacts only pixels that actually
> 	   are translucent. Transparent pixels are skipped, while
> 	   opaque pixels are copied. Thus, there can be a lot of
> 	   speed to gain by keeping the alpha channel clean, and
> 	   not using more translucency effects than absolutely
> 	   required.
> 
> 
> //David Olofson - Programmer, Composer, Open Source Advocate
> 
> .-------  http://olofson.net - Games, SDL examples  -------.
> |        http://zeespace.net - 2.5D rendering engine       |
> |       http://audiality.org - Music/audio engine          |
> |     http://eel.olofson.net - Real time scripting         |
> '--  http://www.reologica.se - Rheology instrumentation  --'
> 
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
> 
> 


Thanks so much for your help, i manged to create a hardware accelerated
black fade surface and make the whole map dark but however i am a bit
confused as to how exactly to set an alpha channel that creates a smooth
shadow, i hear that there is a way to set alpha on a surface depending on
the greyscale of another or something? but i cant seem to find a way of
doing this. Thanks in advance.

-James 
-- 
View this message in context: http://www.nabble.com/Bad-performence-problems-tf2088149.html#a5768018
Sent from the SDL forum at Nabble.com.





More information about the SDL mailing list