5
5
#include < utility>
6
6
7
7
#include " nbl/system/IApplicationFramework.h"
8
+ #include " nbl/ui/IWindow.h"
9
+ #include " nbl/ui/ICursorControl.h"
8
10
#include " nbl/system/CStdoutLogger.h"
9
11
#include " nbl/ext/ImGui/ImGui.h"
10
12
#include " shaders/common.hlsl"
@@ -21,7 +23,7 @@ using namespace nbl::ui;
21
23
22
24
namespace nbl ::ext::imgui
23
25
{
24
- void UI::createPipeline (core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> descriptorSetLayout, video::IGPURenderpass* renderpass, IGPUPipelineCache* pipelineCache)
26
+ void UI::createPipeline (core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> descriptorSetLayout, video::IGPURenderpass* renderpass, uint32_t subpassIx, IGPUPipelineCache* pipelineCache)
25
27
{
26
28
// Constants: we are using 'vec2 offset' and 'vec2 scale' instead of a full 3d projection matrix
27
29
SPushConstantRange pushConstantRanges[] =
@@ -128,7 +130,7 @@ namespace nbl::ext::imgui
128
130
param.layout = pipelineLayout.get ();
129
131
param.shaders = specs;
130
132
param.renderpass = renderpass;
131
- param.cached = { .vertexInput = vertexInputParams, .primitiveAssembly = primitiveAssemblyParams, .rasterization = rasterizationParams, .blend = blendParams, .subpassIx = 0u }; // TODO: check "subpassIx"
133
+ param.cached = { .vertexInput = vertexInputParams, .primitiveAssembly = primitiveAssemblyParams, .rasterization = rasterizationParams, .blend = blendParams, .subpassIx = subpassIx };
132
134
};
133
135
134
136
if (!m_device->createGraphicsPipelines (pipelineCache, params, &pipeline))
@@ -309,13 +311,14 @@ namespace nbl::ext::imgui
309
311
io.FontGlobalScale = 1 .0f ;
310
312
}
311
313
312
- void UI::handleMouseEvents (const nbl::hlsl::float32_t2& mousePosition, const core::SRange<const nbl::ui::SMouseEvent>& events) const
314
+ void UI::handleMouseEvents (const core::SRange<const nbl::ui::SMouseEvent>& events, const ui::IWindow* window ) const
313
315
{
314
316
auto & io = ImGui::GetIO ();
315
317
316
- const auto position = mousePosition - nbl::hlsl::float32_t2 (m_window->getX (), m_window->getY ());
318
+ const auto cursorPosition = window->getCursorControl ()->getPosition ();
319
+ const auto mousePixelPosition = nbl::hlsl::float32_t2 (cursorPosition.x , cursorPosition.y ) - nbl::hlsl::float32_t2 (window->getX (), window->getY ());
317
320
318
- io.AddMousePosEvent (position .x , position .y );
321
+ io.AddMousePosEvent (mousePixelPosition .x , mousePixelPosition .y );
319
322
320
323
for (const auto & e : events)
321
324
{
@@ -519,8 +522,8 @@ namespace nbl::ext::imgui
519
522
}
520
523
}
521
524
522
- UI::UI (smart_refctd_ptr<ILogicalDevice> _device, core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> _descriptorSetLayout, video::IGPURenderpass* renderpass, IGPUPipelineCache* pipelineCache, smart_refctd_ptr<IWindow> window )
523
- : m_device(core::smart_refctd_ptr(_device)), m_window(core::smart_refctd_ptr(window))
525
+ UI::UI (smart_refctd_ptr<ILogicalDevice> _device, core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> _descriptorSetLayout, video::IGPURenderpass* renderpass, uint32_t subpassIx, IGPUPipelineCache* pipelineCache, uint32_t mdiTotalByteSize )
526
+ : m_device(core::smart_refctd_ptr(_device))
524
527
{
525
528
createSystem ();
526
529
struct
@@ -571,7 +574,7 @@ namespace nbl::ext::imgui
571
574
smart_refctd_ptr<nbl::video::IGPUCommandBuffer> transistentCMD;
572
575
{
573
576
using pool_flags_t = IGPUCommandPool::CREATE_FLAGS;
574
- // need to be individually resettable such that we can form a valid SIntendedSubmit out of the commandbuffer allocated from the pool
577
+
575
578
smart_refctd_ptr<nbl::video::IGPUCommandPool> pool = m_device->createCommandPool (families.id .transfer , pool_flags_t ::RESET_COMMAND_BUFFER_BIT|pool_flags_t ::TRANSIENT_BIT);
576
579
if (!pool)
577
580
{
@@ -593,17 +596,15 @@ namespace nbl::ext::imgui
593
596
IMGUI_CHECKVERSION ();
594
597
ImGui::CreateContext ();
595
598
596
- createPipeline (core::smart_refctd_ptr (_descriptorSetLayout), renderpass, pipelineCache);
599
+ createPipeline (core::smart_refctd_ptr (_descriptorSetLayout), renderpass, subpassIx, pipelineCache);
597
600
createFontAtlasTexture (transistentCMD.get (), tQueue);
598
601
adjustGlobalFontScale ();
599
602
}
600
603
tQueue->endCapture ();
601
604
602
- static constexpr auto DEFAULT_MDI_SIZE = 1024u * 1024u * 2u ; // 2 Mb
603
- createMDIBuffer (DEFAULT_MDI_SIZE);
605
+ createMDIBuffer (mdiTotalByteSize);
604
606
605
607
auto & io = ImGui::GetIO ();
606
- io.DisplaySize = ImVec2 (m_window->getWidth (), m_window->getHeight ());
607
608
io.DisplayFramebufferScale = ImVec2 (1 .0f , 1 .0f );
608
609
io.BackendUsingLegacyKeyArrays = 0 ; // 0: using AddKeyEvent() [new way of handling events in imgui]
609
610
}
@@ -931,7 +932,7 @@ namespace nbl::ext::imgui
931
932
VkRect2D scissor[] = { {.offset = {(int32_t )viewport.x , (int32_t )viewport.y }, .extent = {(uint32_t )viewport.width , (uint32_t )viewport.height }} };
932
933
commandBuffer->setScissor (scissor); // cover whole viewport (only to not throw validation errors)
933
934
}
934
-
935
+
935
936
/*
936
937
Setup scale and translation, our visible imgui space lies from draw_data->DisplayPps (top left) to
937
938
draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
@@ -976,14 +977,17 @@ namespace nbl::ext::imgui
976
977
return true ;
977
978
}
978
979
979
- void UI::update (float const deltaTimeInSec, const nbl::hlsl::float32_t2 mousePosition , const core::SRange<const nbl::ui::SMouseEvent> mouseEvents, const core::SRange<const nbl::ui::SKeyboardEvent> keyboardEvents)
980
+ bool UI::update (const ui::IWindow* window, float const deltaTimeInSec , const core::SRange<const nbl::ui::SMouseEvent> mouseEvents, const core::SRange<const nbl::ui::SKeyboardEvent> keyboardEvents)
980
981
{
982
+ if (!window)
983
+ return false ;
984
+
981
985
auto & io = ImGui::GetIO ();
982
986
983
987
io.DeltaTime = deltaTimeInSec;
984
- io.DisplaySize = ImVec2 (m_window ->getWidth (), m_window ->getHeight ());
988
+ io.DisplaySize = ImVec2 (window ->getWidth (), window ->getHeight ());
985
989
986
- handleMouseEvents (mousePosition, mouseEvents );
990
+ handleMouseEvents (mouseEvents, window );
987
991
handleKeyEvents (keyboardEvents);
988
992
989
993
ImGui::NewFrame ();
@@ -992,6 +996,8 @@ namespace nbl::ext::imgui
992
996
subscriber.listener ();
993
997
994
998
ImGui::Render (); // note it doesn't touch GPU or graphics API at all, internal call for IMGUI cpu geometry buffers update
999
+
1000
+ return true ;
995
1001
}
996
1002
997
1003
int UI::registerListener (std::function<void ()> const & listener)
@@ -1024,5 +1030,4 @@ namespace nbl::ext::imgui
1024
1030
{
1025
1031
ImGui::SetCurrentContext (reinterpret_cast <ImGuiContext*>(imguiContext));
1026
1032
}
1027
-
1028
1033
}
0 commit comments