Skip to content

Commit acbd88a

Browse files
committed
Add P3 colors for MacOS if available
1 parent 3f293ed commit acbd88a

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/main/java/net/vulkanmod/mixin/window/WindowMixin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ private void redirect(int hint, int value) { }
6161
private void vulkanHint(WindowEventHandler windowEventHandler, ScreenManager screenManager, DisplayData displayData, String string, String string2, CallbackInfo ci) {
6262
GLFW.glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
6363

64+
// Enable 32bit P3 wide color gamut on macOS
65+
if (Platform.isMacOS()) {
66+
GLFW.glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE);
67+
GLFW.glfwWindowHint(GLFW_RED_BITS, 10);
68+
GLFW.glfwWindowHint(GLFW_GREEN_BITS, 10);
69+
GLFW.glfwWindowHint(GLFW_BLUE_BITS, 10);
70+
GLFW.glfwWindowHint(GLFW_ALPHA_BITS, 2);
71+
}
72+
6473
//Fix Gnome Client-Side Decorators
6574
boolean b = (Platform.isGnome() | Platform.isWeston() | Platform.isGeneric()) && Platform.isWayLand();
6675
GLFW.glfwWindowHint(GLFW_DECORATED, (b ? GLFW_FALSE : GLFW_TRUE));

src/main/java/net/vulkanmod/vulkan/framebuffer/SwapChain.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.vulkanmod.vulkan.queue.Queue;
1010
import net.vulkanmod.vulkan.texture.SamplerManager;
1111
import net.vulkanmod.vulkan.texture.VulkanImage;
12+
import net.vulkanmod.config.Platform;
1213
import org.lwjgl.system.MemoryStack;
1314
import org.lwjgl.vulkan.*;
1415

@@ -243,19 +244,33 @@ public long getImageView(int i) {
243244
private VkSurfaceFormatKHR getFormat(VkSurfaceFormatKHR.Buffer availableFormats) {
244245
List<VkSurfaceFormatKHR> list = availableFormats.stream().toList();
245246

246-
VkSurfaceFormatKHR format = list.get(0);
247+
// Extended sRGB (P3 gamut with sRGB gamma) on macOS
248+
if (Platform.isMacOS()) {
249+
for (VkSurfaceFormatKHR f : list) {
250+
if (f.format() == VK_FORMAT_B8G8R8A8_UNORM && f.colorSpace() == 1000104001) {
251+
isBGRAformat = true;
252+
return f;
253+
}
254+
}
255+
}
247256

257+
// If fail try RGBA format with standard sRGB
248258
for (VkSurfaceFormatKHR availableFormat : list) {
249259
if (availableFormat.format() == VK_FORMAT_R8G8B8A8_UNORM && availableFormat.colorSpace() == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
250260
return availableFormat;
261+
}
251262

263+
// Standard BGRA sRGB
264+
VkSurfaceFormatKHR format = list.get(0);
265+
for (VkSurfaceFormatKHR availableFormat : list) {
252266
if (availableFormat.format() == VK_FORMAT_B8G8R8A8_UNORM && availableFormat.colorSpace() == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
253267
format = availableFormat;
254268
}
255269
}
256270

257271
if (format.format() == VK_FORMAT_B8G8R8A8_UNORM)
258272
isBGRAformat = true;
273+
259274
return format;
260275
}
261276

0 commit comments

Comments
 (0)