Skip to content

Commit 423b7e1

Browse files
committed
fix: repair macOS reduced resolution presentation (#566)
1 parent 4120e2b commit 423b7e1

4 files changed

Lines changed: 59 additions & 9 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package me.flashyreese.mods.sodiumextra.client.util;
2+
3+
import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod;
4+
import net.minecraft.Util;
5+
6+
public final class MacReducedResolution {
7+
public static boolean isEnabled() {
8+
return Util.getPlatform() == Util.OS.OSX && SodiumExtraClientMod.options().extraSettings.reduceResolutionOnMac;
9+
}
10+
11+
public static int reduce(int value) {
12+
return Math.max(1, value / 2);
13+
}
14+
15+
public static boolean shouldScalePresentation(int sourceWidth, int sourceHeight, int targetWidth, int targetHeight) {
16+
return isEnabled() && (sourceWidth < targetWidth || sourceHeight < targetHeight);
17+
}
18+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package me.flashyreese.mods.sodiumextra.mixin.reduce_resolution_on_mac;
2+
3+
import com.mojang.blaze3d.pipeline.RenderTarget;
4+
import me.flashyreese.mods.sodiumextra.client.util.MacReducedResolution;
5+
import net.minecraft.client.Minecraft;
6+
import org.lwjgl.glfw.GLFW;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.Shadow;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.ModifyArgs;
11+
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
12+
13+
@Mixin(RenderTarget.class)
14+
public class MixinRenderTarget {
15+
@Shadow
16+
public int viewWidth;
17+
18+
@Shadow
19+
public int viewHeight;
20+
21+
@ModifyArgs(method = "_blitToScreen", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;_viewport(IIII)V"))
22+
private void scalePresentedTexture(Args args) {
23+
int[] framebufferWidth = new int[1];
24+
int[] framebufferHeight = new int[1];
25+
26+
GLFW.glfwGetFramebufferSize(Minecraft.getInstance().getWindow().getWindow(), framebufferWidth, framebufferHeight);
27+
28+
if (!MacReducedResolution.shouldScalePresentation(this.viewWidth, this.viewHeight, framebufferWidth[0], framebufferHeight[0])) {
29+
return;
30+
}
31+
32+
args.set(2, framebufferWidth[0]);
33+
args.set(3, framebufferHeight[0]);
34+
}
35+
}

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

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

33
import com.mojang.blaze3d.platform.Window;
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.objectweb.asm.Opcodes;
77
import org.spongepowered.asm.mixin.Mixin;
@@ -23,9 +23,6 @@
2323
*/
2424
@Mixin(Window.class)
2525
public class MixinWindow {
26-
@Unique
27-
private static final String OS_NAME = System.getProperty("os.name").toLowerCase();
28-
2926
@Shadow
3027
private int framebufferWidth;
3128

@@ -36,14 +33,13 @@ public class MixinWindow {
3633
private void onDefaultWindowHints() {
3734
GLFW.glfwDefaultWindowHints();
3835

39-
if (OS_NAME.contains("mac") && SodiumExtraClientMod.options().extraSettings.reduceResolutionOnMac) {
36+
if (MacReducedResolution.isEnabled()) {
4037
GLFW.glfwWindowHint(GLFW.GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW.GLFW_FALSE);
4138
}
4239
}
4340

4441
@Inject(at = @At(value = "RETURN"), method = "refreshFramebufferSize")
4542
private void afterUpdateFrameBufferSize(CallbackInfo ci) {
46-
// prevents mis-scaled startup screen
4743
this.scaleFramebufferSize();
4844
}
4945

@@ -54,11 +50,11 @@ private void afterFramebufferResize(long handle, int newWidth, int newHeight, Ca
5450

5551
@Unique
5652
private void scaleFramebufferSize() {
57-
if (!OS_NAME.contains("mac") || !SodiumExtraClientMod.options().extraSettings.reduceResolutionOnMac) {
53+
if (!MacReducedResolution.isEnabled()) {
5854
return;
5955
}
6056

61-
framebufferWidth = Math.max(1, framebufferWidth / 2);
62-
framebufferHeight = Math.max(1, framebufferHeight / 2);
57+
framebufferWidth = MacReducedResolution.reduce(framebufferWidth);
58+
framebufferHeight = MacReducedResolution.reduce(framebufferHeight);
6359
}
6460
}

common/src/main/resources/sodium-extra.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"particle.MixinLevelRenderer",
2626
"particle.MixinParticleEngine",
2727
"prevent_shaders.MixinGameRenderer",
28+
"reduce_resolution_on_mac.MixinRenderTarget",
2829
"reduce_resolution_on_mac.MixinWindow",
2930
"render.block.entity.MixinBeaconRenderer",
3031
"render.block.entity.MixinEnchantingTableBlockEntityRenderer",

0 commit comments

Comments
 (0)