Slowness

In a message dated 1/1/02 12:03:09 PM Pacific Standard Time,
sdl-request at libsdl.org writes:

You may have run out of memory on your video card and are blitting from
system memory to video card memory. But for 1 fps it sounds like you are
reading graphic data from your video card. Perhaps you have alpha blending
switched on and one of the surfaces is in system memory and one is in video
card memory.

No, i have tons of video memory and I’m sure all the video settings are
correct…here is my code…

void Init_SDL()
{
/* Initialize the SDL library */
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
“Could not initialize SDL: %s\n”, SDL_GetError());
exit(1);
}

atexit(SDL_Quit); //Cleanup on exit


screen = SDL_SetVideoMode(800, 600, 24, SDL_HWSURFACE || SDL_DOUBLEBUF); 

//set screen to 800x600x24
if ( screen == NULL ) {
fprintf(stderr, “Could not set 800x600x24 video mode: %s\n”,
SDL_GetError());
exit(1);
}

temp = SDL_CreateRGBSurface(SDL_SWSURFACE, 800, 600, 24,
                               NULL, NULL, NULL, NULL);

}

I have tried just blit-ing to the screen and I have tried blit-ing to temp
and then when I’m done blit temp to the screen…but nothing works. I’ve
read some other messages about such slowness and they suggest blit-ing the
part of the screen that doesn’t need redrawing back onto the screen in it’s
new location…so if I were to move left 20 pixels it would be
SDL_BlitSurface(screen, &srect, temp, &drect); where srect is X = 0 Y = 0
W = 800 - 20 H = 600 drect is X = 20 Y = 0 and then
draw the left side of the screen onto temp and blit temp to the
screen…not a bad idea, and it would help too, but I should have to do
that. I can redraw the whole screen with triple buffering on a 800x600x8
screen in QB at more than 24fps…so why can’t I do it in C?

that. I can redraw the whole screen with triple buffering on a 800x600x8
screen in QB at more than 24fps…so why can’t I do it in C?

Because if you are blitting 800x600 24-bit pixels, then you are blitting
960,000 more bytes PER FRAME than at 800x600x8-bits, for a total of
1,440,000 bytes per frame. If SDL has to do extra conversion on this
(i.e. - your display is only capable of doing 16 or 32 bit color), it can
more than double the amount of memory that gets pushed around. Double
buffering can, too. Using a hardware surface that doesn’t do page flipping
doubles the memory touching again.

If you need high resolution with high color, you might want to think about
using OpenGL.

–ryan.

that. I can redraw the whole screen with triple buffering on a 800x600x8
screen in QB at more than 24fps…so why can’t I do it in C?

See Ryan’s answer… Aside from that, you’re doing a whole lot of pointless
multiplications and divisions per tile per frame … Its not enough for that
much of a slowdown, but it doesn’t help either. Make your tile sizes a power
of 2 (fx 8 or 16) to get some more speed.–
Trick


Linux User #229006 * http://counter.li.org

“There is no magic” - Nakor, magic user

well i’m not sure if this will help you but i guess you get an ugly
conversion overhead because that you did NOT createt the surface correct!

temp = SDL_CreateRGBSurface(SDL_SWSURFACE, 800, 600, 24,
NULL, NULL, NULL, NULL);
}

this wrong! as i know from the sdl docu and my expiriences you must set the
right r/g/b/a masks. by the way NULL is not an acceptable value.
i wonder that it works what you’ve done because it is’nt said that you may
ommit them.

you should take them from your “screen” e.g.:
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, 800, 600, 24,
screen->format->Rmask, screen->format->Gmask,
screen->format->Bmask, screen->format->Amask);
}

try this. maybe it helps.

ciao, stefan

Am Dienstag, 1. Januar 2002 23:02 schrieben Sie:> In a message dated 1/1/02 12:03:09 PM Pacific Standard Time,

sdl-request at libsdl.org writes:

You may have run out of memory on your video card and are blitting from
system memory to video card memory. But for 1 fps it sounds like you are
reading graphic data from your video card. Perhaps you have alpha
blending switched on and one of the surfaces is in system memory and one
is in video card memory.

No, i have tons of video memory and I’m sure all the video settings are
correct…here is my code…

void Init_SDL()
{
/* Initialize the SDL library */
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
“Could not initialize SDL: %s\n”, SDL_GetError());
exit(1);
}

atexit(SDL_Quit); //Cleanup on exit


screen = SDL_SetVideoMode(800, 600, 24, SDL_HWSURFACE ||

SDL_DOUBLEBUF); //set screen to 800x600x24
if ( screen == NULL ) {
fprintf(stderr, “Could not set 800x600x24 video mode: %s\n”,
SDL_GetError());
exit(1);
}

temp = SDL_CreateRGBSurface(SDL_SWSURFACE, 800, 600, 24,
                               NULL, NULL, NULL, NULL);

}

I have tried just blit-ing to the screen and I have tried blit-ing to temp
and then when I’m done blit temp to the screen…but nothing works. I’ve
read some other messages about such slowness and they suggest blit-ing the
part of the screen that doesn’t need redrawing back onto the screen in it’s
new location…so if I were to move left 20 pixels it would be
SDL_BlitSurface(screen, &srect, temp, &drect); where srect is X = 0 Y =
0 W = 800 - 20 H = 600 drect is X = 20 Y = 0 and then
draw the left side of the screen onto temp and blit temp to the
screen…not a bad idea, and it would help too, but I should have to do
that. I can redraw the whole screen with triple buffering on a 800x600x8
screen in QB at more than 24fps…so why can’t I do it in C?

screen = SDL_SetVideoMode(800, 600, 24, SDL_HWSURFACE || SDL_DOUBLEBUF);

Just a pedantic point – if this is an actual copy of your code (and not a
typo), the above probably means you’re either asking for a hardware surface,
but without double-buffering, or you’re just sending 1 for the flags. Not
sure what that’ll be interpreted as.

It should be SDL_HWSURFACE | SDL_DOUBLEBUF - bitwise or, not logical or.

If it was a typo, ignore this ramble :-)On Tue, 1 Jan 2002 VBillybob87 at aol.com wrote:


Mike.