make imgui version runtime selectable

This commit is contained in:
milek7
2022-04-13 22:15:43 +02:00
parent 5395e6c060
commit 129bc9059c
5 changed files with 30 additions and 62 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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();
}