Skip to content

Commit 9116dc2

Browse files
committed
fix: skip extra macOS resolution scaling on OpenGL
1 parent 4ef90d2 commit 9116dc2

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

common/src/main/java/me/flashyreese/mods/sodiumextra/client/util/MacReducedResolution.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
import net.minecraft.util.Util;
66

77
public final class MacReducedResolution {
8+
private enum Backend {
9+
UNKNOWN,
10+
OPENGL,
11+
VULKAN
12+
}
13+
14+
private static Backend backend = Backend.UNKNOWN;
815
private static int windowWidth = -1;
916
private static int windowHeight = -1;
1017

@@ -16,17 +23,25 @@ public static int reduce(int value) {
1623
return Math.max(1, value / 2);
1724
}
1825

26+
public static void useOpenGlBackend() {
27+
backend = Backend.OPENGL;
28+
}
29+
30+
public static void useVulkanBackend() {
31+
backend = Backend.VULKAN;
32+
}
33+
1934
public static void rememberWindowSize(int width, int height) {
2035
windowWidth = width;
2136
windowHeight = height;
2237
}
2338

2439
public static boolean shouldReduceFramebuffer(int framebufferWidth, int framebufferHeight, int windowWidth, int windowHeight) {
25-
return isEnabled() && isHighDpiFramebuffer(framebufferWidth, framebufferHeight, windowWidth, windowHeight);
40+
return isEnabled() && backend != Backend.OPENGL && isHighDpiFramebuffer(framebufferWidth, framebufferHeight, windowWidth, windowHeight);
2641
}
2742

2843
public static GpuSurface.Configuration reduceSurfaceConfiguration(GpuSurface.Configuration config) {
29-
if (!shouldReduceFramebuffer(config.width(), config.height(), windowWidth, windowHeight)) {
44+
if (!isEnabled() || backend != Backend.VULKAN || !isHighDpiFramebuffer(config.width(), config.height(), windowWidth, windowHeight)) {
3045
return config;
3146
}
3247

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
package me.flashyreese.mods.sodiumextra.mixin.reduce_resolution_on_mac;
22

33
import com.mojang.blaze3d.opengl.GlBackend;
4-
import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod;
4+
import me.flashyreese.mods.sodiumextra.client.util.MacReducedResolution;
55
import org.lwjgl.glfw.GLFW;
66
import org.spongepowered.asm.mixin.Mixin;
7-
import org.spongepowered.asm.mixin.Unique;
87
import org.spongepowered.asm.mixin.injection.At;
98
import org.spongepowered.asm.mixin.injection.Inject;
109
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1110

1211
@Mixin(GlBackend.class)
1312
public class MixinGlBackend {
14-
@Unique
15-
private static final String OS_NAME = System.getProperty("os.name").toLowerCase();
16-
1713
@Inject(method = "setWindowHints", at = @At(value = "HEAD"))
1814
private void preSetWindowHints(CallbackInfo ci) {
19-
if (OS_NAME.contains("mac") && SodiumExtraClientMod.options().extraSettings.reduceResolutionOnMac) {
15+
MacReducedResolution.useOpenGlBackend();
16+
17+
if (MacReducedResolution.isEnabled()) {
2018
GLFW.glfwWindowHint(GLFW.GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW.GLFW_FALSE);
2119
}
2220
}
23-
}
21+
}

common/src/main/java/me/flashyreese/mods/sodiumextra/mixin/reduce_resolution_on_mac/MixinVulkanBackend.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package me.flashyreese.mods.sodiumextra.mixin.reduce_resolution_on_mac;
22

33
import com.mojang.blaze3d.vulkan.VulkanBackend;
4-
import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod;
4+
import me.flashyreese.mods.sodiumextra.client.util.MacReducedResolution;
55
import org.lwjgl.glfw.GLFW;
66
import org.spongepowered.asm.mixin.Mixin;
7-
import org.spongepowered.asm.mixin.Unique;
87
import org.spongepowered.asm.mixin.injection.At;
98
import org.spongepowered.asm.mixin.injection.Inject;
109
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1110

1211
@Mixin(VulkanBackend.class)
1312
public class MixinVulkanBackend {
14-
@Unique
15-
private static final String OS_NAME = System.getProperty("os.name").toLowerCase();
16-
1713
@Inject(method = "setWindowHints", at = @At(value = "HEAD"))
1814
private void preSetWindowHints(CallbackInfo ci) {
19-
if (OS_NAME.contains("mac") && SodiumExtraClientMod.options().extraSettings.reduceResolutionOnMac) {
15+
MacReducedResolution.useVulkanBackend();
16+
17+
if (MacReducedResolution.isEnabled()) {
2018
GLFW.glfwWindowHint(GLFW.GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW.GLFW_FALSE);
2119
}
2220
}

0 commit comments

Comments
 (0)