Skip to content

Commit

Permalink
Added optional ImPlot dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
corporateshark committed Nov 5, 2023
1 parent e46e128 commit 3a74f77
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ option(LVK_WITH_GLFW "Enable GLFW" ON)
option(LVK_WITH_SAMPLES "Enable sample demo apps" ON)
option(LVK_WITH_TRACY "Enable Tracy profiler" ON)
option(LVK_WITH_WAYLAND "Enable Wayland" OFF)
option(LVK_WITH_IMPLOT "Enable ImPlot" ON)

cmake_dependent_option(LVK_WITH_VULKAN_PORTABILITY "Enable portability extension" ON "APPLE" OFF)
# cmake-format: on
Expand Down Expand Up @@ -74,6 +75,7 @@ message(STATUS "LVK_WITH_SAMPLES = ${LVK_WITH_SAMPLES}")
message(STATUS "LVK_WITH_TRACY = ${LVK_WITH_TRACY}")
message(STATUS "LVK_WITH_VULKAN_PORTABILITY = ${LVK_WITH_VULKAN_PORTABILITY}")
message(STATUS "LVK_WITH_WAYLAND = ${LVK_WITH_WAYLAND}")
message(STATUS "LVK_WITH_IMPLOT = ${LVK_WITH_IMPLOT}")
# cmake-format: on

if(NOT DEFINED CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -141,6 +143,10 @@ if(LVK_WITH_GLFW)
target_compile_definitions(LVKLibrary PUBLIC "LVK_WITH_GLFW=1")
endif()

if(LVK_WITH_IMPLOT)
target_compile_definitions(LVKLibrary PUBLIC "LVK_WITH_IMPLOT=1")
endif()

if(LVK_DEPLOY_DEPS)
add_dependencies(LVKLibrary LVKDependencies)
endif()
Expand Down Expand Up @@ -207,9 +213,4 @@ if(LVK_WITH_TRACY)
endif()

# ImGui
target_sources(LVKLibrary PRIVATE "${LVK_ROOT_DIR}/third-party/deps/src/imgui/imgui.cpp")
target_sources(LVKLibrary PRIVATE "${LVK_ROOT_DIR}/third-party/deps/src/imgui/imgui_demo.cpp")
target_sources(LVKLibrary PRIVATE "${LVK_ROOT_DIR}/third-party/deps/src/imgui/imgui_draw.cpp")
target_sources(LVKLibrary PRIVATE "${LVK_ROOT_DIR}/third-party/deps/src/imgui/imgui_tables.cpp")
target_sources(LVKLibrary PRIVATE "${LVK_ROOT_DIR}/third-party/deps/src/imgui/imgui_widgets.cpp")
target_include_directories(LVKLibrary PUBLIC "${LVK_ROOT_DIR}/third-party/deps/src/imgui")
15 changes: 15 additions & 0 deletions lvk/HelpersImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

#include "HelpersImGui.h"

#include "imgui/imgui.cpp"
#include "imgui/imgui_draw.cpp"
#include "imgui/imgui_tables.cpp"
#include "imgui/imgui_widgets.cpp"
#if defined(LVK_WITH_IMPLOT)
#include "implot/implot.cpp"
#include "implot/implot_items.cpp"
#endif // LVK_WITH_IMPLOT

#include <math.h>

static const char* codeVS = R"(
Expand Down Expand Up @@ -88,6 +97,9 @@ lvk::Holder<lvk::RenderPipelineHandle> ImGuiRenderer::createNewPipelineState(con

ImGuiRenderer::ImGuiRenderer(lvk::IContext& device, const char* defaultFontTTF, float fontSizePixels) : ctx_(device) {
ImGui::CreateContext();
#if defined(LVK_WITH_IMPLOT)
ImPlot::CreateContext();
#endif // LVK_WITH_IMPLOT

ImGuiIO& io = ImGui::GetIO();
io.BackendRendererName = "imgui-lvk";
Expand All @@ -102,6 +114,9 @@ ImGuiRenderer::ImGuiRenderer(lvk::IContext& device, const char* defaultFontTTF,
ImGuiRenderer::~ImGuiRenderer() {
ImGuiIO& io = ImGui::GetIO();
io.Fonts->TexID = nullptr;
#if defined(LVK_WITH_IMPLOT)
ImPlot::DestroyContext();
#endif // LVK_WITH_IMPLOT
ImGui::DestroyContext();
}

Expand Down
2 changes: 2 additions & 0 deletions lvk/HelpersImGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#pragma once

#define IMGUI_DEFINE_MATH_OPERATORS

#include <lvk/LVK.h>
#include <imgui/imgui.h>

Expand Down
4 changes: 3 additions & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ ADD_DEMO("Tiny_Mesh")
ADD_DEMO("Tiny_MeshLarge")

target_sources(Tiny_MeshLarge
PUBLIC "${LVK_ROOT_DIR}/third-party/deps/src/3D-Graphics-Rendering-Cookbook/shared/UtilsCubemap.cpp")
PRIVATE "${LVK_ROOT_DIR}/third-party/deps/src/3D-Graphics-Rendering-Cookbook/shared/UtilsCubemap.cpp")

target_sources(Tiny_MeshLarge PRIVATE "${LVK_ROOT_DIR}/third-party/deps/src/imgui/imgui_demo.cpp")
8 changes: 8 additions & 0 deletions third-party/bootstrap-deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@
"revision": "v1.89.9"
}
},
{
"name": "implot",
"source": {
"type": "git",
"url": "https://github.com/epezent/implot",
"revision": "065acc3319f0422479c0fed5a5edccd0f563729f"
}
},
{
"name": "volk",
"source": {
Expand Down

0 comments on commit 3a74f77

Please sign in to comment.