Call Window.onFramebufferSizeChanged to resize (fixes #705)

Instead of setting the the values via accessor and calling the handler directly.
This allows mods like ResolutionControl+ to properly resize its internal
framebuffers as well.
This commit is contained in:
Jonas Herzig
2022-04-10 19:53:15 +02:00
parent 5be57681af
commit 497b8440ca
3 changed files with 8 additions and 11 deletions

View File

@@ -27,9 +27,9 @@ import net.minecraft.resource.ResourcePackSource;
//#if MC>=11400 //#if MC>=11400
import com.replaymod.render.mixin.MainWindowAccessor; import com.replaymod.render.mixin.MainWindowAccessor;
import net.minecraft.SharedConstants; import net.minecraft.SharedConstants;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.AbstractButtonWidget; import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.util.Window;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@@ -106,17 +106,10 @@ public class MCVer {
public static void resizeMainWindow(MinecraftClient mc, int width, int height) { public static void resizeMainWindow(MinecraftClient mc, int width, int height) {
//#if MC>=11400 //#if MC>=11400
Framebuffer fb = mc.getFramebuffer(); Window window = mc.getWindow();
if (fb.viewportWidth != width || fb.viewportHeight != height) { MainWindowAccessor mainWindow = (MainWindowAccessor) (Object) window;
fb.resize(width, height, false);
}
//noinspection ConstantConditions //noinspection ConstantConditions
MainWindowAccessor mainWindow = (MainWindowAccessor) (Object) mc.getWindow(); mainWindow.invokeOnFramebufferSizeChanged(window.getHandle(), width, height);
mainWindow.setFramebufferWidth(width);
mainWindow.setFramebufferHeight(height);
//#if MC>=11500
mc.gameRenderer.onResized(width, height);
//#endif
//#else //#else
//$$ if (width != mc.displayWidth || height != mc.displayHeight) { //$$ if (width != mc.displayWidth || height != mc.displayHeight) {
//$$ mc.resize(width, height); //$$ mc.resize(width, height);

View File

@@ -56,12 +56,14 @@ public class VirtualWindow implements Closeable {
gameHeight = acc.getFramebufferHeight(); gameHeight = acc.getFramebufferHeight();
acc.setFramebufferWidth(framebufferWidth); acc.setFramebufferWidth(framebufferWidth);
acc.setFramebufferHeight(framebufferHeight); acc.setFramebufferHeight(framebufferHeight);
applyScaleFactor();
isBound = true; isBound = true;
} }
public void unbind() { public void unbind() {
acc.setFramebufferWidth(gameWidth); acc.setFramebufferWidth(gameWidth);
acc.setFramebufferHeight(gameHeight); acc.setFramebufferHeight(gameHeight);
applyScaleFactor();
isBound = false; isBound = false;
} }

View File

@@ -15,4 +15,6 @@ public interface MainWindowAccessor {
int getFramebufferHeight(); int getFramebufferHeight();
@Accessor @Accessor
void setFramebufferHeight(int value); void setFramebufferHeight(int value);
@Invoker
void invokeOnFramebufferSizeChanged(long window, int width, int height);
} }