32-bit fullscreen alpha - slow

Hello all,

I’m trying to create a isometric game using SDL. For the game’s tiles to
look nice I wanted to use Alpha-channeled *.png files for all the tiles. All
was going well untill I changed to fullscreen… In 640x480 with 128x64
tiles when running windowed I got usualy 40fps. But changing to fullscreen
on the same settings gave me 4fps! Why is that?

Settings :
SDL_SetVideoMode(480, 640, 32, SDL_HWSURFACE | SDL_DOUBLEBUF |
SDL_FULLSCREEN);
Images:
SDL_DisplayFormatAlpha(IMG_Load(“blah.png”));

I noticed that changing SDL_DisplayFormatAlpha to SDL_DisplayFormat gave me
back the 40fps on fullscreen but of course turned off Alpha-blending. Is
there any way to get 32-bit images on fullscreen running faster? And why
does the windowed mode run 40fps while the fullscreen mode can’t?

I have a GF4FX g-card if that matters.

regards,–
Kornel Kisielewicz

look nice I wanted to use Alpha-channeled *.png files for all the tiles. All
was going well untill I changed to fullscreen… In 640x480 with 128x64
tiles when running windowed I got usualy 40fps. But changing to fullscreen
on the same settings gave me 4fps! Why is that?

Settings :
SDL_SetVideoMode(480, 640, 32, SDL_HWSURFACE | SDL_DOUBLEBUF |

I think you meant:

SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF |
SDL_FULLSCREEN)

It’s supposed to be X/Y, not Y/X.

I noticed that changing SDL_DisplayFormatAlpha to SDL_DisplayFormat gave me
back the 40fps on fullscreen but of course turned off Alpha-blending. Is
there any way to get 32-bit images on fullscreen running faster? And why
does the windowed mode run 40fps while the fullscreen mode can’t?

I’d have to look at the rest of your code to know exactly why. There are
plenty of things that could cause this problem, far too numerous to
list.

–>Neil-------------------------------------------------------------------------------
Neil Bradley "Your mistletoe is no match for my T.O.W. missile!"
Synthcom Systems, Inc. - Santabot - Futurama
ICQ #29402898

look nice I wanted to use Alpha-channeled *.png files for all the tiles.
All

was going well untill I changed to fullscreen… In 640x480 with 128x64
tiles when running windowed I got usualy 40fps. But changing to
fullscreen

on the same settings gave me 4fps! Why is that?

Settings :
SDL_SetVideoMode(480, 640, 32, SDL_HWSURFACE | SDL_DOUBLEBUF |

I think you meant:

Yeah I did ;). In the code though it’s alright - I made a mistake while
typing this post.

I noticed that changing SDL_DisplayFormatAlpha to SDL_DisplayFormat gave
me

back the 40fps on fullscreen but of course turned off Alpha-blending. Is
there any way to get 32-bit images on fullscreen running faster? And why
does the windowed mode run 40fps while the fullscreen mode can’t?

I’d have to look at the rest of your code to know exactly why. There are
plenty of things that could cause this problem, far too numerous to
list.

Currently it’s quite unreadable - because of the graphics lib abstraction
that’s half finished. Here are the main functions:

#define SCREENX 800
#define SCREENY 600
#define BITDEPTH 32
#define SDLFLAGS SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN

void CImage::load(char * fname) {
if (image) SDL_FreeSurface(image);
image = SDL_DisplayFormatAlpha(IMG_Load(image));
if (!image) Error(strcat("IMG_Load failed : ",fname));
}.

inline void CScreen::draw(SDL_Surface* image, int x, int y) {
destination.x = x;
destination.y = y;
destination.w = image->w;
destination.h = image->h;
SDL_BlitSurface(image, NULL, screenSurface, &destination);
}

inline void CScreen::update() {
SDL_Flip(screenSurface);
SDL_FillRect(screenSurface,0,0);
}

void CScreen::init() {
if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1))

  fprintf(stderr,"Could not initialize SDL: %s.\n", SDL_GetError());
  exit(-1);
}
screenSurface = SDL_SetVideoMode(SCREENX, SCREENY, BITDEPTH, SDLFLAGS);
if ( screenSurface == NULL ) {
    fprintf(stderr, "Couldn't set video mode: %s\n",
                    SDL_GetError());
    exit(-1);

}
initialized = true;
}

void CScreen::done() {
SDL_FreeSurface(screenSurface);
SDL_Quit();
initialized = false;
}

Kornel Kisieleiwcz wrote:

Settings :
SDL_SetVideoMode(480, 640, 32, SDL_HWSURFACE | SDL_DOUBLEBUF |
SDL_FULLSCREEN);
Images:
SDL_DisplayFormatAlpha(IMG_Load(“blah.png”));

I noticed that changing SDL_DisplayFormatAlpha to SDL_DisplayFormat gave me
back the 40fps on fullscreen but of course turned off Alpha-blending. Is
there any way to get 32-bit images on fullscreen running faster? And why
does the windowed mode run 40fps while the fullscreen mode can’t?

Never use Alpha together with HWSURFACE (*), simply change your
SetVideoMode call to:

SDL_SetVideoMode(640, 480, 32, SDL_FULLSCREEN)

… and you’ll be back to at least the speed you have with the windowed
version.

Bye,
Gabry

(*): Alpha is done by CPU and needs to READ from the videosurface. Video
card memory access is optimized for writing but very slow for reading.

Gabriele Greco wrote:

Kornel Kisieleiwcz wrote:

I noticed that changing SDL_DisplayFormatAlpha to SDL_DisplayFormat
gave me back the 40fps on fullscreen but of course turned off
Alpha-blending. Is there any way to get 32-bit images on fullscreen
running faster? And why does the windowed mode run 40fps while the
fullscreen mode can’t?

Never use Alpha together with HWSURFACE (*), simply change your
SetVideoMode call to:

You’re right, impressive!
But that leaves me then with 3 questions:
** Why does the windowed mode have 40fps on HW?
** What do I lose when I run it without HWSURFACE and DOUBLEBUF?
** What good are Hardware surfaces then? (Except OpenGL that is…)

regards,
Kornel Kisielewicz

Kornel Kisieleiwcz wrote:

Gabriele Greco wrote:

Kornel Kisieleiwcz wrote:

I noticed that changing SDL_DisplayFormatAlpha to SDL_DisplayFormat
gave me back the 40fps on fullscreen but of course turned off
Alpha-blending. Is there any way to get 32-bit images on fullscreen
running faster? And why does the windowed mode run 40fps while the
fullscreen mode can’t?

Never use Alpha together with HWSURFACE (*), simply change your
SetVideoMode call to:

You’re right, impressive!
But that leaves me then with 3 questions:
** Why does the windowed mode have 40fps on HW?

Are you sure you really have HW ? Check the flags returned by
SDL_SetVideoMode :slight_smile:

** What do I lose when I run it without HWSURFACE and DOUBLEBUF?

You lose fast solid blits. But if your app is really alpha-intensive,
that’s the only way (unless you use a backend that accelerates alpha blits).

** What good are Hardware surfaces then? (Except OpenGL that is…)

They’re good, as in they’re in video memory, which means fast for
"normal" blits (solid blits & colorkeyed blits, depending on the driver
used).

But doing alpha blits on a hardware surface means you have to :

  • read the destination surface from video memory
  • do the source->destination alpha blit (in software) in system memory
  • upload the resulting surface to video memory
    Given that transfers from/to video memory are quite expensive, that can
    explain such a slowdown.

So it’s obvious that if the surface is in system memory in the first
place, the first and third point won’t need to happen. And don’t worry
about alpha speed too much, alpha blitters in SDL are quite well optimized.

Oh, and once the glSDL backend is out, alpha blits will be hardware
accelerated (and you won’t need any OpenGL programming for that).

Stephane