From 929af320da564ff5ec739811920a16999afb6880 Mon Sep 17 00:00:00 2001 From: Fabian Sperber Date: Wed, 27 Jul 2022 22:49:08 +0200 Subject: [PATCH 1/2] Add more windows bindings --- core/sys/windows/user32.odin | 32 +++++++++++++++++++++- core/sys/windows/window_messages.odin | 39 +++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/core/sys/windows/user32.odin b/core/sys/windows/user32.odin index d0a0d5b0a..90961ba8c 100644 --- a/core/sys/windows/user32.odin +++ b/core/sys/windows/user32.odin @@ -42,6 +42,7 @@ foreign user32 { GetTopWindow :: proc(hWnd: HWND) -> HWND --- SetForegroundWindow :: proc(hWnd: HWND) -> BOOL --- GetForegroundWindow :: proc() -> HWND --- + UpdateWindow :: proc(hWnd: HWND) -> BOOL --- SetActiveWindow :: proc(hWnd: HWND) -> HWND --- GetActiveWindow :: proc() -> HWND --- @@ -95,6 +96,7 @@ foreign user32 { GetSystemMetrics :: proc(nIndex: c_int) -> c_int --- AdjustWindowRect :: proc(lpRect: LPRECT, dwStyle: DWORD, bMenu: BOOL) -> BOOL --- AdjustWindowRectEx :: proc(lpRect: LPRECT, dwStyle: DWORD, bMenu: BOOL, dwExStyle: DWORD) -> BOOL --- + AdjustWindowRectExForDpi :: proc(lpRect: LPRECT, dwStyle: DWORD, bMenu: BOOL, dwExStyle: DWORD, dpi: UINT) -> BOOL --- SystemParametersInfoW :: proc(uiAction, uiParam: UINT, pvParam: PVOID, fWinIni: UINT) -> BOOL --- @@ -137,7 +139,19 @@ foreign user32 { SetCursor :: proc(hCursor: HCURSOR) -> HCURSOR --- EnumDisplaySettingsW :: proc(lpszDeviceName: LPCWSTR, iModeNum: DWORD, lpDevMode: ^DEVMODEW) -> BOOL --- - + + MonitorFromPoint :: proc(pt: POINT, dwFlags: Monitor_From_Flags) -> HMONITOR --- + MonitorFromRect :: proc(lprc: LPRECT, dwFlags: Monitor_From_Flags) -> HMONITOR --- + MonitorFromWindow :: proc(hwnd: HWND, dwFlags: Monitor_From_Flags) -> HMONITOR --- + EnumDisplayMonitors :: proc(hdc: HDC, lprcClip: LPRECT, lpfnEnum: Monitor_Enum_Proc, dwData: LPARAM) -> BOOL --- + + SetThreadDpiAwarenessContext :: proc(dpiContext: DPI_AWARENESS_CONTEXT) -> DPI_AWARENESS_CONTEXT --- + GetThreadDpiAwarenessContext :: proc() -> DPI_AWARENESS_CONTEXT --- + GetWindowDpiAwarenessContext :: proc(hwnd: HWND) -> DPI_AWARENESS_CONTEXT --- + GetDpiFromDpiAwarenessContext :: proc(value: DPI_AWARENESS_CONTEXT) -> UINT --- + GetDpiForWindow :: proc(hwnd: HWND) -> UINT --- + SetProcessDpiAwarenessContext :: proc(value: DPI_AWARENESS_CONTEXT) -> BOOL --- + BroadcastSystemMessageW :: proc( flags: DWORD, lpInfo: LPDWORD, @@ -247,3 +261,19 @@ GET_XBUTTON_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> WORD MAKEINTRESOURCEW :: #force_inline proc "contextless" (#any_int i: int) -> LPWSTR { return cast(LPWSTR)uintptr(WORD(i)) } + +Monitor_From_Flags :: enum DWORD { + MONITOR_DEFAULTTONULL = 0x00000000, // Returns NULL + MONITOR_DEFAULTTOPRIMARY = 0x00000001, // Returns a handle to the primary display monitor + MONITOR_DEFAULTTONEAREST = 0x00000002, // Returns a handle to the display monitor that is nearest to the window +} + +Monitor_Enum_Proc :: #type proc "stdcall" (HMONITOR, HDC, LPRECT, LPARAM) -> BOOL + +USER_DEFAULT_SCREEN_DPI :: 96 +DPI_AWARENESS_CONTEXT :: distinct HANDLE +DPI_AWARENESS_CONTEXT_UNAWARE :: DPI_AWARENESS_CONTEXT(~uintptr(0)) // -1 +DPI_AWARENESS_CONTEXT_SYSTEM_AWARE :: DPI_AWARENESS_CONTEXT(~uintptr(1)) // -2 +DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE :: DPI_AWARENESS_CONTEXT(~uintptr(2)) // -3 +DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 :: DPI_AWARENESS_CONTEXT(~uintptr(3)) // -4 +DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED :: DPI_AWARENESS_CONTEXT(~uintptr(4)) // -5 diff --git a/core/sys/windows/window_messages.odin b/core/sys/windows/window_messages.odin index d6b883916..7ce9e545c 100644 --- a/core/sys/windows/window_messages.odin +++ b/core/sys/windows/window_messages.odin @@ -153,6 +153,7 @@ BM_CLICK :: 0x00f5 BM_GETIMAGE :: 0x00f6 BM_SETIMAGE :: 0x00f7 BM_SETDONTCLICK :: 0x00f8 +WM_INPUT_DEVICE_CHANGE :: 0x00fe WM_INPUT :: 0x00ff WM_KEYDOWN :: 0x0100 WM_KEYFIRST :: 0x0100 @@ -165,6 +166,7 @@ WM_SYSCHAR :: 0x0106 WM_SYSDEADCHAR :: 0x0107 WM_UNICHAR :: 0x0109 WM_KEYLAST :: 0x0109 +UNICODE_NOCHAR :: 0xFFFF WM_WNT_CONVERTREQUESTEX :: 0x0109 WM_CONVERTREQUEST :: 0x010a WM_CONVERTRESULT :: 0x010b @@ -279,6 +281,27 @@ WM_ENTERSIZEMOVE :: 0x0231 WM_EXITSIZEMOVE :: 0x0232 WM_DROPFILES :: 0x0233 WM_MDIREFRESHMENU :: 0x0234 +WM_POINTERDEVICECHANGE :: 0x0238 +WM_POINTERDEVICEINRANGE :: 0x0239 +WM_POINTERDEVICEOUTOFRANGE :: 0x023a +WM_TOUCH :: 0x0240 +WM_NCPOINTERUPDATE :: 0x0241 +WM_NCPOINTERDOWN :: 0x0242 +WM_NCPOINTERUP :: 0x0243 +WM_POINTERUPDATE :: 0x0245 +WM_POINTERDOWN :: 0x0246 +WM_POINTERUP :: 0x0247 +WM_POINTERENTER :: 0x0249 +WM_POINTERLEAVE :: 0x024a +WM_POINTERACTIVATE :: 0x024b +WM_POINTERCAPTURECHANGED :: 0x024c +WM_TOUCHHITTESTING :: 0x024d +WM_POINTERWHEEL :: 0x024e +WM_POINTERHWHEEL :: 0x024f +DM_POINTERHITTEST :: 0x0250 +WM_POINTERROUTEDTO :: 0x0251 +WM_POINTERROUTEDAWAY :: 0x0252 +WM_POINTERROUTEDRELEASED :: 0x0253 WM_IME_REPORT :: 0x0280 WM_IME_SETCONTEXT :: 0x0281 WM_IME_NOTIFY :: 0x0282 @@ -295,6 +318,13 @@ WM_NCMOUSEHOVER :: 0x02a0 WM_MOUSEHOVER :: 0x02a1 WM_NCMOUSELEAVE :: 0x02a2 WM_MOUSELEAVE :: 0x02a3 +WM_WTSSESSION_CHANGE :: 0x02b1 +WM_TABLET_FIRST :: 0x02c0 +WM_TABLET_LAST :: 0x02df +WM_DPICHANGED :: 0x02e0 +WM_DPICHANGED_BEFOREPARENT :: 0x02e2 +WM_DPICHANGED_AFTERPARENT :: 0x02e3 +WM_GETDPISCALEDSIZE :: 0x02e4 WM_CUT :: 0x0300 WM_COPY :: 0x0301 WM_PASTE :: 0x0302 @@ -317,6 +347,15 @@ WM_HOTKEY :: 0x0312 WM_PRINT :: 0x0317 WM_PRINTCLIENT :: 0x0318 WM_APPCOMMAND :: 0x0319 +WM_THEMECHANGED :: 0x031A +WM_CLIPBOARDUPDATE :: 0x031D +WM_DWMCOMPOSITIONCHANGED :: 0x031E +WM_DWMNCRENDERINGCHANGED :: 0x031F +WM_DWMCOLORIZATIONCOLORCHANGED:: 0x0320 +WM_DWMWINDOWMAXIMIZEDCHANGE :: 0x0321 +WM_DWMSENDICONICTHUMBNAIL :: 0x0323 +WM_DWMSENDICONICLIVEPREVIEWBITMAP :: 0x0326 +WM_GETTITLEBARINFOEX :: 0x033F WM_HANDHELDFIRST :: 0x0358 WM_HANDHELDLAST :: 0x035f WM_AFXFIRST :: 0x0360 From e50648279d29e2fd158e4edbb15d483802038765 Mon Sep 17 00:00:00 2001 From: Fabian Sperber Date: Mon, 1 Aug 2022 21:09:38 +0200 Subject: [PATCH 2/2] Add some wgl extensions - fix upper case for wglSwapIntervalEXT to be the same as the exported name --- core/sys/windows/wgl.odin | 2 +- core/sys/windows/wglext.odin | 147 +++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 core/sys/windows/wglext.odin diff --git a/core/sys/windows/wgl.odin b/core/sys/windows/wgl.odin index 689a41dea..150358d01 100644 --- a/core/sys/windows/wgl.odin +++ b/core/sys/windows/wgl.odin @@ -62,7 +62,7 @@ GetExtensionsStringARBType :: #type proc "c" (HDC) -> cstring // Procedures wglCreateContextAttribsARB: CreateContextAttribsARBType wglChoosePixelFormatARB: ChoosePixelFormatARBType - wglSwapIntervalExt: SwapIntervalEXTType + wglSwapIntervalEXT: SwapIntervalEXTType wglGetExtensionsStringARB: GetExtensionsStringARBType diff --git a/core/sys/windows/wglext.odin b/core/sys/windows/wglext.odin new file mode 100644 index 000000000..0c4b51d65 --- /dev/null +++ b/core/sys/windows/wglext.odin @@ -0,0 +1,147 @@ +// +build windows +package sys_windows + +// WGL_ARB_buffer_region +WGL_FRONT_COLOR_BUFFER_BIT_ARB :: 0x00000001 +WGL_BACK_COLOR_BUFFER_BIT_ARB :: 0x00000002 +WGL_DEPTH_BUFFER_BIT_ARB :: 0x00000004 +WGL_STENCIL_BUFFER_BIT_ARB :: 0x00000008 + +wglCreateBufferRegionARBType :: #type proc "c" (hDC: HDC, iLayerPlane: c_int, uType: UINT) -> HANDLE +wglDeleteBufferRegionARBType :: #type proc "c" (hRegion: HANDLE) +wglSaveBufferRegionARBType :: #type proc "c" (hRegion: HANDLE, x: c_int, y: c_int, width: c_int, height: c_int) -> BOOL +wglRestoreBufferRegionARBType :: #type proc "c" (hRegion: HANDLE, x: c_int, y: c_int, width: c_int, height: c_int, xSrc: c_int, ySrc: c_int) -> BOOL + +// wglCreateBufferRegionARB: wglCreateBufferRegionARBType +// wglDeleteBufferRegionARB: wglDeleteBufferRegionARBType +// wglSaveBufferRegionARB: wglSaveBufferRegionARBType +// wglRestoreBufferRegionARB: wglRestoreBufferRegionARBType + +// WGL_ARB_context_flush_control +WGL_CONTEXT_RELEASE_BEHAVIOR_ARB :: 0x2097 +WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB :: 0 +WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB :: 0x2098 + +// WGL_ARB_create_context +WGL_CONTEXT_DEBUG_BIT_ARB :: 0x0001 +WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB :: 0x0002 +WGL_CONTEXT_MAJOR_VERSION_ARB :: 0x2091 +WGL_CONTEXT_MINOR_VERSION_ARB :: 0x2092 +WGL_CONTEXT_LAYER_PLANE_ARB :: 0x2093 +WGL_CONTEXT_FLAGS_ARB :: 0x2094 +ERROR_INVALID_VERSION_ARB :: 0x2095 + +// WGL_ARB_create_context_no_error +WGL_CONTEXT_OPENGL_NO_ERROR_ARB :: 0x31B3 + +// WGL_ARB_create_context_profile +WGL_CONTEXT_PROFILE_MASK_ARB :: 0x9126 +WGL_CONTEXT_CORE_PROFILE_BIT_ARB :: 0x0001 +WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x0002 +ERROR_INVALID_PROFILE_ARB :: 0x2096 + +// WGL_ARB_create_context_robustness +WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB :: 0x00000004 +WGL_LOSE_CONTEXT_ON_RESET_ARB :: 0x8252 +WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB :: 0x8256 +WGL_NO_RESET_NOTIFICATION_ARB :: 0x8261 + +// WGL_ARB_framebuffer_sRGB +WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB :: 0x20A9 + +// WGL_ARB_make_current_read +ERROR_INVALID_PIXEL_TYPE_ARB :: 0x2043 +ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB :: 0x2054 + +wglMakeContextCurrentARBType :: #type proc "c" (hDrawDC: HDC, hReadDC:HDC, hglrc: HGLRC) -> BOOL +wglGetCurrentReadDCARBType :: #type proc "c" () -> HDC + +// wglMakeContextCurrentARB: wglMakeContextCurrentARBType +// wglGetCurrentReadDCARB: wglGetCurrentReadDCARBType + +// WGL_ARB_multisample +WGL_SAMPLE_BUFFERS_ARB :: 0x2041 +WGL_SAMPLES_ARB :: 0x2042 + +// WGL_ARB_pbuffer +HPBUFFERARB :: distinct rawptr +WGL_DRAW_TO_PBUFFER_ARB :: 0x202D +WGL_MAX_PBUFFER_PIXELS_ARB :: 0x202E +WGL_MAX_PBUFFER_WIDTH_ARB :: 0x202F +WGL_MAX_PBUFFER_HEIGHT_ARB :: 0x2030 +WGL_PBUFFER_LARGEST_ARB :: 0x2033 +WGL_PBUFFER_WIDTH_ARB :: 0x2034 +WGL_PBUFFER_HEIGHT_ARB :: 0x2035 +WGL_PBUFFER_LOST_ARB :: 0x2036 + +wglCreatePbufferARBType :: #type proc "c" (hDC: HDC, iPixelFormat, iWidth, iHeight: c_int, piAttribList: [^]c_int) -> HPBUFFERARB +wglGetPbufferDCARBType :: #type proc "c" (hPbuffer: HPBUFFERARB) -> HDC +wglReleasePbufferDCARBType :: #type proc "c" (hPbuffer: HPBUFFERARB, hDC: HDC) -> c_int +wglDestroyPbufferARBType :: #type proc "c" (hPbuffer: HPBUFFERARB) -> BOOL +wglQueryPbufferARBType :: #type proc "c" (hPbuffer: HPBUFFERARB, iAttribute: c_int, piValue: ^c_int) -> BOOL + +// wglCreatePbufferARB: wglCreatePbufferARBType +// wglGetPbufferDCARB: wglGetPbufferDCARBType +// wglReleasePbufferDCARB: wglReleasePbufferDCARBType +// wglDestroyPbufferARB: wglDestroyPbufferARBType +// wglQueryPbufferARB: wglQueryPbufferARBType + +// WGL_ARB_pixel_format +WGL_NUMBER_PIXEL_FORMATS_ARB :: 0x2000 +WGL_DRAW_TO_WINDOW_ARB :: 0x2001 +WGL_DRAW_TO_BITMAP_ARB :: 0x2002 +WGL_ACCELERATION_ARB :: 0x2003 +WGL_NEED_PALETTE_ARB :: 0x2004 +WGL_NEED_SYSTEM_PALETTE_ARB :: 0x2005 +WGL_SWAP_LAYER_BUFFERS_ARB :: 0x2006 +WGL_SWAP_METHOD_ARB :: 0x2007 +WGL_NUMBER_OVERLAYS_ARB :: 0x2008 +WGL_NUMBER_UNDERLAYS_ARB :: 0x2009 +WGL_TRANSPARENT_ARB :: 0x200A +WGL_TRANSPARENT_RED_VALUE_ARB :: 0x2037 +WGL_TRANSPARENT_GREEN_VALUE_ARB :: 0x2038 +WGL_TRANSPARENT_BLUE_VALUE_ARB :: 0x2039 +WGL_TRANSPARENT_ALPHA_VALUE_ARB :: 0x203A +WGL_TRANSPARENT_INDEX_VALUE_ARB :: 0x203B +WGL_SHARE_DEPTH_ARB :: 0x200C +WGL_SHARE_STENCIL_ARB :: 0x200D +WGL_SHARE_ACCUM_ARB :: 0x200E +WGL_SUPPORT_GDI_ARB :: 0x200F +WGL_SUPPORT_OPENGL_ARB :: 0x2010 +WGL_DOUBLE_BUFFER_ARB :: 0x2011 +WGL_STEREO_ARB :: 0x2012 +WGL_PIXEL_TYPE_ARB :: 0x2013 +WGL_COLOR_BITS_ARB :: 0x2014 +WGL_RED_BITS_ARB :: 0x2015 +WGL_RED_SHIFT_ARB :: 0x2016 +WGL_GREEN_BITS_ARB :: 0x2017 +WGL_GREEN_SHIFT_ARB :: 0x2018 +WGL_BLUE_BITS_ARB :: 0x2019 +WGL_BLUE_SHIFT_ARB :: 0x201A +WGL_ALPHA_BITS_ARB :: 0x201B +WGL_ALPHA_SHIFT_ARB :: 0x201C +WGL_ACCUM_BITS_ARB :: 0x201D +WGL_ACCUM_RED_BITS_ARB :: 0x201E +WGL_ACCUM_GREEN_BITS_ARB :: 0x201F +WGL_ACCUM_BLUE_BITS_ARB :: 0x2020 +WGL_ACCUM_ALPHA_BITS_ARB :: 0x2021 +WGL_DEPTH_BITS_ARB :: 0x2022 +WGL_STENCIL_BITS_ARB :: 0x2023 +WGL_AUX_BUFFERS_ARB :: 0x2024 +WGL_NO_ACCELERATION_ARB :: 0x2025 +WGL_GENERIC_ACCELERATION_ARB :: 0x2026 +WGL_FULL_ACCELERATION_ARB :: 0x2027 +WGL_SWAP_EXCHANGE_ARB :: 0x2028 +WGL_SWAP_COPY_ARB :: 0x2029 +WGL_SWAP_UNDEFINED_ARB :: 0x202A +WGL_TYPE_RGBA_ARB :: 0x202B +WGL_TYPE_COLORINDEX_ARB :: 0x202C + +wglGetPixelFormatAttribivARBType :: #type proc "c" (hdc: HDC, iPixelFormat, iLayerPlane: c_int, nAttributes: UINT, piAttributes: [^]c_int, piValues: [^]c_int) -> BOOL +wglGetPixelFormatAttribfvARBType :: #type proc "c" (hdc: HDC, iPixelFormat, iLayerPlane: c_int, nAttributes: UINT, piAttributes: [^]c_int, pfValues: [^]f32) -> BOOL + +// wglGetPixelFormatAttribivARB: wglGetPixelFormatAttribivARBType +// wglGetPixelFormatAttribfvARB: wglGetPixelFormatAttribfvARBType + +// WGL_ARB_pixel_format_float +WGL_TYPE_RGBA_FLOAT_ARB :: 0x21A0