i experence strange behalfier when doing per surface alpha enabled
blits. setting also a colorkey decreases speed dramatically.
i have written a short program to demonstrate this:
#include <stdio.h>
#include <SDL.h>
int main(int argc, char **argv) {
unsigned int rgb, bpp, flg = SDL_SWSURFACE | SDL_ANYFORMAT;
SDL_Surface *screen, *sfc1, *sfc2;
SDL_Rect r1 = { 240, 200, 0, 0 };
SDL_Rect r2 = r1;
int x;
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(800, 600, 0, flg);
bpp = screen->format->BitsPerPixel;
sfc1 = SDL_CreateRGBSurface(flg, 320, 200, bpp, 0, 0, 0, 0);
sfc2 = SDL_CreateRGBSurface(flg, 320, 200, bpp, 0, 0, 0, 0);
rgb = SDL_MapRGB(sfc1->format, 0xff, 0x00, 0xff);
if (argc>1) {
SDL_SetColorKey(sfc1, SDL_SRCCOLORKEY, rgb);
SDL_SetColorKey(sfc2, SDL_SRCCOLORKEY, rgb);
}
SDL_SetAlpha(sfc1, SDL_SRCALPHA, 128);
SDL_SetAlpha(sfc2, SDL_SRCALPHA, 128);
rgb = SDL_MapRGB(sfc1->format, 0xdd, 0x11, 0x11);
SDL_FillRect(sfc1, NULL, rgb);
rgb = SDL_MapRGB(sfc1->format, 0x11, 0x11, 0xdd);
SDL_FillRect(sfc2, NULL, rgb);
rgb = SDL_MapRGB(sfc1->format, 0xff, 0xff, 0xff);
SDL_FillRect(screen, NULL, rgb);
for (x=0; x<480; x++) {
r2.x = x;
SDL_BlitSurface(sfc1, NULL, screen, &r1);
SDL_BlitSurface(sfc2, NULL, screen, &r2);
SDL_Flip(screen);
SDL_FillRect(screen, &r1, rgb);
SDL_FillRect(screen, &r2, rgb);
}
return (0);
}
gcc -Wall sdl-config --cflags --libs -o bla bla.c
time ./bla
real 0m10.134s
time ./bla 1
real 0m14.180s
i understand that enabling colorkey means an additional branch to the
blitter, but i wouldn’t expect that much of a slowdown. (note: the
numbers are much to low, because it measures not only the blits but
also initializing SDL, clearing the screen and flipping it.)
is there something i can do about this? can SDL be improved in that
direction or is it even a bug in my program?
many thx …
clemens