xo-imgui: imgui_ex4 working on native ubuntu
requires etc/hostubuntu shim
This commit is contained in:
parent
826298d097
commit
5fcfadce9a
5 changed files with 555 additions and 586 deletions
|
|
@ -1,9 +1,6 @@
|
|||
/* imgui_ex4.cpp */
|
||||
|
||||
#include "xo/imgui/VulkanApp.hpp"
|
||||
#ifdef TEMPORARILY_REMOVE
|
||||
#include "xo/imgui/ImRect.hpp"
|
||||
#endif
|
||||
#include "AppState.hpp"
|
||||
#include "DrawState.hpp"
|
||||
#include <backends/imgui_impl_sdl2.h>
|
||||
|
|
@ -87,9 +84,7 @@ namespace {
|
|||
{
|
||||
scope log(XO_DEBUG(false));
|
||||
|
||||
#ifdef TEMPORARILY_REMOVE
|
||||
app_duty_cycle_top(p_app_state, p_draw_state);
|
||||
#endif
|
||||
|
||||
log && log(xtag("imgui_cx", (void*)ImGui::GetCurrentContext()));
|
||||
|
||||
|
|
@ -98,7 +93,6 @@ namespace {
|
|||
ImGui_ImplSDL2_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
#ifdef TEMPORARILY_REMOVE
|
||||
log && log("after NewFrame", xtag("imgui_cx", (void*)ImGui::GetCurrentContext()));
|
||||
|
||||
ImGuiIO & io = ImGui::GetIO(); (void)io;
|
||||
|
|
@ -113,12 +107,10 @@ namespace {
|
|||
| ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoDecoration);
|
||||
ImGui::End();
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// 1. create a simple ImGui window
|
||||
ImGui::Begin("Hello, Vulkan + SDL2!");
|
||||
ImGui::Text("This is a minimal ImGui + Vulkan + SDL2 example!");
|
||||
#ifdef TEMPORARILY_REMOVE
|
||||
ImGui::Text("appl average %.3f ms/frame (%.1f fps)",
|
||||
1000.0f / io.Framerate, io.Framerate);
|
||||
|
||||
|
|
@ -212,15 +204,12 @@ namespace {
|
|||
p_app_state->copy_detail_tenured_dest_size_ = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
ImGui::End();
|
||||
|
||||
#ifdef TEMPORARILY_REMOVE
|
||||
// 2. big demo window
|
||||
if (p_draw_state->show_demo_window_)
|
||||
ImGui::ShowDemoWindow(&p_draw_state->show_demo_window_);
|
||||
#endif
|
||||
|
||||
// Rendering
|
||||
ImGui::Render();
|
||||
|
|
@ -296,13 +285,10 @@ int main() {
|
|||
= make_imgui_draw_frame(&app_state, &draw_state, &f, &counter);
|
||||
VulkanApp vk_app(draw_fn);
|
||||
|
||||
/* establishes imgui context */
|
||||
vk_app.setup(app_imgui_load_fonts);
|
||||
|
||||
#ifdef NOT_YET
|
||||
app_state.gc_->add_gc_copy_callback
|
||||
(draw_state.make_gc_copy_animation(&app_state));
|
||||
#endif
|
||||
|
||||
try {
|
||||
vk_app.main_loop();
|
||||
|
|
|
|||
|
|
@ -41,10 +41,7 @@ MinimalImGuiVulkan::init_vulkan()
|
|||
this->create_surface();
|
||||
this->pick_physical_device();
|
||||
this->create_logical_device();
|
||||
this->create_swapchain();
|
||||
this->create_image_views();
|
||||
this->create_render_pass(); // must come before createFrameBuffers
|
||||
this->create_framebuffers();
|
||||
this->create_xswapchain(true /*create_render_pass_flag*/);
|
||||
this->create_command_pool();
|
||||
this->create_command_buffers();
|
||||
this->create_sync_objects();
|
||||
|
|
@ -503,7 +500,7 @@ MinimalImGuiVulkan::draw_frame()
|
|||
case VK_SUBOPTIMAL_KHR:
|
||||
break;
|
||||
case VK_ERROR_OUT_OF_DATE_KHR:
|
||||
recreate_swapchain();
|
||||
this->recreate_xswapchain();
|
||||
// deliberate earlyexit
|
||||
return;
|
||||
default:
|
||||
|
|
@ -559,7 +556,7 @@ MinimalImGuiVulkan::draw_frame()
|
|||
case VK_ERROR_OUT_OF_DATE_KHR:
|
||||
case VK_SUBOPTIMAL_KHR:
|
||||
framebuffer_resized_flag_ = false;
|
||||
this->recreate_swapchain();
|
||||
this->recreate_xswapchain();
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("failed to present swapchain image!");
|
||||
|
|
@ -624,7 +621,25 @@ MinimalImGuiVulkan::record_command_buffer(VkCommandBuffer cmdbuf, uint32_t image
|
|||
}
|
||||
|
||||
void
|
||||
MinimalImGuiVulkan::recreate_swapchain()
|
||||
MinimalImGuiVulkan::create_xswapchain(bool create_render_pass_flag)
|
||||
{
|
||||
this->create_swapchain();
|
||||
this->create_image_views();
|
||||
if(create_render_pass_flag)
|
||||
this->create_render_pass();
|
||||
this->create_framebuffers();
|
||||
}
|
||||
|
||||
void
|
||||
MinimalImGuiVulkan::cleanup_xswapchain()
|
||||
{
|
||||
this->cleanup_framebuffers();
|
||||
this->cleanup_image_views();
|
||||
this->cleanup_swapchain();
|
||||
}
|
||||
|
||||
void
|
||||
MinimalImGuiVulkan::recreate_xswapchain()
|
||||
{
|
||||
// handle window minimization: wait until window has valid size
|
||||
this->wait_not_minimized();
|
||||
|
|
@ -632,15 +647,11 @@ MinimalImGuiVulkan::recreate_swapchain()
|
|||
// wait until device idle before cleaning up resources
|
||||
vkDeviceWaitIdle(device_);
|
||||
|
||||
// cleanup old swapchain
|
||||
this->cleanup_framebuffers();
|
||||
this->cleanup_image_views();
|
||||
this->cleanup_swapchain();
|
||||
// cleanup old xswapchain
|
||||
this->cleanup_xswapchain();
|
||||
|
||||
// create new swapchain
|
||||
this->create_swapchain();
|
||||
this->create_image_views();
|
||||
this->create_framebuffers();
|
||||
this->create_xswapchain(false);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -694,9 +705,7 @@ MinimalImGuiVulkan::cleanup()
|
|||
|
||||
vkDestroyCommandPool(device_, command_pool_, nullptr);
|
||||
|
||||
this->cleanup_framebuffers();
|
||||
this->cleanup_image_views();
|
||||
this->cleanup_swapchain();
|
||||
this->cleanup_xswapchain();
|
||||
|
||||
vkDestroyRenderPass(device_, render_pass_, nullptr);
|
||||
vkDestroyDescriptorPool(device_, descriptor_pool_, nullptr);
|
||||
|
|
|
|||
|
|
@ -47,6 +47,12 @@ private:
|
|||
*/
|
||||
void create_logical_device();
|
||||
|
||||
/* populates @ref swapchain_, @ref swapchain_images_,
|
||||
* @ref swapchain_image_views_, @ref framebuffers_.
|
||||
* Also $ref render_pass_ iff @p create_render_pass_flag
|
||||
*/
|
||||
void create_xswapchain(bool create_render_pass_flag);
|
||||
|
||||
/*
|
||||
* populates @ref swapchain_, @ref swapchain_images_
|
||||
*/
|
||||
|
|
@ -123,11 +129,14 @@ private:
|
|||
/* Teardown + create swapchain (swapchain + framebuffers + image views).
|
||||
* Need this after window size changes
|
||||
*/
|
||||
void recreate_swapchain();
|
||||
void recreate_xswapchain();
|
||||
|
||||
/* wait until non-minimized window */
|
||||
void wait_not_minimized();
|
||||
|
||||
/* orderly disposal of swapchin + image_views + framebuffers */
|
||||
void cleanup_xswapchain();
|
||||
|
||||
/* orderly disposal of @ref framebuffers_ */
|
||||
void cleanup_framebuffers();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue