[WIP] Viewports backend

This commit is contained in:
SpaiR committed 2020-08-30 15:47:27 +03:00
1 parent 8494bd8361
commit e328d738ce
16 files changed
+676 -177

No files matched your search

@@ -1,29 +1,5 @@
import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks;
import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MAJOR;
import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MINOR;
import static org.lwjgl.glfw.GLFW.GLFW_FALSE;
import static org.lwjgl.glfw.GLFW.GLFW_OPENGL_CORE_PROFILE;
import static org.lwjgl.glfw.GLFW.GLFW_OPENGL_FORWARD_COMPAT;
import static org.lwjgl.glfw.GLFW.GLFW_OPENGL_PROFILE;
import static org.lwjgl.glfw.GLFW.GLFW_TRUE;
import static org.lwjgl.glfw.GLFW.GLFW_VISIBLE;
import static org.lwjgl.glfw.GLFW.glfwCreateWindow;
import static org.lwjgl.glfw.GLFW.glfwDefaultWindowHints;
import static org.lwjgl.glfw.GLFW.glfwDestroyWindow;
import static org.lwjgl.glfw.GLFW.glfwGetPrimaryMonitor;
import static org.lwjgl.glfw.GLFW.glfwGetVideoMode;
import static org.lwjgl.glfw.GLFW.glfwGetWindowSize;
import static org.lwjgl.glfw.GLFW.glfwInit;
import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent;
import static org.lwjgl.glfw.GLFW.glfwPollEvents;
import static org.lwjgl.glfw.GLFW.glfwSetErrorCallback;
import static org.lwjgl.glfw.GLFW.glfwSetWindowPos;
import static org.lwjgl.glfw.GLFW.glfwShowWindow;
import static org.lwjgl.glfw.GLFW.glfwSwapBuffers;
import static org.lwjgl.glfw.GLFW.glfwSwapInterval;
import static org.lwjgl.glfw.GLFW.glfwTerminate;
import static org.lwjgl.glfw.GLFW.glfwWindowHint;
import static org.lwjgl.glfw.GLFW.glfwWindowShouldClose;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL32.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL32.GL_TRUE;
import static org.lwjgl.opengl.GL32.glClear;
@@ -65,23 +41,20 @@ public final class ImGuiGlfwExample {
private final ExampleUi exampleUi = new ExampleUi();
public void run() throws Exception {
// IMPORTANT!!
// This line is critical for Dear ImGui to work.
ImGui.createContext();
setupGlfw();
setupImGui();
// Method initializes GLFW backend.
// This method SHOULD be called after you've setup GLFW.
// ImGui context should be created as well.
setupGlfw();
imGuiGlfw.init(windowPtr, true);
// Method initializes LWJGL3 renderer.
// This method SHOULD be called after you've initialized your ImGui configuration (fonts and so on).
// ImGui context should be created as well.
setupImGui();
imGuiGl3.init(glslVersion);
exampleUi.init();
loop();
// You should clean up after yourself in reverse order.
@@ -162,12 +135,16 @@ public final class ImGuiGlfwExample {
// Initialize Dear ImGui.
private void setupImGui() {
// IMPORTANT!!
// This line is critical for Dear ImGui to work.
ImGui.createContext();
// ------------------------------------------------------------
// Initialize ImGuiIO config
final ImGuiIO io = ImGui.getIO();
io.setIniFilename(null); // We don't want to save .ini file
io.addConfigFlags(ImGuiConfigFlags.NavEnableKeyboard | ImGuiConfigFlags.DockingEnable); // Navigation with keyboard and enabled docking
io.addConfigFlags(ImGuiConfigFlags.NavEnableKeyboard | ImGuiConfigFlags.DockingEnable | ImGuiConfigFlags.ViewportsEnable);
// ------------------------------------------------------------
// Fonts configuration
@@ -235,7 +212,14 @@ public final class ImGuiGlfwExample {
private void endFrame() {
// After Dear ImGui prepared a draw data, we use it in the LWJGL3 renderer.
// At that moment ImGui will be rendered to the current OpenGL context.
imGuiGl3.render(ImGui.getDrawData());
imGuiGl3.renderDrawData(ImGui.getDrawData());
if ((ImGui.getIO().getConfigFlags() & ImGuiConfigFlags.ViewportsEnable) != 0) {
final long backupWindowPtr = glfwGetCurrentContext();
ImGui.updatePlatformWindows();
ImGui.renderPlatformWindowsDefault();
glfwMakeContextCurrent(backupWindowPtr);
}
glfwSwapBuffers(windowPtr);
glfwPollEvents();