From 38cd047cc65f042398650af3c341436647a86c92 Mon Sep 17 00:00:00 2001
From: Martin Pulec <martin.pulec@cesnet.cz>
Date: Fri, 22 Apr 2022 09:21:27 +0200
Subject: [PATCH 1/6] mac: set use 16-bit depth framebuffer

Use 16-bit depth framebuffer to allow rendering of higher bit-depth color spaces.

Using the code from this page:
https://www.zephray.me/post/edr_hdr_on_macos_opengl/
---
 src/nsgl_context.m | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/nsgl_context.m b/src/nsgl_context.m
index d19622c6..20404a80 100644
--- a/src/nsgl_context.m
+++ b/src/nsgl_context.m
@@ -245,15 +245,26 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
         fbconfig->greenBits != GLFW_DONT_CARE &&
         fbconfig->blueBits != GLFW_DONT_CARE)
     {
-        int colorBits = fbconfig->redBits +
-                        fbconfig->greenBits +
-                        fbconfig->blueBits;
-
-        // macOS needs non-zero color size, so set reasonable values
-        if (colorBits == 0)
-            colorBits = 24;
-        else if (colorBits < 15)
-            colorBits = 15;
+        int colorBits;
+
+        if (fbconfig->redBits > 8 ||
+            fbconfig->greenBits > 8 ||
+            fbconfig->blueBits > 8)
+        {
+            colorBits = 64;
+            ADD_ATTRIB(NSOpenGLPFAColorFloat);
+        }
+        else {
+            colorBits = fbconfig->redBits +
+                    fbconfig->greenBits +
+                    fbconfig->blueBits;
+
+            // macOS needs non-zero color size, so set reasonable values
+            if (colorBits == 0)
+                colorBits = 24;
+            else if (colorBits < 15)
+                colorBits = 15;
+        }
 
         SET_ATTRIB(NSOpenGLPFAColorSize, colorBits);
     }
-- 
2.43.2

