Performance optimisation for blitting loops and depth3d

This commit is contained in:
Simon Robertshaw
2016-07-12 19:48:58 +01:00
parent 0cf117a5f0
commit b66ca770da

View File

@@ -279,11 +279,11 @@ void blit(pixel * vid)
unsigned int red, green, blue; unsigned int red, green, blue;
pixel px, lastpx, nextpx; pixel px, lastpx, nextpx;
SDL_PixelFormat *fmt = sdl_scrn->format; SDL_PixelFormat *fmt = sdl_scrn->format;
if(depth3d)
{
for (j=0; j<h; j++) for (j=0; j<h; j++)
{ {
for (i=0; i<w; i++) for (i=0; i<w; i++)
{
if (depth3d)
{ {
lastpx = i >= depth3d && i < w+depth3d ? src[i-depth3d] : 0; lastpx = i >= depth3d && i < w+depth3d ? src[i-depth3d] : 0;
nextpx = i >= -depth3d && i < w-depth3d ? src[i+depth3d] : 0; nextpx = i >= -depth3d && i < w-depth3d ? src[i+depth3d] : 0;
@@ -296,14 +296,6 @@ void blit(pixel * vid)
red = ((int)(PIXR(lastpx)*.69f+redshift*.3f)>>fmt->Rloss)<<fmt->Rshift; red = ((int)(PIXR(lastpx)*.69f+redshift*.3f)>>fmt->Rloss)<<fmt->Rshift;
green = ((int)(PIXG(nextpx)*.3f)>>fmt->Gloss)<<fmt->Gshift; green = ((int)(PIXG(nextpx)*.3f)>>fmt->Gloss)<<fmt->Gshift;
blue = ((int)(PIXB(nextpx)*.69f+blueshift*.3f)>>fmt->Bloss)<<fmt->Bshift; blue = ((int)(PIXB(nextpx)*.69f+blueshift*.3f)>>fmt->Bloss)<<fmt->Bshift;
}
else
{
px = src[i];
red = (PIXR(px)>>fmt->Rloss)<<fmt->Rshift;
green = (PIXG(px)>>fmt->Gloss)<<fmt->Gshift;
blue = (PIXB(px)>>fmt->Bloss)<<fmt->Bshift;
}
dst[i] = red|green|blue; dst[i] = red|green|blue;
} }
dst+=sdl_scrn->pitch/PIXELSIZE; dst+=sdl_scrn->pitch/PIXELSIZE;
@@ -312,12 +304,29 @@ void blit(pixel * vid)
} }
else else
{ {
int i;
for (j=0; j<h; j++) for (j=0; j<h; j++)
{ {
if (depth3d) for (i=0; i<w; i++)
{
px = src[i];
red = (PIXR(px)>>fmt->Rloss)<<fmt->Rshift;
green = (PIXG(px)>>fmt->Gloss)<<fmt->Gshift;
blue = (PIXB(px)>>fmt->Bloss)<<fmt->Bshift;
dst[i] = red|green|blue;
}
dst+=sdl_scrn->pitch/PIXELSIZE;
src+=pitch;
}
}
}
else
{
int i;
if(depth3d)
{ {
pixel lastpx, nextpx; pixel lastpx, nextpx;
for (j=0; j<h; j++)
{
for (i=0; i<w; i++) for (i=0; i<w; i++)
{ {
lastpx = i >= depth3d && i < w+depth3d ? src[i-depth3d] : 0; lastpx = i >= depth3d && i < w+depth3d ? src[i-depth3d] : 0;
@@ -330,13 +339,20 @@ void blit(pixel * vid)
blueshift = 255; blueshift = 255;
dst[i] = PIXRGB((int)(PIXR(lastpx)*.69f+redshift*.3f), (int)(PIXG(nextpx)*.3f), (int)(PIXB(nextpx)*.69f+blueshift*.3f)); dst[i] = PIXRGB((int)(PIXR(lastpx)*.69f+redshift*.3f), (int)(PIXG(nextpx)*.3f), (int)(PIXB(nextpx)*.69f+blueshift*.3f));
} }
dst+=sdl_scrn->pitch/PIXELSIZE;
src+=pitch;
}
} }
else else
{
for (j=0; j<h; j++)
{
memcpy(dst, src, w*PIXELSIZE); memcpy(dst, src, w*PIXELSIZE);
dst+=sdl_scrn->pitch/PIXELSIZE; dst+=sdl_scrn->pitch/PIXELSIZE;
src+=pitch; src+=pitch;
} }
} }
}
if (SDL_MUSTLOCK(sdl_scrn)) if (SDL_MUSTLOCK(sdl_scrn))
SDL_UnlockSurface(sdl_scrn); SDL_UnlockSurface(sdl_scrn);
SDL_UpdateRect(sdl_scrn,0,0,0,0); SDL_UpdateRect(sdl_scrn,0,0,0,0);