From 47e076071b37ee285a1439b554c0d14c7a735bc4 Mon Sep 17 00:00:00 2001 From: cpw Date: Sun, 22 Nov 2020 16:59:47 -0500 Subject: [PATCH] Fix #6692 Thanks @AterAnimAvis for help and suggestions Signed-off-by: cpw --- .../minecraft/client/MainWindow.java.patch | 8 ++++++ .../loading/progress/ClientVisualization.java | 26 ++++++++++++++++--- .../progress/EarlyProgressVisualization.java | 8 ++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/patches/minecraft/net/minecraft/client/MainWindow.java.patch b/patches/minecraft/net/minecraft/client/MainWindow.java.patch index bb6677bab..5cdbf3393 100644 --- a/patches/minecraft/net/minecraft/client/MainWindow.java.patch +++ b/patches/minecraft/net/minecraft/client/MainWindow.java.patch @@ -9,3 +9,11 @@ if (monitor != null) { VideoMode videomode = monitor.func_197992_a(this.field_198125_l ? this.field_198124_k : Optional.empty()); this.field_198120_g = this.field_198127_n = monitor.func_197989_c() + videomode.func_198064_a() / 2 - this.field_198129_p / 2; +@@ -271,6 +271,7 @@ + GLFW.glfwGetFramebufferSize(this.field_198119_f, aint, aint1); + this.field_198131_r = aint[0]; + this.field_198132_s = aint1[0]; ++ if (this.field_198132_s == 0 || this.field_198131_r==0) net.minecraftforge.fml.loading.progress.EarlyProgressVisualization.INSTANCE.updateFBSize(w->this.field_198131_r=w, h->this.field_198132_s=h); + } + + private void func_198089_c(long p_198089_1_, int p_198089_3_, int p_198089_4_) { diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java index 8af6253ff..ec9553a6e 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java @@ -22,9 +22,7 @@ package net.minecraftforge.fml.loading.progress; import com.google.common.io.ByteStreams; import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; -import org.lwjgl.glfw.GLFWErrorCallback; -import org.lwjgl.glfw.GLFWImage; -import org.lwjgl.glfw.GLFWVidMode; +import org.lwjgl.glfw.*; import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; @@ -40,6 +38,7 @@ import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.IntBuffer; import java.util.List; +import java.util.function.IntConsumer; import java.util.function.IntSupplier; import java.util.function.LongSupplier; import java.util.function.Supplier; @@ -58,6 +57,8 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { private Thread renderThread = new Thread(this::renderThreadFunc); private boolean running = true; + private GLFWFramebufferSizeCallback framebufferSizeCallback; + private int[] fbSize; private void initWindow() { GLFWErrorCallback.createPrint(System.err).set(); @@ -85,6 +86,7 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { if (window == NULL) { throw new RuntimeException("Failed to create the GLFW window"); // ignore it and make the GUI optional? } + framebufferSizeCallback = GLFWFramebufferSizeCallback.create(this::fbResize); try (MemoryStack stack = stackPush()) { IntBuffer pWidth = stack.mallocInt(1); @@ -126,6 +128,11 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { System.err.println("Failed to load forge logo"); } } + int[] w = new int[1]; + int[] h = new int[1]; + glfwGetFramebufferSize(window, w, h); + fbSize = new int[] {w[0], h[0]}; + glfwSetFramebufferSizeCallback(window, framebufferSizeCallback); glfwShowWindow(window); glfwPollEvents(); } @@ -220,6 +227,11 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { glVertex2f(screenWidth, 0); glEnd(); } + private void fbResize(long window, int width, int height) { + if (window == this.window && width != 0 && height != 0) { + fbSize = new int[] {width, height}; + } + } private void renderMessages() { List> messages = StartupMessageManager.getMessages(); @@ -233,6 +245,12 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { renderMemoryInfo(); } + @Override + public void updateFBSize(final IntConsumer width, final IntConsumer height) { + width.accept(this.fbSize[0]); + height.accept(this.fbSize[1]); + } + private static final float[] memorycolour = new float[] { 0.0f, 0.0f, 0.0f}; private void renderMemoryInfo() { @@ -309,6 +327,8 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { glfwSwapInterval(0); glfwSwapBuffers(window); glfwSwapInterval(1); + final GLFWFramebufferSizeCallback previous = glfwSetFramebufferSizeCallback(window, null); + previous.free(); return window; } } diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/EarlyProgressVisualization.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/EarlyProgressVisualization.java index b7d7e610c..8563356c3 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/EarlyProgressVisualization.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/EarlyProgressVisualization.java @@ -22,6 +22,7 @@ package net.minecraftforge.fml.loading.progress; import net.minecraftforge.api.distmarker.Dist; import java.util.Locale; +import java.util.function.IntConsumer; import java.util.function.IntSupplier; import java.util.function.LongSupplier; import java.util.function.Supplier; @@ -40,6 +41,10 @@ public enum EarlyProgressVisualization { return visualization.handOffWindow(width, height, title, monitor); } + public void updateFBSize(IntConsumer width, IntConsumer height) { + visualization.updateFBSize(width, height); + } + interface Visualization { Runnable start(); @@ -51,6 +56,9 @@ public enum EarlyProgressVisualization { } }.getAsLong(); } + + default void updateFBSize(IntConsumer width, IntConsumer height) { + } } private static class NoVisualization implements Visualization {