Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDLSurfaceSprite2D: consolidate SetSurfaceRLE calls into a private fu…
…nction this is hopefully compatible with SDL 1.2
- Loading branch information
1 parent
43aa7fd
commit 1ede211
Showing
3 changed files
with
26 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -32,9 +32,7 @@ SDLSurfaceSprite2D::SDLSurfaceSprite2D(int Width, int Height, int Bpp, void* pix | ||
surface = SDL_CreateRGBSurfaceFrom( pixels, Width, Height, Bpp < 8 ? 8 : Bpp, Width * ( Bpp / 8 ), | surface = SDL_CreateRGBSurfaceFrom( pixels, Width, Height, Bpp < 8 ? 8 : Bpp, Width * ( Bpp / 8 ), | ||
0, 0, 0, 0 ); | 0, 0, 0, 0 ); | ||
freePixels = true; | freePixels = true; | ||
#if SDL_VERSION_ATLEAST(1,3,0) | SetSurfaceRLE(true); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
wjp
Member
|
|||
SDL_SetSurfaceRLE(surface, SDL_TRUE); | |||
#endif | |||
} | } | ||
|
|
||
SDLSurfaceSprite2D::SDLSurfaceSprite2D (int Width, int Height, int Bpp, void* pixels, | SDLSurfaceSprite2D::SDLSurfaceSprite2D (int Width, int Height, int Bpp, void* pixels, | ||
|
@@ -44,9 +42,7 @@ SDLSurfaceSprite2D::SDLSurfaceSprite2D (int Width, int Height, int Bpp, void* pi | ||
surface = SDL_CreateRGBSurfaceFrom( pixels, Width, Height, Bpp < 8 ? 8 : Bpp, Width * ( Bpp / 8 ), | surface = SDL_CreateRGBSurfaceFrom( pixels, Width, Height, Bpp < 8 ? 8 : Bpp, Width * ( Bpp / 8 ), | ||
rmask, gmask, bmask, amask ); | rmask, gmask, bmask, amask ); | ||
freePixels = true; | freePixels = true; | ||
#if SDL_VERSION_ATLEAST(1,3,0) | SetSurfaceRLE(true); | ||
SDL_SetSurfaceRLE(surface, SDL_TRUE); | |||
#endif | |||
} | } | ||
|
|
||
SDLSurfaceSprite2D::SDLSurfaceSprite2D(const SDLSurfaceSprite2D &obj) | SDLSurfaceSprite2D::SDLSurfaceSprite2D(const SDLSurfaceSprite2D &obj) | ||
|
@@ -55,9 +51,7 @@ SDLSurfaceSprite2D::SDLSurfaceSprite2D(const SDLSurfaceSprite2D &obj) | ||
surface = SDL_ConvertSurface(obj.surface, obj.surface->format, obj.surface->flags); | surface = SDL_ConvertSurface(obj.surface, obj.surface->format, obj.surface->flags); | ||
pixels = surface->pixels; | pixels = surface->pixels; | ||
freePixels = false; | freePixels = false; | ||
#if SDL_VERSION_ATLEAST(1,3,0) | SetSurfaceRLE(obj.RLE); | ||
SDL_SetSurfaceRLE(surface, SDL_TRUE); | |||
#endif | |||
} | } | ||
|
|
||
SDLSurfaceSprite2D* SDLSurfaceSprite2D::copy() const | SDLSurfaceSprite2D* SDLSurfaceSprite2D::copy() const | ||
|
@@ -114,6 +108,7 @@ ieDword SDLSurfaceSprite2D::GetColorKey() const | ||
void SDLSurfaceSprite2D::SetColorKey(ieDword ck) | void SDLSurfaceSprite2D::SetColorKey(ieDword ck) | ||
{ | { | ||
#if SDL_VERSION_ATLEAST(1,3,0) | #if SDL_VERSION_ATLEAST(1,3,0) | ||
// SDL 2 will enforce SDL_RLEACCEL | |||
SDL_SetColorKey(surface, SDL_TRUE, ck); | SDL_SetColorKey(surface, SDL_TRUE, ck); | ||
#else | #else | ||
SDL_SetColorKey(surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, ck); | SDL_SetColorKey(surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, ck); | ||
|
@@ -190,6 +185,24 @@ bool SDLSurfaceSprite2D::ConvertFormatTo(int bpp, ieDword rmask, ieDword gmask, | ||
return false; | return false; | ||
} | } | ||
|
|
||
void SDLSurfaceSprite2D::SetSurfaceRLE(bool rle) | |||
{ | |||
#if SDL_VERSION_ATLEAST(1,3,0) | |||
SDL_SetSurfaceRLE(surface, rle); | |||
#else | |||
if (rle) { | |||
surface->flags |= SDL_RLEACCEL; | |||
This comment has been minimized.
Sorry, something went wrong.
wjp
Member
|
|||
} else { | |||
surface->flags &= ~SDL_RLEACCEL; | |||
} | |||
#endif | |||
// regardless of rle or the success of SDL_SetSurfaceRLE | |||
// we must keep RLE false because SDL hides the actual RLE data from us (see SDL_BlitMap) | |||
// and we are left to access the pixels in decoded form (updated by SDL_UnlockSurface). | |||
// SDL Blits will make use of RLE acceleration, but our internal blitters cannot. | |||
assert(RLE == false); | |||
} | |||
|
|||
void SDLSurfaceSprite2D::SetSurfacePalette(SDL_Surface* surf, SDL_Color* pal, int numcolors) | void SDLSurfaceSprite2D::SetSurfacePalette(SDL_Surface* surf, SDL_Color* pal, int numcolors) | ||
{ | { | ||
#if SDL_VERSION_ATLEAST(1,3,0) | #if SDL_VERSION_ATLEAST(1,3,0) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It's not a good idea to always force SDL_RLEACCEL. First of all it is meaningless when there is no colourkey or per-pixel alpha, and second some sprites regularly need direct pixel data access (such as TIS tiles via BlitTile), and having to do an SDL_LockSurface each call will be too expensive.