Skip to content

Commit d743059

Browse files
committed
Merge branch 'imgui_rework'
2 parents b45dbbb + f451747 commit d743059

File tree

11 files changed

+1270
-3
lines changed

11 files changed

+1270
-3
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@
8484
[submodule "3rdparty/tcpp"]
8585
path = 3rdparty/tcpp
8686
url = [email protected]:Erfan-Ahmadi/tcpp.git
87+
[submodule "3rdparty/imgui"]
88+
path = 3rdparty/imgui
89+
url = [email protected]:ocornut/imgui.git

3rdparty/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,29 @@ add_library(spirv_cross OBJECT
228228
)
229229
target_compile_definitions(spirv_cross PUBLIC SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
230230

231+
if(NBL_BUILD_IMGUI)
232+
add_library(imgui STATIC
233+
"imgui/imconfig.h"
234+
"imgui/imgui_demo.cpp"
235+
"imgui/imgui_draw.cpp"
236+
"imgui/imgui_internal.h"
237+
"imgui/imgui_tables.cpp"
238+
"imgui/imgui_widgets.cpp"
239+
"imgui/imgui.cpp"
240+
"imgui/imgui.h"
241+
"imgui/misc/cpp/imgui_stdlib.cpp"
242+
"imgui/misc/cpp/imgui_stdlib.h"
243+
"imgui/imstb_rectpack.h"
244+
"imgui/imstb_textedit.h"
245+
"imgui/imstb_truetype.h"
246+
)
247+
target_include_directories(imgui
248+
PUBLIC "imgui"
249+
PUBLIC "imgui/misc/cpp"
250+
PUBLIC "imgui/backends"
251+
)
252+
253+
endif()
231254

232255
add_library(aesGladman OBJECT
233256
aesGladman/aes_ni.c
@@ -336,6 +359,9 @@ endif()
336359
if (NBL_BUILD_MITSUBA_LOADER)
337360
list(APPEND NBL_3RDPARTY_TARGETS expat)
338361
endif()
362+
if (NBL_BUILD_IMGUI)
363+
list(APPEND NBL_3RDPARTY_TARGETS imgui)
364+
endif()
339365
if(ENABLE_HLSL)
340366
list(APPEND NBL_3RDPARTY_TARGETS HLSL)
341367
endif()

3rdparty/bullet3

Submodule bullet3 updated 1529 files

3rdparty/imgui

Submodule imgui added at e489e40

CMakeLists.txt

100755100644
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ option(NBL_BUILD_TOOLS "Enable building tools (just convert2BAW as for now)" ON)
273273

274274
option(NBL_BUILD_MITSUBA_LOADER "Enable nbl::ext::MitsubaLoader?" OFF) # TODO: once it compies turn this ON by default!
275275

276+
option(NBL_BUILD_IMGUI "Enable nbl::ext::ImGui?" ON)
277+
276278
option(NBL_BUILD_OPTIX "Enable nbl::ext::OptiX?" OFF)
277279
if(NBL_COMPILE_WITH_CUDA)
278280
find_package(OPTIX REQUIRED)

include/nbl/core/decl/smart_refctd_ptr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ class smart_refctd_ptr
9898
inline I_REFERENCE_COUNTED& operator[](size_t idx) { return ptr[idx]; }
9999
inline const I_REFERENCE_COUNTED& operator[](size_t idx) const { return ptr[idx]; }
100100

101-
102101
inline explicit operator bool() const { return ptr; }
103102
inline bool operator!() const { return !ptr; }
104103

include/nbl/ext/ImGui/ImGui.h

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#ifndef NBL_EXT_IMGUI_UI_H
2+
#define NBL_EXT_IMGUI_UI_H
3+
4+
#include <glm/vec3.hpp>
5+
6+
namespace nbl::ext::imgui
7+
{
8+
class NBL_API2 UI final : public core::IReferenceCounted{
9+
public:
10+
11+
explicit UI(
12+
core::smart_refctd_ptr<video::ILogicalDevice> device,
13+
int maxFramesInFlight,
14+
core::smart_refctd_ptr<video::IGPURenderpass>& renderPass,
15+
video::IGPUPipelineCache* pipelineCache,
16+
video::IGPUObjectFromAssetConverter::SParams& cpu2GpuParams,
17+
core::smart_refctd_ptr<ui::IWindow> window
18+
);
19+
20+
~UI() override;
21+
22+
bool Render(nbl::video::IGPUCommandBuffer& commandBuffer, int frameIndex);
23+
24+
void Update(
25+
float deltaTimeInSec,
26+
float mousePosX,
27+
float mousePosY,
28+
size_t mouseEventsCount,
29+
ui::SMouseEvent const * mouseEvents
30+
// TODO: Keyboard events
31+
);
32+
33+
void BeginWindow(char const* windowName);
34+
35+
void EndWindow();
36+
37+
int Register(std::function<void()> const& listener);
38+
39+
bool UnRegister(int listenerId);
40+
41+
void SetNextItemWidth(float nextItemWidth);
42+
43+
void SetWindowSize(float width, float height);
44+
45+
void Text(char const* label, ...);
46+
47+
void InputFloat(char const* label, float* value);
48+
49+
void InputFloat2(char const* label, float* value);
50+
51+
void InputFloat3(char const* label, float* value);
52+
53+
void InputFloat4(char const* label, float* value);
54+
55+
void InputFloat3(char const* label, glm::vec3& value);
56+
57+
bool Combo(
58+
char const* label,
59+
int32_t* selectedItemIndex,
60+
char const** items,
61+
int32_t itemsCount
62+
);
63+
64+
bool Combo(
65+
const char* label,
66+
int* selectedItemIndex,
67+
std::vector<std::string>& values
68+
);
69+
70+
void SliderInt(
71+
char const* label,
72+
int* value,
73+
int minValue,
74+
int maxValue
75+
);
76+
77+
void SliderFloat(
78+
char const* label,
79+
float* value,
80+
float minValue,
81+
float maxValue
82+
);
83+
84+
void Checkbox(
85+
char const* label,
86+
bool* value
87+
);
88+
89+
void Spacing();
90+
91+
void Button(
92+
char const* label,
93+
std::function<void()> const& onPress
94+
);
95+
96+
void InputText(
97+
char const* label,
98+
std::string& outValue
99+
);
100+
101+
[[nodiscard]]
102+
bool HasFocus();
103+
104+
[[nodiscard]]
105+
bool IsItemActive();
106+
107+
[[nodiscard]]
108+
bool TreeNode(char const* name);
109+
110+
void TreePop();
111+
112+
private:
113+
114+
core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> CreateDescriptorSetLayout();
115+
116+
void CreatePipeline(
117+
core::smart_refctd_ptr<video::IGPURenderpass>& renderPass,
118+
video::IGPUPipelineCache* pipelineCache
119+
);
120+
121+
void CreateFontTexture(video::IGPUObjectFromAssetConverter::SParams& cpu2GpuParams);
122+
123+
void UpdateDescriptorSets();
124+
125+
void CreateFontSampler();
126+
127+
void CreateDescriptorPool();
128+
129+
void HandleMouseEvents(
130+
float mousePosX,
131+
float mousePosY,
132+
size_t mouseEventsCount,
133+
ui::SMouseEvent const * mouseEvents
134+
) const;
135+
136+
core::smart_refctd_ptr<video::ILogicalDevice> m_device{};
137+
core::smart_refctd_ptr<video::IGPUSampler> m_fontSampler{};
138+
core::smart_refctd_ptr<video::IDescriptorPool> m_descriptorPool{};
139+
core::smart_refctd_ptr<video::IGPUDescriptorSet> m_gpuDescriptorSet{};
140+
core::smart_refctd_ptr<video::IGPURenderpassIndependentPipeline> m_independentPipeline{};
141+
core::smart_refctd_ptr<video::IGPUGraphicsPipeline> m_pipeline{};
142+
core::smart_refctd_ptr<video::IGPUImageView> m_fontTexture{};
143+
core::smart_refctd_ptr<ui::IWindow> m_window{};
144+
std::vector<core::smart_refctd_ptr<video::IGPUBuffer>> m_vertexBuffers{};
145+
std::vector<core::smart_refctd_ptr<video::IGPUBuffer>> m_indexBuffers{};
146+
bool hasFocus = false;
147+
148+
// TODO: Use a signal class instead like Signal<> UIRecordSignal{};
149+
struct Subscriber {
150+
int id = -1;
151+
std::function<void()> listener = nullptr;
152+
};
153+
std::vector<Subscriber> m_subscribers{};
154+
155+
};
156+
};
157+
158+
#endif // NBL_EXT_IMGUI_UI_H

src/nbl/ext/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,17 @@ if (NBL_BUILD_OPTIX)
5353
)
5454
endif()
5555

56+
if (NBL_BUILD_IMGUI)
57+
add_subdirectory(ImGui)
58+
set(NBL_EXT_IMGUI_UI_INCLUDE_DIRS
59+
${NBL_EXT_IMGUI_UI_INCLUDE_DIRS}
60+
PARENT_SCOPE
61+
)
62+
set(NBL_EXT_IMGUI_UI_LIB
63+
${NBL_EXT_IMGUI_UI_LIB}
64+
PARENT_SCOPE
65+
)
66+
endif()
67+
5668

5769
propagate_changed_variables_to_parent_scope()

src/nbl/ext/ImGui/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
include(${NBL_ROOT_PATH}/cmake/common.cmake)
2+
3+
set(NBL_EXT_INTERNAL_INCLUDE_DIR "${NBL_ROOT_PATH}/include/nbl/ext/ImGui")
4+
5+
set(NBL_EXT_IMGUI_H
6+
${NBL_EXT_INTERNAL_INCLUDE_DIR}/ImGui.h
7+
)
8+
9+
set(NBL_EXT_IMGUI_SRC
10+
ImGui.cpp
11+
)
12+
13+
set(NBL_EXT_IMGUI_EXTERNAL_INCLUDE
14+
"${NBL_ROOT_PATH}/3rdparty"
15+
# "${IMGUI_INCLUDE_DIR}"
16+
)
17+
18+
nbl_create_ext_library_project(
19+
IMGUI_UI
20+
"${NBL_EXT_IMGUI_H}"
21+
"${NBL_EXT_IMGUI_SRC}"
22+
"${NBL_EXT_IMGUI_EXTERNAL_INCLUDE}"
23+
""
24+
""
25+
)

0 commit comments

Comments
 (0)