Thanks @AterAnimAvis for help and suggestions

Signed-off-by: cpw <[email protected]>
This commit is contained in:
cpw committed 2020-11-22 17:00:48 -05:00
1 parent a73e003dd3
commit 47e076071b
3 files changed
+39 -3

No files matched your search

@@ -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<Pair<Integer, StartupMessageManager.Message>> 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;
}
}
@@ -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 {