From 8fcc91cdd8a8dcfb5bd8ac5a0295a6b60fe9f43c Mon Sep 17 00:00:00 2001 From: Firestar99 <31222740+Firestar99@users.noreply.github.com> Date: Sat, 20 Jan 2018 23:06:15 +0100 Subject: [PATCH] a bit more work on GLFW Rethink: - AttributeList needs a "update" feature -- maybe have two AttributeLists: -- one being created by the Creator be StateAttributeList -- one ModifyAttributeList, gotten from StateAttributeList#modify() and then apply()-ed later, triggering updates --- .../engine/render/window/WindowFormat.java | 30 ++++--- .../window/glfw/GLFWWindowFramework.java | 90 +++++++++++-------- 2 files changed, 69 insertions(+), 51 deletions(-) diff --git a/src/space/engine/render/window/WindowFormat.java b/src/space/engine/render/window/WindowFormat.java index 5ff5607..8601819 100644 --- a/src/space/engine/render/window/WindowFormat.java +++ b/src/space/engine/render/window/WindowFormat.java @@ -27,24 +27,26 @@ public class WindowFormat { public static final AttributeListCreator ATTRIBUTE_LIST_CREATOR = new AttributeListCreator(); //main window settings - public static final IKey WINDOW_WIDTH = ATTRIBUTE_LIST_CREATOR.generateKey(800); //done - public static final IKey WINDOW_HEIGHT = ATTRIBUTE_LIST_CREATOR.generateKey(600); //done - public static final IKey WINDOW_MODE = ATTRIBUTE_LIST_CREATOR.generateKey(WINDOWED); //done + public static final IKey WINDOW_POS_X = ATTRIBUTE_LIST_CREATOR.generateKey(); + public static final IKey WINDOW_POS_Y = ATTRIBUTE_LIST_CREATOR.generateKey(); + public static final IKey WINDOW_WIDTH = ATTRIBUTE_LIST_CREATOR.generateKey(800); + public static final IKey WINDOW_HEIGHT = ATTRIBUTE_LIST_CREATOR.generateKey(600); + public static final IKey WINDOW_MODE = ATTRIBUTE_LIST_CREATOR.generateKey(WINDOWED); //additional window settings - public static final IKey VISIBLE = ATTRIBUTE_LIST_CREATOR.generateKey(TRUE); //done - public static final IKey MONITOR = ATTRIBUTE_LIST_CREATOR.generateKey(); //done - public static final IKey TITLE = ATTRIBUTE_LIST_CREATOR.generateKey("Untitled Window"); //done - public static final IKey RESIZEABLE = ATTRIBUTE_LIST_CREATOR.generateKey(FALSE); //done - public static final IKey DOUBLEBUFFER = ATTRIBUTE_LIST_CREATOR.generateKey(TRUE); //done + public static final IKey VISIBLE = ATTRIBUTE_LIST_CREATOR.generateKey(TRUE); + public static final IKey MONITOR = ATTRIBUTE_LIST_CREATOR.generateKey(); + public static final IKey TITLE = ATTRIBUTE_LIST_CREATOR.generateKey("Untitled Window"); + public static final IKey RESIZEABLE = ATTRIBUTE_LIST_CREATOR.generateKey(FALSE); + public static final IKey DOUBLEBUFFER = ATTRIBUTE_LIST_CREATOR.generateKey(TRUE); //gl window settings - public static final IKey GL_API_TYPE = ATTRIBUTE_LIST_CREATOR.generateKey(GL); //done - public static final IKey GL_PROFILE = ATTRIBUTE_LIST_CREATOR.generateKey(PROFILE_ANY); //done - public static final IKey GL_VERSION_MAJOR = ATTRIBUTE_LIST_CREATOR.generateKey(2); //done - public static final IKey GL_VERSION_MINOR = ATTRIBUTE_LIST_CREATOR.generateKey(1); //done - public static final IKey GL_FORWARD_COMPATIBLE = ATTRIBUTE_LIST_CREATOR.generateKey(TRUE); //done - public static final IKey GL_CONTEXT_SHARE = ATTRIBUTE_LIST_CREATOR.generateKey(); //done + public static final IKey GL_API_TYPE = ATTRIBUTE_LIST_CREATOR.generateKey(GL); + public static final IKey GL_PROFILE = ATTRIBUTE_LIST_CREATOR.generateKey(PROFILE_ANY); + public static final IKey GL_VERSION_MAJOR = ATTRIBUTE_LIST_CREATOR.generateKey(2); + public static final IKey GL_VERSION_MINOR = ATTRIBUTE_LIST_CREATOR.generateKey(1); + public static final IKey GL_FORWARD_COMPATIBLE = ATTRIBUTE_LIST_CREATOR.generateKey(TRUE); + public static final IKey GL_CONTEXT_SHARE = ATTRIBUTE_LIST_CREATOR.generateKey(); //fbo public static final IKey FBO_R = ATTRIBUTE_LIST_CREATOR.generateKey(8); diff --git a/src/space/engine/render/window/glfw/GLFWWindowFramework.java b/src/space/engine/render/window/glfw/GLFWWindowFramework.java index 1147fc4..5d81f56 100644 --- a/src/space/engine/render/window/glfw/GLFWWindowFramework.java +++ b/src/space/engine/render/window/glfw/GLFWWindowFramework.java @@ -59,25 +59,31 @@ public class GLFWWindow implements IWindow { public GLFWWindow(IAttributeList format) { synchronized (GLFW_SYNC) { - glfwWindowHint(GLFW_VISIBLE, curr.pull(format, VISIBLE) ? GLFW_TRUE : GLFW_FALSE); - glfwWindowHint(GLFW_RESIZABLE, curr.pull(format, RESIZEABLE) ? GLFW_TRUE : GLFW_FALSE); - glfwWindowHint(GLFW_DOUBLEBUFFER, curr.pull(format, DOUBLEBUFFER) ? GLFW_TRUE : GLFW_FALSE); + glfwWindowHint(GLFW_VISIBLE, format.push(curr, VISIBLE) ? GLFW_TRUE : GLFW_FALSE); + glfwWindowHint(GLFW_RESIZABLE, format.push(curr, RESIZEABLE) ? GLFW_TRUE : GLFW_FALSE); + glfwWindowHint(GLFW_DOUBLEBUFFER, format.push(curr, DOUBLEBUFFER) ? GLFW_TRUE : GLFW_FALSE); //GLApi - glfwWindowHint(GLFW_CLIENT_API, covertGLApiTypeToGLFWApi(curr.pull(format, GL_API_TYPE))); - glfwWindowHint(GLFW_OPENGL_PROFILE, covertGLProfileToGLFWProfile(curr.pull(format, GL_PROFILE))); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, curr.pull(format, GL_VERSION_MAJOR)); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, curr.pull(format, GL_VERSION_MINOR)); - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, curr.pull(format, GL_FORWARD_COMPATIBLE) ? GLFW_TRUE : GLFW_FALSE); + glfwWindowHint(GLFW_CLIENT_API, covertGLApiTypeToGLFWApi(format.push(curr, GL_API_TYPE))); + glfwWindowHint(GLFW_OPENGL_PROFILE, covertGLProfileToGLFWProfile(format.push(curr, GL_PROFILE))); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, format.push(curr, GL_VERSION_MAJOR)); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, format.push(curr, GL_VERSION_MINOR)); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, format.push(curr, GL_FORWARD_COMPATIBLE) ? GLFW_TRUE : GLFW_FALSE); //FBO + glfwWindowHint(GLFW_RED_BITS, format.push(curr, FBO_R)); + glfwWindowHint(GLFW_GREEN_BITS, format.push(curr, FBO_G)); + glfwWindowHint(GLFW_BLUE_BITS, format.push(curr, FBO_B)); + glfwWindowHint(GLFW_ALPHA_BITS, format.push(curr, FBO_A)); + glfwWindowHint(GLFW_DEPTH_BITS, format.push(curr, FBO_DEPTH)); + glfwWindowHint(GLFW_STENCIL_BITS, format.push(curr, FBO_STENCIL)); //windowMode long monitorPointer; - WindowMode windowMode = curr.pull(format, WINDOW_MODE); + WindowMode windowMode = format.push(curr, WINDOW_MODE); if (windowMode == FULLSCREEN) { glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); - monitorPointer = getMonitorPointer(curr.pull(format, MONITOR)); + monitorPointer = getMonitorPointer(format.push(curr, MONITOR)); } else { glfwWindowHint(GLFW_DECORATED, windowMode == BORDERLESS ? GLFW_FALSE : GLFW_TRUE); curr.reset(MONITOR); @@ -85,13 +91,24 @@ public GLFWWindow(IAttributeList format) { } //create - windowPointer = glfwCreateWindow(curr.pull(format, WINDOW_WIDTH), curr.pull(format, WINDOW_HEIGHT), curr.pull(format, TITLE), monitorPointer, getWindowSharePointer(curr.get(GL_CONTEXT_SHARE))); + windowPointer = glfwCreateWindow(format.push(curr, WINDOW_WIDTH), format.push(curr, WINDOW_HEIGHT), format.push(curr, TITLE), monitorPointer, getWindowSharePointer(curr.get(GL_CONTEXT_SHARE))); } } @Override public void update(IAttributeList format) { - + if (format.anyDifference(curr, VISIBLE)) + if (format.push(curr, VISIBLE)) { + glfwShowWindow(windowPointer); + } else { + glfwHideWindow(windowPointer); + } + if (format.anyDifference(curr, RESIZEABLE)) + glfwSetWindowAttrib(windowPointer, GLFW_RESIZABLE, format.push(curr, RESIZEABLE) ? GLFW_TRUE : GLFW_FALSE); + if (format.anyDifference(curr, DOUBLEBUFFER)) + glfwSetWindowAttrib(windowPointer, GLFW_DOUBLEBUFFER, format.push(curr, DOUBLEBUFFER) ? GLFW_TRUE : GLFW_FALSE); + +// glfwSetWindowMon } @Override @@ -141,36 +158,35 @@ protected static int covertGLProfileToGLFWProfile(GLProfile type) { } protected static long getMonitorPointer(String monitorName) { - if (monitorName != null && !monitorName.isEmpty()) { - BufferAllocatorStack allocStack = Side.getSide().get(Side.BUFFER_STACK_ALLOC); - try { - allocStack.push(); - Buffer sizeBuffer = allocStack.malloc(8); - long dest = nglfwGetMonitors(sizeBuffer.address()); - long size = sizeBuffer.getLong(0); - Buffer list = allocStack.alloc(dest, size); - - for (long i = 0; i < size; i += 8) { - long monitorPointer = list.getLong(i); - if (monitorName.equals(glfwGetMonitorName(monitorPointer))) - return monitorPointer; - } - - throw new IllegalArgumentException("Monitor named '" + monitorName + "' not found!"); - } finally { - allocStack.pop(); + if (monitorName == null || monitorName.isEmpty()) + return glfwGetPrimaryMonitor(); + + BufferAllocatorStack allocStack = Side.getSide().get(Side.BUFFER_STACK_ALLOC); + try { + allocStack.push(); + Buffer sizeBuffer = allocStack.malloc(8); + long dest = nglfwGetMonitors(sizeBuffer.address()); + long size = sizeBuffer.getLong(0); + Buffer list = allocStack.alloc(dest, size); + + for (long i = 0; i < size; i += 8) { + long monitorPointer = list.getLong(i); + if (monitorName.equals(glfwGetMonitorName(monitorPointer))) + return monitorPointer; } + throw new IllegalArgumentException("Monitor named '" + monitorName + "' not found!"); + } finally { + allocStack.pop(); } - return glfwGetPrimaryMonitor(); } protected static long getWindowSharePointer(IWindow windowShare) { - if (windowShare != null) { - if (!(windowShare instanceof GLFWWindow)) - throw new IllegalArgumentException("GL_CONTEXT_SHARE was not of type GLFWWindow, instead was " + windowShare.getClass().getName()); - return ((GLFWWindow) windowShare).windowPointer; - } - return 0; + if (windowShare == null) + return 0; + + if (!(windowShare instanceof GLFWWindow)) + throw new IllegalArgumentException("GL_CONTEXT_SHARE was not of type GLFWWindow, instead was " + windowShare.getClass().getName()); + return ((GLFWWindow) windowShare).windowPointer; } //free