Skip to content

Commit 494f620

Browse files
committed
fix: repair macOS reduced resolution presentation (#566)
1 parent c2ed00d commit 494f620

4 files changed

Lines changed: 56 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.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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package me.flashyreese.mods.sodiumextra.mixin.reduce_resolution_on_mac;
2+
3+
import com.mojang.blaze3d.textures.GpuTextureView;
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.injection.At;
9+
import org.spongepowered.asm.mixin.injection.ModifyArgs;
10+
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
11+
12+
@Mixin(targets = "com.mojang.blaze3d.opengl.GlCommandEncoder")
13+
public class MixinGlCommandEncoder {
14+
@ModifyArgs(method = "presentTexture", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/opengl/DirectStateAccess;blitFrameBuffers(IIIIIIIIIIII)V"))
15+
private void scalePresentedTexture(Args args, GpuTextureView textureView) {
16+
int sourceWidth = args.get(4);
17+
int sourceHeight = args.get(5);
18+
int[] framebufferWidth = new int[1];
19+
int[] framebufferHeight = new int[1];
20+
21+
GLFW.glfwGetFramebufferSize(Minecraft.getInstance().getWindow().handle(), framebufferWidth, framebufferHeight);
22+
23+
if (!MacReducedResolution.shouldScalePresentation(sourceWidth, sourceHeight, framebufferWidth[0], framebufferHeight[0])) {
24+
return;
25+
}
26+
27+
args.set(6, 0);
28+
args.set(7, 0);
29+
args.set(8, framebufferWidth[0]);
30+
args.set(9, framebufferHeight[0]);
31+
}
32+
}

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
@@ -35,6 +35,7 @@
3535
"particle.MixinLevelRenderer",
3636
"particle.MixinParticleEngine",
3737
"prevent_shaders.MixinGameRenderer",
38+
"reduce_resolution_on_mac.MixinGlCommandEncoder",
3839
"reduce_resolution_on_mac.MixinWindow",
3940
"render.block.entity.MixinBeaconRenderer",
4041
"render.block.entity.MixinEnchantingTableBlockEntityRenderer",

0 commit comments

Comments
 (0)