Kaynağa Gözat

Add SDL2+OpenGL3 backend to imgui (#1690)

* Add SDL2+OpenGL3 backend to imgui

* Update comment

* Clean up duplicate code
Aidan Sun 2 yıl önce
ebeveyn
işleme
0fef911d3c
2 değiştirilmiş dosya ile 49 ekleme ve 25 silme
  1. 42 21
      packages/i/imgui/port/xmake.lua
  2. 7 4
      packages/i/imgui/xmake.lua

+ 42 - 21
packages/i/imgui/port/xmake.lua

@@ -6,24 +6,36 @@ option("freetype",     {showmenu = true,  default = false})
 option("glfw_opengl3", {showmenu = true,  default = false})
 option("glfw_vulkan",  {showmenu = true,  default = false})
 option("sdl2",         {showmenu = true,  default = false})
+option("sdl2_opengl3", {showmenu = true,  default = false})
 option("user_config",  {showmenu = true,  default = nil, type = "string"})
 option("use_glad",     {showmenu = true,  default = false})
 
-if has_config("freetype") then 
+-- Renderer backends
+local has_opengl3 = has_config("glfw_opengl3") or has_config("sdl2_opengl3")
+local has_vulkan = has_config("glfw_vulkan")
+local has_sdl_renderer = has_config("sdl2")
+
+-- Platform backends
+local has_glfw = has_config("glfw_opengl3") or has_config("glfw_vulkan")
+local has_sdl2 = has_config("sdl2") or has_config("sdl2_opengl3")
+
+if has_config("freetype") then
     add_requires("freetype")
 end
 
-if has_config("glfw_opengl3") then
-    add_requires("glfw")
-    if has_config("use_glad") then
-        add_requires("glad")
-    end
+if has_opengl3 and has_config("use_glad") then
+    add_requires("glad")
 end
-if has_config("glfw_vulkan") then
-    add_requires("glfw")
+
+if has_vulkan then
     add_requires("vulkansdk")
 end
-if has_config("sdl2") then
+
+if has_glfw then
+    add_requires("glfw")
+end
+
+if has_sdl2 then
     add_requires("libsdl >=2.0.17")
 end
 
@@ -44,10 +56,9 @@ target("imgui")
         add_defines("IMGUI_ENABLE_FREETYPE")
     end
 
-    if has_config("glfw_opengl3") then
-        add_files("backends/imgui_impl_glfw.cpp", "backends/imgui_impl_opengl3.cpp")
-        add_headerfiles("backends/imgui_impl_glfw.h", "backends/imgui_impl_opengl3.h")
-        add_packages("glfw")
+    if has_opengl3 then
+        add_files("backends/imgui_impl_opengl3.cpp")
+        add_headerfiles("backends/imgui_impl_opengl3.h")
         if has_config("use_glad") then
             add_defines("IMGUI_IMPL_OPENGL_LOADER_GLAD")
             add_packages("glad")
@@ -56,16 +67,26 @@ target("imgui")
         end
     end
 
-    if has_config("glfw_vulkan") then
-        add_files("backends/imgui_impl_vulkan.cpp", "backends/imgui_impl_glfw.cpp")
-        add_headerfiles("backends/imgui_impl_vulkan.h", "backends/imgui_impl_glfw.h")
-        add_packages("glfw")
+    if has_vulkan then
+        add_files("backends/imgui_impl_vulkan.cpp")
+        add_headerfiles("backends/imgui_impl_vulkan.h")
         add_packages("vulkansdk")
     end
-    
-    if has_config("sdl2") then
-        add_files("backends/imgui_impl_sdl.cpp", "backends/imgui_impl_sdlrenderer.cpp")
-        add_headerfiles("backends/imgui_impl_sdl.h", "backends/imgui_impl_sdlrenderer.h")
+
+    if has_sdl_renderer then
+        add_files("backends/imgui_impl_sdlrenderer.cpp")
+        add_headerfiles("backends/imgui_impl_sdlrenderer.h")
+    end
+
+    if has_glfw then
+        add_files("backends/imgui_impl_glfw.cpp")
+        add_headerfiles("backends/imgui_impl_glfw.h")
+        add_packages("glfw")
+    end
+
+    if has_sdl2 then
+        add_files("backends/imgui_impl_sdl.cpp")
+        add_headerfiles("backends/imgui_impl_sdl.h")
         add_packages("libsdl")
     end
 

+ 7 - 4
packages/i/imgui/xmake.lua

@@ -29,6 +29,7 @@ package("imgui")
     add_configs("glfw_opengl3", {description = "Enable glfw+opengl3 backend", default = false, type = "boolean"})
     add_configs("glfw_vulkan", {description = "Enable glfw+vulkan backend", default = false, type = "boolean"})
     add_configs("sdl2", {description = "Enable sdl2 backend", default = false, type = "boolean"})
+    add_configs("sdl2_opengl3", {description = "Enable sdl2+opengl3 backend", default = false, type = "boolean"})
     add_configs("wchar32", {description = "Use 32-bit for ImWchar (default is 16-bit)", default = false, type = "boolean"})
     add_configs("freetype", {description = "Use FreeType to build and rasterize the font atlas", default = false, type = "boolean"})
 
@@ -42,18 +43,19 @@ package("imgui")
         if package:config("freetype") then
             package:add("deps", "freetype")
         end
-        if package:config("glfw_opengl3") then
+        if package:config("glfw_opengl3") or package:config("sdl2_opengl3") then
             if package:version():lt("1.84") then
                 package:add("deps", "glad")
                 package:add("defines", "IMGUI_IMPL_OPENGL_LOADER_GLAD")
             end
+        end
+        if package:config("glfw_opengl3") or package:config("glfw_vulkan") then
             package:add("deps", "glfw")
         end
         if package:config("glfw_vulkan") then
-            package:add("deps", "glfw")
             package:add("deps", "vulkansdk")
         end
-        if package:config("sdl2") then
+        if package:config("sdl2") or package:config("sdl2_opengl3") then
             package:add("deps", "libsdl >=2.0.17")
         end
         if package:version_str():find("-docking", 1, true) then
@@ -68,8 +70,9 @@ package("imgui")
             glfw_opengl3 = package:config("glfw_opengl3"),
             glfw_vulkan  = package:config("glfw_vulkan"),
             sdl2         = package:config("sdl2"),
+            sdl2_opengl3 = package:config("sdl2_opengl3"),
             user_config  = package:config("user_config"),
-            use_glad     = package:version() and package:version():lt("1.84") -- this flag will be used if glfw_opengl3 is enabled
+            use_glad     = package:version() and package:version():lt("1.84") -- this flag will be used if glfw_opengl3 or sdl2_opengl3 is enabled
         }
 
         os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")