From 3b395c26396ddd225c465fc8cc9c590dc833fbb7 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 14 Feb 2019 06:47:15 +0000 Subject: [PATCH] Draw.cpp fix and optimisations For whatever reason, alpha blending is enabled by default on surfaces. Disabling it should result in faster blits, and also follow DirectDraw's behaviour more closely. --- src/Draw.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Draw.cpp b/src/Draw.cpp index 6917b752..016b4a7b 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -155,6 +155,7 @@ bool MakeSurface_Generic(int bxsize, int bysize, int surf_no) { //Create surface surf[surf_no].surface = SDL_CreateRGBSurfaceWithFormat(0, bxsize * magnification, bysize * magnification, 0, SDL_PIXELFORMAT_RGBA32); + SDL_SetSurfaceBlendMode(surf[surf_no].surface, SDL_BLENDMODE_NONE); if (surf[surf_no].surface == NULL) { @@ -224,7 +225,7 @@ static bool LoadBitmap(SDL_RWops *fp, int surf_no, bool create_surface) } else { - SDL_Surface *surface = SDL_LoadBMP_RW(fp, 1); + SDL_Surface *surface = SDL_LoadBMP_RW(fp, 0); if (surface == NULL) { @@ -238,7 +239,6 @@ static bool LoadBitmap(SDL_RWops *fp, int surf_no, bool create_surface) { SDL_Rect dst_rect = {0, 0, surface->w, surface->h}; SDL_BlitSurface(surface, NULL, surf[surf_no].surface, &dst_rect); - SDL_FreeSurface(surface); surf[surf_no].needs_updating = true; printf(" ^ Successfully loaded\n"); success = true; @@ -287,6 +287,8 @@ static bool LoadBitmap(SDL_RWops *fp, int surf_no, bool create_surface) } } + fp->close(fp); + return success; } @@ -379,6 +381,7 @@ void BackupSurface(int surf_no, RECT *rect) //Get texture of what's currently rendered on screen SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, SDL_PIXELFORMAT_RGBA32); + SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE); SDL_RenderReadPixels(gRenderer, NULL, SDL_PIXELFORMAT_RGBA32, surface->pixels, surface->pitch); //Get rects