SDL_Flip and fps

Hi there,
i got problems with my fps using SDL_Flip. Thats the important code
lines:

screen = SDL_SetVideoMode(1024, 768, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
for (;:wink: {
if ( gettimeofday(&tv, NULL) < 0 )
log_Error(“Could not get the time of the day”, strerror(errno));

if (starttime == 0) starttime = tv.tv_sec;

curtime = (tv.tv_sec - starttime)*1000 + tv.tv_usec/1000;

if (oldtime == 0) oldtime = curtime;

if (oldtime+1000 <= curtime) {
cl_fps = fps;
fps = 0;
oldtime = curtime;
printf(fps: %i\n", cl_fps);
}

SDL_Split();

fps++;
}

With that code, i only get 14 fps on my system, removing SDL_Split(); i
get up to 600000 fps. I really don’t get why SDL_Split is so slow, it’s
a hardware surface and it only needs to change the buffers, or do i miss
the point?

mIc

Michael Sauer wrote:

Hi there,
i got problems with my fps using SDL_Flip. Thats the important code
lines:

screen = SDL_SetVideoMode(1024, 768, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
for (;:wink: {
if ( gettimeofday(&tv, NULL) < 0 )
log_Error(“Could not get the time of the day”, strerror(errno));

if (starttime == 0) starttime = tv.tv_sec;

curtime = (tv.tv_sec - starttime)*1000 + tv.tv_usec/1000;

if (oldtime == 0) oldtime = curtime;

if (oldtime+1000 <= curtime) {
cl_fps = fps;
fps = 0;
oldtime = curtime;
printf(fps: %i\n", cl_fps);
}

SDL_Split();

Do you mean SDL_Flip ?

fps++;
}

With that code, i only get 14 fps on my system, removing SDL_Split(); i
get up to 600000 fps. I really don’t get why SDL_Split is so slow, it’s
a hardware surface and it only needs to change the buffers, or do i miss
the point?

You’re probably running on an unaccelerated platform (X11 maybe ?), so
SDL emulates doublebuffering by copying a shadow surface to the screen
every time you do a SDL_Flip().

Specifying the SDL_HWSURFACE flag won’t get you a hardware surface on
all platforms, only on platforms that support it.

Stephane

— Stephane Marchesin <stephane.marchesin at wanadoo.fr> wrote:

You’re probably running on an unaccelerated platform (X11 maybe ?),
so SDL emulates doublebuffering by copying a shadow surface to the
screen every time you do a SDL_Flip().

Specifying the SDL_HWSURFACE flag won’t get you a hardware surface
on all platforms, only on platforms that support it.

My code, after calling SDL_SetVideoMode, checks the flags returned
from that call and echos data about the video surface into stdout.
Makes for quick data about the environment if I need to debug.

It’s my understanding from the list here that most 2d game
applications (for those of us attempting to recapture he glory days
of 8 and 16 bit game consoles :slight_smile: ) should be using software
surfaces. It’s possible to implement the system to use hardware
surfaces, but that greatly limits the target systems and is not
entirely necessary to achieve solid framerates for simpleÂŽ 2d
games. I don’t have a lot of practical experience trying to
optomize such things, though (yet), so there is probably someone
here that could tell you more.

                                                         NBarnes__________________________________

Do you Yahoo!?
Yahoo! Domains ? Claim yours for only $14.70/year
http://smallbusiness.promotions.yahoo.com/offer

[…]

My code, after calling SDL_SetVideoMode, checks the flags returned
from that call and echos data about the video surface into stdout.
Makes for quick data about the environment if I need to debug.

It’s my understanding from the list here that most 2d game
applications (for those of us attempting to recapture he glory days
of 8 and 16 bit game consoles :slight_smile: ) should be using software
surfaces. It’s possible to implement the system to use hardware
surfaces, but that greatly limits the target systems and is not
entirely necessary to achieve solid framerates for simpleÂŽ 2d
games. I don’t have a lot of practical experience trying to
optomize such things, though (yet), so there is probably someone
here that could tell you more.

                                                        NBarnes

jup. even on win32 software surfaces are sometimes faster than hardware
surfaces.