move window pointer into rendering engine
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-15 15:29:30 -04:00
parent f65d56d667
commit 3a5aa301de
7 changed files with 48 additions and 45 deletions

View File

@ -1823,6 +1823,7 @@ Move timeKeeper into engineState
Move signalSystem into engineState Move signalSystem into engineState
Move some global state into rendering engine Move some global state into rendering engine
Push settings into config variable Push settings into config variable
Move window pointer into rendering engine

View File

@ -397,7 +397,7 @@ public class ControlHandler {
private void getMousePositionInBuffer(){ private void getMousePositionInBuffer(){
//only if not headless, gather position //only if not headless, gather position
if(!Globals.HEADLESS){ if(!Globals.HEADLESS){
glfwGetCursorPos(Globals.window, this.mouseState.getMouseBufferX(), this.mouseState.getMouseBufferY()); glfwGetCursorPos(Globals.renderingEngine.getWindowPtr(), this.mouseState.getMouseBufferX(), this.mouseState.getMouseBufferY());
} }
} }
@ -483,8 +483,8 @@ public class ControlHandler {
* Hides the mouse * Hides the mouse
*/ */
public void hideMouse(){ public void hideMouse(){
glfwSetInputMode(Globals.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode(Globals.renderingEngine.getWindowPtr(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
glfwSetInputMode(Globals.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetInputMode(Globals.renderingEngine.getWindowPtr(), GLFW_CURSOR, GLFW_CURSOR_DISABLED);
mouseIsVisible = false; mouseIsVisible = false;
} }
@ -492,7 +492,7 @@ public class ControlHandler {
* Shows the mouse * Shows the mouse
*/ */
public void showMouse(){ public void showMouse(){
glfwSetInputMode(Globals.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode(Globals.renderingEngine.getWindowPtr(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
mouseIsVisible = true; mouseIsVisible = true;
} }
@ -511,7 +511,7 @@ public class ControlHandler {
public Vector2f getMousePosition(){ public Vector2f getMousePosition(){
double posX[] = new double[1]; double posX[] = new double[1];
double posY[] = new double[1]; double posY[] = new double[1];
GLFW.glfwGetCursorPos(Globals.window, posX, posY); GLFW.glfwGetCursorPos(Globals.renderingEngine.getWindowPtr(), posX, posY);
Vector2f rVal = new Vector2f((float)posX[0],(float)posY[0]); Vector2f rVal = new Vector2f((float)posX[0],(float)posY[0]);
return rVal; return rVal;
} }
@ -523,10 +523,10 @@ public class ControlHandler {
public Vector2f getMousePositionNormalized(){ public Vector2f getMousePositionNormalized(){
double posX[] = new double[1]; double posX[] = new double[1];
double posY[] = new double[1]; double posY[] = new double[1];
GLFW.glfwGetCursorPos(Globals.window, posX, posY); GLFW.glfwGetCursorPos(Globals.renderingEngine.getWindowPtr(), posX, posY);
int sizeX[] = new int[1]; int sizeX[] = new int[1];
int sizeY[] = new int[1]; int sizeY[] = new int[1];
GLFW.glfwGetWindowSize(Globals.window, sizeX, sizeY); GLFW.glfwGetWindowSize(Globals.renderingEngine.getWindowPtr(), sizeX, sizeY);
Vector2f rVal = new Vector2f((float)((2.0 * posX[0] / sizeX[0]) - 1.0),(float)(1.0 - (2.0 * posY[0] / sizeY[0]))); Vector2f rVal = new Vector2f((float)((2.0 * posX[0] / sizeX[0]) - 1.0),(float)(1.0 - (2.0 * posY[0] / sizeY[0])));
return rVal; return rVal;
} }

View File

@ -57,6 +57,11 @@ public class Globals {
*/ */
public static EngineState engineState; public static EngineState engineState;
/**
* The engine and game configuration
*/
public static electrosphere.data.Config gameConfigCurrent;
/** /**
* State for the client * State for the client
*/ */
@ -145,13 +150,6 @@ public class Globals {
public static ScrollCallback scrollCallback = new ScrollCallback(); public static ScrollCallback scrollCallback = new ScrollCallback();
public static CursorState cursorState = new CursorState(); public static CursorState cursorState = new CursorState();
//
// Game config
//
public static electrosphere.data.Config gameConfigDefault;
public static electrosphere.data.Config gameConfigCurrent;
// //
// Database stuff // Database stuff
// //
@ -162,11 +160,6 @@ public class Globals {
// //
public static CameraHandler cameraHandler = new CameraHandler(); public static CameraHandler cameraHandler = new CameraHandler();
//
//Generic OpenGL Statements
//
public static long window = -1;
// //
@ -291,8 +284,7 @@ public class Globals {
Globals.engineState = new EngineState(); Globals.engineState = new EngineState();
//game config //game config
gameConfigDefault = electrosphere.data.Config.loadDefaultConfig(); gameConfigCurrent = electrosphere.data.Config.loadDefaultConfig();
gameConfigCurrent = gameConfigDefault;
NetConfig.readNetConfig(); NetConfig.readNetConfig();
//render flags //render flags
@ -534,7 +526,6 @@ public class Globals {
Globals.RENDER_FLAG_RENDER_UI = false; Globals.RENDER_FLAG_RENDER_UI = false;
Globals.RENDER_FLAG_RENDER_BLACK_BACKGROUND = false; Globals.RENDER_FLAG_RENDER_BLACK_BACKGROUND = false;
Globals.RENDER_FLAG_RENDER_WHITE_BACKGROUND = false; Globals.RENDER_FLAG_RENDER_WHITE_BACKGROUND = false;
Globals.window = -1;
LoggerInterface.destroyLoggers(); LoggerInterface.destroyLoggers();
} }

View File

@ -368,7 +368,7 @@ public class Main {
running = false; running = false;
} }
} else { } else {
if(Globals.ENGINE_SHUTDOWN_FLAG || (Globals.RUN_CLIENT && GLFW.glfwWindowShouldClose(Globals.window))){ if(Globals.ENGINE_SHUTDOWN_FLAG || (Globals.RUN_CLIENT && GLFW.glfwWindowShouldClose(Globals.renderingEngine.getWindowPtr()))){
running = false; running = false;
} }
} }

View File

@ -59,6 +59,12 @@ import electrosphere.renderer.texture.Texture;
*/ */
public class RenderingEngine { public class RenderingEngine {
/**
* Handle for the window created by glfw
*/
private long windowPtr = -1;
public static final int GL_DEFAULT_FRAMEBUFFER = 0; public static final int GL_DEFAULT_FRAMEBUFFER = 0;
@ -231,12 +237,12 @@ public class RenderingEngine {
//Creates the window reference object //Creates the window reference object
if(Globals.gameConfigCurrent.getSettings().displayFullscreen() || Globals.WINDOW_FULLSCREEN){ if(Globals.gameConfigCurrent.getSettings().displayFullscreen() || Globals.WINDOW_FULLSCREEN){
//below line is for fullscreen //below line is for fullscreen
Globals.window = GLFW.glfwCreateWindow(Globals.gameConfigCurrent.getSettings().getDisplayWidth(), Globals.gameConfigCurrent.getSettings().getDisplayHeight(), "ORPG", GLFW.glfwGetPrimaryMonitor(), NULL); this.windowPtr = GLFW.glfwCreateWindow(Globals.gameConfigCurrent.getSettings().getDisplayWidth(), Globals.gameConfigCurrent.getSettings().getDisplayHeight(), "ORPG", GLFW.glfwGetPrimaryMonitor(), NULL);
} else { } else {
Globals.window = GLFW.glfwCreateWindow(Globals.gameConfigCurrent.getSettings().getDisplayWidth(), Globals.gameConfigCurrent.getSettings().getDisplayHeight(), "ORPG", NULL, NULL); this.windowPtr = GLFW.glfwCreateWindow(Globals.gameConfigCurrent.getSettings().getDisplayWidth(), Globals.gameConfigCurrent.getSettings().getDisplayHeight(), "ORPG", NULL, NULL);
} }
// Errors for failure to create window (IE: No GUI mode on linux ?) // Errors for failure to create window (IE: No GUI mode on linux ?)
if (Globals.window == NULL) { if (this.windowPtr == NULL) {
String message = "Failed to create window!\n" + String message = "Failed to create window!\n" +
"Error code: " + this.getGLFWErrorMessage(this.getGLFWError()); "Error code: " + this.getGLFWErrorMessage(this.getGLFWError());
; ;
@ -245,19 +251,19 @@ public class RenderingEngine {
} }
//set resize callback //set resize callback
GLFW.glfwSetWindowSizeCallback(Globals.window, (long window, int width, int height) -> { GLFW.glfwSetWindowSizeCallback(this.windowPtr, (long window, int width, int height) -> {
Globals.WINDOW_HEIGHT = height; Globals.WINDOW_HEIGHT = height;
Globals.WINDOW_WIDTH = width; Globals.WINDOW_WIDTH = width;
}); });
//Makes the window that was just created the current OS-level window context //Makes the window that was just created the current OS-level window context
GLFW.glfwMakeContextCurrent(Globals.window); GLFW.glfwMakeContextCurrent(this.windowPtr);
//Maximize it //Maximize it
GLFW.glfwMaximizeWindow(Globals.window); GLFW.glfwMaximizeWindow(this.windowPtr);
GLFW.glfwPollEvents(); GLFW.glfwPollEvents();
//grab actual framebuffer //grab actual framebuffer
IntBuffer xBuffer = BufferUtils.createIntBuffer(1); IntBuffer xBuffer = BufferUtils.createIntBuffer(1);
IntBuffer yBuffer = BufferUtils.createIntBuffer(1); IntBuffer yBuffer = BufferUtils.createIntBuffer(1);
GLFW.glfwGetFramebufferSize(Globals.window, xBuffer, yBuffer); GLFW.glfwGetFramebufferSize(this.windowPtr, xBuffer, yBuffer);
int bufferWidth = xBuffer.get(); int bufferWidth = xBuffer.get();
int bufferHeight = yBuffer.get(); int bufferHeight = yBuffer.get();
@ -275,9 +281,9 @@ public class RenderingEngine {
// Attach controls callbacks // Attach controls callbacks
// //
//set key callback //set key callback
GLFW.glfwSetKeyCallback(Globals.window, Globals.controlCallback); GLFW.glfwSetKeyCallback(this.windowPtr, Globals.controlCallback);
GLFW.glfwSetMouseButtonCallback(Globals.window, Globals.mouseCallback); GLFW.glfwSetMouseButtonCallback(this.windowPtr, Globals.mouseCallback);
GLFW.glfwSetScrollCallback(Globals.window, Globals.scrollCallback); GLFW.glfwSetScrollCallback(this.windowPtr, Globals.scrollCallback);
//get title bar dimensions //get title bar dimensions
// setTitleBarDimensions(); // setTitleBarDimensions();
@ -299,7 +305,7 @@ public class RenderingEngine {
openGLContext = new OpenGLContext(); openGLContext = new OpenGLContext();
//init imgui pipeline //init imgui pipeline
imGuiPipeline = new ImGuiPipeline(Globals.window, glslVersion); imGuiPipeline = new ImGuiPipeline(this.windowPtr, glslVersion);
//This enables Z-buffering so that farther-back polygons are not drawn over nearer ones //This enables Z-buffering so that farther-back polygons are not drawn over nearer ones
openGLState.glDepthTest(true); openGLState.glDepthTest(true);
@ -454,7 +460,7 @@ public class RenderingEngine {
// //
//Set file drag-and-drop for app //Set file drag-and-drop for app
// //
GLFW.glfwSetDropCallback(Globals.window, (long window, int count, long names) -> { GLFW.glfwSetDropCallback(this.windowPtr, (long window, int count, long names) -> {
PointerBuffer charPointers = MemoryUtil.memPointerBuffer(names, count); PointerBuffer charPointers = MemoryUtil.memPointerBuffer(names, count);
List<String> paths = new LinkedList<String>(); List<String> paths = new LinkedList<String>();
for(int i = 0; i < count; i++){ for(int i = 0; i < count; i++){
@ -567,7 +573,7 @@ public class RenderingEngine {
//check and call events and swap the buffers //check and call events and swap the buffers
LoggerInterface.loggerRenderer.DEBUG_LOOP("GLFW Swap buffers"); LoggerInterface.loggerRenderer.DEBUG_LOOP("GLFW Swap buffers");
GLFW.glfwSwapBuffers(Globals.window); GLFW.glfwSwapBuffers(this.windowPtr);
LoggerInterface.loggerRenderer.DEBUG_LOOP("GLFW Poll Events"); LoggerInterface.loggerRenderer.DEBUG_LOOP("GLFW Poll Events");
GLFW.glfwPollEvents(); GLFW.glfwPollEvents();
LoggerInterface.loggerRenderer.DEBUG_LOOP("Check OpenGL Errors"); LoggerInterface.loggerRenderer.DEBUG_LOOP("Check OpenGL Errors");
@ -592,7 +598,7 @@ public class RenderingEngine {
IntBuffer tBottom = BufferUtils.createIntBuffer(1); IntBuffer tBottom = BufferUtils.createIntBuffer(1);
// Get the title bar dims // Get the title bar dims
GLFW.glfwGetWindowFrameSize(Globals.window, tLeft, tTop, tRight, tBottom); GLFW.glfwGetWindowFrameSize(this.windowPtr, tLeft, tTop, tRight, tBottom);
Globals.WINDOW_TITLE_BAR_HEIGHT = tTop.get(); Globals.WINDOW_TITLE_BAR_HEIGHT = tTop.get();
// System.out.println(tLeft.get() + " " + tTop.get() + " " + tRight.get() + " " + tBottom.get()); // System.out.println(tLeft.get() + " " + tTop.get() + " " + tRight.get() + " " + tBottom.get());
} }
@ -739,17 +745,25 @@ public class RenderingEngine {
return this.nearClip; return this.nearClip;
} }
/**
* Gets the window pointer of the rendering engine
* @return The window pointer
*/
public long getWindowPtr(){
return this.windowPtr;
}
/** /**
* Tries to recapture the screen * Tries to recapture the screen
*/ */
public static void recaptureIfNecessary(){ public static void recaptureIfNecessary(){
if(Globals.controlHandler.shouldRecapture()){ if(Globals.controlHandler.shouldRecapture()){
//Makes the window that was just created the current OS-level window context //Makes the window that was just created the current OS-level window context
GLFW.glfwMakeContextCurrent(Globals.window); GLFW.glfwMakeContextCurrent(Globals.renderingEngine.windowPtr);
// //Maximize it // //Maximize it
GLFW.glfwMaximizeWindow(Globals.window); GLFW.glfwMaximizeWindow(Globals.renderingEngine.windowPtr);
//grab focus //grab focus
GLFW.glfwFocusWindow(Globals.window); GLFW.glfwFocusWindow(Globals.renderingEngine.windowPtr);
//apply mouse controls state //apply mouse controls state
if(Globals.controlHandler.isMouseVisible()){ if(Globals.controlHandler.isMouseVisible()){
Globals.controlHandler.showMouse(); Globals.controlHandler.showMouse();
@ -913,7 +927,7 @@ public class RenderingEngine {
Globals.assetManager.handleDeleteQueue(); Globals.assetManager.handleDeleteQueue();
//end glfw //end glfw
GLFW.glfwDestroyWindow(Globals.window); GLFW.glfwDestroyWindow(this.windowPtr);
GLFW.glfwTerminate(); GLFW.glfwTerminate();
} }

View File

@ -49,7 +49,7 @@ public class ImGuiPipeline implements RenderPipeline {
throw new IllegalStateException("Imgui failed to initialize."); throw new IllegalStateException("Imgui failed to initialize.");
} }
ImPlot.createContext(); ImPlot.createContext();
imGuiGlfw.init(Globals.window,true); imGuiGlfw.init(Globals.renderingEngine.getWindowPtr(),true);
imGuiGl13.init(glslVersion); imGuiGl13.init(glslVersion);
} }

View File

@ -28,9 +28,6 @@ public class StateCleanupCheckerExtension implements AfterEachCallback {
throw new Exception("Failed to cleanup state after test! " + object.toString()); throw new Exception("Failed to cleanup state after test! " + object.toString());
} }
} }
if(Globals.window != -1){
throw new Exception("Failed to cleanup global window pointer!");
}
} }
} }