Skip to content

Commit b6f3de6

Browse files
committed
fix: repair macOS reduced resolution presentation (#566)
1 parent bcfe85e commit b6f3de6

4 files changed

Lines changed: 55 additions & 8 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: 4 additions & 8 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.objectweb.asm.Opcodes;
66
import org.spongepowered.asm.mixin.Mixin;
77
import org.spongepowered.asm.mixin.Shadow;
@@ -21,9 +21,6 @@
2121
*/
2222
@Mixin(Window.class)
2323
public class MixinWindow {
24-
@Unique
25-
private static final String OS_NAME = System.getProperty("os.name").toLowerCase();
26-
2724
@Shadow
2825
private int framebufferWidth;
2926

@@ -32,7 +29,6 @@ public class MixinWindow {
3229

3330
@Inject(at = @At(value = "RETURN"), method = "refreshFramebufferSize")
3431
private void afterUpdateFrameBufferSize(CallbackInfo ci) {
35-
// prevents mis-scaled startup screen
3632
this.scaleFramebufferSize();
3733
}
3834

@@ -43,11 +39,11 @@ private void afterFramebufferResize(long handle, int newWidth, int newHeight, Ca
4339

4440
@Unique
4541
private void scaleFramebufferSize() {
46-
if (!OS_NAME.contains("mac") || !SodiumExtraClientMod.options().extraSettings.reduceResolutionOnMac) {
42+
if (!MacReducedResolution.isEnabled()) {
4743
return;
4844
}
4945

50-
framebufferWidth = Math.max(1, framebufferWidth / 2);
51-
framebufferHeight = Math.max(1, framebufferHeight / 2);
46+
framebufferWidth = MacReducedResolution.reduce(framebufferWidth);
47+
framebufferHeight = MacReducedResolution.reduce(framebufferHeight);
5248
}
5349
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"particle.MixinParticleEngine",
3535
"prevent_shaders.MixinGameRenderer",
3636
"reduce_resolution_on_mac.MixinGlBackend",
37+
"reduce_resolution_on_mac.MixinGlCommandEncoder",
3738
"reduce_resolution_on_mac.MixinWindow",
3839
"render.block.entity.MixinBeaconRenderer",
3940
"render.block.entity.MixinEnchantingTableBlockEntityRenderer",

0 commit comments

Comments
 (0)