shithub: choc

Download patch

ref: f4d455c2f00c0e7b172357c05a01ad2f14b0745e
parent: 2be292a66210d3d2a1376e8eb1f1075c0d01eb53
author: Simon Howard <fraggle@soulsphere.org>
date: Sat Jul 9 11:27:08 EDT 2016

video: Set pixel format correctly for rgbabuffer.

When drawing the screen we convert from the 8-bit surface to the
32-bit RGBA surface and then import the surface data into the texture
for hardware rendering. However, the RGBA mask for the 32-bit surface
must match the RGBA format for the screen otherwise the colors may
end up wrong.

Thanks to Ryan Freeman (CSonicGo) for reporting this problem on
Twitter: <https://twitter.com/Sneakernets/status/751612074967568388>
I have not tested this on a Raspberry Pi but I believe this should
fix the problem.

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1004,6 +1004,8 @@
     byte *doompal;
     int w, h;
     int x, y;
+    unsigned int rmask, gmask, bmask, amask;
+    int unused_bpp;
     int flags = 0;
 
     doompal = W_CacheLumpName(DEH_String("PLAYPAL"), PU_CACHE);
@@ -1103,9 +1105,13 @@
                                         0, 0, 0, 0);
     SDL_FillRect(screenbuffer, NULL, 0);
 
+    // Format of rgbabuffer must match the screen pixel format because we
+    // import the surface data into the texture.
+    SDL_PixelFormatEnumToMasks(SDL_GetWindowPixelFormat(screen), &unused_bpp,
+                               &rmask, &gmask, &bmask, &amask);
     rgbabuffer = SDL_CreateRGBSurface(0,
                                       SCREENWIDTH, SCREENHEIGHT, 32,
-                                      0, 0, 0, 0);
+                                      rmask, gmask, bmask, amask);
     SDL_FillRect(rgbabuffer, NULL, 0);
 
     // Set the scaling quality for rendering the intermediate texture into