整理代码
This commit is contained in:
parent
4d8b91ca98
commit
a6fe6f15f6
@ -3,8 +3,6 @@
|
||||
#include "imgui_impl_glfw.h"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
extern GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
|
||||
|
||||
static void check_vk_result(vk::Result err) {
|
||||
if (err == vk::Result::eSuccess)
|
||||
return;
|
||||
@ -123,13 +121,13 @@ void renderer_vulkan::setup_vulkan(ImVector<const char*> instance_extensions) {
|
||||
|
||||
// All the ImGui_ImplVulkanH_XXX structures/functions are optional helpers used by the demo.
|
||||
// Your real engine/app may not use them.
|
||||
void renderer_vulkan::setup_vulkan_window(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width,
|
||||
int height) const {
|
||||
wd->Surface = surface;
|
||||
void renderer_vulkan::setup_vulkan_window(VkSurfaceKHR surface, int width,
|
||||
int height) {
|
||||
main_window_data.Surface = surface;
|
||||
|
||||
// Check for WSI support
|
||||
vk::Bool32 res;
|
||||
const auto err = physical_device.getSurfaceSupportKHR(queue_family, wd->Surface, &res);
|
||||
const auto err = physical_device.getSurfaceSupportKHR(queue_family, main_window_data.Surface, &res);
|
||||
check_vk_result(err);
|
||||
if (res != VK_TRUE) {
|
||||
fprintf(stderr, "Error no WSI support on physical device 0\n");
|
||||
@ -141,7 +139,7 @@ void renderer_vulkan::setup_vulkan_window(ImGui_ImplVulkanH_Window* wd, VkSurfac
|
||||
VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM
|
||||
};
|
||||
constexpr VkColorSpaceKHR requestSurfaceColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
|
||||
wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(physical_device, wd->Surface, requestSurfaceImageFormat,
|
||||
main_window_data.SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(physical_device, main_window_data.Surface, requestSurfaceImageFormat,
|
||||
(size_t) IM_ARRAYSIZE(requestSurfaceImageFormat),
|
||||
requestSurfaceColorSpace);
|
||||
|
||||
@ -151,14 +149,14 @@ void renderer_vulkan::setup_vulkan_window(ImGui_ImplVulkanH_Window* wd, VkSurfac
|
||||
#else
|
||||
VkPresentModeKHR present_modes[] = {VK_PRESENT_MODE_FIFO_KHR};
|
||||
#endif
|
||||
wd->PresentMode = ImGui_ImplVulkanH_SelectPresentMode(physical_device, wd->Surface, &present_modes[0],
|
||||
main_window_data.PresentMode = ImGui_ImplVulkanH_SelectPresentMode(physical_device, main_window_data.Surface, &present_modes[0],
|
||||
IM_ARRAYSIZE(present_modes));
|
||||
//printf("[vulkan] Selected PresentMode = %d\n", wd->PresentMode);
|
||||
|
||||
// Create SwapChain, RenderPass, Framebuffer, etc.
|
||||
IM_ASSERT(min_image_count >= 2);
|
||||
|
||||
ImGui_ImplVulkanH_CreateOrResizeWindow(instance, physical_device, device, wd, queue_family,
|
||||
ImGui_ImplVulkanH_CreateOrResizeWindow(instance, physical_device, device, &main_window_data, queue_family,
|
||||
reinterpret_cast<VkAllocationCallbacks*>(allocator), width,
|
||||
height, min_image_count);
|
||||
}
|
||||
@ -369,8 +367,7 @@ void renderer_vulkan::init_vulkan(GLFWwindow* window_handle) {
|
||||
// Create Framebuffers
|
||||
int w, h;
|
||||
glfwGetFramebufferSize(window_handle, &w, &h);
|
||||
ImGui_ImplVulkanH_Window* wd = &main_window_data;
|
||||
setup_vulkan_window(wd, surface, w, h);
|
||||
setup_vulkan_window(surface, w, h);
|
||||
|
||||
ImGui_ImplGlfw_InitForVulkan(window_handle, true);
|
||||
|
||||
@ -382,10 +379,10 @@ void renderer_vulkan::init_vulkan(GLFWwindow* window_handle) {
|
||||
init_info.Queue = queue;
|
||||
init_info.PipelineCache = pipeline_cache;
|
||||
init_info.DescriptorPool = descriptor_pool;
|
||||
init_info.RenderPass = wd->RenderPass;
|
||||
init_info.RenderPass = main_window_data.RenderPass;
|
||||
init_info.Subpass = 0;
|
||||
init_info.MinImageCount = min_image_count;
|
||||
init_info.ImageCount = wd->ImageCount;
|
||||
init_info.ImageCount = main_window_data.ImageCount;
|
||||
init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
init_info.Allocator = reinterpret_cast<VkAllocationCallbacks*>(allocator);
|
||||
init_info.CheckVkResultFn = check_vk_result;
|
||||
|
@ -46,11 +46,11 @@ public:
|
||||
bool swap_chain_rebuild = false;
|
||||
|
||||
protected:
|
||||
vk::PhysicalDevice setup_vulkan_select_physical_device() const;
|
||||
[[nodiscard]] vk::PhysicalDevice setup_vulkan_select_physical_device() const;
|
||||
|
||||
void setup_vulkan(ImVector<const char*> instance_extensions);
|
||||
|
||||
void setup_vulkan_window(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height) const;
|
||||
void setup_vulkan_window(VkSurfaceKHR surface, int width, int height);
|
||||
|
||||
void cleanup_vulkan() const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user