diff --git a/CMakeLists.txt b/CMakeLists.txt index 663484115c..ebf8e782f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1145,8 +1145,6 @@ if(USE_OPENGL) core/wsi/osx.h core/wsi/sdl.cpp core/wsi/sdl.h - core/wsi/wgl.cpp - core/wsi/wgl.h core/wsi/xgl.cpp core/wsi/xgl.h) @@ -1478,9 +1476,6 @@ if((USE_OPENGL OR USE_GLES2 OR USE_GLES) AND NOT LIBRETRO) if(ANDROID OR USE_GLES2 OR USE_GLES) target_sources(glad PRIVATE core/deps/glad/src/egl.c) endif() - if(WIN32) - target_sources(glad PRIVATE core/deps/glad/src/wgl.c) - endif() endif() target_include_directories(glad PUBLIC core/deps/glad/include) target_link_libraries(${PROJECT_NAME} PRIVATE glad) @@ -1703,9 +1698,7 @@ if(NOT LIBRETRO) target_sources(${PROJECT_NAME} PRIVATE core/windows/rawinput.cpp core/windows/rawinput.h - core/windows/win_keyboard.h - core/windows/winmain.cpp - core/windows/xinput_gamepad.h) + core/windows/winmain.cpp) endif() if(WINDOWS_STORE) file(READ shell/uwp/Package.appxmanifest MANIFEST) diff --git a/core/deps/glad/include/glad/wgl.h b/core/deps/glad/include/glad/wgl.h deleted file mode 100644 index 6640d460a5..0000000000 --- a/core/deps/glad/include/glad/wgl.h +++ /dev/null @@ -1,316 +0,0 @@ -/** - * Loader generated by glad 2.0.4 on Fri Nov 10 07:48:39 2023 - * - * SPDX-License-Identifier: (WTFPL OR CC0-1.0) AND Apache-2.0 - * - * Generator: C/C++ - * Specification: wgl - * Extensions: 4 - * - * APIs: - * - wgl=1.0 - * - * Options: - * - ALIAS = False - * - DEBUG = False - * - HEADER_ONLY = False - * - LOADER = True - * - MX = False - * - ON_DEMAND = False - * - * Commandline: - * --api='wgl=1.0' --extensions='WGL_ARB_create_context,WGL_ARB_create_context_profile,WGL_ARB_extensions_string,WGL_EXT_extensions_string' c --loader - * - * Online: - * http://glad.sh/#api=wgl%3D1.0&extensions=WGL_ARB_create_context%2CWGL_ARB_create_context_profile%2CWGL_ARB_extensions_string%2CWGL_EXT_extensions_string&generator=c&options=LOADER - * - */ - -#ifndef GLAD_WGL_H_ -#define GLAD_WGL_H_ - -#include -#include - -#define GLAD_WGL -#define GLAD_OPTION_WGL_LOADER - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef GLAD_PLATFORM_H_ -#define GLAD_PLATFORM_H_ - -#ifndef GLAD_PLATFORM_WIN32 - #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__MINGW32__) - #define GLAD_PLATFORM_WIN32 1 - #else - #define GLAD_PLATFORM_WIN32 0 - #endif -#endif - -#ifndef GLAD_PLATFORM_APPLE - #ifdef __APPLE__ - #define GLAD_PLATFORM_APPLE 1 - #else - #define GLAD_PLATFORM_APPLE 0 - #endif -#endif - -#ifndef GLAD_PLATFORM_EMSCRIPTEN - #ifdef __EMSCRIPTEN__ - #define GLAD_PLATFORM_EMSCRIPTEN 1 - #else - #define GLAD_PLATFORM_EMSCRIPTEN 0 - #endif -#endif - -#ifndef GLAD_PLATFORM_UWP - #if defined(_MSC_VER) && !defined(GLAD_INTERNAL_HAVE_WINAPIFAMILY) - #ifdef __has_include - #if __has_include() - #define GLAD_INTERNAL_HAVE_WINAPIFAMILY 1 - #endif - #elif _MSC_VER >= 1700 && !_USING_V110_SDK71_ - #define GLAD_INTERNAL_HAVE_WINAPIFAMILY 1 - #endif - #endif - - #ifdef GLAD_INTERNAL_HAVE_WINAPIFAMILY - #include - #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) - #define GLAD_PLATFORM_UWP 1 - #endif - #endif - - #ifndef GLAD_PLATFORM_UWP - #define GLAD_PLATFORM_UWP 0 - #endif -#endif - -#ifdef __GNUC__ - #define GLAD_GNUC_EXTENSION __extension__ -#else - #define GLAD_GNUC_EXTENSION -#endif - -#define GLAD_UNUSED(x) (void)(x) - -#ifndef GLAD_API_CALL - #if defined(GLAD_API_CALL_EXPORT) - #if GLAD_PLATFORM_WIN32 || defined(__CYGWIN__) - #if defined(GLAD_API_CALL_EXPORT_BUILD) - #if defined(__GNUC__) - #define GLAD_API_CALL __attribute__ ((dllexport)) extern - #else - #define GLAD_API_CALL __declspec(dllexport) extern - #endif - #else - #if defined(__GNUC__) - #define GLAD_API_CALL __attribute__ ((dllimport)) extern - #else - #define GLAD_API_CALL __declspec(dllimport) extern - #endif - #endif - #elif defined(__GNUC__) && defined(GLAD_API_CALL_EXPORT_BUILD) - #define GLAD_API_CALL __attribute__ ((visibility ("default"))) extern - #else - #define GLAD_API_CALL extern - #endif - #else - #define GLAD_API_CALL extern - #endif -#endif - -#ifdef APIENTRY - #define GLAD_API_PTR APIENTRY -#elif GLAD_PLATFORM_WIN32 - #define GLAD_API_PTR __stdcall -#else - #define GLAD_API_PTR -#endif - -#ifndef GLAPI -#define GLAPI GLAD_API_CALL -#endif - -#ifndef GLAPIENTRY -#define GLAPIENTRY GLAD_API_PTR -#endif - -#define GLAD_MAKE_VERSION(major, minor) (major * 10000 + minor) -#define GLAD_VERSION_MAJOR(version) (version / 10000) -#define GLAD_VERSION_MINOR(version) (version % 10000) - -#define GLAD_GENERATOR_VERSION "2.0.4" - -typedef void (*GLADapiproc)(void); - -typedef GLADapiproc (*GLADloadfunc)(const char *name); -typedef GLADapiproc (*GLADuserptrloadfunc)(void *userptr, const char *name); - -typedef void (*GLADprecallback)(const char *name, GLADapiproc apiproc, int len_args, ...); -typedef void (*GLADpostcallback)(void *ret, const char *name, GLADapiproc apiproc, int len_args, ...); - -#endif /* GLAD_PLATFORM_H_ */ - -#define ERROR_INVALID_PROFILE_ARB 0x2096 -#define ERROR_INVALID_VERSION_ARB 0x2095 -#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 -#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 -#define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001 -#define WGL_CONTEXT_FLAGS_ARB 0x2094 -#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 -#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 -#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 -#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 -#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 -#define WGL_FONT_LINES 0 -#define WGL_FONT_POLYGONS 1 -#define WGL_SWAP_MAIN_PLANE 0x00000001 -#define WGL_SWAP_OVERLAY1 0x00000002 -#define WGL_SWAP_OVERLAY10 0x00000400 -#define WGL_SWAP_OVERLAY11 0x00000800 -#define WGL_SWAP_OVERLAY12 0x00001000 -#define WGL_SWAP_OVERLAY13 0x00002000 -#define WGL_SWAP_OVERLAY14 0x00004000 -#define WGL_SWAP_OVERLAY15 0x00008000 -#define WGL_SWAP_OVERLAY2 0x00000004 -#define WGL_SWAP_OVERLAY3 0x00000008 -#define WGL_SWAP_OVERLAY4 0x00000010 -#define WGL_SWAP_OVERLAY5 0x00000020 -#define WGL_SWAP_OVERLAY6 0x00000040 -#define WGL_SWAP_OVERLAY7 0x00000080 -#define WGL_SWAP_OVERLAY8 0x00000100 -#define WGL_SWAP_OVERLAY9 0x00000200 -#define WGL_SWAP_UNDERLAY1 0x00010000 -#define WGL_SWAP_UNDERLAY10 0x02000000 -#define WGL_SWAP_UNDERLAY11 0x04000000 -#define WGL_SWAP_UNDERLAY12 0x08000000 -#define WGL_SWAP_UNDERLAY13 0x10000000 -#define WGL_SWAP_UNDERLAY14 0x20000000 -#define WGL_SWAP_UNDERLAY15 0x40000000 -#define WGL_SWAP_UNDERLAY2 0x00020000 -#define WGL_SWAP_UNDERLAY3 0x00040000 -#define WGL_SWAP_UNDERLAY4 0x00080000 -#define WGL_SWAP_UNDERLAY5 0x00100000 -#define WGL_SWAP_UNDERLAY6 0x00200000 -#define WGL_SWAP_UNDERLAY7 0x00400000 -#define WGL_SWAP_UNDERLAY8 0x00800000 -#define WGL_SWAP_UNDERLAY9 0x01000000 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -struct _GPU_DEVICE { - DWORD cb; - CHAR DeviceName[32]; - CHAR DeviceString[128]; - DWORD Flags; - RECT rcVirtualScreen; -}; -DECLARE_HANDLE(HPBUFFERARB); -DECLARE_HANDLE(HPBUFFEREXT); -DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV); -DECLARE_HANDLE(HPVIDEODEV); -DECLARE_HANDLE(HPGPUNV); -DECLARE_HANDLE(HGPUNV); -DECLARE_HANDLE(HVIDEOINPUTDEVICENV); -typedef struct _GPU_DEVICE GPU_DEVICE; -typedef struct _GPU_DEVICE *PGPU_DEVICE; - - -#define WGL_VERSION_1_0 1 -GLAD_API_CALL int GLAD_WGL_VERSION_1_0; -#define WGL_ARB_create_context 1 -GLAD_API_CALL int GLAD_WGL_ARB_create_context; -#define WGL_ARB_create_context_profile 1 -GLAD_API_CALL int GLAD_WGL_ARB_create_context_profile; -#define WGL_ARB_extensions_string 1 -GLAD_API_CALL int GLAD_WGL_ARB_extensions_string; -#define WGL_EXT_extensions_string 1 -GLAD_API_CALL int GLAD_WGL_EXT_extensions_string; - - -typedef int (GLAD_API_PTR *PFNCHOOSEPIXELFORMATPROC)(HDC hDc, const PIXELFORMATDESCRIPTOR * pPfd); -typedef int (GLAD_API_PTR *PFNDESCRIBEPIXELFORMATPROC)(HDC hdc, int ipfd, UINT cjpfd, PIXELFORMATDESCRIPTOR * ppfd); -typedef UINT (GLAD_API_PTR *PFNGETENHMETAFILEPIXELFORMATPROC)(HENHMETAFILE hemf, UINT cbBuffer, PIXELFORMATDESCRIPTOR * ppfd); -typedef int (GLAD_API_PTR *PFNGETPIXELFORMATPROC)(HDC hdc); -typedef BOOL (GLAD_API_PTR *PFNSETPIXELFORMATPROC)(HDC hdc, int ipfd, const PIXELFORMATDESCRIPTOR * ppfd); -typedef BOOL (GLAD_API_PTR *PFNSWAPBUFFERSPROC)(HDC hdc); -typedef BOOL (GLAD_API_PTR *PFNWGLCOPYCONTEXTPROC)(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask); -typedef HGLRC (GLAD_API_PTR *PFNWGLCREATECONTEXTPROC)(HDC hDc); -typedef HGLRC (GLAD_API_PTR *PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC hDC, HGLRC hShareContext, const int * attribList); -typedef HGLRC (GLAD_API_PTR *PFNWGLCREATELAYERCONTEXTPROC)(HDC hDc, int level); -typedef BOOL (GLAD_API_PTR *PFNWGLDELETECONTEXTPROC)(HGLRC oldContext); -typedef BOOL (GLAD_API_PTR *PFNWGLDESCRIBELAYERPLANEPROC)(HDC hDc, int pixelFormat, int layerPlane, UINT nBytes, LAYERPLANEDESCRIPTOR * plpd); -typedef HGLRC (GLAD_API_PTR *PFNWGLGETCURRENTCONTEXTPROC)(void); -typedef HDC (GLAD_API_PTR *PFNWGLGETCURRENTDCPROC)(void); -typedef const char * (GLAD_API_PTR *PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC hdc); -typedef const char * (GLAD_API_PTR *PFNWGLGETEXTENSIONSSTRINGEXTPROC)(void); -typedef int (GLAD_API_PTR *PFNWGLGETLAYERPALETTEENTRIESPROC)(HDC hdc, int iLayerPlane, int iStart, int cEntries, COLORREF * pcr); -typedef PROC (GLAD_API_PTR *PFNWGLGETPROCADDRESSPROC)(LPCSTR lpszProc); -typedef BOOL (GLAD_API_PTR *PFNWGLMAKECURRENTPROC)(HDC hDc, HGLRC newContext); -typedef BOOL (GLAD_API_PTR *PFNWGLREALIZELAYERPALETTEPROC)(HDC hdc, int iLayerPlane, BOOL bRealize); -typedef int (GLAD_API_PTR *PFNWGLSETLAYERPALETTEENTRIESPROC)(HDC hdc, int iLayerPlane, int iStart, int cEntries, const COLORREF * pcr); -typedef BOOL (GLAD_API_PTR *PFNWGLSHARELISTSPROC)(HGLRC hrcSrvShare, HGLRC hrcSrvSource); -typedef BOOL (GLAD_API_PTR *PFNWGLSWAPLAYERBUFFERSPROC)(HDC hdc, UINT fuFlags); -typedef BOOL (GLAD_API_PTR *PFNWGLUSEFONTBITMAPSPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase); -typedef BOOL (GLAD_API_PTR *PFNWGLUSEFONTBITMAPSAPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase); -typedef BOOL (GLAD_API_PTR *PFNWGLUSEFONTBITMAPSWPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase); -typedef BOOL (GLAD_API_PTR *PFNWGLUSEFONTOUTLINESPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf); -typedef BOOL (GLAD_API_PTR *PFNWGLUSEFONTOUTLINESAPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf); -typedef BOOL (GLAD_API_PTR *PFNWGLUSEFONTOUTLINESWPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf); - -GLAD_API_CALL PFNWGLCREATECONTEXTATTRIBSARBPROC glad_wglCreateContextAttribsARB; -#define wglCreateContextAttribsARB glad_wglCreateContextAttribsARB -GLAD_API_CALL PFNWGLGETEXTENSIONSSTRINGARBPROC glad_wglGetExtensionsStringARB; -#define wglGetExtensionsStringARB glad_wglGetExtensionsStringARB -GLAD_API_CALL PFNWGLGETEXTENSIONSSTRINGEXTPROC glad_wglGetExtensionsStringEXT; -#define wglGetExtensionsStringEXT glad_wglGetExtensionsStringEXT - - - - - -GLAD_API_CALL int gladLoadWGLUserPtr(HDC hdc, GLADuserptrloadfunc load, void *userptr); -GLAD_API_CALL int gladLoadWGL(HDC hdc, GLADloadfunc load); - -#ifdef GLAD_WGL - -GLAD_API_CALL int gladLoaderLoadWGL(HDC hdc); - -#endif -#ifdef __cplusplus -} -#endif -#endif diff --git a/core/deps/glad/src/wgl.c b/core/deps/glad/src/wgl.c deleted file mode 100644 index 0dcefcc9b4..0000000000 --- a/core/deps/glad/src/wgl.c +++ /dev/null @@ -1,143 +0,0 @@ -/** - * SPDX-License-Identifier: (WTFPL OR CC0-1.0) AND Apache-2.0 - */ -#include -#include -#include -#include - -#ifndef GLAD_IMPL_UTIL_C_ -#define GLAD_IMPL_UTIL_C_ - -#ifdef _MSC_VER -#define GLAD_IMPL_UTIL_SSCANF sscanf_s -#else -#define GLAD_IMPL_UTIL_SSCANF sscanf -#endif - -#endif /* GLAD_IMPL_UTIL_C_ */ - -#ifdef __cplusplus -extern "C" { -#endif - - - -int GLAD_WGL_VERSION_1_0 = 0; -int GLAD_WGL_ARB_create_context = 0; -int GLAD_WGL_ARB_create_context_profile = 0; -int GLAD_WGL_ARB_extensions_string = 0; -int GLAD_WGL_EXT_extensions_string = 0; - - - -PFNWGLCREATECONTEXTATTRIBSARBPROC glad_wglCreateContextAttribsARB = NULL; -PFNWGLGETEXTENSIONSSTRINGARBPROC glad_wglGetExtensionsStringARB = NULL; -PFNWGLGETEXTENSIONSSTRINGEXTPROC glad_wglGetExtensionsStringEXT = NULL; - - -static void glad_wgl_load_WGL_ARB_create_context(GLADuserptrloadfunc load, void *userptr) { - if(!GLAD_WGL_ARB_create_context) return; - glad_wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) load(userptr, "wglCreateContextAttribsARB"); -} -static void glad_wgl_load_WGL_ARB_extensions_string(GLADuserptrloadfunc load, void *userptr) { - if(!GLAD_WGL_ARB_extensions_string) return; - glad_wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) load(userptr, "wglGetExtensionsStringARB"); -} -static void glad_wgl_load_WGL_EXT_extensions_string(GLADuserptrloadfunc load, void *userptr) { - if(!GLAD_WGL_EXT_extensions_string) return; - glad_wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC) load(userptr, "wglGetExtensionsStringEXT"); -} - - - -static int glad_wgl_has_extension(HDC hdc, const char *ext) { - const char *terminator; - const char *loc; - const char *extensions; - - if(wglGetExtensionsStringEXT == NULL && wglGetExtensionsStringARB == NULL) - return 0; - - if(wglGetExtensionsStringARB == NULL || hdc == INVALID_HANDLE_VALUE) - extensions = wglGetExtensionsStringEXT(); - else - extensions = wglGetExtensionsStringARB(hdc); - - if(extensions == NULL || ext == NULL) - return 0; - - while(1) { - loc = strstr(extensions, ext); - if(loc == NULL) - break; - - terminator = loc + strlen(ext); - if((loc == extensions || *(loc - 1) == ' ') && - (*terminator == ' ' || *terminator == '\0')) - { - return 1; - } - extensions = terminator; - } - - return 0; -} - -static GLADapiproc glad_wgl_get_proc_from_userptr(void *userptr, const char* name) { - return (GLAD_GNUC_EXTENSION (GLADapiproc (*)(const char *name)) userptr)(name); -} - -static int glad_wgl_find_extensions_wgl(HDC hdc) { - GLAD_WGL_ARB_create_context = glad_wgl_has_extension(hdc, "WGL_ARB_create_context"); - GLAD_WGL_ARB_create_context_profile = glad_wgl_has_extension(hdc, "WGL_ARB_create_context_profile"); - GLAD_WGL_ARB_extensions_string = glad_wgl_has_extension(hdc, "WGL_ARB_extensions_string"); - GLAD_WGL_EXT_extensions_string = glad_wgl_has_extension(hdc, "WGL_EXT_extensions_string"); - return 1; -} - -static int glad_wgl_find_core_wgl(void) { - int major = 1, minor = 0; - GLAD_WGL_VERSION_1_0 = (major == 1 && minor >= 0) || major > 1; - return GLAD_MAKE_VERSION(major, minor); -} - -int gladLoadWGLUserPtr(HDC hdc, GLADuserptrloadfunc load, void *userptr) { - int version; - wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) load(userptr, "wglGetExtensionsStringARB"); - wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC) load(userptr, "wglGetExtensionsStringEXT"); - if(wglGetExtensionsStringARB == NULL && wglGetExtensionsStringEXT == NULL) return 0; - version = glad_wgl_find_core_wgl(); - - - if (!glad_wgl_find_extensions_wgl(hdc)) return 0; - glad_wgl_load_WGL_ARB_create_context(load, userptr); - glad_wgl_load_WGL_ARB_extensions_string(load, userptr); - glad_wgl_load_WGL_EXT_extensions_string(load, userptr); - - - return version; -} - -int gladLoadWGL(HDC hdc, GLADloadfunc load) { - return gladLoadWGLUserPtr(hdc, glad_wgl_get_proc_from_userptr, GLAD_GNUC_EXTENSION (void*) load); -} - - -#ifdef GLAD_WGL - -static GLADapiproc glad_wgl_get_proc(void *vuserptr, const char* name) { - GLAD_UNUSED(vuserptr); - return GLAD_GNUC_EXTENSION (GLADapiproc) wglGetProcAddress(name); -} - -int gladLoaderLoadWGL(HDC hdc) { - return gladLoadWGLUserPtr(hdc, glad_wgl_get_proc, NULL); -} - - -#endif /* GLAD_WGL */ - -#ifdef __cplusplus -} -#endif diff --git a/core/windows/win_keyboard.h b/core/windows/win_keyboard.h deleted file mode 100644 index 4897d6ebc3..0000000000 --- a/core/windows/win_keyboard.h +++ /dev/null @@ -1,151 +0,0 @@ -#pragma once -#include "input/keyboard_device.h" - -#include - -// Used to differentiate between main enter key and num keypad one -#define VK_NUMPAD_RETURN 0x0E - -class Win32KeyboardDevice : public KeyboardDevice -{ -public: - Win32KeyboardDevice(int maple_port) : KeyboardDevice(maple_port, "win32") - { - kb_map['A'] = 0x04; - kb_map['B'] = 0x05; - kb_map['C'] = 0x06; - kb_map['D'] = 0x07; - kb_map['E'] = 0x08; - kb_map['F'] = 0x09; - kb_map['G'] = 0x0A; - kb_map['H'] = 0x0B; - kb_map['I'] = 0x0C; - kb_map['J'] = 0x0D; - kb_map['K'] = 0x0E; - kb_map['L'] = 0x0F; - kb_map['M'] = 0x10; - kb_map['N'] = 0x11; - kb_map['O'] = 0x12; - kb_map['P'] = 0x13; - kb_map['Q'] = 0x14; - kb_map['R'] = 0x15; - kb_map['S'] = 0x16; - kb_map['T'] = 0x17; - kb_map['U'] = 0x18; - kb_map['V'] = 0x19; - kb_map['W'] = 0x1A; - kb_map['X'] = 0x1B; - kb_map['Y'] = 0x1C; - kb_map['Z'] = 0x1D; - - //1E-27 Number keys 1-0 - kb_map['1'] = 0x1E; - kb_map['2'] = 0x1F; - kb_map['3'] = 0x20; - kb_map['4'] = 0x21; - kb_map['5'] = 0x22; - kb_map['6'] = 0x23; - kb_map['7'] = 0x24; - kb_map['8'] = 0x25; - kb_map['9'] = 0x26; - kb_map['0'] = 0x27; - - kb_map[VK_RETURN] = 0x28; - kb_map[VK_ESCAPE] = 0x29; - kb_map[VK_BACK] = 0x2A; - kb_map[VK_TAB] = 0x2B; - kb_map[VK_SPACE] = 0x2C; - - kb_map[VK_OEM_MINUS] = 0x2D; // - - kb_map[VK_OEM_PLUS] = 0x2E; // = - kb_map[VK_OEM_4] = 0x2F; // [ - kb_map[VK_OEM_6] = 0x30; // ] - - kb_map[VK_OEM_5] = 0x31; // \ (US) unsure of keycode - - //32-34 "]", ";" and ":" (the 3 keys right of L) - kb_map[VK_OEM_8] = 0x32; // ~ (non-US) *,ยต in FR layout - kb_map[VK_OEM_1] = 0x33; // ; - kb_map[VK_OEM_7] = 0x34; // ' - - //35 hankaku/zenkaku / kanji (top left) - kb_map[VK_OEM_3] = 0x35; // `~ (US) - - //36-38 ",", "." and "/" (the 3 keys right of M) - kb_map[VK_OEM_COMMA] = 0x36; - kb_map[VK_OEM_PERIOD] = 0x37; - kb_map[VK_OEM_2] = 0x38; - - // CAPSLOCK - kb_map[VK_CAPITAL] = 0x39; - - //3A-45 Function keys F1-F12 - for (int i = 0;i < 12; i++) - kb_map[VK_F1 + i] = 0x3A + i; - - //46-4E Control keys above cursor keys - kb_map[VK_SNAPSHOT] = 0x46; // Print Screen - kb_map[VK_SCROLL] = 0x47; // Scroll Lock - kb_map[VK_PAUSE] = 0x48; // Pause - kb_map[VK_INSERT] = 0x49; - kb_map[VK_HOME] = 0x4A; - kb_map[VK_PRIOR] = 0x4B; - kb_map[VK_DELETE] = 0x4C; - kb_map[VK_END] = 0x4D; - kb_map[VK_NEXT] = 0x4E; - - //4F-52 Cursor keys - kb_map[VK_RIGHT] = 0x4F; - kb_map[VK_LEFT] = 0x50; - kb_map[VK_DOWN] = 0x51; - kb_map[VK_UP] = 0x52; - - //53 Num Lock (Numeric keypad) - kb_map[VK_NUMLOCK] = 0x53; - //54 "/" (Numeric keypad) - kb_map[VK_DIVIDE] = 0x54; - //55 "*" (Numeric keypad) - kb_map[VK_MULTIPLY] = 0x55; - //56 "-" (Numeric keypad) - kb_map[VK_SUBTRACT] = 0x56; - //57 "+" (Numeric keypad) - kb_map[VK_ADD] = 0x57; - //58 Enter (Numeric keypad) - kb_map[VK_NUMPAD_RETURN] = 0x58; - //59-62 Number keys 1-0 (Numeric keypad) - kb_map[VK_NUMPAD1] = 0x59; - kb_map[VK_NUMPAD2] = 0x5A; - kb_map[VK_NUMPAD3] = 0x5B; - kb_map[VK_NUMPAD4] = 0x5C; - kb_map[VK_NUMPAD5] = 0x5D; - kb_map[VK_NUMPAD6] = 0x5E; - kb_map[VK_NUMPAD7] = 0x5F; - kb_map[VK_NUMPAD8] = 0x60; - kb_map[VK_NUMPAD9] = 0x61; - kb_map[VK_NUMPAD0] = 0x62; - //63 "." (Numeric keypad) - kb_map[VK_DECIMAL] = 0x63; - //64 #| (non-US) - //kb_map[94] = 0x64; - //65 S3 key - //66-A4 Not used - //A5-DF Reserved - kb_map[VK_CONTROL] = 0xE0; // Left Control - kb_map[VK_SHIFT] = 0xE1; // Left Shift - //E2 Left Alt - //E3 Left S1 - //E4 Right Control - //E5 Right Shift - //E6 Right Alt - //E7 Right S3 - //E8-FF Reserved - - } - - void input(u8 keycode, bool pressed) { - KeyboardDevice::input(kb_map[keycode], pressed, 0); - } - -private: - std::map kb_map; -}; diff --git a/core/windows/winmain.cpp b/core/windows/winmain.cpp index d4e3fe7a9d..771d732232 100644 --- a/core/windows/winmain.cpp +++ b/core/windows/winmain.cpp @@ -26,23 +26,18 @@ #include #include #include +#include "cfg/option.h" +#include "rend/gui.h" +#else +#include "rawinput.h" #endif #include "oslib/oslib.h" -#include "imgread/common.h" #include "stdclass.h" #include "cfg/cfg.h" -#include "win_keyboard.h" #include "log/LogManager.h" -#include "wsi/context.h" -#if defined(USE_SDL) #include "sdl/sdl.h" -#else -#include "xinput_gamepad.h" -#endif #include "emulator.h" #include "rend/mainui.h" -#include "../shell/windows/resource.h" -#include "rawinput.h" #include "oslib/directory.h" #ifdef USE_BREAKPAD #include "breakpad/client/windows/handler/exception_handler.h" @@ -50,172 +45,16 @@ #endif #include "profiler/fc_profiler.h" -#if defined(USE_SDL) || defined(DEF_CONSOLE) #include -#endif #include #include #include -#if !defined(USE_SDL) && !defined(DEF_CONSOLE) -static PCHAR* - commandLineToArgvA( - PCHAR CmdLine, - int* _argc - ) -{ - PCHAR* argv; - PCHAR _argv; - ULONG len; - ULONG argc; - CHAR a; - ULONG i, j; - - BOOLEAN in_QM; - BOOLEAN in_TEXT; - BOOLEAN in_SPACE; - - len = strlen(CmdLine); - i = ((len+2)/2)*sizeof(PVOID) + sizeof(PVOID); - - argv = (PCHAR*)GlobalAlloc(GMEM_FIXED, - i + (len+2)*sizeof(CHAR)); - - _argv = (PCHAR)(((PUCHAR)argv)+i); - - argc = 0; - argv[argc] = _argv; - in_QM = FALSE; - in_TEXT = FALSE; - in_SPACE = TRUE; - i = 0; - j = 0; - - while ((a = CmdLine[i]) != 0) - { - if(in_QM) - { - if(a == '\"') - { - in_QM = FALSE; - } - else - { - _argv[j] = a; - j++; - } - } - else - { - switch(a) - { - case '\"': - in_QM = TRUE; - in_TEXT = TRUE; - if(in_SPACE) { - argv[argc] = _argv+j; - argc++; - } - in_SPACE = FALSE; - break; - case ' ': - case '\t': - case '\n': - case '\r': - if(in_TEXT) - { - _argv[j] = '\0'; - j++; - } - in_TEXT = FALSE; - in_SPACE = TRUE; - break; - default: - in_TEXT = TRUE; - if(in_SPACE) - { - argv[argc] = _argv+j; - argc++; - } - _argv[j] = a; - j++; - in_SPACE = FALSE; - break; - } - } - i++; - } - _argv[j] = '\0'; - argv[argc] = NULL; - - (*_argc) = argc; - return argv; -} -#endif - -#ifndef USE_SDL - -static std::shared_ptr mouse; -static std::shared_ptr keyboard; -static bool mouseCaptured; -static POINT savedMousePos; -static bool gameRunning; - -static void captureMouse(bool); - -static void emuEventCallback(Event event, void *) -{ - static bool captureOn; - switch (event) - { - case Event::Pause: - captureOn = mouseCaptured; - captureMouse(false); - gameRunning = false; - break; - case Event::Resume: - gameRunning = true; - captureMouse(captureOn); - break; - default: - break; - } -} - -static void checkRawInput() -{ - if ((bool)config::UseRawInput != (bool)keyboard) - return; - if (config::UseRawInput) - { - GamepadDevice::Unregister(keyboard); - keyboard = nullptr;; - GamepadDevice::Unregister(mouse); - mouse = nullptr; - rawinput::init(); - } - else - { - rawinput::term(); - keyboard = std::make_shared(0); - GamepadDevice::Register(keyboard); - mouse = std::make_shared(); - GamepadDevice::Register(mouse); - } -} -#endif - void os_SetupInput() { -#if defined(USE_SDL) input_sdl_init(); -#else - XInputGamepadDevice::CreateDevices(); - EventManager::listen(Event::Pause, emuEventCallback); - EventManager::listen(Event::Resume, emuEventCallback); - checkRawInput(); -#endif + #ifndef TARGET_UWP if (config::UseRawInput) rawinput::init(); @@ -224,9 +63,8 @@ void os_SetupInput() void os_TermInput() { -#if defined(USE_SDL) input_sdl_quit(); -#endif + #ifndef TARGET_UWP if (config::UseRawInput) rawinput::term(); @@ -276,328 +114,17 @@ void UpdateInputState() { FC_PROFILE_SCOPE; -#if defined(USE_SDL) input_sdl_handle(); -#else - for (int port = 0; port < 4; port++) - { - std::shared_ptr gamepad = XInputGamepadDevice::GetXInputDevice(port); - if (gamepad != nullptr) - gamepad->ReadInput(); - } -#endif -} - -#ifndef USE_SDL -static HWND hWnd; - -// Windows class name to register -#define WINDOW_CLASS "nilDC" -static int window_x, window_y; - -// Width and height of the window -#define DEFAULT_WINDOW_WIDTH 1280 -#define DEFAULT_WINDOW_HEIGHT 720 -static bool window_maximized = false; - -static void centerMouse() -{ - RECT rect; - GetWindowRect(hWnd, &rect); - SetCursorPos((rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2); -} - -static void captureMouse(bool capture) -{ - if (hWnd == nullptr || !gameRunning) - return; - if (capture == mouseCaptured) - return; - - if (!capture) - { - os_SetWindowText(VER_EMUNAME); - mouseCaptured = false; - SetCursorPos(savedMousePos.x, savedMousePos.y); - while (ShowCursor(true) < 0) - ; - } - else - { - os_SetWindowText("Flycast - mouse capture"); - mouseCaptured = true; - GetCursorPos(&savedMousePos); - while (ShowCursor(false) >= 0) - ; - centerMouse(); - } -} - -static void toggleFullscreen(); - -static LRESULT CALLBACK WndProc2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) - { - /* - Here we are handling 2 system messages: screen saving and monitor power. - They are especially relevant on mobile devices. - */ - case WM_SYSCOMMAND: - { - switch (wParam) - { - case SC_SCREENSAVE: // Screensaver trying to start ? - case SC_MONITORPOWER: // Monitor trying to enter powersave ? - return 0; // Prevent this from happening - } - break; - } - // Handles the close message when a user clicks the quit icon of the window - case WM_CLOSE: - PostQuitMessage(0); - return 1; - - case WM_SIZE: - settings.display.width = LOWORD(lParam); - settings.display.height = HIWORD(lParam); - window_maximized = (wParam & SIZE_MAXIMIZED) != 0; - if (GraphicsContext::Instance()) - GraphicsContext::Instance()->resize(); - return 0; - - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - gui_set_mouse_position(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); - checkRawInput(); - switch (message) - { - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - if (!mouseCaptured && !config::UseRawInput) - mouse->setButton(Mouse::LEFT_BUTTON, message == WM_LBUTTONDOWN); - gui_set_mouse_button(0, message == WM_LBUTTONDOWN); - break; - - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - if (!mouseCaptured && !config::UseRawInput) - mouse->setButton(Mouse::MIDDLE_BUTTON, message == WM_MBUTTONDOWN); - gui_set_mouse_button(2, message == WM_MBUTTONDOWN); - break; - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - if (!mouseCaptured && !config::UseRawInput) - mouse->setButton(Mouse::RIGHT_BUTTON, message == WM_RBUTTONDOWN); - gui_set_mouse_button(1, message == WM_RBUTTONDOWN); - break; - } - if (mouseCaptured) - break; - /* no break */ - case WM_MOUSEMOVE: - gui_set_mouse_position(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); - checkRawInput(); - if (mouseCaptured) - // TODO relative mouse move if !rawinput - centerMouse(); - else if (!config::UseRawInput) - { - int xPos = GET_X_LPARAM(lParam); - int yPos = GET_Y_LPARAM(lParam); - mouse->setAbsPos(xPos, yPos, settings.display.width, settings.display.height); - - if (wParam & MK_LBUTTON) - mouse->setButton(Mouse::LEFT_BUTTON, true); - if (wParam & MK_MBUTTON) - mouse->setButton(Mouse::MIDDLE_BUTTON, true); - if (wParam & MK_RBUTTON) - mouse->setButton(Mouse::RIGHT_BUTTON, true); - } - if (message != WM_MOUSEMOVE) - return 0; - break; - case WM_MOUSEWHEEL: - gui_set_mouse_wheel(-(float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA * 16); - checkRawInput(); - if (!config::UseRawInput) - mouse->setWheel(-GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA); - break; - - case WM_KEYDOWN: - case WM_KEYUP: - { - if (message == WM_KEYDOWN - && ((wParam == VK_CONTROL && GetAsyncKeyState(VK_LMENU) < 0) - || (wParam == VK_MENU && GetAsyncKeyState(VK_LCONTROL) < 0))) - { - captureMouse(!mouseCaptured); - break; - } - checkRawInput(); - if (!config::UseRawInput) - { - u8 keycode; - // bit 24 indicates whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. - // (It also distinguishes between the main Return key and the numeric keypad Enter key) - // The value is 1 if it is an extended key; otherwise, it is 0. - if (wParam == VK_RETURN && ((lParam & (1 << 24)) != 0)) - keycode = VK_NUMPAD_RETURN; - else - keycode = wParam & 0xff; - keyboard->input(keycode, message == WM_KEYDOWN); - } - } - break; - - case WM_SYSKEYDOWN: - if (wParam == VK_RETURN) - { - if ((HIWORD(lParam) & KF_ALTDOWN)) - toggleFullscreen(); - } - else if (wParam == VK_CONTROL && (lParam & (1 << 24)) == 0 && GetAsyncKeyState(VK_LMENU) < 0) - { - captureMouse(!mouseCaptured); - } - break; - - case WM_CHAR: - gui_keyboard_input((u16)wParam); - return 0; - - default: - break; - } - - // Calls the default window procedure for messages we did not handle - return DefWindowProc(hWnd, message, wParam, lParam); -} - -static bool windowClassRegistered; - -void CreateMainWindow() -{ - if (hWnd != NULL) - return; - HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(0); - if (!windowClassRegistered) - { - WNDCLASS sWC; - sWC.style = CS_HREDRAW | CS_VREDRAW; - sWC.lpfnWndProc = WndProc2; - sWC.cbClsExtra = 0; - sWC.cbWndExtra = 0; - sWC.hInstance = hInstance; - sWC.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); - sWC.hCursor = LoadCursor(NULL, IDC_ARROW); - sWC.lpszMenuName = 0; - sWC.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); - sWC.lpszClassName = WINDOW_CLASS; - ATOM registerClass = RegisterClass(&sWC); - if (!registerClass) - MessageBox(0, "Failed to register the window class", "Error", MB_OK | MB_ICONEXCLAMATION); - else - windowClassRegistered = true; - settings.display.width = cfgLoadInt("window", "width", DEFAULT_WINDOW_WIDTH); - settings.display.height = cfgLoadInt("window", "height", DEFAULT_WINDOW_HEIGHT); - window_maximized = cfgLoadBool("window", "maximized", false); - } - - // Create the eglWindow - RECT sRect; - SetRect(&sRect, 0, 0, settings.display.width, settings.display.height); - AdjustWindowRectEx(&sRect, WS_OVERLAPPEDWINDOW, false, 0); - - hWnd = CreateWindow(WINDOW_CLASS, VER_EMUNAME, WS_VISIBLE | WS_OVERLAPPEDWINDOW | (window_maximized ? WS_MAXIMIZE : 0), - window_x, window_y, sRect.right - sRect.left, sRect.bottom - sRect.top, NULL, NULL, hInstance, NULL); - if (GraphicsContext::Instance() != nullptr) - GraphicsContext::Instance()->setWindow((void *)hWnd, (void *)GetDC((HWND)hWnd)); } -#endif void os_CreateWindow() { -#if defined(USE_SDL) sdl_window_create(); -#else - CreateMainWindow(); - initRenderApi((void *)hWnd, (void *)GetDC((HWND)hWnd)); -#endif // !USE_SDL } -#ifndef USE_SDL -static void destroyMainWindow() -{ - if (hWnd) - { - WINDOWPLACEMENT placement; - placement.length = sizeof(WINDOWPLACEMENT); - GetWindowPlacement(hWnd, &placement); - window_maximized = placement.showCmd == SW_SHOWMAXIMIZED; - window_x = placement.rcNormalPosition.left; - window_y = placement.rcNormalPosition.top; - DestroyWindow(hWnd); - hWnd = NULL; - } -} - -static void toggleFullscreen() -{ - static RECT rSaved; - static bool fullscreen=false; - - fullscreen = !fullscreen; - - - if (fullscreen) - { - GetWindowRect(hWnd, &rSaved); - - MONITORINFO mi = { sizeof(mi) }; - HMONITOR hmon = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); - if (GetMonitorInfo(hmon, &mi)) { - - SetWindowLongPtr(hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST); - SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP | WS_VISIBLE); - - SetWindowPos(hWnd, HWND_TOPMOST, mi.rcMonitor.left, mi.rcMonitor.top, - mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, - SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_ASYNCWINDOWPOS); - } - } - else { - - SetWindowLongPtr(hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST); - SetWindowLongPtr(hWnd, GWL_STYLE, WS_VISIBLE | WS_OVERLAPPEDWINDOW | (window_maximized ? WS_MAXIMIZE : 0)); - - SetWindowPos(hWnd, NULL, rSaved.left, rSaved.top, - rSaved.right - rSaved.left, rSaved.bottom - rSaved.top, - SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_ASYNCWINDOWPOS|SWP_NOZORDER); - } - -} - -HWND getNativeHwnd() -{ - return hWnd; -} -#endif - void os_SetWindowText(const char* text) { -#if defined(USE_SDL) sdl_window_set_text(text); -#else - if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_BORDER) - { - SetWindowText(hWnd, text); - } -#endif } static void reserveBottomMemory() @@ -852,33 +379,10 @@ int remove(char const *name) } #endif -#ifdef USE_SDL int main(int argc, char* argv[]) { nowide::args _(argc, argv); -#elif defined(DEF_CONSOLE) -// DEF_CONSOLE allows you to override linker subsystem and therefore default console -// : pragma isn't pretty but def's are configurable -#pragma comment(linker, "/subsystem:console") - -int main(int argc, char** argv) -{ - nowide::args _(argc, argv); - -#else -#pragma comment(linker, "/subsystem:windows") - -int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShowCmd) -{ - wchar_t *cmd_line = GetCommandLineW(); - nowide::stackstring converter; - int argc = 0; - char **argv = nullptr; - if (converter.convert(cmd_line)) - argv = commandLineToArgvA(converter.get(), &argc); -#endif - #ifdef USE_BREAKPAD wchar_t tempDir[MAX_PATH + 1]; GetTempPathW(MAX_PATH + 1, tempDir); @@ -929,18 +433,7 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi mainui_loop(); -#ifdef USE_SDL sdl_window_destroy(); -#else - termRenderApi(); - destroyMainWindow(); - cfgSaveBool("window", "maximized", window_maximized); - if (!window_maximized && settings.display.width != 0 && settings.display.height != 0) - { - cfgSaveInt("window", "width", settings.display.width); - cfgSaveInt("window", "height", settings.display.height); - } -#endif flycast_term(); os_UninstallFaultHandler(); diff --git a/core/windows/xinput_gamepad.h b/core/windows/xinput_gamepad.h deleted file mode 100644 index a6243e8fe4..0000000000 --- a/core/windows/xinput_gamepad.h +++ /dev/null @@ -1,222 +0,0 @@ -#include "input/gamepad_device.h" -#include "input/mouse.h" - -#include -#include - -class XInputMapping : public InputMapping -{ -public: - XInputMapping() - { - name = "XInput"; - set_button(DC_BTN_A, XINPUT_GAMEPAD_A); - set_button(DC_BTN_B, XINPUT_GAMEPAD_B); - set_button(DC_BTN_X, XINPUT_GAMEPAD_X); - set_button(DC_BTN_Y, XINPUT_GAMEPAD_Y); - set_button(DC_DPAD_UP, XINPUT_GAMEPAD_DPAD_UP); - set_button(DC_DPAD_DOWN, XINPUT_GAMEPAD_DPAD_DOWN); - set_button(DC_DPAD_LEFT, XINPUT_GAMEPAD_DPAD_LEFT); - set_button(DC_DPAD_RIGHT, XINPUT_GAMEPAD_DPAD_RIGHT); - set_button(DC_BTN_START, XINPUT_GAMEPAD_START); - set_button(DC_AXIS_LT, XINPUT_GAMEPAD_LEFT_SHOULDER); - set_button(DC_AXIS_RT, XINPUT_GAMEPAD_RIGHT_SHOULDER); - set_button(EMU_BTN_MENU, XINPUT_GAMEPAD_BACK); - set_axis(DC_AXIS_LT, 0, false); - set_axis(DC_AXIS_RT, 1, false); - set_axis(DC_AXIS_LEFT, 2, false); - set_axis(DC_AXIS_RIGHT, 2, true); - set_axis(DC_AXIS_UP, 3, true); - set_axis(DC_AXIS_DOWN, 3, false); - set_axis(DC_AXIS2_LEFT, 4, false); - set_axis(DC_AXIS2_RIGHT, 4, true); - set_axis(DC_AXIS2_UP, 5, true); - set_axis(DC_AXIS2_DOWN, 5, false); - dirty = false; - } -}; - -class XInputGamepadDevice : public GamepadDevice -{ -public: - XInputGamepadDevice(int maple_port, int xinput_port) - : GamepadDevice(maple_port, "xinput"), _xinput_port(xinput_port) - { - char buf[32]; - sprintf(buf, "xinput-%d", xinput_port + 1); - _unique_id = buf; - hasAnalogStick = true; - } - - std::shared_ptr getDefaultMapping() override { - return std::make_shared(); - } - - void ReadInput() - { - update_rumble(); - - XINPUT_STATE state; - - if (XInputGetState(_xinput_port, &state) == 0) - { - if (!input_mapper) - Open(); - u32 xbutton = state.Gamepad.wButtons; - u32 changes = xbutton ^ last_buttons_state; - - for (int i = 0; i < 16; i++) - if ((changes & (1 << i)) != 0) - gamepad_btn_input(1 << i, (xbutton & (1 << i)) != 0); - last_buttons_state = xbutton; - - if (state.Gamepad.bLeftTrigger != last_left_trigger) - { - gamepad_axis_input(0, (state.Gamepad.bLeftTrigger << 7) + (state.Gamepad.bLeftTrigger >> 1)); - last_left_trigger = state.Gamepad.bLeftTrigger; - } - if (state.Gamepad.bRightTrigger != last_right_trigger) - { - gamepad_axis_input(1, (state.Gamepad.bRightTrigger << 7) + (state.Gamepad.bRightTrigger >> 1)); - last_right_trigger = state.Gamepad.bRightTrigger; - } - if (state.Gamepad.sThumbLX != last_left_thumb_x) - { - gamepad_axis_input(2, state.Gamepad.sThumbLX); - last_left_thumb_x = state.Gamepad.sThumbLX; - } - if (state.Gamepad.sThumbLY != last_left_thumb_y) - { - gamepad_axis_input(3, state.Gamepad.sThumbLY); - last_left_thumb_y = state.Gamepad.sThumbLY; - } - if (state.Gamepad.sThumbRX != last_right_thumb_x) - { - gamepad_axis_input(4, state.Gamepad.sThumbRX); - last_right_thumb_x = state.Gamepad.sThumbRX; - } - if (state.Gamepad.sThumbRY != last_right_thumb_y) - { - gamepad_axis_input(5, state.Gamepad.sThumbRY); - last_right_thumb_y = state.Gamepad.sThumbRY; - } - } - else if (input_mapper) - { - INFO_LOG(INPUT, "xinput: Controller '%s' on port %d disconnected", _name.c_str(), _xinput_port); - GamepadDevice::Unregister(xinput_gamepads[_xinput_port]); - input_mapper.reset(); - last_buttons_state = 0; - last_left_trigger = 0; - last_right_trigger = 0; - last_left_thumb_x = 0; - last_left_thumb_y = 0; - last_right_thumb_x = 0; - last_right_thumb_y = 0; - } - } - void rumble(float power, float inclination, u32 duration_ms) override - { - vib_inclination = inclination * power; - vib_stop_time = os_GetSeconds() + duration_ms / 1000.0; - - do_rumble(power); - } - void update_rumble() override - { - if (vib_stop_time > 0) - { - int rem_time = (int)((vib_stop_time - os_GetSeconds()) * 1000.0); - if (rem_time <= 0) - { - vib_stop_time = 0; - do_rumble(0); - } - else if (vib_inclination > 0) - do_rumble(vib_inclination * rem_time); - } - } - - void Open() - { - JOYCAPS joycaps; - int rc = joyGetDevCaps(_xinput_port, &joycaps, sizeof(joycaps)); - if (rc != 0) - _name = "xinput" + std::to_string(_xinput_port); - else - _name = joycaps.szPname; - INFO_LOG(INPUT, "xinput: Opened controller '%s' on port %d", _name.c_str(), _xinput_port); - loadMapping(); - - GamepadDevice::Register(xinput_gamepads[_xinput_port]); - } - - static void CreateDevices() - { - for (int port = 0; port < XUSER_MAX_COUNT; port++) - xinput_gamepads[port] = std::make_shared(port, port); - } - static void CloseDevices() - { - for (int port = 0; port < XUSER_MAX_COUNT; port++) - GamepadDevice::Unregister(xinput_gamepads[port]); - } - - static std::shared_ptr GetXInputDevice(int port) - { - return xinput_gamepads[port]; - } - -protected: - void load_axis_min_max(u32 axis) - { - if (axis == 0 || axis == 1) - { - axis_ranges[axis] = 255; - axis_min_values[axis] = 0; - } - else - { - axis_ranges[axis] = 65535; - axis_min_values[axis] = -32768; - } - } - -private: - void do_rumble(float power) - { - XINPUT_VIBRATION vib; - - vib.wLeftMotorSpeed = (u16)(65535 * power); - vib.wRightMotorSpeed = (u16)(65535 * power); - - XInputSetState(_xinput_port, &vib); - } - - const int _xinput_port; - u32 last_buttons_state = 0; - u8 last_left_trigger = 0; - u8 last_right_trigger = 0; - s16 last_left_thumb_x = 0; - s16 last_left_thumb_y = 0; - s16 last_right_thumb_x = 0; - s16 last_right_thumb_y = 0; - double vib_stop_time; - float vib_inclination; - std::map axis_min_values; - std::map axis_ranges; - static std::vector> xinput_gamepads; -}; - -std::vector> XInputGamepadDevice::xinput_gamepads(XUSER_MAX_COUNT); - -class WinMouse : public Mouse -{ -public: - WinMouse() : Mouse("win32") - { - _unique_id = "win_mouse"; - loadMapping(); - } -}; - diff --git a/core/wsi/gl_context.h b/core/wsi/gl_context.h index 5094f5cb79..fa7c2914d9 100644 --- a/core/wsi/gl_context.h +++ b/core/wsi/gl_context.h @@ -88,10 +88,6 @@ class GLGraphicsContext : public GraphicsContext #include "egl.h" -#elif defined(_WIN32) - -#include "wgl.h" - #elif defined(SUPPORT_X11) #include "xgl.h" diff --git a/core/wsi/wgl.cpp b/core/wsi/wgl.cpp deleted file mode 100644 index 7703f11b92..0000000000 --- a/core/wsi/wgl.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - Created on: Oct 18, 2019 - - Copyright 2019 flyinghead - - This file is part of Flycast. - - Flycast is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - Flycast is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Flycast. If not, see . -*/ -#if defined(_WIN32) && !defined(USE_SDL) && !defined(LIBRETRO) -#include "types.h" -#include "wgl.h" - -#include - -void CreateMainWindow(); - -WGLGraphicsContext theGLContext; - -bool WGLGraphicsContext::init() -{ - if (ourOpenGLRenderingContext != NULL) - // Already initialized - return true; - - instance = this; - CreateMainWindow(); - PIXELFORMATDESCRIPTOR pfd = - { - sizeof(PIXELFORMATDESCRIPTOR), - 1, - PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, //Flags - PFD_TYPE_RGBA, //The kind of framebuffer. RGBA or palette. - 32, //Colordepth of the framebuffer. - 0, 0, 0, 0, 0, 0, - 0, - 0, - 0, - 0, 0, 0, 0, - 0, //Number of bits for the depthbuffer - 0, //Number of bits for the stencilbuffer - 0, //Number of Aux buffers in the framebuffer. - PFD_MAIN_PLANE, - 0, - 0, 0, 0 - }; - - int letWindowsChooseThisPixelFormat; - letWindowsChooseThisPixelFormat = ChoosePixelFormat((HDC)display, &pfd); - SetPixelFormat((HDC)display,letWindowsChooseThisPixelFormat, &pfd); - - HGLRC tempOpenGLContext = wglCreateContext((HDC)display); - wglMakeCurrent((HDC)display, tempOpenGLContext); - - gladLoaderLoadWGL((HDC) display); - - int attribs[] = - { - WGL_CONTEXT_MAJOR_VERSION_ARB, 4, - WGL_CONTEXT_MINOR_VERSION_ARB, 3, - WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, - WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, - 0 - }; - - ourOpenGLRenderingContext = wglCreateContextAttribsARB((HDC)display, 0, attribs); - - if (!ourOpenGLRenderingContext) - { - INFO_LOG(RENDERER, "OpenGL 4.3 not supported"); - // Try Gl 3.1 - attribs[1] = 3; - attribs[3] = 1; - ourOpenGLRenderingContext = wglCreateContextAttribsARB((HDC)display, 0, attribs); - } - - bool rv = true; - - if (ourOpenGLRenderingContext) - wglMakeCurrent((HDC)display, ourOpenGLRenderingContext); - else - rv = false; - - wglDeleteContext(tempOpenGLContext); - - if (rv) { - rv = (gladLoadGL((GLADloadfunc) wglGetProcAddress) != 0) && GLAD_GL_VERSION_3_1; - } - - RECT r; - GetClientRect((HWND)window, &r); - settings.display.width = r.right - r.left; - settings.display.height = r.bottom - r.top; - - if (rv) - postInit(); - - return rv; -} - -void WGLGraphicsContext::swap() -{ - do_swap_automation(); - wglSwapLayerBuffers((HDC)display, WGL_SWAP_MAIN_PLANE); -} - -void WGLGraphicsContext::term() -{ - preTerm(); - if (ourOpenGLRenderingContext != NULL) - { - wglMakeCurrent((HDC)display, NULL); - wglDeleteContext(ourOpenGLRenderingContext); - ourOpenGLRenderingContext = NULL; - } -} - -#endif diff --git a/core/wsi/wgl.h b/core/wsi/wgl.h deleted file mode 100644 index 9b0a30d809..0000000000 --- a/core/wsi/wgl.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - Created on: Oct 18, 2019 - - Copyright 2019 flyinghead - - This file is part of Flycast. - - Flycast is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - Flycast is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Flycast. If not, see . -*/ -#pragma once -#include "gl_context.h" -#include - -class WGLGraphicsContext : public GLGraphicsContext -{ -public: - bool init(); - void term() override; - void swap(); - -private: - HGLRC ourOpenGLRenderingContext = NULL; -}; - -extern WGLGraphicsContext theGLContext;