From 11e79b1072c7f12d84258b77948cda3b166aac59 Mon Sep 17 00:00:00 2001 From: Connor Broyles Date: Wed, 24 Jan 2024 19:19:51 -0500 Subject: [PATCH] [vsgimgui] New port (#33276) * [vsgimgui] New port * Fix indentation * Fix version * Remove files through portfile instead of patch * Update version * Add patch to remove font texture creation. The Vulkan backend now does this automatically. --------- Co-authored-by: Cheney-Wang <850426846@qq.com> --- ports/vsgimgui/devendor.patch | 144 ++++++++++++++++++ ports/vsgimgui/portfile.cmake | 21 +++ .../remove-manual-font-creation.patch | 63 ++++++++ ports/vsgimgui/vcpkg.json | 25 +++ versions/baseline.json | 4 + versions/v-/vsgimgui.json | 9 ++ 6 files changed, 266 insertions(+) create mode 100644 ports/vsgimgui/devendor.patch create mode 100644 ports/vsgimgui/portfile.cmake create mode 100644 ports/vsgimgui/remove-manual-font-creation.patch create mode 100644 ports/vsgimgui/vcpkg.json create mode 100644 versions/v-/vsgimgui.json diff --git a/ports/vsgimgui/devendor.patch b/ports/vsgimgui/devendor.patch new file mode 100644 index 0000000000..c73c849181 --- /dev/null +++ b/ports/vsgimgui/devendor.patch @@ -0,0 +1,144 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index a9e6265..96a2ecb 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -22,34 +22,13 @@ if (VULKAN_SDK) + set(ENV{VULKAN_SDK} ${VULKAN_SDK}) + endif() + +-find_package(vsg 1.0.5) ++find_package(vsg REQUIRED) ++find_package(imgui REQUIRED) ++find_package(implot REQUIRED) + + vsg_setup_dir_vars() + vsg_setup_build_vars() + +-if ( (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/imgui/imgui.h) OR +- (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/implot/implot.h) ) +- find_package(Git QUIET) +- +- execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive +- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +- RESULT_VARIABLE GIT_SUBMOD_RESULT) +- +- if(NOT GIT_SUBMOD_RESULT EQUAL "0") +- message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") +- endif() +-endif() +- +-vsg_copy_imgui_headers( +- FILES +- ${VSGIMGUI_SOURCE_DIR}/src/imgui/imgui.h +- ${VSGIMGUI_SOURCE_DIR}/src/imgui/imconfig.h +- ${VSGIMGUI_SOURCE_DIR}/src/imgui/imgui_internal.h +- ${VSGIMGUI_SOURCE_DIR}/src/imgui/imstb_textedit.h +- ${VSGIMGUI_SOURCE_DIR}/src/imgui//misc/cpp/imgui_stdlib.h +- ${VSGIMGUI_SOURCE_DIR}/src/implot/implot.h +- ${VSGIMGUI_SOURCE_DIR}/src/implot/implot_internal.h +-) + + vsg_add_target_clang_format( + FILES +diff --git a/include/vsgImGui/RenderImGui.h b/include/vsgImGui/RenderImGui.h +index b4210d2..33198e4 100644 +--- a/include/vsgImGui/RenderImGui.h ++++ b/include/vsgImGui/RenderImGui.h +@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + #include + + #include +-#include ++#include + + namespace vsgImGui + { +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 2226b13..1200b42 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -6,34 +6,15 @@ set(EXTRA_INCLUDES) + SET(HEADER_PATH ${VSGIMGUI_SOURCE_DIR}/include/vsgImGui) + + set(HEADERS +- ${HEADER_PATH}/imgui.h + ${HEADER_PATH}/SendEventsToImGui.h + ${HEADER_PATH}/RenderImGui.h + ${HEADER_PATH}/Texture.h +- imgui/imconfig.h +- imgui/imgui_internal.h +- imgui/imstb_rectpack.h +- imgui/imstb_textedit.h +- imgui/imstb_truetype.h +- imgui/misc/cpp/imgui_stdlib.h +- implot/implot.h +- implot/implot_internal.h + ) + + set(SOURCES + vsgImGui/RenderImGui.cpp + vsgImGui/SendEventsToImGui.cpp + vsgImGui/Texture.cpp +- imgui/imgui.cpp +- imgui/imgui_demo.cpp +- imgui/imgui_draw.cpp +- imgui/imgui_tables.cpp +- imgui/imgui_widgets.cpp +- imgui/backends/imgui_impl_vulkan.cpp +- imgui/misc/cpp/imgui_stdlib.cpp +- implot/implot.cpp +- implot/implot_demo.cpp +- implot/implot_items.cpp + ) + + +@@ -63,6 +44,8 @@ target_include_directories(vsgImGui PUBLIC + target_link_libraries(vsgImGui + PUBLIC + vsg::vsg ++ imgui::imgui ++ implot::implot + PRIVATE + ${EXTRA_LIBRARIES} + ) +diff --git a/src/vsgImGui/RenderImGui.cpp b/src/vsgImGui/RenderImGui.cpp +index 5d7cf06..dac2227 100644 +--- a/src/vsgImGui/RenderImGui.cpp ++++ b/src/vsgImGui/RenderImGui.cpp +@@ -22,9 +22,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + #include +-#include ++#include + +-#include "../imgui/backends/imgui_impl_vulkan.h" ++#include + + #include + #include +diff --git a/src/vsgImGui/SendEventsToImGui.cpp b/src/vsgImGui/SendEventsToImGui.cpp +index 4e83e4c..b1f4d83 100644 +--- a/src/vsgImGui/SendEventsToImGui.cpp ++++ b/src/vsgImGui/SendEventsToImGui.cpp +@@ -22,7 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + #include +-#include ++#include + + #include + #include +diff --git a/src/vsgImGuiConfig.cmake.in b/src/vsgImGuiConfig.cmake.in +index e2c14f2..5cf8bd9 100644 +--- a/src/vsgImGuiConfig.cmake.in ++++ b/src/vsgImGuiConfig.cmake.in +@@ -2,5 +2,7 @@ include(CMakeFindDependencyMacro) + + find_dependency(Vulkan) + find_dependency(vsg) ++find_dependency(imgui) ++find_dependency(implot) + + include("${CMAKE_CURRENT_LIST_DIR}/vsgImGuiTargets.cmake") diff --git a/ports/vsgimgui/portfile.cmake b/ports/vsgimgui/portfile.cmake new file mode 100644 index 0000000000..5c4a773340 --- /dev/null +++ b/ports/vsgimgui/portfile.cmake @@ -0,0 +1,21 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO vsg-dev/vsgImGui + REF "v${VERSION}" + SHA512 8f3fca47ed7fd4b0a43eaff190457a3e1cf20355f69dd5000bd9f01218855f658fd934ec2abe8b768c11d3c1389a652cdafd9f0b589392878e666b4acd86fc70 + HEAD_REF master + PATCHES + devendor.patch + remove-manual-font-creation.patch +) + +file(REMOVE "${SOURCE_PATH}/include/vsgImGui/imgui.h") + +vcpkg_cmake_configure(SOURCE_PATH "${SOURCE_PATH}") +vcpkg_cmake_install() +vcpkg_cmake_config_fixup(PACKAGE_NAME "vsgImGui" CONFIG_PATH "lib/cmake/vsgImGui") +vcpkg_copy_pdbs() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.md") diff --git a/ports/vsgimgui/remove-manual-font-creation.patch b/ports/vsgimgui/remove-manual-font-creation.patch new file mode 100644 index 0000000000..0efbb7c4bd --- /dev/null +++ b/ports/vsgimgui/remove-manual-font-creation.patch @@ -0,0 +1,63 @@ +diff --git a/include/vsgImGui/RenderImGui.h b/include/vsgImGui/RenderImGui.h +index e8186c6..8059d75 100644 +--- a/include/vsgImGui/RenderImGui.h ++++ b/include/vsgImGui/RenderImGui.h +@@ -86,7 +86,6 @@ namespace vsgImGui + vsg::ref_ptr renderPass, + uint32_t minImageCount, uint32_t imageCount, + VkExtent2D imageSize, bool useClearAttachments); +- void _uploadFonts(); + }; + + } // namespace vsgImGui +diff --git a/src/vsgImGui/RenderImGui.cpp b/src/vsgImGui/RenderImGui.cpp +index bda3137..7ec6136 100644 +--- a/src/vsgImGui/RenderImGui.cpp ++++ b/src/vsgImGui/RenderImGui.cpp +@@ -60,7 +60,6 @@ namespace vsgImGui + RenderImGui::RenderImGui(const vsg::ref_ptr& window, bool useClearAttachments) + { + _init(window, useClearAttachments); +- _uploadFonts(); + } + + RenderImGui::RenderImGui(vsg::ref_ptr device, uint32_t queueFamily, +@@ -69,7 +68,6 @@ RenderImGui::RenderImGui(vsg::ref_ptr device, uint32_t queueFamily, + VkExtent2D imageSize, bool useClearAttachments) + { + _init(device, queueFamily, renderPass, minImageCount, imageCount, imageSize, useClearAttachments); +- _uploadFonts(); + } + + RenderImGui::~RenderImGui() +@@ -183,30 +181,6 @@ void RenderImGui::_init( + } + } + +-void RenderImGui::_uploadFonts() +-{ +- auto commandPool = vsg::CommandPool::create(_device, _queueFamily, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT); +- auto fence = vsg::Fence::create(_device); +- +- uint64_t timeout = 1000000000; +- vsg::submitCommandsToQueue(commandPool, fence, timeout, _queue, [&](vsg::CommandBuffer& commandBuffer) { +- ImGui_ImplVulkan_CreateFontsTexture(commandBuffer); +- }); +- +- VkResult result = fence->status(); +- while (result == VK_NOT_READY) +- { +- result = fence->wait(timeout); +- } +- +- if (result != VK_SUCCESS) +- { +- vsg::error("RenderImGui::_uploadFonts(), fence->state() = ", result); +- } +- +- ImGui_ImplVulkan_DestroyFontUploadObjects(); +-} +- + void RenderImGui::accept(vsg::RecordTraversal& rt) const + { + auto& commandBuffer = *(rt.getState()->_commandBuffer); diff --git a/ports/vsgimgui/vcpkg.json b/ports/vsgimgui/vcpkg.json new file mode 100644 index 0000000000..4a13c67257 --- /dev/null +++ b/ports/vsgimgui/vcpkg.json @@ -0,0 +1,25 @@ +{ + "name": "vsgimgui", + "version": "0.1.0", + "description": "Library that integrates VulkanSceneGraph with Dear ImGui & ImPlot.", + "homepage": "https://github.com/vsg-dev/vsgImGui", + "license": "MIT", + "dependencies": [ + { + "name": "imgui", + "features": [ + "vulkan-binding" + ] + }, + "implot", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + }, + "vsg" + ] +} diff --git a/versions/baseline.json b/versions/baseline.json index 3709ff5fa4..066cba5306 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -9020,6 +9020,10 @@ "baseline": "1.0.5", "port-version": 1 }, + "vsgimgui": { + "baseline": "0.1.0", + "port-version": 0 + }, "vtk": { "baseline": "9.2.0-pv5.11.0", "port-version": 10 diff --git a/versions/v-/vsgimgui.json b/versions/v-/vsgimgui.json new file mode 100644 index 0000000000..3579ead2a1 --- /dev/null +++ b/versions/v-/vsgimgui.json @@ -0,0 +1,9 @@ +{ + "versions": [ + { + "git-tree": "eb1104907bad19da30c10108718f012c7a1c6c22", + "version": "0.1.0", + "port-version": 0 + } + ] +}