From df73277ca80d9ccf1e90575d660a3478cb267d3c Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 17 Jul 2020 02:31:12 +0200 Subject: [PATCH] (WGL) Bind different callback for Vulkan --- gfx/common/win32_common.c | 64 +++++++++++++++++++++++++++++++++++ gfx/common/win32_common.h | 9 ++++- gfx/drivers_context/wgl_ctx.c | 58 +++++++++++++++++-------------- 3 files changed, 105 insertions(+), 26 deletions(-) diff --git a/gfx/common/win32_common.c b/gfx/common/win32_common.c index 976a2340c6..370b94b68e 100644 --- a/gfx/common/win32_common.c +++ b/gfx/common/win32_common.c @@ -1133,6 +1133,70 @@ LRESULT CALLBACK WndProcWGL(HWND hwnd, UINT message, } #endif +#ifdef HAVE_VULKAN +LRESULT CALLBACK WndProcVK(HWND hwnd, UINT message, + WPARAM wparam, LPARAM lparam) +{ + LRESULT ret; + bool quit = false; + win32_common_state_t *g_win32 = (win32_common_state_t*)&win32_st; + + switch (message) + { + case WM_MOUSEMOVE: + case WM_POINTERDOWN: + case WM_POINTERUP: + case WM_POINTERUPDATE: + case WM_DEVICECHANGE: + case WM_MOUSEWHEEL: + case WM_MOUSEHWHEEL: + case WM_NCLBUTTONDBLCLK: +#if _WIN32_WINNT >= 0x0500 /* 2K */ + if (g_win32->taskbar_message && message == g_win32->taskbar_message) + taskbar_is_created = true; +#endif +#ifdef HAVE_DINPUT + if (input_get_ptr() == &input_dinput) + { + void* input_data = input_get_data(); + if (input_data && dinput_handle_message(input_data, + message, wparam, lparam)) + return 0; + } +#endif + break; + case WM_DROPFILES: + case WM_SYSCOMMAND: + case WM_CHAR: + case WM_KEYDOWN: + case WM_KEYUP: + case WM_SYSKEYUP: + case WM_SYSKEYDOWN: + case WM_CLOSE: + case WM_DESTROY: + case WM_QUIT: + case WM_MOVE: + case WM_SIZE: + case WM_COMMAND: + ret = wnd_proc_common(&quit, hwnd, message, wparam, lparam); + if (quit) + return ret; +#if _WIN32_WINNT >= 0x0500 /* 2K */ + if (g_win32->taskbar_message && message == g_win32->taskbar_message) + taskbar_is_created = true; +#endif + break; + case WM_CREATE: + create_vk_context(hwnd, &g_win32->quit); + if (DragAcceptFiles_func) + DragAcceptFiles_func(hwnd, true); + return 0; + } + + return DefWindowProc(hwnd, message, wparam, lparam); +} +#endif + #ifdef HAVE_GDI LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) diff --git a/gfx/common/win32_common.h b/gfx/common/win32_common.h index 4f8b700228..1968214a50 100644 --- a/gfx/common/win32_common.h +++ b/gfx/common/win32_common.h @@ -60,6 +60,8 @@ int win32_change_display_settings(const char *str, void *devmode_data, void create_graphics_context(HWND hwnd, bool *quit); +void create_vk_context(HWND hwnd, bool *quit); + void create_gdi_context(HWND hwnd, bool *quit); bool win32_get_video_output(DEVMODE *dm, int mode, size_t len); @@ -124,11 +126,16 @@ LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); #endif -#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE) || defined(HAVE_VULKAN) +#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE) LRESULT CALLBACK WndProcWGL(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); #endif +#if defined(HAVE_VULKAN) +LRESULT CALLBACK WndProcVK(HWND hwnd, UINT message, + WPARAM wparam, LPARAM lparam); +#endif + LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); diff --git a/gfx/drivers_context/wgl_ctx.c b/gfx/drivers_context/wgl_ctx.c index 3456a95fe9..91986778cd 100644 --- a/gfx/drivers_context/wgl_ctx.c +++ b/gfx/drivers_context/wgl_ctx.c @@ -444,36 +444,35 @@ void create_graphics_context(HWND hwnd, bool *quit) #endif break; - case GFX_CTX_VULKAN_API: - { -#ifdef HAVE_VULKAN - RECT rect; - HINSTANCE instance; - unsigned width = 0; - unsigned height = 0; - - GetClientRect(hwnd, &rect); - - instance = GetModuleHandle(NULL); - width = rect.right - rect.left; - height = rect.bottom - rect.top; - - if (!vulkan_surface_create(&win32_vk, VULKAN_WSI_WIN32, - &instance, &hwnd, - width, height, win32_interval)) - *quit = true; - - g_win32_inited = true; -#endif - } - break; - case GFX_CTX_NONE: default: break; } } +void create_vk_context(HWND hwnd, bool *quit) +{ +#ifdef HAVE_VULKAN + RECT rect; + HINSTANCE instance; + unsigned width = 0; + unsigned height = 0; + + GetClientRect(hwnd, &rect); + + instance = GetModuleHandle(NULL); + width = rect.right - rect.left; + height = rect.bottom - rect.top; + + if (!vulkan_surface_create(&win32_vk, VULKAN_WSI_WIN32, + &instance, &hwnd, + width, height, win32_interval)) + *quit = true; + + g_win32_inited = true; +#endif +} + static void gfx_ctx_wgl_swap_interval(void *data, int interval) { (void)data; @@ -743,7 +742,16 @@ static void *gfx_ctx_wgl_init(void *video_driver) win32_window_reset(); win32_monitor_init(); - wndclass.lpfnWndProc = WndProcWGL; + switch (win32_api) + { + case GFX_CTX_VULKAN_API: + wndclass.lpfnWndProc = WndProcVK; + break; + default: + wndclass.lpfnWndProc = WndProcWGL; + break; + } + if (!win32_window_init(&wndclass, true, NULL)) goto error;