From d19a6cc437bfb79b9e1b33b70e20d3feaadb56be Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 5 Mar 2021 20:17:56 -0800 Subject: [PATCH] Copy blend mode to recreated surface This fixes a "root cause" bug (that's existed since 2.2 and below) where recreated surfaces wouldn't preserve the blend mode of their original surface. The surface-level (pun genuinely unintended) bug that this root bug fixes is the one where there's no background to the room name during the map menu animation in Flip Mode. This is because the room name background relies on graphics.backBuffer being filled with complete black. This is achieved by a call to ClearSurface() - however, ClearSurface() actually fills it with transparent black (this is not a regression; in 2.2 and previous, this was an "inlined" FillRect(backBuffer, 0x00000000)). This would be okay, and indeed the room name background renders fine in unflipped mode - but it suddenly breaks in Flip Mode. Why? Because backBuffer gets fed through FlipSurfaceVerticle(), and FlipSurfaceVerticle() creates a temporary surface with the same dimensions and color masks as backBuffer - it, however, does NOT create it with the same blend mode, and kind of sort of just forgets that the original was SDL_BLENDMODE_NONE; the new surface is SDL_BLENDMODE_BLEND. Thus, transparency applies on the new surface, and instead of the room name being drawn against black, it gets drawn against transparency. --- desktop_version/src/GraphicsUtil.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/desktop_version/src/GraphicsUtil.cpp b/desktop_version/src/GraphicsUtil.cpp index ca7ff512..2eef6cfe 100644 --- a/desktop_version/src/GraphicsUtil.cpp +++ b/desktop_version/src/GraphicsUtil.cpp @@ -17,6 +17,7 @@ static SDL_Surface* RecreateSurfaceWithDimensions( const int height ) { SDL_Surface* retval; + SDL_BlendMode blend_mode; if (surface == NULL) { @@ -39,6 +40,9 @@ static SDL_Surface* RecreateSurfaceWithDimensions( return NULL; } + SDL_GetSurfaceBlendMode(surface, &blend_mode); + SDL_SetSurfaceBlendMode(retval, blend_mode); + return retval; }