Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial working X11 implementation with Vulkan #3372

Draft
wants to merge 59 commits into
base: docking
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
666dc9a
Initial working X11 implementation
RoryO Jul 31, 2020
edd6695
remove sdl reference
RoryO Jul 31, 2020
33f7124
Handle modifier keys
RoryO Aug 2, 2020
04109df
proper x11 shifted input handling
RoryO Aug 3, 2020
55877c9
remove debug
RoryO Aug 5, 2020
5f4b254
Signal no key repeating, fixing space keycode
RoryO Aug 5, 2020
5fa5bb2
remove stdio
RoryO Aug 5, 2020
a3fb8e9
Update sfml example for best swapchain recreation
RoryO Aug 6, 2020
797b765
Fix updating clear color
RoryO Aug 6, 2020
a487ee4
Update sdl example for best swapchain recreation
RoryO Aug 6, 2020
46ba0d7
Fix updating clear color on sdl
RoryO Aug 6, 2020
cf58cc5
Remove duplicate keymap entry
RoryO Aug 6, 2020
bfe84e0
Updated per review
RoryO Aug 7, 2020
512160e
Add hiding of X cursor
RoryO Aug 7, 2020
486fcb6
Update X cursor based on the the current imgui cursor
RoryO Aug 9, 2020
5a5c2b4
Mouse cursor done!
RoryO Aug 9, 2020
4767922
typo
RoryO Aug 9, 2020
5a38ce9
fix spacing
RoryO Aug 9, 2020
4815279
Set full mouse cursor support config flag
RoryO Aug 9, 2020
575f244
Add xcb-xkb to linker
RoryO Aug 9, 2020
6033447
Being a good memory citizen and freeing replies
RoryO Aug 11, 2020
bec22e6
Add "copying to clipboard" to x11 impl
RoryO Aug 11, 2020
5e0d60d
Need both addinputchar and keysdown
RoryO Aug 13, 2020
11aa7d4
style fixes
RoryO Aug 13, 2020
b8d1351
Move disconnect to main, it opened the connection
RoryO Aug 13, 2020
5c4ac14
Finish full clipboard implementation
RoryO Aug 13, 2020
b070912
do not use relative path
RoryO Aug 15, 2020
2437d16
Merge branch 'docking' into x11-samples
RoryO Aug 15, 2020
9b83203
work around xcb C header
RoryO Aug 17, 2020
ac30911
Merge branch 'docking' into update-vulkan-examples
RoryO Aug 18, 2020
aef0254
Examples: Vulkan: Reworked buffer resize handling, fix for Linux/X11.…
ocornut Aug 7, 2020
9f079b7
Clean up clear color copying
RoryO Aug 18, 2020
ee2086e
Rebuild swapchain data when viewport out of date
RoryO Aug 19, 2020
77515c0
Swapchain may become out of date before acquiring image
RoryO Aug 21, 2020
a2118b1
Remove unused window parameter
RoryO Aug 21, 2020
d6210b9
Invalidate draw data if swapchain out of date
RoryO Aug 23, 2020
5813927
style fixes
RoryO Aug 23, 2020
afd429b
clean up build script
RoryO Aug 25, 2020
42c7155
Initial working X11 viewport support
RoryO Aug 25, 2020
16062ca
update function prototype
RoryO Aug 25, 2020
3574bcb
Update header documentation
RoryO Aug 25, 2020
8d21acc
remove old code
RoryO Aug 25, 2020
731559c
Merge branch 'update-vulkan-examples' into x11-samples
RoryO Aug 28, 2020
675984e
Adding removal of window manager decoration
RoryO Aug 28, 2020
2b26f46
Update sfml example for best swapchain recreation
RoryO Aug 6, 2020
02e3799
Fix updating clear color
RoryO Aug 6, 2020
55b78ac
Update sdl example for best swapchain recreation
RoryO Aug 6, 2020
e08aafd
Fix updating clear color on sdl
RoryO Aug 6, 2020
b4e1fd5
Examples: Vulkan: Reworked buffer resize handling, fix for Linux/X11.…
ocornut Aug 7, 2020
0c1887f
Clean up clear color copying
RoryO Aug 18, 2020
f6b7856
Rebuild swapchain data when viewport out of date
RoryO Aug 19, 2020
e83410a
Swapchain may become out of date before acquiring image
RoryO Aug 21, 2020
fe2d0f3
Remove unused window parameter
RoryO Aug 21, 2020
c6cb885
Invalidate draw data if swapchain out of date
RoryO Aug 23, 2020
a776e29
style fixes
RoryO Aug 23, 2020
d4fbb60
Merge branch 'docking' into x11-samples
RoryO Sep 1, 2020
28ee257
Fix bad merge
RoryO Sep 1, 2020
04a6efe
Merge branch 'update-vulkan-examples' into x11-samples
RoryO Sep 1, 2020
4976ce3
Fix bad merge
RoryO Sep 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Other Changes:
- Backends: OpenGL3: Added support for glad2 loader. (#3330) [@moritz-h]
- Backends: Allegro 5: Fixed horizontal scrolling direction with mouse wheel / touch pads (it seems
like Allegro 5 reports it differently from GLFW and SDL). (#3394, #2424, #1463) [@nobody-special666]
- Examples: Vulkan: Reworked buffer resize handling, fix for Linux/X11. (#3390, #2626) [@RoryO]
- Examples: Vulkan: Fixed GLFW+Vulkan and SDL+Vulkan clear color not being set. (#3390) [@RoryO]
- CI: Emscripten has stopped their support for their fastcomp backend, switching to latest sdk [@Xipiryon]

Expand Down
26 changes: 17 additions & 9 deletions examples/example_glfw_vulkan/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
static ImGui_ImplVulkanH_Window g_MainWindowData;
static int g_MinImageCount = 2;
static bool g_SwapChainRebuild = false;
static int g_SwapChainResizeWidth = 0;
static int g_SwapChainResizeHeight = 0;

static void check_vk_result(VkResult err)
{
Expand Down Expand Up @@ -255,6 +253,11 @@ static void FrameRender(ImGui_ImplVulkanH_Window* wd, ImDrawData* draw_data)
VkSemaphore image_acquired_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].ImageAcquiredSemaphore;
VkSemaphore render_complete_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].RenderCompleteSemaphore;
err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex);
if (err == VK_ERROR_OUT_OF_DATE_KHR)
{
g_SwapChainRebuild = true;
return;
}
check_vk_result(err);

ImGui_ImplVulkanH_Frame* fd = &wd->Frames[wd->FrameIndex];
Expand Down Expand Up @@ -310,7 +313,7 @@ static void FrameRender(ImGui_ImplVulkanH_Window* wd, ImDrawData* draw_data)
}
}

static void FramePresent(ImGui_ImplVulkanH_Window* wd, GLFWwindow* window)
static void FramePresent(ImGui_ImplVulkanH_Window* wd)
{
VkSemaphore render_complete_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].RenderCompleteSemaphore;
VkPresentInfoKHR info = {};
Expand All @@ -323,7 +326,6 @@ static void FramePresent(ImGui_ImplVulkanH_Window* wd, GLFWwindow* window)
VkResult err = vkQueuePresentKHR(g_Queue, &info);
if (err == VK_ERROR_OUT_OF_DATE_KHR)
{
glfwGetFramebufferSize(window, &g_SwapChainResizeWidth, &g_SwapChainResizeHeight);
g_SwapChainRebuild = true;
return;
}
Expand Down Expand Up @@ -455,6 +457,7 @@ int main(int, char**)
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));

// Main loop
while (!glfwWindowShouldClose(window))
Expand All @@ -467,11 +470,13 @@ int main(int, char**)
glfwPollEvents();

// Resize swap chain?
if (g_SwapChainRebuild && g_SwapChainResizeWidth > 0 && g_SwapChainResizeHeight > 0)
if (g_SwapChainRebuild)
{
g_SwapChainRebuild = false;
int width, height;
glfwGetWindowSize(window, &width, &height);
ImGui_ImplVulkan_SetMinImageCount(g_MinImageCount);
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, &g_MainWindowData, g_QueueFamily, g_Allocator, g_SwapChainResizeWidth, g_SwapChainResizeHeight, g_MinImageCount);
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, &g_MainWindowData, g_QueueFamily, g_Allocator, width, height, g_MinImageCount);
g_MainWindowData.FrameIndex = 0;
}

Expand All @@ -496,7 +501,8 @@ int main(int, char**)
ImGui::Checkbox("Another Window", &show_another_window);

ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
if (ImGui::ColorEdit3("clear color", (float*)&clear_color)) // Edit 3 floats representing a color
memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));

if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
counter++;
Expand All @@ -521,7 +527,6 @@ int main(int, char**)
ImGui::Render();
ImDrawData* main_draw_data = ImGui::GetDrawData();
const bool main_is_minimized = (main_draw_data->DisplaySize.x <= 0.0f || main_draw_data->DisplaySize.y <= 0.0f);
memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));
if (!main_is_minimized)
FrameRender(wd, main_draw_data);

Expand All @@ -532,11 +537,14 @@ int main(int, char**)
ImGui::RenderPlatformWindowsDefault();
}

if (g_SwapChainRebuild) // Main viewport resized in the middle of this frame, go on to next frame.
continue;

// Present Main Platform Window
if (!main_is_minimized)
FramePresent(wd);
}

}
// Cleanup
err = vkDeviceWaitIdle(g_Device);
check_vk_result(err);
Expand Down
24 changes: 16 additions & 8 deletions examples/example_sdl_vulkan/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
static ImGui_ImplVulkanH_Window g_MainWindowData;
static uint32_t g_MinImageCount = 2;
static bool g_SwapChainRebuild = false;
static int g_SwapChainResizeWidth = 0;
static int g_SwapChainResizeHeight = 0;

static void check_vk_result(VkResult err)
{
Expand Down Expand Up @@ -247,6 +245,11 @@ static void FrameRender(ImGui_ImplVulkanH_Window* wd, ImDrawData* draw_data)
VkSemaphore image_acquired_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].ImageAcquiredSemaphore;
VkSemaphore render_complete_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].RenderCompleteSemaphore;
err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex);
if (err == VK_ERROR_OUT_OF_DATE_KHR)
{
g_SwapChainRebuild = true;
return;
}
check_vk_result(err);

ImGui_ImplVulkanH_Frame* fd = &wd->Frames[wd->FrameIndex];
Expand Down Expand Up @@ -302,7 +305,7 @@ static void FrameRender(ImGui_ImplVulkanH_Window* wd, ImDrawData* draw_data)
}
}

static void FramePresent(ImGui_ImplVulkanH_Window* wd, SDL_Window* window)
static void FramePresent(ImGui_ImplVulkanH_Window* wd)
{
VkSemaphore render_complete_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].RenderCompleteSemaphore;
VkPresentInfoKHR info = {};
Expand All @@ -315,7 +318,6 @@ static void FramePresent(ImGui_ImplVulkanH_Window* wd, SDL_Window* window)
VkResult err = vkQueuePresentKHR(g_Queue, &info);
if (err == VK_ERROR_OUT_OF_DATE_KHR)
{
SDL_GetWindowSize(window, &g_SwapChainResizeWidth, &g_SwapChainResizeHeight);
g_SwapChainRebuild = true;
return;
}
Expand Down Expand Up @@ -447,6 +449,7 @@ int main(int, char**)
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));

// Main loop
bool done = false;
Expand All @@ -466,11 +469,13 @@ int main(int, char**)
}

// Resize swap chain?
if (g_SwapChainRebuild && g_SwapChainResizeWidth > 0 && g_SwapChainResizeHeight > 0)
if (g_SwapChainRebuild)
{
g_SwapChainRebuild = false;
int width, height;
SDL_GetWindowSize(window, &width, &height);
ImGui_ImplVulkan_SetMinImageCount(g_MinImageCount);
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, &g_MainWindowData, g_QueueFamily, g_Allocator, g_SwapChainResizeWidth, g_SwapChainResizeHeight, g_MinImageCount);
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, &g_MainWindowData, g_QueueFamily, g_Allocator, width, height, g_MinImageCount);
g_MainWindowData.FrameIndex = 0;
}

Expand All @@ -495,7 +500,8 @@ int main(int, char**)
ImGui::Checkbox("Another Window", &show_another_window);

ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
if (ImGui::ColorEdit3("clear color", (float*)&clear_color)) // Edit 3 floats representing a color
memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));

if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
counter++;
Expand All @@ -520,7 +526,6 @@ int main(int, char**)
ImGui::Render();
ImDrawData* main_draw_data = ImGui::GetDrawData();
const bool main_is_minimized = (main_draw_data->DisplaySize.x <= 0.0f || main_draw_data->DisplaySize.y <= 0.0f);
memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));
if (!main_is_minimized)
FrameRender(wd, main_draw_data);

Expand All @@ -531,6 +536,9 @@ int main(int, char**)
ImGui::RenderPlatformWindowsDefault();
}

if (g_SwapChainRebuild) // Main viewport resized in the middle of this frame, go on to next frame.
continue;

// Present Main Platform Window
if (!main_is_minimized)
FramePresent(wd);
Expand Down
9 changes: 9 additions & 0 deletions examples/example_x11_vulkan/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

mkdir -p Debug
mkdir -p Release

FILES=(main.cpp ../imgui_impl_x11.cpp ../imgui_impl_vulkan.cpp ../../imgui*.cpp)
LIBS="xcb xcb-keysyms xcb-xfixes xcb-xkb xcb-cursor xcb-randr vulkan"
cc -Wall -g -I .. -I ../.. -DHAS_VULKAN -o Debug/example_x11_vulkan "${FILES[@]}" -lm -lstdc++ -lrt $(pkg-config --libs $LIBS)
cc -Wall -O3 -I .. -I ../.. -DHAS_VULKAN -o Release/example_x11_vulkan "${FILES[@]}" -lm -lstdc++ -lrt $(pkg-config --libs $LIBS)
Loading