Skip to content

Commit b306eff

Browse files
committed
Added a fast path to SDL_MapRGB() for SDL_PIXELFORMAT_XRGB8888
This improves the performance of TTSIOD renderer by about 10 FPS on my system (333 -> 342)
1 parent 7f7b1e6 commit b306eff

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/sdl2_compat.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9999,11 +9999,18 @@ static const SDL_PixelFormatDetails *GetPixelFormatDetails(const SDL2_PixelForma
99999999
SDL_DECLSPEC Uint32 SDLCALL
1000010000
SDL_MapRGB(const SDL2_PixelFormat *format2, Uint8 r, Uint8 g, Uint8 b)
1000110001
{
10002-
const SDL_PixelFormatDetails *format = GetPixelFormatDetails(format2);
10003-
if (!format) {
10004-
return 0;
10002+
const SDL_PixelFormatDetails *format;
10003+
10004+
switch (format2->format) {
10005+
case SDL_PIXELFORMAT_XRGB8888:
10006+
return ((Uint32)r << 24) | ((Uint32)g << 16) | b;
10007+
default:
10008+
format = GetPixelFormatDetails(format2);
10009+
if (!format) {
10010+
return 0;
10011+
}
10012+
return SDL3_MapRGB(format, format2->palette, r, g, b);
1000510013
}
10006-
return SDL3_MapRGB(format, format2->palette, r, g, b);
1000710014
}
1000810015

1000910016
SDL_DECLSPEC Uint32 SDLCALL

0 commit comments

Comments
 (0)