2323 */
2424@ Mixin (Window .class )
2525public class MixinWindow {
26+ @ Shadow
27+ private int width ;
28+
29+ @ Shadow
30+ private int height ;
31+
2632 @ Shadow
2733 private int framebufferWidth ;
2834
@@ -32,6 +38,7 @@ public class MixinWindow {
3238 @ Redirect (at = @ At (value = "INVOKE" , target = "Lorg/lwjgl/glfw/GLFW;glfwDefaultWindowHints()V" ), method = "<init>" , remap = false )
3339 private void onDefaultWindowHints () {
3440 GLFW .glfwDefaultWindowHints ();
41+ MacReducedResolution .useOpenGlBackend ();
3542
3643 if (MacReducedResolution .isEnabled ()) {
3744 GLFW .glfwWindowHint (GLFW .GLFW_COCOA_RETINA_FRAMEBUFFER , GLFW .GLFW_FALSE );
@@ -40,21 +47,45 @@ private void onDefaultWindowHints() {
4047
4148 @ Inject (at = @ At (value = "RETURN" ), method = "refreshFramebufferSize" )
4249 private void afterUpdateFrameBufferSize (CallbackInfo ci ) {
43- this .scaleFramebufferSize ();
50+ this .scaleInitialFramebufferSize ();
4451 }
4552
4653 @ Inject (method = "onFramebufferResize" , at = @ At (value = "FIELD" , target = "Lcom/mojang/blaze3d/platform/Window;framebufferHeight:I" , opcode = Opcodes .PUTFIELD , shift = At .Shift .AFTER ))
4754 private void afterFramebufferResize (long handle , int newWidth , int newHeight , CallbackInfo ci ) {
4855 this .scaleFramebufferSize ();
4956 }
5057
58+ @ Unique
59+ private void scaleInitialFramebufferSize () {
60+ /*
61+ * OpenGL only: the Cocoa non-Retina window hint gives us the correct
62+ * reduced drawable, but the first refreshFramebufferSize() during startup
63+ * can leave Minecraft's Window framebuffer fields at the Retina backing
64+ * size. A manual resize fixes it through the normal callback path; pinning
65+ * the initial values to the logical window size avoids the startup-only
66+ * stretched/offset GUI without changing resize behavior.
67+ */
68+ if (MacReducedResolution .shouldUseWindowSizeForInitialFramebuffer ()) {
69+ this .framebufferWidth = Math .max (1 , this .width );
70+ this .framebufferHeight = Math .max (1 , this .height );
71+ return ;
72+ }
73+
74+ this .scaleFramebufferSize ();
75+ }
76+
5177 @ Unique
5278 private void scaleFramebufferSize () {
53- if (!MacReducedResolution .isEnabled ()) {
79+ /*
80+ * Do not halve on the OpenGL backend. GLFW already returned the reduced
81+ * drawable after GLFW_COCOA_RETINA_FRAMEBUFFER=false, and a second halving
82+ * was confirmed on 26.2 to render 1440p as 720p.
83+ */
84+ if (!MacReducedResolution .shouldReduceFramebuffer ()) {
5485 return ;
5586 }
5687
57- framebufferWidth = MacReducedResolution .reduce (framebufferWidth );
58- framebufferHeight = MacReducedResolution .reduce (framebufferHeight );
88+ this . framebufferWidth = MacReducedResolution .reduce (this . framebufferWidth );
89+ this . framebufferHeight = MacReducedResolution .reduce (this . framebufferHeight );
5990 }
6091}
0 commit comments