Skip to content

Commit 2de19f2

Browse files
committed
adjust to comments & also support ImGUI shared atlas capability, add more logs, update examples_tests submodule
1 parent 5ba096a commit 2de19f2

File tree

7 files changed

+215
-96
lines changed

7 files changed

+215
-96
lines changed

3rdparty/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,12 @@ if(NBL_BUILD_IMGUI)
381381
set(IMGUIZMO_BUILD_EXAMPLE OFF)
382382
add_subdirectory(imguizmo EXCLUDE_FROM_ALL)
383383

384+
# note we override imgui config with our own
385+
set(NBL_IMGUI_USER_CONFIG_FILEPATH "${NBL_IMGUI_ROOT}/nabla_imconfig.h")
386+
384387
if(NOT EXISTS "${NBL_IMGUI_USER_CONFIG_FILEPATH}")
385388
message(FATAL_ERROR "\"${NBL_IMGUI_USER_CONFIG_FILEPATH}\" doesn't exist!")
386389
endif()
387-
388-
# note we override imgui config with our own
389-
set(NBL_IMGUI_USER_CONFIG_FILEPATH "${NBL_IMGUI_ROOT}/nabla_imconfig.h")
390390

391391
target_compile_definitions(imgui PUBLIC
392392
IMGUI_USER_CONFIG="${NBL_IMGUI_USER_CONFIG_FILEPATH}"

examples_tests

include/nbl/ext/ImGui/ImGui.h

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace nbl::ext::imgui
99
class UI final : public core::IReferenceCounted
1010
{
1111
public:
12-
//! Reserved font atlas indicies for default backend textures & samplers descriptor binding's array
12+
//! Reserved font atlas indicies for default backend textures & samplers descriptor binding's array, remember you can still override font's indices at runtime and don't have to use those at all
1313
static constexpr auto FontAtlasTexId = 0u, FontAtlasSamplerId = 0u;
1414

1515
//! Reserved indexes for default backend samplers descriptor binding's array - use only if you created your pipeline layout with createDefaultPipelineLayout. If you need more or custom samplers then create the pipeline layout yourself
@@ -113,8 +113,11 @@ class UI final : public core::IReferenceCounted
113113
std::span<const ui::SKeyboardEvent> keyboardEvents = {};
114114
};
115115

116-
UI(SCreationParameters&& params);
117-
~UI() override;
116+
//! validates creation parameters
117+
static bool validateCreationParameters(SCreationParameters& _params);
118+
119+
//! creates the UI instance, we allow to pass external font atlas & then ownership of the atlas is yours (the same way imgui context allows you to do & what you pass here is "ImFontAtlas" instance then!) - it can fail so you are required to check if returned UI instance != nullptr
120+
static core::smart_refctd_ptr<UI> create(SCreationParameters&& _params, void* const imSharedFontAtlas = nullptr);
118121

119122
//! updates ImGuiIO & records ImGUI *cpu* draw command lists, you have to call it before .render
120123
bool update(const SUpdateParameters& params);
@@ -143,30 +146,43 @@ class UI final : public core::IReferenceCounted
143146
//! ImGUI graphics pipeline
144147
inline const video::IGPUGraphicsPipeline* getPipeline() const { return m_pipeline.get(); }
145148

146-
//! image view default font texture
147-
//! TODO: we cannot expose immutable view of our default font texture because user MUST be able to write a descriptor,
148-
//! we can have mutable getter or we can decide to not create any default font texture at all and force users
149-
//! to do it externally (have a static helper to do it which gives you mutable view)
149+
// default ImGUI font atlas view
150150
inline video::IGPUImageView* getFontAtlasView() const { return m_fontAtlasTexture.get(); }
151151

152152
//! mdi streaming buffer
153153
inline const auto* getStreamingBuffer() const {return m_cachedCreationParams.streamingBuffer.get();}
154154

155155
//! ImGUI context, you are supposed to cast it, eg. reinterpret_cast<ImGuiContext*>(this->getContext());
156156
void* getContext();
157+
158+
protected:
159+
UI(SCreationParameters&& params, core::smart_refctd_ptr<video::IGPUGraphicsPipeline> pipeline, core::smart_refctd_ptr<video::IGPUImageView> defaultFont, void* const imFontAtlas, void* const imContext);
160+
~UI() override;
161+
157162
private:
158-
void createPipeline(SCreationParameters& creationParams);
159-
void createMDIBuffer(SCreationParameters& creationParams);
163+
static core::smart_refctd_ptr<video::IGPUGraphicsPipeline> createPipeline(SCreationParameters& creationParams);
164+
static bool createMDIBuffer(SCreationParameters& creationParams);
165+
// NOTE: in the future this will also need a compute queue to do mip-maps
166+
static video::ISemaphore::future_t<video::IQueue::RESULT> createFontAtlasTexture(SCreationParameters& creationParams, void* const imFontAtlas, core::smart_refctd_ptr<video::IGPUImageView>& outFontView);
167+
160168
void handleMouseEvents(const SUpdateParameters& params) const;
161169
void handleKeyEvents(const SUpdateParameters& params) const;
162-
// NOTE: in the future this will also need a compute queue to do mip-maps
163-
video::ISemaphore::future_t<video::IQueue::RESULT> createFontAtlasTexture(video::IQueue* transfer);
164170

171+
// cached creation parameters
165172
SCachedCreationParams m_cachedCreationParams;
166173

174+
// graphics pipeline you are required to bind
167175
core::smart_refctd_ptr<video::IGPUGraphicsPipeline> m_pipeline;
176+
177+
// image view to default font created
168178
core::smart_refctd_ptr<video::IGPUImageView> m_fontAtlasTexture;
169179

180+
// note we track pointer to atlas only if it belongs to the extension instance (is not "shared" in imgui world)
181+
void* const m_imFontAtlasBackPointer;
182+
183+
// context we created for instance which we must free at destruction
184+
void* const m_imContextBackPointer;
185+
170186
std::vector<std::function<void()>> m_subscribers {};
171187
};
172188
}

0 commit comments

Comments
 (0)