[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>
This commit is contained in:
Connor Broyles 2024-01-24 19:19:51 -05:00 committed by GitHub
parent 1b65197e93
commit 11e79b1072
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 266 additions and 0 deletions

View File

@ -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 <vsg/vk/DescriptorPool.h>
#include <vsgImGui/Export.h>
-#include <vsgImGui/imgui.h>
+#include <imgui.h>
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.
</editor-fold> */
#include <vsgImGui/RenderImGui.h>
-#include <vsgImGui/implot.h>
+#include <implot.h>
-#include "../imgui/backends/imgui_impl_vulkan.h"
+#include <imgui_impl_vulkan.h>
#include <vsg/io/Logger.h>
#include <vsg/vk/State.h>
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.
</editor-fold> */
#include <vsgImGui/SendEventsToImGui.h>
-#include <vsgImGui/imgui.h>
+#include <imgui.h>
#include <vsg/ui/KeyEvent.h>
#include <vsg/ui/PointerEvent.h>
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")

View File

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

View File

@ -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<vsg::RenderPass> 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<vsg::Window>& window, bool useClearAttachments)
{
_init(window, useClearAttachments);
- _uploadFonts();
}
RenderImGui::RenderImGui(vsg::ref_ptr<vsg::Device> device, uint32_t queueFamily,
@@ -69,7 +68,6 @@ RenderImGui::RenderImGui(vsg::ref_ptr<vsg::Device> 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);

25
ports/vsgimgui/vcpkg.json Normal file
View File

@ -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"
]
}

View File

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

View File

@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "eb1104907bad19da30c10108718f012c7a1c6c22",
"version": "0.1.0",
"port-version": 0
}
]
}