From: John Tsiombikas Date: Sat, 7 Sep 2024 09:44:20 +0000 (+0300) Subject: windows X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=aab1505dc9f012397b8b3037d837d126fca5b5b7;p=vktest3 windows --- diff --git a/src/app.c b/src/app.c index bc931d1..6f9e8f9 100644 --- a/src/app.c +++ b/src/app.c @@ -1,6 +1,5 @@ #include #include -#include #include "app.h" #include "vk.h" @@ -107,8 +106,6 @@ void app_display(void) /* swap buffers after drawing is finished */ vk_present(queue, imgid, sem_draw); - - usleep(10000); } void app_reshape(int x, int y) diff --git a/src/main_w32.c b/src/main_w32.c new file mode 100644 index 0000000..119df1b --- /dev/null +++ b/src/main_w32.c @@ -0,0 +1,246 @@ +#include +#include +#include "app.h" +#include "vk.h" + +static int create_window(const char *title, int xsz, int ysz); +static void destroy_window(void); +static void handle_events(void); + +static int translate_vkey(int vkey); +static void calc_win_rect(RECT *rect, int x, int y, int w, int h); +static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam); + +static HINSTANCE hinst; +static HWND win; +static int quit; + +static int win_width, win_height, mapped; + +static int init_done, reshape_pending; +static HDC dc; +static WNDCLASSEX wc; + + +int main(int argc, char **argv) +{ + hinst = GetModuleHandle(0); + + if(create_window("vulkan test 3", 1280, 800) == -1) { + return 1; + } + vk_init_win(hinst, win); + + win_width = 1280; + win_height = 800; + + if(app_init() == -1) { + destroy_window(); + return 1; + } + + for(;;) { + MSG msg; + while(PeekMessage(&msg, win, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + if(quit) return; + } + + if(reshape_pending) { + reshape_pending = 0; + app_reshape(win_width, win_height); + } + + app_display(); + } + + app_cleanup(); + destroy_window(); + return 0; +} + +void app_quit(void) +{ + quit = 1; +} + +void app_swap_buffers(void) +{ +} + + +static int create_window(const char *title, int xsz, int ysz) +{ + RECT rect; + + if(!init_done) { + wc.cbSize = sizeof wc; + wc.hbrBackground = GetStockObject(BLACK_BRUSH); + wc.hCursor = LoadCursor(0, IDC_ARROW); + wc.hIcon = wc.hIconSm = LoadIcon(0, IDI_APPLICATION); + wc.hInstance = hinst; + wc.lpfnWndProc = handle_msg; + wc.lpszClassName = "vktest3"; + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + if(!RegisterClassEx(&wc)) { + fprintf(stderr, "failed to register window class\n"); + return -1; + } + init_done = 1; + } + + rect.left = GetSystemMetrics(SM_CXSCREEN) / 3; + rect.top = GetSystemMetrics(SM_CYSCREEN) / 3; + calc_win_rect(&rect, rect.left, rect.top, xsz, ysz); + + if(!(win = CreateWindow("vktest3", title, WS_OVERLAPPEDWINDOW, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, 0, 0, hinst, 0))) { + return -1; + } + dc = GetDC(win); + ShowWindow(win, 1); + SetForegroundWindow(win); + SetFocus(win); + + reshape_pending = 1; + return 0; +} + +static void destroy_window(void) +{ + if(win) { + DestroyWindow(win); + win = 0; + } +} + +static void handle_events(void) +{ + MSG msg; + while(PeekMessage(&msg, win, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + if(quit) return; + } + + if(reshape_pending) { + reshape_pending = 0; + app_reshape(win_width, win_height); + } +} + +static void calc_win_rect(RECT *rect, int x, int y, int w, int h) +{ + rect->left = x; + rect->top = y; + rect->right = x + w; + rect->bottom = y + h; + AdjustWindowRect(rect, WS_OVERLAPPEDWINDOW, 0); +} + +static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) +{ + static int mouse_x, mouse_y; + int x, y, bn, key; + + switch(msg) { + case WM_CLOSE: + case WM_DESTROY: + PostQuitMessage(0); + quit = 1; + break; + + case WM_PAINT: + ValidateRect(win, 0); + break; + + case WM_SIZE: + x = lparam & 0xffff; + y = lparam >> 16; + if(x != win_width || y != win_height) { + win_width = x; + win_height = y; + reshape_pending = 1; + } + break; + + case WM_SHOWWINDOW: + mapped = wparam; + break; + + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + key = translate_vkey(wparam); + app_keyboard(key, 1); + break; + + case WM_KEYUP: + case WM_SYSKEYUP: + key = translate_vkey(wparam); + app_keyboard(key, 1); + break; + + case WM_LBUTTONDOWN: + bn = 0; + if(0) + case WM_MBUTTONDOWN: + bn = 1; + if(0) + case WM_RBUTTONDOWN: + bn = 2; + app_mouse(bn, 1, lparam & 0xffff, lparam >> 16); + break; + + case WM_LBUTTONUP: + bn = 0; + if(0) + case WM_MBUTTONUP: + bn = 1; + if(0) + case WM_RBUTTONUP: + bn = 2; + app_mouse(bn, 0, lparam & 0xffff, lparam >> 16); + break; + + case WM_MOUSEMOVE: + app_motion(lparam & 0xffff, lparam >> 16); + break; + + default: + return DefWindowProc(win, msg, wparam, lparam); + } + + return 0; +} + +static int translate_vkey(int vkey) +{ + switch(vkey) { + /*case VK_PRIOR: return GLUT_KEY_PAGE_UP; + case VK_NEXT: return GLUT_KEY_PAGE_DOWN; + case VK_END: return GLUT_KEY_END; + case VK_HOME: return GLUT_KEY_HOME; + case VK_LEFT: return GLUT_KEY_LEFT; + case VK_UP: return GLUT_KEY_UP; + case VK_RIGHT: return GLUT_KEY_RIGHT; + case VK_DOWN: return GLUT_KEY_DOWN;*/ + case VK_OEM_1: return ';'; + case VK_OEM_2: return '/'; + case VK_OEM_3: return '`'; + case VK_OEM_4: return '['; + case VK_OEM_5: return '\\'; + case VK_OEM_6: return ']'; + case VK_OEM_7: return '\''; + default: + break; + } + + if(vkey >= 'A' && vkey <= 'Z') { + vkey += 32; + }/* else if(vkey >= VK_F1 && vkey <= VK_F12) { + vkey -= VK_F1 + GLUT_KEY_F1; + }*/ + + return vkey; +} diff --git a/src/util.h b/src/util.h index 61ae532..61f6d47 100644 --- a/src/util.h +++ b/src/util.h @@ -4,7 +4,7 @@ #include #include -#if defined(__WATCOMC__) || defined(WIN32) +#if defined(__WATCOMC__) || defined(_WIN32) #include #else #if !defined(__FreeBSD__) && !defined(__OpenBSD__) diff --git a/src/vk.c b/src/vk.c index a18a0cd..c73cf31 100644 --- a/src/vk.c +++ b/src/vk.c @@ -86,6 +86,7 @@ static int create_device(void); static int create_swapchain(void); static int create_default_cmdbuf(void); +static void *init_rayext_list(void); static int choose_pixfmt(void); static int eval_pdev_score(VkPhysicalDevice dev); static int have_inst_layer(const char *name); @@ -133,6 +134,7 @@ static uint32_t num_pdev; static int have_raytrace, have_debug_report; + #ifdef _WIN32 void vk_init_win(HINSTANCE hi, HWND w) { @@ -323,7 +325,7 @@ int vk_find_qfamily(unsigned int flags) if(!qfam) return -1; /* not initialized I guess... */ - for(i=0; i= qfam[fam].queueCount) { + if(n < 0 || n >= (int)qfam[fam].queueCount) { fprintf(stderr, "vk_getq_fam: invalid index %d, family %d has %d queues\n", n, fam, qfam[fam].queueCount); return 0; @@ -1160,11 +1162,11 @@ static int create_instance(void) vkEnumerateInstanceExtensionProperties(0, &inst_ext_count, inst_ext); printf("Layers:\n"); - for(i=0; i + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {862fe05b-cded-4eb5-b591-53e5e62b6d63} + vktest3 + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + C:\VulkanSDK\1.3.290.0\Include;%(AdditionalIncludeDirectories) + 4996;4244 + + + Console + true + C:\VulkanSDK\1.3.290.0\Lib32;%(AdditionalLibraryDirectories) + vulkan-1.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + C:\VulkanSDK\1.3.290.0\Include;%(AdditionalIncludeDirectories) + 4996;4244 + + + Console + true + true + true + C:\VulkanSDK\1.3.290.0\Lib32;%(AdditionalLibraryDirectories) + vulkan-1.lib;%(AdditionalDependencies) + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + C:\VulkanSDK\1.3.290.0\Include;%(AdditionalIncludeDirectories) + 4996;4244 + + + Console + true + C:\VulkanSDK\1.3.290.0\Lib;%(AdditionalLibraryDirectories) + vulkan-1.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + C:\VulkanSDK\1.3.290.0\Include;%(AdditionalIncludeDirectories) + 4996;4244 + + + Console + true + true + true + C:\VulkanSDK\1.3.290.0\Lib;%(AdditionalLibraryDirectories) + vulkan-1.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + diff --git a/vktest3.vcxproj.filters b/vktest3.vcxproj.filters new file mode 100644 index 0000000..201506d --- /dev/null +++ b/vktest3.vcxproj.filters @@ -0,0 +1,40 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + + + src + + + src + + + src + + + src + + + src + + + + + src + + + src + + + src + + + src + + +