Thanks @AterAnimAvis for help and suggestions

Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw 2020-11-22 16:59:47 -05:00
parent a73e003dd3
commit 47e076071b
No known key found for this signature in database
GPG key ID: 8EB3DF749553B1B7
3 changed files with 39 additions and 3 deletions

View file

@ -9,3 +9,11 @@
if (monitor != null) { if (monitor != null) {
VideoMode videomode = monitor.func_197992_a(this.field_198125_l ? this.field_198124_k : Optional.empty()); 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; 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_) {

View file

@ -22,9 +22,7 @@ package net.minecraftforge.fml.loading.progress;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.lwjgl.glfw.GLFWErrorCallback; import org.lwjgl.glfw.*;
import org.lwjgl.glfw.GLFWImage;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL14; import org.lwjgl.opengl.GL14;
@ -40,6 +38,7 @@ import java.nio.Buffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.util.List; import java.util.List;
import java.util.function.IntConsumer;
import java.util.function.IntSupplier; import java.util.function.IntSupplier;
import java.util.function.LongSupplier; import java.util.function.LongSupplier;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -58,6 +57,8 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization {
private Thread renderThread = new Thread(this::renderThreadFunc); private Thread renderThread = new Thread(this::renderThreadFunc);
private boolean running = true; private boolean running = true;
private GLFWFramebufferSizeCallback framebufferSizeCallback;
private int[] fbSize;
private void initWindow() { private void initWindow() {
GLFWErrorCallback.createPrint(System.err).set(); GLFWErrorCallback.createPrint(System.err).set();
@ -85,6 +86,7 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization {
if (window == NULL) { if (window == NULL) {
throw new RuntimeException("Failed to create the GLFW window"); // ignore it and make the GUI optional? 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()) { try (MemoryStack stack = stackPush()) {
IntBuffer pWidth = stack.mallocInt(1); IntBuffer pWidth = stack.mallocInt(1);
@ -126,6 +128,11 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization {
System.err.println("Failed to load forge logo"); 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); glfwShowWindow(window);
glfwPollEvents(); glfwPollEvents();
} }
@ -220,6 +227,11 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization {
glVertex2f(screenWidth, 0); glVertex2f(screenWidth, 0);
glEnd(); 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() { private void renderMessages() {
List<Pair<Integer, StartupMessageManager.Message>> messages = StartupMessageManager.getMessages(); List<Pair<Integer, StartupMessageManager.Message>> messages = StartupMessageManager.getMessages();
@ -233,6 +245,12 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization {
renderMemoryInfo(); 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 static final float[] memorycolour = new float[] { 0.0f, 0.0f, 0.0f};
private void renderMemoryInfo() { private void renderMemoryInfo() {
@ -309,6 +327,8 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization {
glfwSwapInterval(0); glfwSwapInterval(0);
glfwSwapBuffers(window); glfwSwapBuffers(window);
glfwSwapInterval(1); glfwSwapInterval(1);
final GLFWFramebufferSizeCallback previous = glfwSetFramebufferSizeCallback(window, null);
previous.free();
return window; return window;
} }
} }

View file

@ -22,6 +22,7 @@ package net.minecraftforge.fml.loading.progress;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import java.util.Locale; import java.util.Locale;
import java.util.function.IntConsumer;
import java.util.function.IntSupplier; import java.util.function.IntSupplier;
import java.util.function.LongSupplier; import java.util.function.LongSupplier;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -40,6 +41,10 @@ public enum EarlyProgressVisualization {
return visualization.handOffWindow(width, height, title, monitor); return visualization.handOffWindow(width, height, title, monitor);
} }
public void updateFBSize(IntConsumer width, IntConsumer height) {
visualization.updateFBSize(width, height);
}
interface Visualization { interface Visualization {
Runnable start(); Runnable start();
@ -51,6 +56,9 @@ public enum EarlyProgressVisualization {
} }
}.getAsLong(); }.getAsLong();
} }
default void updateFBSize(IntConsumer width, IntConsumer height) {
}
} }
private static class NoVisualization implements Visualization { private static class NoVisualization implements Visualization {