[SDL] CPU Usage

Diaa Sami diaasami at yahoo.com
Thu Jul 28 02:12:03 PDT 2005


I've been using SDL for 2 weeks, so I'm somekind of a newbie with SDL.
everything went fine until I noticed that my app uses about 80~90% (too 
much!) of the CPU, although I'm using a framerate limiter to limit the 
fps to 30.

well, this is my problem, I want to lower the CPU usage of my app, it 
varies according to what's drawn on the screen, but I couldn't manage to 
get it below 40% (which I consider high)

I've checked various apps/games, some using SDL, other using 
DirectDraw(coz I thought the problem is with SDL's implementation), and 
I found some DD and SDL apps which use little < 25% which's perfect.
so I knew it can be achieved.

one of the apps I checked was the testsprite sample that comes with SDL, 
I've checked the source code, and I found out that using 
SDL_UpdateRects() lowers the CPU usage much, but I can't use it 
everywhere in my app, sometimes I need to redraw the whole screen.

I found that by only clearing the screen to black, and then updating, I 
get a relatively high CPU usage(60-70%)!
here's the drawing part of the game loop.
{
SDL_FillRect(screen, NULL, black);
SDL_Update(screen, 0, 0, 0, 0);
SDL_framelimiterDelay(&fpsManager);	// the framerate limiter
}

so could someone help me identify the solution?
please don't tell me to use OpenGL, I already know OpenGL, and I know 
it'll solve the problem, but it's not suitable for my app because of 
some requirements.

Info:
Desktop configuration: 1024*768*32
OS: Windows XP
RAM: 512 MB
VGA Card: RIVA TNT2 32 MB.

SDL Video Mode: Windowed 640*480*24(I've tried also 32 bpp), I use 
SWSURFACE coz I have a fair amount of alpha blending.
SDL_VideoInfo:
Is it possible to create hardware surfaces : 1
Is there a window manager available : 1
Are hardware to hardware blits accelerated : 1
Are hardware to hardware colorkey blits accelerated : 1
Are hardware to hardware alpha blits accelerated : 0
Are software to hardware blits accelerated : 1
Are software to hardware colorkey blits accelerated : 1
Are software to hardware alpha blits accelerated : 0
Are color fills accelerated : 1
Total amount of video memory in Kilobytes : 28688
Driver Name: directx

sorry for the long post and thanks for your effort.





More information about the SDL mailing list