DRY main MC window resizing

This commit is contained in:
Jonas Herzig
2021-02-23 13:00:52 +01:00
parent 3fbb4b50ea
commit e4da7f331b
5 changed files with 45 additions and 77 deletions

View File

@@ -21,6 +21,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import static com.replaymod.core.versions.MCVer.resizeMainWindow;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
@@ -164,7 +165,7 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
@Override
protected OpenGlFrame renderFrame(int frameId, float partialTicks, CubicOpenGlFrameCapturer.Data captureData) {
resize(getFrameWidth(), getFrameHeight());
resizeMainWindow(mc, getFrameWidth(), getFrameHeight());
pushMatrix();
frameBuffer().beginWrite(true);

View File

@@ -16,17 +16,13 @@ import org.lwjgl.opengl.GL12;
import java.io.IOException;
import java.nio.ByteBuffer;
//#if MC>=11400
import com.replaymod.render.mixin.MainWindowAccessor;
import static com.replaymod.core.versions.MCVer.getWindow;
//#endif
//#if MC>=10800
import static com.mojang.blaze3d.platform.GlStateManager.*;
//#else
//$$ import static com.replaymod.core.versions.MCVer.GlStateManager.*;
//#endif
import static com.replaymod.core.versions.MCVer.resizeMainWindow;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
@@ -36,7 +32,7 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
protected int framesDone;
private Framebuffer frameBuffer;
private final MinecraftClient mc = MCVer.getMinecraft();
protected final MinecraftClient mc = MCVer.getMinecraft();
public OpenGlFrameCapturer(WorldRenderer worldRenderer, RenderInfo renderInfo) {
this.worldRenderer = worldRenderer;
@@ -85,7 +81,7 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
}
protected OpenGlFrame renderFrame(int frameId, float partialTicks, D captureData) {
resize(getFrameWidth(), getFrameHeight());
resizeMainWindow(mc, getFrameWidth(), getFrameHeight());
pushMatrix();
frameBuffer().beginWrite(true);
@@ -115,30 +111,6 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
return new OpenGlFrame(frameId, new Dimension(getFrameWidth(), getFrameHeight()), 4, buffer);
}
protected void resize(int width, int height) {
//#if MC>=11400
Framebuffer fb = mc.getFramebuffer();
if (fb.viewportWidth != width || fb.viewportHeight != height) {
fb.resize(width, height
//#if MC>=11400
, false
//#endif
);
}
//noinspection ConstantConditions
MainWindowAccessor mainWindow = (MainWindowAccessor) (Object) getWindow(mc);
mainWindow.setFramebufferWidth(width);
mainWindow.setFramebufferHeight(height);
//#if MC>=11500
mc.gameRenderer.onResized(width, height);
//#endif
//#else
//$$ if (width != mc.displayWidth || height != mc.displayHeight) {
//$$ mc.resize(width, height);
//$$ }
//#endif
}
@Override
public void close() throws IOException {
}

View File

@@ -425,22 +425,7 @@ public class VideoRenderer implements RenderInfo {
}
// Finally, resize the Minecraft framebuffer to the actual width/height of the window
//#if MC>=11400
mc.getFramebuffer().resize(displayWidth, displayHeight
//#if MC>=11400
, false
//#endif
);
//noinspection ConstantConditions
MainWindowAccessor acc = (MainWindowAccessor) (Object) getWindow(mc);
acc.setFramebufferWidth(displayWidth);
acc.setFramebufferHeight(displayHeight);
//#if MC>=11500
mc.gameRenderer.onResized(displayWidth, displayHeight);
//#endif
//#else
//$$ mc.resize(displayWidth, displayHeight);
//#endif
resizeMainWindow(mc, displayWidth, displayHeight);
}
private void executeTaskQueue() {