-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/hello_imgui/internal/backend_impls/rendering_dx11_glfw.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#if defined(HELLOIMGUI_HAS_DIRECTX11) && defined(HELLOIMGUI_USE_GLFW3) | ||
#include "rendering_dx11.h" | ||
|
||
#include <backends/imgui_impl_dx11.h> | ||
#include <backends/imgui_impl_glfw.h> | ||
|
||
#define GLFW_INCLUDE_NONE | ||
#define GLFW_INCLUDE_VULKAN | ||
#include <GLFW/glfw3.h> | ||
|
||
#include "hello_imgui/hello_imgui_logger.h" | ||
#include "hello_imgui/hello_imgui.h" | ||
|
||
|
||
namespace HelloImGui | ||
{ | ||
// Below is implementation of RenderingCallbacks_LinkWindowingToRenderingBackend | ||
void PrepareGlfwForVulkan(GLFWwindow* window) | ||
{ | ||
auto& gVkGlobals = HelloImGui::GetVulkanGlobals(); | ||
|
||
{ | ||
if (!glfwVulkanSupported()) | ||
{ | ||
IM_ASSERT(0 && "GLFW: Vulkan Not Supported"); | ||
exit(1); | ||
} | ||
|
||
ImVector<const char*> extensions; | ||
uint32_t extensions_count = 0; | ||
const char** glfw_extensions = glfwGetRequiredInstanceExtensions(&extensions_count); | ||
for (uint32_t i = 0; i < extensions_count; i++) | ||
extensions.push_back(glfw_extensions[i]); | ||
HelloImGui::VulkanSetup::SetupVulkan(extensions); | ||
|
||
// Create Window Surface | ||
VkSurfaceKHR surface; | ||
VkResult err = glfwCreateWindowSurface(gVkGlobals.Instance, window, gVkGlobals.Allocator, &surface); | ||
HelloImGui::VulkanSetup::check_vk_result(err); | ||
|
||
// Create Framebuffers | ||
int w, h; | ||
glfwGetFramebufferSize(window, &w, &h); | ||
ImGui_ImplVulkanH_Window* wd = &gVkGlobals.ImGuiMainWindowData; | ||
HelloImGui::VulkanSetup::SetupVulkanWindow(wd, surface, w, h); | ||
} | ||
|
||
{ | ||
ImGui_ImplVulkanH_Window* wd = &gVkGlobals.ImGuiMainWindowData; | ||
|
||
// Setup Platform/Renderer backends | ||
ImGui_ImplGlfw_InitForVulkan(window, true); | ||
ImGui_ImplVulkan_InitInfo init_info = {}; | ||
init_info.Instance = gVkGlobals.Instance; | ||
init_info.PhysicalDevice = gVkGlobals.PhysicalDevice; | ||
init_info.Device = gVkGlobals.Device; | ||
init_info.QueueFamily = gVkGlobals.QueueFamily; | ||
init_info.Queue = gVkGlobals.Queue; | ||
init_info.PipelineCache = gVkGlobals.PipelineCache; | ||
init_info.DescriptorPool = gVkGlobals.DescriptorPool; | ||
init_info.Subpass = 0; | ||
init_info.MinImageCount = gVkGlobals.MinImageCount; | ||
init_info.ImageCount = wd->ImageCount; | ||
init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT; | ||
init_info.Allocator = gVkGlobals.Allocator; | ||
init_info.CheckVkResultFn = HelloImGui::VulkanSetup::check_vk_result; | ||
ImGui_ImplVulkan_Init(&init_info, wd->RenderPass); | ||
} | ||
} | ||
|
||
|
||
RenderingCallbacksPtr CreateBackendCallbacks_GlfwVulkan() | ||
{ | ||
auto callbacks = PrepareBackendCallbacksCommonVulkan(); | ||
|
||
callbacks->Impl_GetFrameBufferSize = [] | ||
{ | ||
auto window = (GLFWwindow *) HelloImGui::GetRunnerParams()->backendPointers.glfwWindow; | ||
int width, height; | ||
glfwGetFramebufferSize(window, &width, &height); | ||
return ScreenSize{width, height}; | ||
}; | ||
|
||
return callbacks; | ||
} | ||
|
||
} | ||
|
||
#endif // #if defined(HELLOIMGUI_HAS_VULKAN) && defined(HELLOIMGUI_USE_GLFW3) |