GLFW API for changing colorspace of windows on cocoa

This commit is contained in:
Kovid Goyal 2022-04-26 10:56:34 +05:30
parent f9f6f98527
commit a36d5dcde1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 21 additions and 1 deletions

View File

@ -1731,7 +1731,11 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (!createNativeWindow(window, wndconfig, fbconfig)) if (!createNativeWindow(window, wndconfig, fbconfig))
return false; return false;
[window->ns.object setColorSpace:[NSColorSpace sRGBColorSpace]]; switch((GlfwCocoaColorSpaces)wndconfig->ns.color_space) {
case SRGB_COLORSPACE: [window->ns.object setColorSpace:[NSColorSpace sRGBColorSpace]]; break;
case DISPLAY_P3_COLORSPACE: [window->ns.object setColorSpace:[NSColorSpace displayP3ColorSpace]]; break;
case DEFAULT_COLORSPACE: break;
}
if (ctxconfig->client != GLFW_NO_API) if (ctxconfig->client != GLFW_NO_API)
{ {

10
glfw/glfw3.h vendored
View File

@ -1024,6 +1024,16 @@ typedef enum GLFWMouseButton {
* [window hint](@ref GLFW_COCOA_GRAPHICS_SWITCHING_hint). * [window hint](@ref GLFW_COCOA_GRAPHICS_SWITCHING_hint).
*/ */
#define GLFW_COCOA_GRAPHICS_SWITCHING 0x00023003 #define GLFW_COCOA_GRAPHICS_SWITCHING 0x00023003
/*! @brief macOS specific
* [window hint](@ref GLFW_COCOA_COLOR_SPACE_hint).
*/
#define GLFW_COCOA_COLOR_SPACE 0x00023004
typedef enum {
DEFAULT_COLORSPACE = 0,
SRGB_COLORSPACE = 1,
DISPLAY_P3_COLORSPACE = 2,
} GlfwCocoaColorSpaces;
/*! @brief X11 specific /*! @brief X11 specific
* [window hint](@ref GLFW_X11_CLASS_NAME_hint). * [window hint](@ref GLFW_X11_CLASS_NAME_hint).
*/ */

1
glfw/internal.h vendored
View File

@ -307,6 +307,7 @@ struct _GLFWwndconfig
bool scaleToMonitor; bool scaleToMonitor;
struct { struct {
bool retina; bool retina;
int color_space;
char frameName[256]; char frameName[256];
} ns; } ns;
struct { struct {

5
glfw/window.c vendored
View File

@ -332,6 +332,8 @@ void glfwDefaultWindowHints(void)
// The default is to use full Retina resolution framebuffers // The default is to use full Retina resolution framebuffers
_glfw.hints.window.ns.retina = true; _glfw.hints.window.ns.retina = true;
// use the default colorspace assigned by the system
_glfw.hints.window.ns.color_space = 0;
} }
GLFWAPI void glfwWindowHint(int hint, int value) GLFWAPI void glfwWindowHint(int hint, int value)
@ -412,6 +414,9 @@ GLFWAPI void glfwWindowHint(int hint, int value)
case GLFW_COCOA_RETINA_FRAMEBUFFER: case GLFW_COCOA_RETINA_FRAMEBUFFER:
_glfw.hints.window.ns.retina = value ? true : false; _glfw.hints.window.ns.retina = value ? true : false;
return; return;
case GLFW_COCOA_COLOR_SPACE:
_glfw.hints.window.ns.color_space = value;
return;
case GLFW_COCOA_GRAPHICS_SWITCHING: case GLFW_COCOA_GRAPHICS_SWITCHING:
_glfw.hints.context.nsgl.offline = value ? true : false; _glfw.hints.context.nsgl.offline = value ? true : false;
return; return;