From 129bc9059cc47cb8ec46131e071b403f489a7ca7 Mon Sep 17 00:00:00 2001 From: milek7 Date: Wed, 13 Apr 2022 22:15:43 +0200 Subject: [PATCH] make imgui version runtime selectable --- CMakeLists.txt | 12 ++++------- application.cpp | 18 ++--------------- openglrenderer.cpp | 11 ++-------- openglrenderer.h | 1 - uilayer.cpp | 50 ++++++++++++++++++++-------------------------- 5 files changed, 30 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87154233..c37dbb27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,6 @@ if (APPLE) set (CMAKE_FIND_FRAMEWORK LAST) endif() -option(USE_IMGUI_GL3 "Use OpenGL3+ imgui implementation" ON) option(WITH_OPENGL_MODERN "Compile with OpenGL modern renderer" ON) option(WITH_OPENGL_LEGACY "Compile with OpenGL legacy renderer" ON) option(WITH_UART "Compile with libserialport" ON) @@ -201,13 +200,10 @@ set(SOURCES "vr/vr_interface.cpp" ) -if (USE_IMGUI_GL3) - set(SOURCES ${SOURCES} "imgui/imgui_impl_opengl3.cpp") -else() - add_definitions(-DEU07_USEIMGUIIMPLOPENGL2) - set(SOURCES ${SOURCES} "imgui/imgui_impl_opengl2.cpp") - set_source_files_properties("imgui/imgui_impl_opengl2.cpp" PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE) -endif() +set(SOURCES ${SOURCES} "imgui/imgui_impl_opengl3.cpp") +set(SOURCES ${SOURCES} "imgui/imgui_impl_opengl2.cpp") +set_source_files_properties("imgui/imgui_impl_opengl3.cpp" PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE) +set_source_files_properties("imgui/imgui_impl_opengl2.cpp" PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE) if (WITH_CRASHPAD) add_definitions(-DWITH_CRASHPAD) diff --git a/application.cpp b/application.cpp index 388a8dc8..ccd49af3 100644 --- a/application.cpp +++ b/application.cpp @@ -820,32 +820,23 @@ eu07_application::init_glfw() { if (!monitor) monitor = glfwGetPrimaryMonitor(); - auto const uselegacyrenderer { Global.GfxRenderer != "default" }; glfwWindowHint( GLFW_AUTO_ICONIFY, GLFW_FALSE ); - if ((Global.gfx_skippipeline || uselegacyrenderer) && Global.iMultisampling > 0) { + if ((Global.gfx_skippipeline || Global.LegacyRenderer) && Global.iMultisampling > 0) { glfwWindowHint( GLFW_SAMPLES, 1 << Global.iMultisampling ); } crashreport_add_info("gfxrenderer", Global.GfxRenderer); - if( false == uselegacyrenderer ) { + if( !Global.LegacyRenderer ) { Global.bUseVBO = true; // activate core profile for opengl 3.3 renderer if( !Global.gfx_usegles ) { -#ifndef EU07_USEIMGUIIMPLOPENGL2 glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE ); glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE ); -#else - glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE ); -#endif glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3 ); glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 3 ); } else { -#ifdef EU07_USEIMGUIIMPLOPENGL2 - ErrorLog("gles not supported in imgui gl2 build"); - return -1; -#endif #ifdef GLFW_CONTEXT_CREATION_API if (m_glfwversion >= 30200) glfwWindowHint( GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API ); @@ -861,13 +852,8 @@ eu07_application::init_glfw() { } Global.gfx_shadergamma = false; glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE ); -#ifndef EU07_USEIMGUIIMPLOPENGL2 - glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3 ); - glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 0 ); -#else glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 2 ); glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 1 ); -#endif } if (Global.gfx_gldebug) diff --git a/openglrenderer.cpp b/openglrenderer.cpp index e30010ca..469f495c 100644 --- a/openglrenderer.cpp +++ b/openglrenderer.cpp @@ -4392,17 +4392,10 @@ opengl_renderer::Init_caps() { + " Vendor: " + gl_vendor + " OpenGL Version: " + gl_version ); -#ifdef EU07_USEIMGUIIMPLOPENGL2 - if( !GLAD_GL_VERSION_1_5 ) { - ErrorLog( "Requires openGL >= 1.5" ); + if( !GLAD_GL_VERSION_2_1 ) { + ErrorLog( "Requires openGL >= 2.1" ); return false; } -#else - if( !GLAD_GL_VERSION_3_0 ) { - ErrorLog( "Requires openGL >= 3.0" ); - return false; - } -#endif char* extensions = (char*)glGetString( GL_EXTENSIONS ); if (extensions) diff --git a/openglrenderer.h b/openglrenderer.h index c84440d6..ec3512cc 100644 --- a/openglrenderer.h +++ b/openglrenderer.h @@ -25,7 +25,6 @@ http://mozilla.org/MPL/2.0/. //#define EU07_USE_DEBUG_CABSHADOWMAP //#define EU07_USE_DEBUG_CAMERA //#define EU07_USE_DEBUG_SOUNDEMITTERS -//#define EU07_USEIMGUIIMPLOPENGL2 //#define EU07_DISABLECABREFLECTIONS // bare-bones render controller, in lack of anything better yet diff --git a/uilayer.cpp b/uilayer.cpp index d677bba1..fa73feef 100644 --- a/uilayer.cpp +++ b/uilayer.cpp @@ -19,11 +19,8 @@ http://mozilla.org/MPL/2.0/. #include "application.h" #include "imgui/imgui_impl_glfw.h" -#ifdef EU07_USEIMGUIIMPLOPENGL2 #include "imgui/imgui_impl_opengl2.h" -#else #include "imgui/imgui_impl_opengl3.h" -#endif GLFWwindow *ui_layer::m_window{nullptr}; ImGuiIO *ui_layer::m_imguiio{nullptr}; @@ -241,16 +238,16 @@ bool ui_layer::init(GLFWwindow *Window) imgui_style(); ImGui_ImplGlfw_InitForOpenGL(m_window, false); -#ifdef EU07_USEIMGUIIMPLOPENGL2 - crashreport_add_info("imgui_ver", "gl2"); - ImGui_ImplOpenGL2_Init(); -#else - crashreport_add_info("imgui_ver", "gl3"); - if (Global.gfx_usegles) - ImGui_ImplOpenGL3_Init("#version 300 es\nprecision highp float;"); - else - ImGui_ImplOpenGL3_Init("#version 330 core"); -#endif + if (Global.LegacyRenderer) { + crashreport_add_info("imgui_ver", "gl2"); + ImGui_ImplOpenGL2_Init(); + } else { + crashreport_add_info("imgui_ver", "gl3"); + if (Global.gfx_usegles) + ImGui_ImplOpenGL3_Init("#version 300 es\nprecision highp float;"); + else + ImGui_ImplOpenGL3_Init("#version 330 core"); + } return true; } @@ -259,11 +256,10 @@ void ui_layer::shutdown() { ImGui::EndFrame(); -#ifdef EU07_USEIMGUIIMPLOPENGL2 - ImGui_ImplOpenGL2_Shutdown(); -#else - ImGui_ImplOpenGL3_Shutdown(); -#endif + if (Global.LegacyRenderer) + ImGui_ImplOpenGL2_Shutdown(); + else + ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); } @@ -344,11 +340,10 @@ void ui_layer::render_internal() { ImGui::Render(); -#ifdef EU07_USEIMGUIIMPLOPENGL2 - ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); -#else - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); -#endif + if (Global.LegacyRenderer) + ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); + else + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } void ui_layer::begin_ui_frame() @@ -358,11 +353,10 @@ void ui_layer::begin_ui_frame() void ui_layer::begin_ui_frame_internal() { -#ifdef EU07_USEIMGUIIMPLOPENGL2 - ImGui_ImplOpenGL2_NewFrame(); -#else - ImGui_ImplOpenGL3_NewFrame(); -#endif + if (Global.LegacyRenderer) + ImGui_ImplOpenGL2_NewFrame(); + else + ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); }