macOS: fix colors appearing oversaturated on P3 displays.

The fix only applies to macOS 11+ when using OpenGL.
This commit is contained in:
slime
2022-09-30 15:17:46 -03:00
parent 60036d5dfe
commit 6173c1638d
4 changed files with 49 additions and 28 deletions
+8
View File
@@ -26,6 +26,8 @@
#include <string>
typedef struct SDL_Window SDL_Window;
namespace love
{
namespace macos
@@ -55,6 +57,12 @@ void requestAttention(bool continuous);
void setMetalLayerVSync(void *metallayer, bool vsync);
bool getMetalLayerVSync(void *metallayer);
/**
* Explicitly sets the window's color space to be sRGB - which stops the OS
* from interpreting the backbuffer output as P3 on P3-capable displays.
**/
void setWindowSRGBColorSpace(SDL_Window *window);
} // macos
} // love
+20 -3
View File
@@ -27,9 +27,11 @@
#import <QuartzCore/CAMetalLayer.h>
#ifdef LOVE_MACOSX_SDL_DIRECT_INCLUDE
# include <SDL.h>
#include <SDL.h>
#include <SDL_syswm.h>
#else
# include <SDL2/SDL.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_syswm.h>
#endif
namespace love
@@ -112,7 +114,22 @@ bool getMetalLayerVSync(void *metallayer)
return true;
}
} // osx
void setWindowSRGBColorSpace(SDL_Window *window)
{
@autoreleasepool
{
// This works on earlier macOS versions, but performance may be worse
// (at least, it was back when I tested in December 2016).
if (@available(macOS 11.0, *))
{
SDL_SysWMinfo info = {};
if (SDL_GetWindowWMInfo(window, &info))
info.info.cocoa.window.colorSpace = [NSColorSpace sRGBColorSpace];
}
}
}
} // macos
} // love
#endif // LOVE_MACOS