medfall

A super great game engine
Log | Files | Refs

win32_platform.h (10895B)


      1 //========================================================================
      2 // GLFW 3.3 Win32 - www.glfw.org
      3 //------------------------------------------------------------------------
      4 // Copyright (c) 2002-2006 Marcus Geelnard
      5 // Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org>
      6 //
      7 // This software is provided 'as-is', without any express or implied
      8 // warranty. In no event will the authors be held liable for any damages
      9 // arising from the use of this software.
     10 //
     11 // Permission is granted to anyone to use this software for any purpose,
     12 // including commercial applications, and to alter it and redistribute it
     13 // freely, subject to the following restrictions:
     14 //
     15 // 1. The origin of this software must not be misrepresented; you must not
     16 //    claim that you wrote the original software. If you use this software
     17 //    in a product, an acknowledgment in the product documentation would
     18 //    be appreciated but is not required.
     19 //
     20 // 2. Altered source versions must be plainly marked as such, and must not
     21 //    be misrepresented as being the original software.
     22 //
     23 // 3. This notice may not be removed or altered from any source
     24 //    distribution.
     25 //
     26 //========================================================================
     27 
     28 // We don't need all the fancy stuff
     29 #ifndef NOMINMAX
     30  #define NOMINMAX
     31 #endif
     32 
     33 #ifndef VC_EXTRALEAN
     34  #define VC_EXTRALEAN
     35 #endif
     36 
     37 #ifndef WIN32_LEAN_AND_MEAN
     38  #define WIN32_LEAN_AND_MEAN
     39 #endif
     40 
     41 // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
     42 // example to allow applications to correctly declare a GL_ARB_debug_output
     43 // callback) but windows.h assumes no one will define APIENTRY before it does
     44 #undef APIENTRY
     45 
     46 // GLFW on Windows is Unicode only and does not work in MBCS mode
     47 #ifndef UNICODE
     48  #define UNICODE
     49 #endif
     50 
     51 // GLFW requires Windows XP or later
     52 #if WINVER < 0x0501
     53  #undef WINVER
     54  #define WINVER 0x0501
     55 #endif
     56 #if _WIN32_WINNT < 0x0501
     57  #undef _WIN32_WINNT
     58  #define _WIN32_WINNT 0x0501
     59 #endif
     60 
     61 // GLFW uses DirectInput8 interfaces
     62 #define DIRECTINPUT_VERSION 0x0800
     63 
     64 #include <wctype.h>
     65 #include <windows.h>
     66 #include <mmsystem.h>
     67 #include <dinput.h>
     68 #include <xinput.h>
     69 #include <dbt.h>
     70 
     71 #if defined(_MSC_VER)
     72  #include <malloc.h>
     73  #define strdup _strdup
     74 #endif
     75 
     76 // HACK: Define macros that some windows.h variants don't
     77 #ifndef WM_MOUSEHWHEEL
     78  #define WM_MOUSEHWHEEL 0x020E
     79 #endif
     80 #ifndef WM_DWMCOMPOSITIONCHANGED
     81  #define WM_DWMCOMPOSITIONCHANGED 0x031E
     82 #endif
     83 #ifndef WM_COPYGLOBALDATA
     84  #define WM_COPYGLOBALDATA 0x0049
     85 #endif
     86 #ifndef WM_UNICHAR
     87  #define WM_UNICHAR 0x0109
     88 #endif
     89 #ifndef UNICODE_NOCHAR
     90  #define UNICODE_NOCHAR 0xFFFF
     91 #endif
     92 #ifndef WM_DPICHANGED
     93  #define WM_DPICHANGED 0x02E0
     94 #endif
     95 #ifndef GET_XBUTTON_WPARAM
     96  #define GET_XBUTTON_WPARAM(w) (HIWORD(w))
     97 #endif
     98 #ifndef EDS_ROTATEDMODE
     99  #define EDS_ROTATEDMODE 0x00000004
    100 #endif
    101 #ifndef DISPLAY_DEVICE_ACTIVE
    102  #define DISPLAY_DEVICE_ACTIVE 0x00000001
    103 #endif
    104 
    105 #if WINVER < 0x0601
    106 typedef struct tagCHANGEFILTERSTRUCT
    107 {
    108     DWORD cbSize;
    109     DWORD ExtStatus;
    110 
    111 } CHANGEFILTERSTRUCT, *PCHANGEFILTERSTRUCT;
    112 #ifndef MSGFLT_ALLOW
    113  #define MSGFLT_ALLOW 1
    114 #endif
    115 #endif /*Windows 7*/
    116 
    117 #ifndef DPI_ENUMS_DECLARED
    118 typedef enum PROCESS_DPI_AWARENESS
    119 {
    120     PROCESS_DPI_UNAWARE = 0,
    121     PROCESS_SYSTEM_DPI_AWARE = 1,
    122     PROCESS_PER_MONITOR_DPI_AWARE = 2
    123 } PROCESS_DPI_AWARENESS;
    124 #endif /*DPI_ENUMS_DECLARED*/
    125 
    126 // HACK: Define macros that some xinput.h variants don't
    127 #ifndef XINPUT_CAPS_WIRELESS
    128  #define XINPUT_CAPS_WIRELESS 0x0002
    129 #endif
    130 #ifndef XINPUT_DEVSUBTYPE_WHEEL
    131  #define XINPUT_DEVSUBTYPE_WHEEL 0x02
    132 #endif
    133 #ifndef XINPUT_DEVSUBTYPE_ARCADE_STICK
    134  #define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03
    135 #endif
    136 #ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK
    137  #define XINPUT_DEVSUBTYPE_FLIGHT_STICK 0x04
    138 #endif
    139 #ifndef XINPUT_DEVSUBTYPE_DANCE_PAD
    140  #define XINPUT_DEVSUBTYPE_DANCE_PAD 0x05
    141 #endif
    142 #ifndef XINPUT_DEVSUBTYPE_GUITAR
    143  #define XINPUT_DEVSUBTYPE_GUITAR 0x06
    144 #endif
    145 #ifndef XINPUT_DEVSUBTYPE_DRUM_KIT
    146  #define XINPUT_DEVSUBTYPE_DRUM_KIT 0x08
    147 #endif
    148 #ifndef XINPUT_DEVSUBTYPE_ARCADE_PAD
    149  #define XINPUT_DEVSUBTYPE_ARCADE_PAD 0x13
    150 #endif
    151 #ifndef XUSER_MAX_COUNT
    152  #define XUSER_MAX_COUNT 4
    153 #endif
    154 
    155 // HACK: Define macros that some dinput.h variants don't
    156 #ifndef DIDFT_OPTIONAL
    157  #define DIDFT_OPTIONAL	0x80000000
    158 #endif
    159 
    160 // winmm.dll function pointer typedefs
    161 typedef DWORD (WINAPI * PFN_timeGetTime)(void);
    162 #define timeGetTime _glfw.win32.winmm.GetTime
    163 
    164 // xinput.dll function pointer typedefs
    165 typedef DWORD (WINAPI * PFN_XInputGetCapabilities)(DWORD,DWORD,XINPUT_CAPABILITIES*);
    166 typedef DWORD (WINAPI * PFN_XInputGetState)(DWORD,XINPUT_STATE*);
    167 #define XInputGetCapabilities _glfw.win32.xinput.GetCapabilities
    168 #define XInputGetState _glfw.win32.xinput.GetState
    169 
    170 // dinput8.dll function pointer typedefs
    171 typedef HRESULT (WINAPI * PFN_DirectInput8Create)(HINSTANCE,DWORD,REFIID,LPVOID*,LPUNKNOWN);
    172 #define DirectInput8Create _glfw.win32.dinput8.Create
    173 
    174 // user32.dll function pointer typedefs
    175 typedef BOOL (WINAPI * PFN_SetProcessDPIAware)(void);
    176 typedef BOOL (WINAPI * PFN_ChangeWindowMessageFilterEx)(HWND,UINT,DWORD,PCHANGEFILTERSTRUCT);
    177 #define _glfw_SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware
    178 #define _glfw_ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx
    179 
    180 // dwmapi.dll function pointer typedefs
    181 typedef HRESULT (WINAPI * PFN_DwmIsCompositionEnabled)(BOOL*);
    182 typedef HRESULT (WINAPI * PFN_DwmFlush)(VOID);
    183 #define _glfw_DwmIsCompositionEnabled _glfw.win32.dwmapi.DwmIsCompositionEnabled
    184 #define _glfw_DwmFlush _glfw.win32.dwmapi.DwmFlush
    185 
    186 // shcore.dll function pointer typedefs
    187 typedef HRESULT (WINAPI * PFN_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS);
    188 #define _glfw_SetProcessDpiAwareness _glfw.win32.shcore.SetProcessDpiAwareness
    189 
    190 typedef VkFlags VkWin32SurfaceCreateFlagsKHR;
    191 
    192 typedef struct VkWin32SurfaceCreateInfoKHR
    193 {
    194     VkStructureType                 sType;
    195     const void*                     pNext;
    196     VkWin32SurfaceCreateFlagsKHR    flags;
    197     HINSTANCE                       hinstance;
    198     HWND                            hwnd;
    199 } VkWin32SurfaceCreateInfoKHR;
    200 
    201 typedef VkResult (APIENTRY *PFN_vkCreateWin32SurfaceKHR)(VkInstance,const VkWin32SurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*);
    202 typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice,uint32_t);
    203 
    204 #include "win32_joystick.h"
    205 #include "wgl_context.h"
    206 #include "egl_context.h"
    207 #include "osmesa_context.h"
    208 
    209 #define _GLFW_WNDCLASSNAME L"GLFW30"
    210 
    211 #define _glfw_dlopen(name) LoadLibraryA(name)
    212 #define _glfw_dlclose(handle) FreeLibrary((HMODULE) handle)
    213 #define _glfw_dlsym(handle, name) GetProcAddress((HMODULE) handle, name)
    214 
    215 #define _GLFW_EGL_NATIVE_WINDOW  ((EGLNativeWindowType) window->win32.handle)
    216 #define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY
    217 
    218 #define _GLFW_PLATFORM_WINDOW_STATE         _GLFWwindowWin32  win32
    219 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32
    220 #define _GLFW_PLATFORM_LIBRARY_TIMER_STATE  _GLFWtimerWin32   win32
    221 #define _GLFW_PLATFORM_MONITOR_STATE        _GLFWmonitorWin32 win32
    222 #define _GLFW_PLATFORM_CURSOR_STATE         _GLFWcursorWin32  win32
    223 #define _GLFW_PLATFORM_TLS_STATE            _GLFWtlsWin32     win32
    224 #define _GLFW_PLATFORM_MUTEX_STATE          _GLFWmutexWin32   win32
    225 
    226 
    227 // Win32-specific per-window data
    228 //
    229 typedef struct _GLFWwindowWin32
    230 {
    231     HWND                handle;
    232     HICON               bigIcon;
    233     HICON               smallIcon;
    234 
    235     GLFWbool            cursorTracked;
    236     GLFWbool            iconified;
    237     GLFWbool            maximized;
    238 
    239     // The last received cursor position, regardless of source
    240     int                 lastCursorPosX, lastCursorPosY;
    241 
    242 } _GLFWwindowWin32;
    243 
    244 // Win32-specific global data
    245 //
    246 typedef struct _GLFWlibraryWin32
    247 {
    248     HWND                helperWindowHandle;
    249     DWORD               foregroundLockTimeout;
    250     int                 acquiredMonitorCount;
    251     char*               clipboardString;
    252     char                keyName[64];
    253     short int           keycodes[512];
    254     short int           scancodes[GLFW_KEY_LAST + 1];
    255     // Where to place the cursor when re-enabled
    256     double              restoreCursorPosX, restoreCursorPosY;
    257     // The window whose disabled cursor mode is active
    258     _GLFWwindow*        disabledCursorWindow;
    259     RAWINPUT*           rawInput;
    260     int                 rawInputSize;
    261 
    262     struct {
    263         HINSTANCE                       instance;
    264         PFN_timeGetTime                 GetTime;
    265     } winmm;
    266 
    267     struct {
    268         HINSTANCE                       instance;
    269         PFN_DirectInput8Create          Create;
    270         IDirectInput8W*                 api;
    271     } dinput8;
    272 
    273     struct {
    274         HINSTANCE                       instance;
    275         PFN_XInputGetCapabilities       GetCapabilities;
    276         PFN_XInputGetState              GetState;
    277     } xinput;
    278 
    279     struct {
    280         HINSTANCE                       instance;
    281         PFN_SetProcessDPIAware          SetProcessDPIAware;
    282         PFN_ChangeWindowMessageFilterEx ChangeWindowMessageFilterEx;
    283     } user32;
    284 
    285     struct {
    286         HINSTANCE                       instance;
    287         PFN_DwmIsCompositionEnabled     DwmIsCompositionEnabled;
    288         PFN_DwmFlush                    DwmFlush;
    289     } dwmapi;
    290 
    291     struct {
    292         HINSTANCE                       instance;
    293         PFN_SetProcessDpiAwareness      SetProcessDpiAwareness;
    294     } shcore;
    295 
    296 } _GLFWlibraryWin32;
    297 
    298 // Win32-specific per-monitor data
    299 //
    300 typedef struct _GLFWmonitorWin32
    301 {
    302     // This size matches the static size of DISPLAY_DEVICE.DeviceName
    303     WCHAR               adapterName[32];
    304     WCHAR               displayName[32];
    305     char                publicAdapterName[64];
    306     char                publicDisplayName[64];
    307     GLFWbool            modesPruned;
    308     GLFWbool            modeChanged;
    309 
    310 } _GLFWmonitorWin32;
    311 
    312 // Win32-specific per-cursor data
    313 //
    314 typedef struct _GLFWcursorWin32
    315 {
    316     HCURSOR             handle;
    317 
    318 } _GLFWcursorWin32;
    319 
    320 // Win32-specific global timer data
    321 //
    322 typedef struct _GLFWtimerWin32
    323 {
    324     GLFWbool            hasPC;
    325     uint64_t            frequency;
    326 
    327 } _GLFWtimerWin32;
    328 
    329 // Win32-specific thread local storage data
    330 //
    331 typedef struct _GLFWtlsWin32
    332 {
    333     GLFWbool            allocated;
    334     DWORD               index;
    335 
    336 } _GLFWtlsWin32;
    337 
    338 // Win32-specific mutex data
    339 //
    340 typedef struct _GLFWmutexWin32
    341 {
    342     GLFWbool            allocated;
    343     CRITICAL_SECTION    section;
    344 
    345 } _GLFWmutexWin32;
    346 
    347 
    348 GLFWbool _glfwRegisterWindowClassWin32(void);
    349 void _glfwUnregisterWindowClassWin32(void);
    350 
    351 WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source);
    352 char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source);
    353 void _glfwInputErrorWin32(int error, const char* description);
    354 
    355 void _glfwInitTimerWin32(void);
    356 
    357 void _glfwPollMonitorsWin32(void);
    358 GLFWbool _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired);
    359 void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor);
    360