Description: Use packaged imgui
 Use the packaged libimgui -- adapt CMakeLists.txt and to obsolete functions removed
 in newer imgui.
Author: Tobias Frost <tobi@debian.org>
Forwarded: https://github.com/RobertBeckebans/RBDOOM-3-BFG/pull/633
Last-Update: 2022-03-28 <YYYY-MM-DD, last update of the meta-information, optional>
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/neo/CMakeLists.txt
+++ b/neo/CMakeLists.txt
@@ -69,6 +69,10 @@
 option(USE_SYSTEM_RAPIDJSON
                 "Use the system rapidjson instead of the bundled one" OFF)
 
+option(USE_SYSTEM_IMGUI
+                "Use the system imgui instead of the bundled one" OFF)
+
+
 set(CPU_TYPE "" CACHE STRING "When set, passes this string as CPU-ID which will be embedded into the binary.")
 
 # SRS - Turn on optimization when cross-compiling from Apple arm64 to x86_64
@@ -355,6 +359,18 @@
 endif (JPEG_FOUND)
 
 
+if (USE_SYSTEM_IMGUI)
+    find_package(PkgConfig REQUIRED)
+    pkg_check_modules(IMGUI REQUIRED imgui)
+endif()
+
+if(IMGUI_FOUND)
+    include_directories(${IMGUI_INCLUDE_DIRS})
+else()
+    include_directories("libs/imgui/../")
+    set(IMGUI_LIBRARIES "")
+endif()
+
 macro(SET_OPTION option value)
   set(${option} ${value} CACHE "" INTERNAL FORCE)
 endmacro()
@@ -481,7 +497,6 @@
 endif (RAPIDJSON_FOUND)
 
 
-	
 add_subdirectory(idlib)
 
 file(GLOB AAS_INCLUDES aas/*.h)
@@ -534,8 +549,13 @@
 file(GLOB IRRXML_INCLUDES libs/irrxml/src/*.h)
 file(GLOB IRRXML_SOURCES libs/irrxml/src/*.cpp)
 
+if(NOT USE_SYSTEM_IMGUI)
 file(GLOB IMGUI_INCLUDES libs/imgui/*.h)
 file(GLOB IMGUI_SOURCES libs/imgui/*.cpp)
+else()
+set(IMGUI_INCLUDES "")
+set(IMGUI_SOURCES "")
+endif()
 
 file(GLOB STB_INCLUDES libs/stb/*.h)
 
@@ -1867,6 +1887,7 @@
             ${PNG_LIBRARY}
             ${JPEG_LIBRARY}
             ${GLEW_LIBRARY}
+            ${IMGUI_LIBRARIES}
 	    	${CMAKE_DL_LIBS}
 			)
 	endif()
--- a/neo/imgui/BFGimgui.h
+++ b/neo/imgui/BFGimgui.h
@@ -2,7 +2,7 @@
 #ifndef NEO_IMGUI_BFGIMGUI_H_
 #define NEO_IMGUI_BFGIMGUI_H_
 
-#include "libs/imgui/imgui.h"
+#include "imgui/imgui.h"
 
 #include "../idlib/math/Vector.h"
 
--- a/neo/renderer/GuiModel.cpp
+++ b/neo/renderer/GuiModel.cpp
@@ -31,7 +31,7 @@
 #pragma hdrstop
 
 #include "RenderCommon.h"
-#include "libs/imgui/imgui.h"
+#include "imgui/imgui.h"
 
 const float idGuiModel::STEREO_DEPTH_NEAR = 0.0f;
 const float idGuiModel::STEREO_DEPTH_MID  = 0.5f;
--- a/neo/renderer/Image_intrinsic.cpp
+++ b/neo/renderer/Image_intrinsic.cpp
@@ -30,7 +30,7 @@
 #include "precompiled.h"
 #pragma hdrstop
 
-#include "libs/imgui/imgui.h"
+#include "imgui/imgui.h"
 
 #include "RenderCommon.h"
 #include "SMAA/AreaTex.h"
--- a/neo/renderer/RenderSystem_init.cpp
+++ b/neo/renderer/RenderSystem_init.cpp
@@ -31,7 +31,7 @@
 #include "precompiled.h"
 #pragma hdrstop
 
-#include "libs/imgui/imgui.h"
+#include "imgui/imgui.h"
 
 #include "RenderCommon.h"
 
--- a/neo/ui/DeviceContext.cpp
+++ b/neo/ui/DeviceContext.cpp
@@ -31,7 +31,7 @@
 
 #include "DeviceContext.h"
 
-#include "libs/imgui/imgui.h"
+#include "imgui/imgui.h"
 #include "../renderer/GuiModel.h"
 
 extern idCVar in_useJoystick;
--- a/neo/imgui/BFGimguiImpl.cpp
+++ b/neo/imgui/BFGimguiImpl.cpp
@@ -249,7 +249,9 @@
 	g_DisplaySize.y = windowHeight;
 	io.DisplaySize = g_DisplaySize;
 
+#if (IMGUI_VERSION_NUM <= 16000)
 	io.RenderDrawListsFn = idRenderBackend::ImGui_RenderDrawLists;
+#endif
 
 	// RB: FIXME double check
 	io.SetClipboardTextFn = SetClipboardText;
@@ -437,6 +439,10 @@
 		//ImGui::End();
 
 		ImGui::Render();
+#if (IMGUI_VERSION_NUM > 16000)
+		idRenderBackend::ImGui_RenderDrawLists(ImGui::GetDrawData());
+#endif
+
 		g_haveNewFrame = false;
 	}
 }
--- rbdoom3bfg-1.4.0+dfsg.orig/neo/renderer/OpenGL/RenderBackend_GL.cpp
+++ rbdoom3bfg-1.4.0+dfsg/neo/renderer/OpenGL/RenderBackend_GL.cpp
@@ -48,7 +48,7 @@
 #include "../RenderBackend.h"
 #include "../../framework/Common_local.h"
 
-#include "../../imgui/imgui.h"
+#include "imgui/imgui.h"
 
 idCVar r_drawFlickerBox( "r_drawFlickerBox", "0", CVAR_RENDERER | CVAR_BOOL, "visual test for dropping frames" );
 idCVar stereoRender_warp( "stereoRender_warp", "0", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_BOOL, "use the optical warping renderprog instead of stereoDeGhost" );
