├── scripts └── env.txt ├── misc └── logo.xcf ├── .gitignore ├── third-party ├── glfw │ ├── src │ │ ├── glfw.rc.in │ │ ├── xkb_unicode.h │ │ ├── posix_poll.h │ │ ├── cocoa_time.h │ │ ├── null_joystick.h │ │ ├── posix_time.h │ │ ├── win32_time.h │ │ ├── posix_thread.h │ │ ├── null_joystick.c │ │ ├── win32_module.c │ │ ├── posix_module.c │ │ ├── cocoa_joystick.h │ │ ├── win32_joystick.h │ │ ├── cocoa_time.c │ │ ├── win32_time.c │ │ ├── win32_thread.h │ │ ├── posix_time.c │ │ ├── linux_joystick.h │ │ ├── posix_poll.c │ │ ├── win32_thread.c │ │ ├── posix_thread.c │ │ ├── mappings.h.in │ │ ├── null_monitor.c │ │ ├── platform.h │ │ ├── platform.c │ │ ├── wl_monitor.c │ │ ├── null_platform.h │ │ ├── vulkan.c │ │ ├── nsgl_context.m │ │ ├── osmesa_context.c │ │ ├── cocoa_platform.h │ │ ├── linux_joystick.c │ │ └── null_init.c │ ├── LICENSE.md │ ├── Makefile │ └── CONTRIBUTORS.md └── imgui │ ├── LICENSE.txt │ ├── imgui_impl_opengl2.h │ ├── imgui_impl_glfw.h │ └── imconfig.h ├── README.md ├── src ├── default_ini.h ├── gdb.h └── common.h └── Makefile /scripts/env.txt: -------------------------------------------------------------------------------- 1 | TUG_VER_MAJOR=1 2 | TUG_VER_MINOR=1 3 | TUG_VER_PATCH=0 4 | -------------------------------------------------------------------------------- /misc/logo.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kyle-sylvestre/Tug/HEAD/misc/logo.xcf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | debug_misc 2 | *.ini 3 | build_debug 4 | ignore 5 | build_release 6 | output 7 | tags 8 | *.o 9 | badrecord* 10 | -------------------------------------------------------------------------------- /third-party/glfw/src/glfw.rc.in: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | VS_VERSION_INFO VERSIONINFO 5 | FILEVERSION @GLFW_VERSION_MAJOR@,@GLFW_VERSION_MINOR@,@GLFW_VERSION_PATCH@,0 6 | PRODUCTVERSION @GLFW_VERSION_MAJOR@,@GLFW_VERSION_MINOR@,@GLFW_VERSION_PATCH@,0 7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 8 | FILEFLAGS 0 9 | FILEOS VOS_NT_WINDOWS32 10 | FILETYPE VFT_DLL 11 | FILESUBTYPE 0 12 | { 13 | BLOCK "StringFileInfo" 14 | { 15 | BLOCK "040904B0" 16 | { 17 | VALUE "CompanyName", "GLFW" 18 | VALUE "FileDescription", "GLFW @GLFW_VERSION@ DLL" 19 | VALUE "FileVersion", "@GLFW_VERSION@" 20 | VALUE "OriginalFilename", "glfw3.dll" 21 | VALUE "ProductName", "GLFW" 22 | VALUE "ProductVersion", "@GLFW_VERSION@" 23 | } 24 | } 25 | BLOCK "VarFileInfo" 26 | { 27 | VALUE "Translation", 0x409, 1200 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /third-party/glfw/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006 Marcus Geelnard 2 | 3 | Copyright (c) 2006-2019 Camilla Löwy 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would 16 | be appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not 19 | be misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | 24 | -------------------------------------------------------------------------------- /third-party/imgui/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2022 Omar Cornut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /third-party/glfw/src/xkb_unicode.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define GLFW_INVALID_CODEPOINT 0xffffffffu 28 | 29 | uint32_t _glfwKeySym2Unicode(unsigned int keysym); 30 | 31 | -------------------------------------------------------------------------------- /third-party/glfw/src/posix_poll.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2022 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | 29 | GLFWbool _glfwPollPOSIX(struct pollfd* fds, nfds_t count, double* timeout); 30 | 31 | -------------------------------------------------------------------------------- /third-party/glfw/src/cocoa_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2021 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define GLFW_COCOA_LIBRARY_TIMER_STATE _GLFWtimerNS ns; 28 | 29 | // Cocoa-specific global timer data 30 | // 31 | typedef struct _GLFWtimerNS 32 | { 33 | uint64_t frequency; 34 | } _GLFWtimerNS; 35 | 36 | -------------------------------------------------------------------------------- /third-party/glfw/src/null_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | GLFWbool _glfwInitJoysticksNull(void); 28 | void _glfwTerminateJoysticksNull(void); 29 | GLFWbool _glfwPollJoystickNull(_GLFWjoystick* js, int mode); 30 | const char* _glfwGetMappingNameNull(void); 31 | void _glfwUpdateGamepadGUIDNull(char* guid); 32 | 33 | -------------------------------------------------------------------------------- /third-party/glfw/src/posix_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | #define GLFW_POSIX_LIBRARY_TIMER_STATE _GLFWtimerPOSIX posix; 29 | 30 | #include 31 | #include 32 | 33 | 34 | // POSIX-specific global timer data 35 | // 36 | typedef struct _GLFWtimerPOSIX 37 | { 38 | clockid_t clock; 39 | uint64_t frequency; 40 | } _GLFWtimerPOSIX; 41 | 42 | -------------------------------------------------------------------------------- /third-party/glfw/src/win32_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for 29 | // example to allow applications to correctly declare a GL_KHR_debug callback) 30 | // but windows.h assumes no one will define APIENTRY before it does 31 | #undef APIENTRY 32 | 33 | #include 34 | 35 | #define GLFW_WIN32_LIBRARY_TIMER_STATE _GLFWtimerWin32 win32; 36 | 37 | // Win32-specific global timer data 38 | // 39 | typedef struct _GLFWtimerWin32 40 | { 41 | uint64_t frequency; 42 | } _GLFWtimerWin32; 43 | 44 | -------------------------------------------------------------------------------- /third-party/glfw/src/posix_thread.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | #include 29 | 30 | #define GLFW_POSIX_TLS_STATE _GLFWtlsPOSIX posix; 31 | #define GLFW_POSIX_MUTEX_STATE _GLFWmutexPOSIX posix; 32 | 33 | 34 | // POSIX-specific thread local storage data 35 | // 36 | typedef struct _GLFWtlsPOSIX 37 | { 38 | GLFWbool allocated; 39 | pthread_key_t key; 40 | } _GLFWtlsPOSIX; 41 | 42 | // POSIX-specific mutex data 43 | // 44 | typedef struct _GLFWmutexPOSIX 45 | { 46 | GLFWbool allocated; 47 | pthread_mutex_t handle; 48 | } _GLFWmutexPOSIX; 49 | 50 | -------------------------------------------------------------------------------- /third-party/glfw/src/null_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | 30 | ////////////////////////////////////////////////////////////////////////// 31 | ////// GLFW platform API ////// 32 | ////////////////////////////////////////////////////////////////////////// 33 | 34 | GLFWbool _glfwInitJoysticksNull(void) 35 | { 36 | return GLFW_TRUE; 37 | } 38 | 39 | void _glfwTerminateJoysticksNull(void) 40 | { 41 | } 42 | 43 | GLFWbool _glfwPollJoystickNull(_GLFWjoystick* js, int mode) 44 | { 45 | return GLFW_FALSE; 46 | } 47 | 48 | const char* _glfwGetMappingNameNull(void) 49 | { 50 | return ""; 51 | } 52 | 53 | void _glfwUpdateGamepadGUIDNull(char* guid) 54 | { 55 | } 56 | 57 | -------------------------------------------------------------------------------- /third-party/glfw/src/win32_module.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2021 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | #if defined(GLFW_BUILD_WIN32_MODULE) 30 | 31 | ////////////////////////////////////////////////////////////////////////// 32 | ////// GLFW platform API ////// 33 | ////////////////////////////////////////////////////////////////////////// 34 | 35 | void* _glfwPlatformLoadModule(const char* path) 36 | { 37 | return LoadLibraryA(path); 38 | } 39 | 40 | void _glfwPlatformFreeModule(void* module) 41 | { 42 | FreeLibrary((HMODULE) module); 43 | } 44 | 45 | GLFWproc _glfwPlatformGetModuleSymbol(void* module, const char* name) 46 | { 47 | return (GLFWproc) GetProcAddress((HMODULE) module, name); 48 | } 49 | 50 | #endif // GLFW_BUILD_WIN32_MODULE 51 | 52 | -------------------------------------------------------------------------------- /third-party/glfw/src/posix_module.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2021 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | #if defined(GLFW_BUILD_POSIX_MODULE) 30 | 31 | #include 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW platform API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | void* _glfwPlatformLoadModule(const char* path) 38 | { 39 | return dlopen(path, RTLD_LAZY | RTLD_LOCAL); 40 | } 41 | 42 | void _glfwPlatformFreeModule(void* module) 43 | { 44 | dlclose(module); 45 | } 46 | 47 | GLFWproc _glfwPlatformGetModuleSymbol(void* module, const char* name) 48 | { 49 | return dlsym(module, name); 50 | } 51 | 52 | #endif // GLFW_BUILD_POSIX_MODULE 53 | 54 | -------------------------------------------------------------------------------- /third-party/glfw/src/cocoa_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Cocoa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define GLFW_COCOA_JOYSTICK_STATE _GLFWjoystickNS ns; 32 | #define GLFW_COCOA_LIBRARY_JOYSTICK_STATE 33 | 34 | // Cocoa-specific per-joystick data 35 | // 36 | typedef struct _GLFWjoystickNS 37 | { 38 | IOHIDDeviceRef device; 39 | CFMutableArrayRef axes; 40 | CFMutableArrayRef buttons; 41 | CFMutableArrayRef hats; 42 | } _GLFWjoystickNS; 43 | 44 | GLFWbool _glfwInitJoysticksCocoa(void); 45 | void _glfwTerminateJoysticksCocoa(void); 46 | GLFWbool _glfwPollJoystickCocoa(_GLFWjoystick* js, int mode); 47 | const char* _glfwGetMappingNameCocoa(void); 48 | void _glfwUpdateGamepadGUIDCocoa(char* guid); 49 | 50 | -------------------------------------------------------------------------------- /third-party/glfw/src/win32_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define GLFW_WIN32_JOYSTICK_STATE _GLFWjoystickWin32 win32; 28 | #define GLFW_WIN32_LIBRARY_JOYSTICK_STATE 29 | 30 | // Joystick element (axis, button or slider) 31 | // 32 | typedef struct _GLFWjoyobjectWin32 33 | { 34 | int offset; 35 | int type; 36 | } _GLFWjoyobjectWin32; 37 | 38 | // Win32-specific per-joystick data 39 | // 40 | typedef struct _GLFWjoystickWin32 41 | { 42 | _GLFWjoyobjectWin32* objects; 43 | int objectCount; 44 | IDirectInputDevice8W* device; 45 | DWORD index; 46 | GUID guid; 47 | } _GLFWjoystickWin32; 48 | 49 | void _glfwDetectJoystickConnectionWin32(void); 50 | void _glfwDetectJoystickDisconnectionWin32(void); 51 | 52 | -------------------------------------------------------------------------------- /third-party/glfw/src/cocoa_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | #if defined(GLFW_BUILD_COCOA_TIMER) 30 | 31 | #include 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW platform API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | void _glfwPlatformInitTimer(void) 39 | { 40 | mach_timebase_info_data_t info; 41 | mach_timebase_info(&info); 42 | 43 | _glfw.timer.ns.frequency = (info.denom * 1e9) / info.numer; 44 | } 45 | 46 | uint64_t _glfwPlatformGetTimerValue(void) 47 | { 48 | return mach_absolute_time(); 49 | } 50 | 51 | uint64_t _glfwPlatformGetTimerFrequency(void) 52 | { 53 | return _glfw.timer.ns.frequency; 54 | } 55 | 56 | #endif // GLFW_BUILD_COCOA_TIMER 57 | 58 | -------------------------------------------------------------------------------- /third-party/glfw/src/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | #include "internal.h" 29 | 30 | #if defined(GLFW_BUILD_WIN32_TIMER) 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW platform API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | void _glfwPlatformInitTimer(void) 37 | { 38 | QueryPerformanceFrequency((LARGE_INTEGER*) &_glfw.timer.win32.frequency); 39 | } 40 | 41 | uint64_t _glfwPlatformGetTimerValue(void) 42 | { 43 | uint64_t value; 44 | QueryPerformanceCounter((LARGE_INTEGER*) &value); 45 | return value; 46 | } 47 | 48 | uint64_t _glfwPlatformGetTimerFrequency(void) 49 | { 50 | return _glfw.timer.win32.frequency; 51 | } 52 | 53 | #endif // GLFW_BUILD_WIN32_TIMER 54 | 55 | -------------------------------------------------------------------------------- /third-party/glfw/src/win32_thread.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for 29 | // example to allow applications to correctly declare a GL_KHR_debug callback) 30 | // but windows.h assumes no one will define APIENTRY before it does 31 | #undef APIENTRY 32 | 33 | #include 34 | 35 | #define GLFW_WIN32_TLS_STATE _GLFWtlsWin32 win32; 36 | #define GLFW_WIN32_MUTEX_STATE _GLFWmutexWin32 win32; 37 | 38 | // Win32-specific thread local storage data 39 | // 40 | typedef struct _GLFWtlsWin32 41 | { 42 | GLFWbool allocated; 43 | DWORD index; 44 | } _GLFWtlsWin32; 45 | 46 | // Win32-specific mutex data 47 | // 48 | typedef struct _GLFWmutexWin32 49 | { 50 | GLFWbool allocated; 51 | CRITICAL_SECTION section; 52 | } _GLFWmutexWin32; 53 | 54 | -------------------------------------------------------------------------------- /third-party/imgui/imgui_impl_opengl2.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for OpenGL2 (legacy OpenGL, fixed pipeline) 2 | // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 7 | 8 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 9 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 10 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 11 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 12 | 13 | // **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** 14 | // **Prefer using the code in imgui_impl_opengl3.cpp** 15 | // This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. 16 | // If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more 17 | // complicated, will require your code to reset every single OpenGL attributes to their initial state, and might 18 | // confuse your GPU driver. 19 | // The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API. 20 | 21 | #pragma once 22 | #include "imgui.h" // IMGUI_IMPL_API 23 | 24 | IMGUI_IMPL_API bool ImGui_ImplOpenGL2_Init(); 25 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_Shutdown(); 26 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_NewFrame(); 27 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data); 28 | 29 | // Called by Init/NewFrame/Shutdown 30 | IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateFontsTexture(); 31 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyFontsTexture(); 32 | IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateDeviceObjects(); 33 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyDeviceObjects(); 34 | -------------------------------------------------------------------------------- /third-party/glfw/src/posix_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | #include "internal.h" 29 | 30 | #if defined(GLFW_BUILD_POSIX_TIMER) 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW platform API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | void _glfwPlatformInitTimer(void) 41 | { 42 | _glfw.timer.posix.clock = CLOCK_REALTIME; 43 | _glfw.timer.posix.frequency = 1000000000; 44 | 45 | #if defined(_POSIX_MONOTONIC_CLOCK) 46 | struct timespec ts; 47 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 48 | _glfw.timer.posix.clock = CLOCK_MONOTONIC; 49 | #endif 50 | } 51 | 52 | uint64_t _glfwPlatformGetTimerValue(void) 53 | { 54 | struct timespec ts; 55 | clock_gettime(_glfw.timer.posix.clock, &ts); 56 | return (uint64_t) ts.tv_sec * _glfw.timer.posix.frequency + (uint64_t) ts.tv_nsec; 57 | } 58 | 59 | uint64_t _glfwPlatformGetTimerFrequency(void) 60 | { 61 | return _glfw.timer.posix.frequency; 62 | } 63 | 64 | #endif // GLFW_BUILD_POSIX_TIMER 65 | 66 | -------------------------------------------------------------------------------- /third-party/glfw/src/linux_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define GLFW_LINUX_JOYSTICK_STATE _GLFWjoystickLinux linjs; 32 | #define GLFW_LINUX_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs; 33 | 34 | // Linux-specific joystick data 35 | // 36 | typedef struct _GLFWjoystickLinux 37 | { 38 | int fd; 39 | char path[PATH_MAX]; 40 | int keyMap[KEY_CNT - BTN_MISC]; 41 | int absMap[ABS_CNT]; 42 | struct input_absinfo absInfo[ABS_CNT]; 43 | int hats[4][2]; 44 | } _GLFWjoystickLinux; 45 | 46 | // Linux-specific joystick API data 47 | // 48 | typedef struct _GLFWlibraryLinux 49 | { 50 | int inotify; 51 | int watch; 52 | regex_t regex; 53 | GLFWbool regexCompiled; 54 | GLFWbool dropped; 55 | } _GLFWlibraryLinux; 56 | 57 | void _glfwDetectJoystickConnectionLinux(void); 58 | 59 | GLFWbool _glfwInitJoysticksLinux(void); 60 | void _glfwTerminateJoysticksLinux(void); 61 | GLFWbool _glfwPollJoystickLinux(_GLFWjoystick* js, int mode); 62 | const char* _glfwGetMappingNameLinux(void); 63 | void _glfwUpdateGamepadGUIDLinux(char* guid); 64 | 65 | -------------------------------------------------------------------------------- /third-party/glfw/Makefile: -------------------------------------------------------------------------------- 1 | DEBUG ?= 0 2 | 3 | CC = gcc 4 | CFLAGS += -I./include 5 | CFLAGS += -std=c99 -g3 -gdwarf-2 -Wall -Werror=format -Wextra -pthread 6 | CFLAGS += -Wno-missing-field-initializers -Wno-unused-parameter -Wno-sign-compare -Wno-cast-function-type 7 | 8 | ifeq ($(DEBUG), 1) 9 | CFLAGS += -DDEBUG -O0 10 | DEFAULT_OBJDIR = ./build_debug 11 | else 12 | CFLAGS += -DNDEBUG -O3 13 | DEFAULT_OBJDIR = ./build_release 14 | endif 15 | 16 | ifeq ($(OBJDIR), ) 17 | OBJDIR = $(DEFAULT_OBJDIR) 18 | endif 19 | 20 | OUT = $(OBJDIR)/libglfw3.a 21 | 22 | SOURCES = ./src/context.c\ 23 | ./src/init.c\ 24 | ./src/input.c\ 25 | ./src/monitor.c\ 26 | ./src/platform.c\ 27 | ./src/vulkan.c\ 28 | ./src/window.c\ 29 | ./src/egl_context.c\ 30 | ./src/osmesa_context.c\ 31 | ./src/null_init.c\ 32 | ./src/null_monitor.c\ 33 | ./src/null_window.c\ 34 | ./src/null_joystick.c 35 | 36 | UNAME_S = $(shell uname -s) 37 | ifeq ($(UNAME_S), Darwin) #APPLE 38 | ECHO_MESSAGE = "Mac OS X" 39 | CFLAGS += -D_GLFW_COCOA 40 | CFLAGS += -I/usr/local/include -I/opt/local/include -I/opt/homebrew/include 41 | SOURCES += ./src/cocoa_time.c\ 42 | ./src/cocoa_init.m\ 43 | ./src/cocoa_joystick.m\ 44 | ./src/cocoa_monitor.m\ 45 | ./src/cocoa_window.m\ 46 | ./src/nsgl_context.m\ 47 | ./src/posix_module.c\ 48 | ./src/posix_thread.c 49 | 50 | else ifeq ($(OS), Windows_NT) 51 | ECHO_MESSAGE = "MinGW" 52 | CFLAGS += -D_GLFW_WIN32 -D_WIN32 # define _WIN32 for cygwin/msys2/mingw 53 | SOURCES += ./src/win32_module.c\ 54 | ./src/win32_time.c\ 55 | ./src/win32_thread.c\ 56 | ./src/win32_init.c\ 57 | ./src/win32_joystick.c\ 58 | ./src/win32_monitor.c\ 59 | ./src/win32_window.c\ 60 | ./src/wgl_context.c 61 | else 62 | # linux, BSD, etc. 63 | CFLAGS += -D_GLFW_X11 -D_POSIX_C_SOURCE=200809L 64 | LIBS += -lpthread -lm -ldl -lGL -lX11 65 | SOURCES += ./src/posix_module.c\ 66 | ./src/posix_time.c\ 67 | ./src/posix_thread.c\ 68 | ./src/x11_init.c\ 69 | ./src/x11_monitor.c\ 70 | ./src/x11_window.c\ 71 | ./src/xkb_unicode.c\ 72 | ./src/glx_context.c\ 73 | ./src/linux_joystick.c\ 74 | ./src/posix_poll.c 75 | endif 76 | 77 | OBJS = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(basename $(notdir $(SOURCES))))) 78 | 79 | all: | $(OUT) 80 | 81 | $(OUT): $(OBJS) 82 | ar rcs $@ $^ 83 | 84 | $(OBJDIR)/%.o:./src/%.c 85 | $(CC) $(CFLAGS) -c -o $@ $< 86 | 87 | $(OBJDIR)/%.o:./src/%.m 88 | $(CC) $(CFLAGS) -c -o $@ $< 89 | 90 | $(OBJS): | $(OBJDIR) 91 | 92 | $(OBJDIR): 93 | mkdir -p $@ 94 | 95 | clean: 96 | rm -f $(OUT) $(OBJS) 97 | 98 | 99 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tug 2 | GDB frontend made with Dear ImGui 3 | 4 | ![image](https://user-images.githubusercontent.com/25188464/160298425-a5267c22-89fc-4d60-b93a-cd6dd9098924.png) 5 | 6 | *Tugboat captain is the GDB archer fish mascot https://sourceware.org/gdb/mascot/*
7 | *Jamie Guinan's original archer fish logo and the vector versions by Andreas Arnez are licensed under CC BY-SA 3.0 US.* 8 | *https://creativecommons.org/licenses/by-sa/3.0/us/* 9 | 10 | ![Untitled](https://github.com/kyle-sylvestre/Tug/assets/25188464/b5db9a13-717e-4e51-9702-dc2d8b28fea9) 11 | 12 | # Building the Project 13 | 14 | 1. Install gcc, gdb, and make
15 | 2. For X11 based systems, install additional packages
16 | **Debian, Ubuntu, Linux Mint:** sudo apt-get install xorg-dev
17 | **Fedora, RHEL:** sudo dnf install libXcursor-devel libXi-devel libXinerama-devel libXrandr-devel
18 | **FreeBSD:** pkg install xorgproto
19 | 20 | 3. Run command "make DEBUG=0", output executable is ./build_release/tug 21 | 22 | # Debugging an Executable 23 | 24 | **NOTE**: Tug defaults to the gdb filename returned by the command "which gdb"
25 | 26 | 1. run program from command line
27 | tug --exe [program to debug filename] --gdb [gdb filename]
28 | 29 | OR 30 | 31 | 1. run tug
32 | 2. click "Debug" menu button
33 | 3. fill in gdb filename and debug filename, args are optional
34 | 4. click "Start" button
35 | 36 | # Source Window 37 | * CTRL-F: open text search mode, N = next match, SHIFT-N = previous match, ESC to exit 38 | * CTRL-G: open goto line window, ENTER to jump to input line, ESC to exit 39 | * hover over any word to query its value, right click it to create a new watch within the control window 40 | * add/remove breakpoint by clicking the empty column to the left of the line number 41 | 42 | # Control Window 43 | program execution buttons
44 | * "---" = jump to next executed line inside source window 45 | * "|>" = start/continue program 46 | * "||" = pause program 47 | * "-->" = step into 48 | * "/\\>" = step over 49 | * " 58 | https://sourceware.org/gdb/download/onlinedocs/gdb#GDB_002fMI
59 | 60 | GLFW:
61 | https://www.glfw.org/download.html
62 | https://www.glfw.org/docs/latest/compile.html
63 | 64 | 65 | -------------------------------------------------------------------------------- /src/default_ini.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 Kyle Sylvestre 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with this program. If not, see . 15 | 16 | #pragma once 17 | 18 | const char *const default_ini = R"( 19 | [Tug] 20 | Callstack=1 21 | Locals=1 22 | Watch=1 23 | Source=1 24 | Control=1 25 | Breakpoints=0 26 | Threads=0 27 | Registers=0 28 | DirectoryViewer=1 29 | FontFilename= 30 | FontSize= 31 | WindowTheme=DarkBlue 32 | 33 | ; ImGui Begin 34 | [Window][DockingWindow] 35 | Size=1270,720 36 | Collapsed=0 37 | 38 | [Window][Debug##Default] 39 | Pos=60,60 40 | Size=400,400 41 | Collapsed=0 42 | 43 | [Window][Source] 44 | Pos=0,19 45 | Size=902,461 46 | Collapsed=0 47 | DockId=0x00000003,0 48 | 49 | [Window][Control] 50 | Pos=0,482 51 | Size=902,238 52 | Collapsed=0 53 | DockId=0x00000004,0 54 | 55 | [Window][Locals] 56 | Pos=904,482 57 | Size=376,238 58 | Collapsed=0 59 | DockId=0x00000006,0 60 | 61 | [Window][Callstack] 62 | Pos=904,252 63 | Size=376,228 64 | Collapsed=0 65 | DockId=0x00000008,0 66 | 67 | [Window][Watch] 68 | Pos=904,19 69 | Size=376,231 70 | Collapsed=0 71 | DockId=0x00000007,0 72 | 73 | [Window][Registers] 74 | Pos=904,248 75 | Size=376,224 76 | Collapsed=0 77 | DockId=0x7FD18564,1 78 | 79 | [Window][DockSpaceViewport_11111111] 80 | Pos=0,19 81 | Size=1280,701 82 | Collapsed=0 83 | 84 | [Table][0x948EDA1E,2] 85 | RefScale=13 86 | Column 0 Width=125 87 | Column 1 Width=35 88 | 89 | [Table][0xFB078A15,2] 90 | RefScale=13 91 | Column 0 Width=123 92 | Column 1 Width=35 93 | 94 | [Table][0x61EA1B4D,2] 95 | RefScale=13 96 | Column 0 Width=125 97 | Column 1 Width=35 98 | 99 | [Docking][Data] 100 | DockSpace ID=0x7FD18564 Pos=0,19 Size=1270,701 CentralNode=1 Selected=0xDA041833 101 | DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,19 Size=1280,701 Split=X 102 | DockNode ID=0x00000001 Parent=0x8B93E3BD SizeRef=902,701 Split=Y Selected=0xDA041833 103 | DockNode ID=0x00000003 Parent=0x00000001 SizeRef=902,461 CentralNode=1 Selected=0xDA041833 104 | DockNode ID=0x00000004 Parent=0x00000001 SizeRef=902,238 Selected=0xCE6F6A26 105 | DockNode ID=0x00000002 Parent=0x8B93E3BD SizeRef=376,701 Split=Y Selected=0x7BFCF530 106 | DockNode ID=0x00000005 Parent=0x00000002 SizeRef=376,461 Split=Y Selected=0x7BFCF530 107 | DockNode ID=0x00000007 Parent=0x00000005 SizeRef=376,231 Selected=0x7BFCF530 108 | DockNode ID=0x00000008 Parent=0x00000005 SizeRef=376,228 Selected=0x2924BF46 109 | DockNode ID=0x00000006 Parent=0x00000002 SizeRef=376,238 Selected=0xFEB5AC5E 110 | 111 | )"; 112 | -------------------------------------------------------------------------------- /third-party/glfw/src/posix_poll.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2022 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define _GNU_SOURCE 28 | 29 | #include "internal.h" 30 | 31 | #if defined(GLFW_BUILD_POSIX_POLL) 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | GLFWbool _glfwPollPOSIX(struct pollfd* fds, nfds_t count, double* timeout) 38 | { 39 | for (;;) 40 | { 41 | if (timeout) 42 | { 43 | const uint64_t base = _glfwPlatformGetTimerValue(); 44 | 45 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) 46 | const time_t seconds = (time_t) *timeout; 47 | const long nanoseconds = (long) ((*timeout - seconds) * 1e9); 48 | const struct timespec ts = { seconds, nanoseconds }; 49 | const int result = ppoll(fds, count, &ts, NULL); 50 | #elif defined(__NetBSD__) 51 | const time_t seconds = (time_t) *timeout; 52 | const long nanoseconds = (long) ((*timeout - seconds) * 1e9); 53 | const struct timespec ts = { seconds, nanoseconds }; 54 | const int result = pollts(fds, count, &ts, NULL); 55 | #else 56 | const int milliseconds = (int) (*timeout * 1e3); 57 | const int result = poll(fds, count, milliseconds); 58 | #endif 59 | const int error = errno; // clock_gettime may overwrite our error 60 | 61 | *timeout -= (_glfwPlatformGetTimerValue() - base) / 62 | (double) _glfwPlatformGetTimerFrequency(); 63 | 64 | if (result > 0) 65 | return GLFW_TRUE; 66 | else if (result == -1 && error != EINTR && error != EAGAIN) 67 | return GLFW_FALSE; 68 | else if (*timeout <= 0.0) 69 | return GLFW_FALSE; 70 | } 71 | else 72 | { 73 | const int result = poll(fds, count, -1); 74 | if (result > 0) 75 | return GLFW_TRUE; 76 | else if (result == -1 && errno != EINTR && errno != EAGAIN) 77 | return GLFW_FALSE; 78 | } 79 | } 80 | } 81 | 82 | #endif // GLFW_BUILD_POSIX_POLL 83 | 84 | -------------------------------------------------------------------------------- /src/gdb.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 Kyle Sylvestre 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with this program. If not, see . 15 | 16 | #pragma once 17 | 18 | struct ParseRecordContext 19 | { 20 | Vector atoms; 21 | size_t atom_idx; 22 | size_t num_end_atoms; // contiguous atoms stored at the end of atoms 23 | 24 | bool error; 25 | 26 | size_t i; 27 | const char *buf; // record line data 28 | size_t bufsize; 29 | }; 30 | 31 | // traverse through all the child elements of an array/struct 32 | struct AtomIter 33 | { 34 | const RecordAtom *iter_begin; 35 | const RecordAtom *iter_end; 36 | const RecordAtom *begin() { return iter_begin; } 37 | const RecordAtom *end() { return iter_end; } 38 | }; 39 | AtomIter GDB_IterChild(const Record &rec, const RecordAtom *array); 40 | 41 | // extract values from parsed records 42 | String GDB_ExtractValue(const char *name, const RecordAtom &root, const Record &rec); 43 | int GDB_ExtractInt(const char *name, const RecordAtom &root, const Record &rec); 44 | const RecordAtom *GDB_ExtractAtom(const char *name, const RecordAtom &root, const Record &rec); 45 | 46 | // helper functions for searching the root node of a record 47 | String GDB_ExtractValue(const char *name, const Record &rec); 48 | int GDB_ExtractInt(const char *name, const Record &rec); 49 | const RecordAtom *GDB_ExtractAtom(const char *name, const Record &rec); 50 | 51 | inline String GetAtomString(Span s, const Record &rec) 52 | { 53 | Assert(s.index + s.length <= rec.buf.size()); 54 | String result = {}; 55 | result.assign(rec.buf.data() + s.index, s.length); 56 | return result; 57 | } 58 | 59 | bool GDB_StartProcess(String gdb_filename, String gdb_args); 60 | 61 | bool GDB_SetInferiorExe(String filename); 62 | 63 | bool GDB_SetInferiorArgs(String args); 64 | 65 | void GDB_Shutdown(); 66 | 67 | // send a message to GDB, don't wait for result 68 | bool GDB_Send(const char *cmd); 69 | 70 | // send a message to GDB, wait for a result record 71 | bool GDB_SendBlocking(const char *cmd, bool remove_after = true); 72 | 73 | // send a message to GDB, wait for a result record, then retrieve it 74 | bool GDB_SendBlocking(const char *cmd, Record &rec); 75 | 76 | // extract a MI record from a newline terminated line 77 | bool GDB_ParseRecord(char *buf, size_t bufsize, ParseRecordContext &ctx); 78 | 79 | // first word after record type char 80 | // ex: ^done, *stopped 81 | String GDB_GetRecordAction(const Record &rec); 82 | 83 | void GDB_GrabBlockData(); 84 | 85 | RecordAtomSequence GDB_RecurseEvaluation(ParseRecordContext &ctx); 86 | 87 | typedef void AtomIterator(Record &rec, RecordAtom &iter, void *ctx); 88 | void IterateAtoms(Record &rec, RecordAtom &iter, AtomIterator *iterator, void *ctx); 89 | 90 | void GDB_PrintRecordAtom(const Record &rec, const RecordAtom &iter, int tab_level, FILE *out = stdout); 91 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | DEBUG ?= 0 2 | SAN ?= 0 3 | IMGUI_DIR = ./third-party/imgui 4 | 5 | VER_MAJOR = ${TUG_VER_MAJOR} 6 | VER_MINOR = ${TUG_VER_MINOR} 7 | VER_PATCH = ${TUG_VER_PATCH} 8 | 9 | ifeq ($(VER_MAJOR),) 10 | VER_MAJOR = 0 11 | endif 12 | 13 | ifeq ($(VER_MINOR),) 14 | VER_MINOR = 0 15 | endif 16 | 17 | ifeq ($(VER_PATCH),) 18 | VER_PATCH = 0 19 | endif 20 | 21 | CXX = g++ 22 | CXXFLAGS += -I./third-party -I./src -I./third-party/glfw/include 23 | CXXFLAGS += -std=c++11 -g3 -gdwarf-2 -Wall -Wextra -Werror=format -Werror=shadow -pedantic -pthread 24 | CXXFLAGS += -DTUG_VER_MAJOR=$(VER_MAJOR) -DTUG_VER_MINOR=$(VER_MINOR) -DTUG_VER_PATCH=$(VER_PATCH) 25 | CXXFLAGS += -Wno-missing-field-initializers 26 | 27 | ifeq ($(DEBUG), 1) 28 | CXXFLAGS += -DDEBUG -O0 29 | DEFAULT_OBJDIR = build_debug 30 | else 31 | CXXFLAGS += -DNDEBUG -O3 32 | DEFAULT_OBJDIR = build_release 33 | endif 34 | 35 | 36 | ifeq ($(OBJDIR), ) 37 | OBJDIR = $(DEFAULT_OBJDIR) 38 | endif 39 | 40 | 41 | ifeq ($(SAN), 1) 42 | CXXFLAGS += -fno-omit-frame-pointer -fsanitize=undefined,address #-fsanitize-undefined-trap-on-error 43 | endif 44 | 45 | 46 | GLFW = glfw3 47 | EXE = $(OBJDIR)/tug 48 | 49 | SOURCES = ./src/main.cpp\ 50 | ./src/gdb.cpp\ 51 | $(IMGUI_DIR)/imgui.cpp\ 52 | $(IMGUI_DIR)/imgui_demo.cpp\ 53 | $(IMGUI_DIR)/imgui_draw.cpp\ 54 | $(IMGUI_DIR)/imgui_impl_glfw.cpp\ 55 | $(IMGUI_DIR)/imgui_impl_opengl2.cpp\ 56 | $(IMGUI_DIR)/imgui_tables.cpp\ 57 | $(IMGUI_DIR)/imgui_widgets.cpp 58 | 59 | OBJS = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(basename $(notdir $(SOURCES))))) 60 | UNAME_S = $(shell uname -s) 61 | 62 | ## from example_glfw_opengl2 makefile 63 | ##--------------------------------------------------------------------- 64 | ## BUILD FLAGS PER PLATFORM 65 | ##--------------------------------------------------------------------- 66 | LIBS += -L ./third-party/glfw/$(OBJDIR) -l $(GLFW) 67 | 68 | ifeq ($(UNAME_S), Darwin) #APPLE 69 | SOURCES += ./third-party/sem_timedwait.cpp 70 | ECHO_MESSAGE = "Mac OS X" 71 | LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo 72 | LIBS += -L/usr/local/lib -L/opt/local/lib -L/opt/homebrew/lib 73 | LIBS += -lpthread 74 | 75 | CXXFLAGS += -I/usr/local/include -I/opt/local/include -I/opt/homebrew/include 76 | else ifeq ($(OS), Windows_NT) 77 | ECHO_MESSAGE = "MinGW" 78 | CXXFLAGS += -D_GNU_SOURCE # ptty and dirent visibility 79 | LIBS += -lpthread -lgdi32 -lopengl32 -limm32 80 | else 81 | # linux, BSD, etc. 82 | ECHO_MESSAGE = $(UNAME_S) 83 | LIBS += -lpthread -lm -ldl -lGL -lX11 84 | endif 85 | 86 | 87 | 88 | all: $(EXE) 89 | @echo build complete for $(ECHO_MESSAGE) 90 | 91 | $(EXE): $(OBJS) 92 | $(CXX) -o $@ $^ $(CXXFLAGS) $(CFLAGS) $(LIBS) 93 | 94 | $(EXE): | $(GLFW) 95 | 96 | $(GLFW): 97 | CFLAGS='$(CFLAGS)' OBJDIR='$(OBJDIR)' $(MAKE) -C ./third-party/glfw DEBUG=$(DEBUG) 98 | 99 | $(OBJDIR)/%.o:./src/%.cpp ./src/gdb.h ./src/common.h 100 | $(CXX) $(CXXFLAGS) $(CFLAGS) -c -o $@ $< 101 | 102 | $(OBJDIR)/%.o:./third-party/%.cpp 103 | $(CXX) $(CXXFLAGS) $(CFLAGS) -c -o $@ $< 104 | 105 | $(OBJDIR)/%.o:$(IMGUI_DIR)/%.cpp 106 | $(CXX) $(CXXFLAGS) $(CFLAGS) -c -o $@ $< 107 | 108 | $(OBJS): | $(OBJDIR) 109 | 110 | $(OBJDIR): 111 | mkdir -p $@ 112 | 113 | clean: 114 | rm -f $(EXE) $(OBJS) 115 | $(MAKE) -C ./third-party/glfw DEBUG=$(DEBUG) clean 116 | 117 | -------------------------------------------------------------------------------- /third-party/glfw/src/win32_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | #include "internal.h" 29 | 30 | #if defined(GLFW_BUILD_WIN32_THREAD) 31 | 32 | #include 33 | 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ////// GLFW platform API ////// 37 | ////////////////////////////////////////////////////////////////////////// 38 | 39 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 40 | { 41 | assert(tls->win32.allocated == GLFW_FALSE); 42 | 43 | tls->win32.index = TlsAlloc(); 44 | if (tls->win32.index == TLS_OUT_OF_INDEXES) 45 | { 46 | _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to allocate TLS index"); 47 | return GLFW_FALSE; 48 | } 49 | 50 | tls->win32.allocated = GLFW_TRUE; 51 | return GLFW_TRUE; 52 | } 53 | 54 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 55 | { 56 | if (tls->win32.allocated) 57 | TlsFree(tls->win32.index); 58 | memset(tls, 0, sizeof(_GLFWtls)); 59 | } 60 | 61 | void* _glfwPlatformGetTls(_GLFWtls* tls) 62 | { 63 | assert(tls->win32.allocated == GLFW_TRUE); 64 | return TlsGetValue(tls->win32.index); 65 | } 66 | 67 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 68 | { 69 | assert(tls->win32.allocated == GLFW_TRUE); 70 | TlsSetValue(tls->win32.index, value); 71 | } 72 | 73 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 74 | { 75 | assert(mutex->win32.allocated == GLFW_FALSE); 76 | InitializeCriticalSection(&mutex->win32.section); 77 | return mutex->win32.allocated = GLFW_TRUE; 78 | } 79 | 80 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 81 | { 82 | if (mutex->win32.allocated) 83 | DeleteCriticalSection(&mutex->win32.section); 84 | memset(mutex, 0, sizeof(_GLFWmutex)); 85 | } 86 | 87 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 88 | { 89 | assert(mutex->win32.allocated == GLFW_TRUE); 90 | EnterCriticalSection(&mutex->win32.section); 91 | } 92 | 93 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 94 | { 95 | assert(mutex->win32.allocated == GLFW_TRUE); 96 | LeaveCriticalSection(&mutex->win32.section); 97 | } 98 | 99 | #endif // GLFW_BUILD_WIN32_THREAD 100 | 101 | -------------------------------------------------------------------------------- /third-party/glfw/src/posix_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | #include "internal.h" 29 | 30 | #if defined(GLFW_BUILD_POSIX_THREAD) 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW platform API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 41 | { 42 | assert(tls->posix.allocated == GLFW_FALSE); 43 | 44 | if (pthread_key_create(&tls->posix.key, NULL) != 0) 45 | { 46 | _glfwInputError(GLFW_PLATFORM_ERROR, 47 | "POSIX: Failed to create context TLS"); 48 | return GLFW_FALSE; 49 | } 50 | 51 | tls->posix.allocated = GLFW_TRUE; 52 | return GLFW_TRUE; 53 | } 54 | 55 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 56 | { 57 | if (tls->posix.allocated) 58 | pthread_key_delete(tls->posix.key); 59 | memset(tls, 0, sizeof(_GLFWtls)); 60 | } 61 | 62 | void* _glfwPlatformGetTls(_GLFWtls* tls) 63 | { 64 | assert(tls->posix.allocated == GLFW_TRUE); 65 | return pthread_getspecific(tls->posix.key); 66 | } 67 | 68 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 69 | { 70 | assert(tls->posix.allocated == GLFW_TRUE); 71 | pthread_setspecific(tls->posix.key, value); 72 | } 73 | 74 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 75 | { 76 | assert(mutex->posix.allocated == GLFW_FALSE); 77 | 78 | if (pthread_mutex_init(&mutex->posix.handle, NULL) != 0) 79 | { 80 | _glfwInputError(GLFW_PLATFORM_ERROR, "POSIX: Failed to create mutex"); 81 | return GLFW_FALSE; 82 | } 83 | 84 | return mutex->posix.allocated = GLFW_TRUE; 85 | } 86 | 87 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 88 | { 89 | if (mutex->posix.allocated) 90 | pthread_mutex_destroy(&mutex->posix.handle); 91 | memset(mutex, 0, sizeof(_GLFWmutex)); 92 | } 93 | 94 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 95 | { 96 | assert(mutex->posix.allocated == GLFW_TRUE); 97 | pthread_mutex_lock(&mutex->posix.handle); 98 | } 99 | 100 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 101 | { 102 | assert(mutex->posix.allocated == GLFW_TRUE); 103 | pthread_mutex_unlock(&mutex->posix.handle); 104 | } 105 | 106 | #endif // GLFW_BUILD_POSIX_THREAD 107 | 108 | -------------------------------------------------------------------------------- /third-party/imgui/imgui_impl_glfw.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for GLFW 2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..) 3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) 4 | // (Requires: GLFW 3.1+. Prefer GLFW 3.3+ for full feature support.) 5 | 6 | // Implemented features: 7 | // [X] Platform: Clipboard support. 8 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 9 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 10 | // [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+). 11 | // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 12 | 13 | // Issues: 14 | // [ ] Platform: Multi-viewport support: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor). 15 | 16 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 17 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 18 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 19 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 20 | 21 | // About GLSL version: 22 | // The 'glsl_version' initialization parameter defaults to "#version 150" if NULL. 23 | // Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure! 24 | 25 | #pragma once 26 | #include "imgui.h" // IMGUI_IMPL_API 27 | 28 | struct GLFWwindow; 29 | struct GLFWmonitor; 30 | 31 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 32 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 33 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks); 34 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 35 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 36 | 37 | // GLFW callbacks (installer) 38 | // - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any. 39 | // - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks. 40 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window); 41 | IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window); 42 | 43 | // GLFW callbacks (individual callbacks to call if you didn't install callbacks) 44 | IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84 45 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84 46 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87 47 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 48 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 49 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 50 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 51 | IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event); 52 | -------------------------------------------------------------------------------- /third-party/glfw/src/mappings.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2018 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // As mappings.h.in, this file is used by CMake to produce the mappings.h 27 | // header file. If you are adding a GLFW specific gamepad mapping, this is 28 | // where to put it. 29 | //======================================================================== 30 | // As mappings.h, this provides all pre-defined gamepad mappings, including 31 | // all available in SDL_GameControllerDB. Do not edit this file. Any gamepad 32 | // mappings not specific to GLFW should be submitted to SDL_GameControllerDB. 33 | // This file can be re-generated from mappings.h.in and the upstream 34 | // gamecontrollerdb.txt with the 'update_mappings' CMake target. 35 | //======================================================================== 36 | 37 | // All gamepad mappings not labeled GLFW are copied from the 38 | // SDL_GameControllerDB project under the following license: 39 | // 40 | // Simple DirectMedia Layer 41 | // Copyright (C) 1997-2013 Sam Lantinga 42 | // 43 | // This software is provided 'as-is', without any express or implied warranty. 44 | // In no event will the authors be held liable for any damages arising from the 45 | // use of this software. 46 | // 47 | // Permission is granted to anyone to use this software for any purpose, 48 | // including commercial applications, and to alter it and redistribute it 49 | // freely, subject to the following restrictions: 50 | // 51 | // 1. The origin of this software must not be misrepresented; you must not 52 | // claim that you wrote the original software. If you use this software 53 | // in a product, an acknowledgment in the product documentation would 54 | // be appreciated but is not required. 55 | // 56 | // 2. Altered source versions must be plainly marked as such, and must not be 57 | // misrepresented as being the original software. 58 | // 59 | // 3. This notice may not be removed or altered from any source distribution. 60 | 61 | const char* _glfwDefaultMappings[] = 62 | { 63 | #if defined(_GLFW_WIN32) 64 | @GLFW_WIN32_MAPPINGS@ 65 | "78696e70757401000000000000000000,XInput Gamepad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 66 | "78696e70757402000000000000000000,XInput Wheel (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 67 | "78696e70757403000000000000000000,XInput Arcade Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 68 | "78696e70757404000000000000000000,XInput Flight Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 69 | "78696e70757405000000000000000000,XInput Dance Pad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 70 | "78696e70757406000000000000000000,XInput Guitar (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 71 | "78696e70757408000000000000000000,XInput Drum Kit (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 72 | #endif // _GLFW_WIN32 73 | 74 | #if defined(_GLFW_COCOA) 75 | @GLFW_COCOA_MAPPINGS@ 76 | #endif // _GLFW_COCOA 77 | 78 | #if defined(GLFW_BUILD_LINUX_JOYSTICK) 79 | @GLFW_LINUX_MAPPINGS@ 80 | #endif // GLFW_BUILD_LINUX_JOYSTICK 81 | }; 82 | 83 | -------------------------------------------------------------------------------- /third-party/glfw/src/null_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2019 Camilla Löwy 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 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | // The the sole (fake) video mode of our (sole) fake monitor 35 | // 36 | static GLFWvidmode getVideoMode(void) 37 | { 38 | GLFWvidmode mode; 39 | mode.width = 1920; 40 | mode.height = 1080; 41 | mode.redBits = 8; 42 | mode.greenBits = 8; 43 | mode.blueBits = 8; 44 | mode.refreshRate = 60; 45 | return mode; 46 | } 47 | 48 | ////////////////////////////////////////////////////////////////////////// 49 | ////// GLFW internal API ////// 50 | ////////////////////////////////////////////////////////////////////////// 51 | 52 | void _glfwPollMonitorsNull(void) 53 | { 54 | const float dpi = 141.f; 55 | const GLFWvidmode mode = getVideoMode(); 56 | _GLFWmonitor* monitor = _glfwAllocMonitor("Null SuperNoop 0", 57 | (int) (mode.width * 25.4f / dpi), 58 | (int) (mode.height * 25.4f / dpi)); 59 | _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_FIRST); 60 | } 61 | 62 | ////////////////////////////////////////////////////////////////////////// 63 | ////// GLFW platform API ////// 64 | ////////////////////////////////////////////////////////////////////////// 65 | 66 | void _glfwFreeMonitorNull(_GLFWmonitor* monitor) 67 | { 68 | _glfwFreeGammaArrays(&monitor->null.ramp); 69 | } 70 | 71 | void _glfwGetMonitorPosNull(_GLFWmonitor* monitor, int* xpos, int* ypos) 72 | { 73 | if (xpos) 74 | *xpos = 0; 75 | if (ypos) 76 | *ypos = 0; 77 | } 78 | 79 | void _glfwGetMonitorContentScaleNull(_GLFWmonitor* monitor, 80 | float* xscale, float* yscale) 81 | { 82 | if (xscale) 83 | *xscale = 1.f; 84 | if (yscale) 85 | *yscale = 1.f; 86 | } 87 | 88 | void _glfwGetMonitorWorkareaNull(_GLFWmonitor* monitor, 89 | int* xpos, int* ypos, 90 | int* width, int* height) 91 | { 92 | const GLFWvidmode mode = getVideoMode(); 93 | 94 | if (xpos) 95 | *xpos = 0; 96 | if (ypos) 97 | *ypos = 10; 98 | if (width) 99 | *width = mode.width; 100 | if (height) 101 | *height = mode.height - 10; 102 | } 103 | 104 | GLFWvidmode* _glfwGetVideoModesNull(_GLFWmonitor* monitor, int* found) 105 | { 106 | GLFWvidmode* mode = _glfw_calloc(1, sizeof(GLFWvidmode)); 107 | *mode = getVideoMode(); 108 | *found = 1; 109 | return mode; 110 | } 111 | 112 | GLFWbool _glfwGetVideoModeNull(_GLFWmonitor* monitor, GLFWvidmode* mode) 113 | { 114 | *mode = getVideoMode(); 115 | return GLFW_TRUE; 116 | } 117 | 118 | GLFWbool _glfwGetGammaRampNull(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 119 | { 120 | if (!monitor->null.ramp.size) 121 | { 122 | unsigned int i; 123 | 124 | _glfwAllocGammaArrays(&monitor->null.ramp, 256); 125 | 126 | for (i = 0; i < monitor->null.ramp.size; i++) 127 | { 128 | const float gamma = 2.2f; 129 | float value; 130 | value = i / (float) (monitor->null.ramp.size - 1); 131 | value = powf(value, 1.f / gamma) * 65535.f + 0.5f; 132 | value = fminf(value, 65535.f); 133 | 134 | monitor->null.ramp.red[i] = (unsigned short) value; 135 | monitor->null.ramp.green[i] = (unsigned short) value; 136 | monitor->null.ramp.blue[i] = (unsigned short) value; 137 | } 138 | } 139 | 140 | _glfwAllocGammaArrays(ramp, monitor->null.ramp.size); 141 | memcpy(ramp->red, monitor->null.ramp.red, sizeof(short) * ramp->size); 142 | memcpy(ramp->green, monitor->null.ramp.green, sizeof(short) * ramp->size); 143 | memcpy(ramp->blue, monitor->null.ramp.blue, sizeof(short) * ramp->size); 144 | return GLFW_TRUE; 145 | } 146 | 147 | void _glfwSetGammaRampNull(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 148 | { 149 | if (monitor->null.ramp.size != ramp->size) 150 | { 151 | _glfwInputError(GLFW_PLATFORM_ERROR, 152 | "Null: Gamma ramp size must match current ramp size"); 153 | return; 154 | } 155 | 156 | memcpy(monitor->null.ramp.red, ramp->red, sizeof(short) * ramp->size); 157 | memcpy(monitor->null.ramp.green, ramp->green, sizeof(short) * ramp->size); 158 | memcpy(monitor->null.ramp.blue, ramp->blue, sizeof(short) * ramp->size); 159 | } 160 | 161 | -------------------------------------------------------------------------------- /third-party/glfw/CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | 3 | GLFW exists because people around the world donated their time and lent their 4 | skills. This list only includes contributions to the main repository and 5 | excludes other invaluable contributions like language bindings and text and 6 | video tutorials. 7 | 8 | - Bobyshev Alexander 9 | - Laurent Aphecetche 10 | - Matt Arsenault 11 | - Takuro Ashie 12 | - ashishgamedev 13 | - David Avedissian 14 | - Luca Bacci 15 | - Keith Bauer 16 | - John Bartholomew 17 | - Coşku Baş 18 | - Bayemite 19 | - Niklas Behrens 20 | - Andrew Belt 21 | - Nevyn Bengtsson 22 | - Niklas Bergström 23 | - Denis Bernard 24 | - BiBi 25 | - Doug Binks 26 | - blanco 27 | - Waris Boonyasiriwat 28 | - Kyle Brenneman 29 | - Rok Breulj 30 | - TheBrokenRail 31 | - Kai Burjack 32 | - Martin Capitanio 33 | - Nicolas Caramelli 34 | - David Carlier 35 | - Arturo Castro 36 | - Chi-kwan Chan 37 | - Victor Chernyakin 38 | - TheChocolateOre 39 | - Ali Chraghi 40 | - Joseph Chua 41 | - Ian Clarkson 42 | - Michał Cichoń 43 | - Lambert Clara 44 | - Anna Clarke 45 | - Josh Codd 46 | - Yaron Cohen-Tal 47 | - Omar Cornut 48 | - Andrew Corrigan 49 | - Bailey Cosier 50 | - Noel Cower 51 | - CuriouserThing 52 | - Bill Currie 53 | - Jason Daly 54 | - danhambleton 55 | - Jarrod Davis 56 | - Olivier Delannoy 57 | - Paul R. Deppe 58 | - Michael Dickens 59 | - Роман Донченко 60 | - Mario Dorn 61 | - Wolfgang Draxinger 62 | - Jonathan Dummer 63 | - Ralph Eastwood 64 | - Fredrik Ehnbom 65 | - Robin Eklind 66 | - Jan Ekström 67 | - Siavash Eliasi 68 | - Ahmad Fatoum 69 | - Nikita Fediuchin 70 | - Felipe Ferreira 71 | - Michael Fogleman 72 | - forworldm 73 | - Jason Francis 74 | - Gerald Franz 75 | - Mário Freitas 76 | - GeO4d 77 | - Marcus Geelnard 78 | - Gegy 79 | - ghuser404 80 | - Charles Giessen 81 | - Ryan C. Gordon 82 | - Stephen Gowen 83 | - Kovid Goyal 84 | - Kevin Grandemange 85 | - Eloi Marín Gratacós 86 | - Grzesiek11 87 | - Stefan Gustavson 88 | - Andrew Gutekanst 89 | - Stephen Gutekanst 90 | - Jonathan Hale 91 | - Daniel Hauser 92 | - hdf89shfdfs 93 | - Moritz Heinemann 94 | - Sylvain Hellegouarch 95 | - Björn Hempel 96 | - Matthew Henry 97 | - heromyth 98 | - Lucas Hinderberger 99 | - Paul Holden 100 | - Hajime Hoshi 101 | - Warren Hu 102 | - Charles Huber 103 | - Brent Huisman 104 | - Florian Hülsmann 105 | - illustris 106 | - InKryption 107 | - IntellectualKitty 108 | - Aaron Jacobs 109 | - JannikGM 110 | - Erik S. V. Jansson 111 | - jjYBdx4IL 112 | - Peter Johnson 113 | - Toni Jovanoski 114 | - Arseny Kapoulkine 115 | - Cem Karan 116 | - Osman Keskin 117 | - Koray Kilinc 118 | - Josh Kilmer 119 | - Byunghoon Kim 120 | - Cameron King 121 | - Peter Knut 122 | - Christoph Kubisch 123 | - Yuri Kunde Schlesner 124 | - Rokas Kupstys 125 | - Konstantin Käfer 126 | - Eric Larson 127 | - Guillaume Lebrun 128 | - Francis Lecavalier 129 | - Jong Won Lee 130 | - Robin Leffmann 131 | - Glenn Lewis 132 | - Shane Liesegang 133 | - Anders Lindqvist 134 | - Leon Linhart 135 | - Marco Lizza 136 | - lo-v-ol 137 | - Eyal Lotem 138 | - Aaron Loucks 139 | - Ned Loynd 140 | - Luflosi 141 | - lukect 142 | - Tristam MacDonald 143 | - Jean-Luc Mackail 144 | - Hans Mackowiak 145 | - Ramiro Magno 146 | - Дмитри Малышев 147 | - Zbigniew Mandziejewicz 148 | - Adam Marcus 149 | - Célestin Marot 150 | - Kyle McDonald 151 | - David V. McKay 152 | - David Medlock 153 | - Bryce Mehring 154 | - Jonathan Mercier 155 | - Marcel Metz 156 | - Liam Middlebrook 157 | - mightgoyardstill 158 | - Ave Milia 159 | - Icyllis Milica 160 | - Jonathan Miller 161 | - Kenneth Miller 162 | - Bruce Mitchener 163 | - Jack Moffitt 164 | - Ravi Mohan 165 | - Jeff Molofee 166 | - Alexander Monakov 167 | - Pierre Morel 168 | - Jon Morton 169 | - Pierre Moulon 170 | - Martins Mozeiko 171 | - Pascal Muetschard 172 | - James Murphy 173 | - Julian Møller 174 | - Julius Häger 175 | - Nat! 176 | - NateIsStalling 177 | - ndogxj 178 | - F. Nedelec 179 | - n3rdopolis 180 | - Kristian Nielsen 181 | - Joel Niemelä 182 | - Victor Nova 183 | - Kamil Nowakowski 184 | - onox 185 | - Denis Ovod 186 | - Ozzy 187 | - Andri Pálsson 188 | - luz paz 189 | - Peoro 190 | - Braden Pellett 191 | - Christopher Pelloux 192 | - Michael Pennington 193 | - Arturo J. Pérez 194 | - Vladimir Perminov 195 | - Olivier Perret 196 | - Anthony Pesch 197 | - Orson Peters 198 | - Emmanuel Gil Peyrot 199 | - Cyril Pichard 200 | - Pilzschaf 201 | - Keith Pitt 202 | - Stanislav Podgorskiy 203 | - Konstantin Podsvirov 204 | - Nathan Poirier 205 | - Pokechu22 206 | - Alexandre Pretyman 207 | - Pablo Prietz 208 | - przemekmirek 209 | - pthom 210 | - Martin Pulec 211 | - Guillaume Racicot 212 | - Juan Ramos 213 | - Christian Rauch 214 | - Philip Rideout 215 | - Eddie Ringle 216 | - Max Risuhin 217 | - Joe Roback 218 | - Jorge Rodriguez 219 | - Jari Ronkainen 220 | - Luca Rood 221 | - Ed Ropple 222 | - Aleksey Rybalkin 223 | - Mikko Rytkönen 224 | - Riku Salminen 225 | - Yoshinori Sano 226 | - Brandon Schaefer 227 | - Sebastian Schuberth 228 | - Scr3amer 229 | - Jan Schuerkamp 230 | - Christian Sdunek 231 | - Matt Sealey 232 | - Steve Sexton 233 | - Arkady Shapkin 234 | - Mingjie Shen 235 | - Ali Sherief 236 | - Yoshiki Shibukawa 237 | - Dmitri Shuralyov 238 | - Joao da Silva 239 | - Daniel Sieger 240 | - Daljit Singh 241 | - Michael Skec 242 | - Daniel Skorupski 243 | - Slemmie 244 | - Anthony Smith 245 | - Bradley Smith 246 | - Cliff Smolinsky 247 | - Patrick Snape 248 | - Erlend Sogge Heggen 249 | - Olivier Sohn 250 | - Julian Squires 251 | - Johannes Stein 252 | - Pontus Stenetorp 253 | - Michael Stocker 254 | - Justin Stoecker 255 | - Elviss Strazdins 256 | - Paul Sultana 257 | - Nathan Sweet 258 | - TTK-Bandit 259 | - Nuno Teixeira 260 | - Jared Tiala 261 | - Sergey Tikhomirov 262 | - Arthur Tombs 263 | - TronicLabs 264 | - Ioannis Tsakpinis 265 | - Samuli Tuomola 266 | - Matthew Turner 267 | - urraka 268 | - Elias Vanderstuyft 269 | - Stef Velzel 270 | - Jari Vetoniemi 271 | - Ricardo Vieira 272 | - Nicholas Vitovitch 273 | - Vladimír Vondruš 274 | - Simon Voordouw 275 | - Corentin Wallez 276 | - Torsten Walluhn 277 | - Patrick Walton 278 | - Jim Wang 279 | - Xo Wang 280 | - Andre Weissflog 281 | - Jay Weisskopf 282 | - Frank Wille 283 | - Andy Williams 284 | - Joel Winarske 285 | - Richard A. Wilkes 286 | - Tatsuya Yatagawa 287 | - Ryogo Yoshimura 288 | - Lukas Zanner 289 | - Andrey Zholos 290 | - Aihui Zhu 291 | - Santi Zupancic 292 | - Jonas Ådahl 293 | - Lasse Öörni 294 | - Leonard König 295 | - All the unmentioned and anonymous contributors in the GLFW community, for bug 296 | reports, patches, feedback, testing and encouragement 297 | 298 | -------------------------------------------------------------------------------- /third-party/glfw/src/platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2018 Camilla Löwy 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 | #if defined(GLFW_BUILD_WIN32_TIMER) || \ 29 | defined(GLFW_BUILD_WIN32_MODULE) || \ 30 | defined(GLFW_BUILD_WIN32_THREAD) || \ 31 | defined(GLFW_BUILD_COCOA_TIMER) || \ 32 | defined(GLFW_BUILD_POSIX_TIMER) || \ 33 | defined(GLFW_BUILD_POSIX_MODULE) || \ 34 | defined(GLFW_BUILD_POSIX_THREAD) || \ 35 | defined(GLFW_BUILD_POSIX_POLL) || \ 36 | defined(GLFW_BUILD_LINUX_JOYSTICK) 37 | #error "You must not define these; define zero or more _GLFW_ macros instead" 38 | #endif 39 | 40 | #include "null_platform.h" 41 | #define GLFW_EXPOSE_NATIVE_EGL 42 | #define GLFW_EXPOSE_NATIVE_OSMESA 43 | 44 | #if defined(_GLFW_WIN32) 45 | #include "win32_platform.h" 46 | #define GLFW_EXPOSE_NATIVE_WIN32 47 | #define GLFW_EXPOSE_NATIVE_WGL 48 | #else 49 | #define GLFW_WIN32_WINDOW_STATE 50 | #define GLFW_WIN32_MONITOR_STATE 51 | #define GLFW_WIN32_CURSOR_STATE 52 | #define GLFW_WIN32_LIBRARY_WINDOW_STATE 53 | #define GLFW_WGL_CONTEXT_STATE 54 | #define GLFW_WGL_LIBRARY_CONTEXT_STATE 55 | #endif 56 | 57 | #if defined(_GLFW_COCOA) 58 | #include "cocoa_platform.h" 59 | #define GLFW_EXPOSE_NATIVE_COCOA 60 | #define GLFW_EXPOSE_NATIVE_NSGL 61 | #else 62 | #define GLFW_COCOA_WINDOW_STATE 63 | #define GLFW_COCOA_MONITOR_STATE 64 | #define GLFW_COCOA_CURSOR_STATE 65 | #define GLFW_COCOA_LIBRARY_WINDOW_STATE 66 | #define GLFW_NSGL_CONTEXT_STATE 67 | #define GLFW_NSGL_LIBRARY_CONTEXT_STATE 68 | #endif 69 | 70 | #if defined(_GLFW_WAYLAND) 71 | #include "wl_platform.h" 72 | #define GLFW_EXPOSE_NATIVE_WAYLAND 73 | #else 74 | #define GLFW_WAYLAND_WINDOW_STATE 75 | #define GLFW_WAYLAND_MONITOR_STATE 76 | #define GLFW_WAYLAND_CURSOR_STATE 77 | #define GLFW_WAYLAND_LIBRARY_WINDOW_STATE 78 | #endif 79 | 80 | #if defined(_GLFW_X11) 81 | #include "x11_platform.h" 82 | #define GLFW_EXPOSE_NATIVE_X11 83 | #define GLFW_EXPOSE_NATIVE_GLX 84 | #else 85 | #define GLFW_X11_WINDOW_STATE 86 | #define GLFW_X11_MONITOR_STATE 87 | #define GLFW_X11_CURSOR_STATE 88 | #define GLFW_X11_LIBRARY_WINDOW_STATE 89 | #define GLFW_GLX_CONTEXT_STATE 90 | #define GLFW_GLX_LIBRARY_CONTEXT_STATE 91 | #endif 92 | 93 | #include "null_joystick.h" 94 | 95 | #if defined(_GLFW_WIN32) 96 | #include "win32_joystick.h" 97 | #else 98 | #define GLFW_WIN32_JOYSTICK_STATE 99 | #define GLFW_WIN32_LIBRARY_JOYSTICK_STATE 100 | #endif 101 | 102 | #if defined(_GLFW_COCOA) 103 | #include "cocoa_joystick.h" 104 | #else 105 | #define GLFW_COCOA_JOYSTICK_STATE 106 | #define GLFW_COCOA_LIBRARY_JOYSTICK_STATE 107 | #endif 108 | 109 | #if (defined(_GLFW_X11) || defined(_GLFW_WAYLAND)) && defined(__linux__) 110 | #define GLFW_BUILD_LINUX_JOYSTICK 111 | #endif 112 | 113 | #if defined(GLFW_BUILD_LINUX_JOYSTICK) 114 | #include "linux_joystick.h" 115 | #else 116 | #define GLFW_LINUX_JOYSTICK_STATE 117 | #define GLFW_LINUX_LIBRARY_JOYSTICK_STATE 118 | #endif 119 | 120 | #define GLFW_PLATFORM_WINDOW_STATE \ 121 | GLFW_WIN32_WINDOW_STATE \ 122 | GLFW_COCOA_WINDOW_STATE \ 123 | GLFW_WAYLAND_WINDOW_STATE \ 124 | GLFW_X11_WINDOW_STATE \ 125 | GLFW_NULL_WINDOW_STATE \ 126 | 127 | #define GLFW_PLATFORM_MONITOR_STATE \ 128 | GLFW_WIN32_MONITOR_STATE \ 129 | GLFW_COCOA_MONITOR_STATE \ 130 | GLFW_WAYLAND_MONITOR_STATE \ 131 | GLFW_X11_MONITOR_STATE \ 132 | GLFW_NULL_MONITOR_STATE \ 133 | 134 | #define GLFW_PLATFORM_CURSOR_STATE \ 135 | GLFW_WIN32_CURSOR_STATE \ 136 | GLFW_COCOA_CURSOR_STATE \ 137 | GLFW_WAYLAND_CURSOR_STATE \ 138 | GLFW_X11_CURSOR_STATE \ 139 | GLFW_NULL_CURSOR_STATE \ 140 | 141 | #define GLFW_PLATFORM_JOYSTICK_STATE \ 142 | GLFW_WIN32_JOYSTICK_STATE \ 143 | GLFW_COCOA_JOYSTICK_STATE \ 144 | GLFW_LINUX_JOYSTICK_STATE 145 | 146 | #define GLFW_PLATFORM_LIBRARY_WINDOW_STATE \ 147 | GLFW_WIN32_LIBRARY_WINDOW_STATE \ 148 | GLFW_COCOA_LIBRARY_WINDOW_STATE \ 149 | GLFW_WAYLAND_LIBRARY_WINDOW_STATE \ 150 | GLFW_X11_LIBRARY_WINDOW_STATE \ 151 | GLFW_NULL_LIBRARY_WINDOW_STATE \ 152 | 153 | #define GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ 154 | GLFW_WIN32_LIBRARY_JOYSTICK_STATE \ 155 | GLFW_COCOA_LIBRARY_JOYSTICK_STATE \ 156 | GLFW_LINUX_LIBRARY_JOYSTICK_STATE 157 | 158 | #define GLFW_PLATFORM_CONTEXT_STATE \ 159 | GLFW_WGL_CONTEXT_STATE \ 160 | GLFW_NSGL_CONTEXT_STATE \ 161 | GLFW_GLX_CONTEXT_STATE 162 | 163 | #define GLFW_PLATFORM_LIBRARY_CONTEXT_STATE \ 164 | GLFW_WGL_LIBRARY_CONTEXT_STATE \ 165 | GLFW_NSGL_LIBRARY_CONTEXT_STATE \ 166 | GLFW_GLX_LIBRARY_CONTEXT_STATE 167 | 168 | #if defined(_WIN32) 169 | #define GLFW_BUILD_WIN32_THREAD 170 | #else 171 | #define GLFW_BUILD_POSIX_THREAD 172 | #endif 173 | 174 | #if defined(GLFW_BUILD_WIN32_THREAD) 175 | #include "win32_thread.h" 176 | #define GLFW_PLATFORM_TLS_STATE GLFW_WIN32_TLS_STATE 177 | #define GLFW_PLATFORM_MUTEX_STATE GLFW_WIN32_MUTEX_STATE 178 | #elif defined(GLFW_BUILD_POSIX_THREAD) 179 | #include "posix_thread.h" 180 | #define GLFW_PLATFORM_TLS_STATE GLFW_POSIX_TLS_STATE 181 | #define GLFW_PLATFORM_MUTEX_STATE GLFW_POSIX_MUTEX_STATE 182 | #endif 183 | 184 | #if defined(_WIN32) 185 | #define GLFW_BUILD_WIN32_TIMER 186 | #elif defined(__APPLE__) 187 | #define GLFW_BUILD_COCOA_TIMER 188 | #else 189 | #define GLFW_BUILD_POSIX_TIMER 190 | #endif 191 | 192 | #if defined(GLFW_BUILD_WIN32_TIMER) 193 | #include "win32_time.h" 194 | #define GLFW_PLATFORM_LIBRARY_TIMER_STATE GLFW_WIN32_LIBRARY_TIMER_STATE 195 | #elif defined(GLFW_BUILD_COCOA_TIMER) 196 | #include "cocoa_time.h" 197 | #define GLFW_PLATFORM_LIBRARY_TIMER_STATE GLFW_COCOA_LIBRARY_TIMER_STATE 198 | #elif defined(GLFW_BUILD_POSIX_TIMER) 199 | #include "posix_time.h" 200 | #define GLFW_PLATFORM_LIBRARY_TIMER_STATE GLFW_POSIX_LIBRARY_TIMER_STATE 201 | #endif 202 | 203 | #if defined(_WIN32) 204 | #define GLFW_BUILD_WIN32_MODULE 205 | #else 206 | #define GLFW_BUILD_POSIX_MODULE 207 | #endif 208 | 209 | #if defined(_GLFW_WAYLAND) || defined(_GLFW_X11) 210 | #define GLFW_BUILD_POSIX_POLL 211 | #endif 212 | 213 | -------------------------------------------------------------------------------- /third-party/glfw/src/platform.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2018 Camilla Löwy 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 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | 33 | // These construct a string literal from individual numeric constants 34 | #define _GLFW_CONCAT_VERSION(m, n, r) #m "." #n "." #r 35 | #define _GLFW_MAKE_VERSION(m, n, r) _GLFW_CONCAT_VERSION(m, n, r) 36 | 37 | ////////////////////////////////////////////////////////////////////////// 38 | ////// GLFW internal API ////// 39 | ////////////////////////////////////////////////////////////////////////// 40 | 41 | static const struct 42 | { 43 | int ID; 44 | GLFWbool (*connect)(int,_GLFWplatform*); 45 | } supportedPlatforms[] = 46 | { 47 | #if defined(_GLFW_WIN32) 48 | { GLFW_PLATFORM_WIN32, _glfwConnectWin32 }, 49 | #endif 50 | #if defined(_GLFW_COCOA) 51 | { GLFW_PLATFORM_COCOA, _glfwConnectCocoa }, 52 | #endif 53 | #if defined(_GLFW_WAYLAND) 54 | { GLFW_PLATFORM_WAYLAND, _glfwConnectWayland }, 55 | #endif 56 | #if defined(_GLFW_X11) 57 | { GLFW_PLATFORM_X11, _glfwConnectX11 }, 58 | #endif 59 | }; 60 | 61 | GLFWbool _glfwSelectPlatform(int desiredID, _GLFWplatform* platform) 62 | { 63 | const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]); 64 | size_t i; 65 | 66 | if (desiredID != GLFW_ANY_PLATFORM && 67 | desiredID != GLFW_PLATFORM_WIN32 && 68 | desiredID != GLFW_PLATFORM_COCOA && 69 | desiredID != GLFW_PLATFORM_WAYLAND && 70 | desiredID != GLFW_PLATFORM_X11 && 71 | desiredID != GLFW_PLATFORM_NULL) 72 | { 73 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X", desiredID); 74 | return GLFW_FALSE; 75 | } 76 | 77 | // Only allow the Null platform if specifically requested 78 | if (desiredID == GLFW_PLATFORM_NULL) 79 | return _glfwConnectNull(desiredID, platform); 80 | else if (count == 0) 81 | { 82 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "This binary only supports the Null platform"); 83 | return GLFW_FALSE; 84 | } 85 | 86 | #if defined(_GLFW_WAYLAND) && defined(_GLFW_X11) 87 | if (desiredID == GLFW_ANY_PLATFORM) 88 | { 89 | const char* const session = getenv("XDG_SESSION_TYPE"); 90 | if (session) 91 | { 92 | // Only follow XDG_SESSION_TYPE if it is set correctly and the 93 | // environment looks plausble; otherwise fall back to detection 94 | if (strcmp(session, "wayland") == 0 && getenv("WAYLAND_DISPLAY")) 95 | desiredID = GLFW_PLATFORM_WAYLAND; 96 | else if (strcmp(session, "x11") == 0 && getenv("DISPLAY")) 97 | desiredID = GLFW_PLATFORM_X11; 98 | } 99 | } 100 | #endif 101 | 102 | if (desiredID == GLFW_ANY_PLATFORM) 103 | { 104 | // If there is exactly one platform available for auto-selection, let it emit the 105 | // error on failure as the platform-specific error description may be more helpful 106 | if (count == 1) 107 | return supportedPlatforms[0].connect(supportedPlatforms[0].ID, platform); 108 | 109 | for (i = 0; i < count; i++) 110 | { 111 | if (supportedPlatforms[i].connect(desiredID, platform)) 112 | return GLFW_TRUE; 113 | } 114 | 115 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Failed to detect any supported platform"); 116 | } 117 | else 118 | { 119 | for (i = 0; i < count; i++) 120 | { 121 | if (supportedPlatforms[i].ID == desiredID) 122 | return supportedPlatforms[i].connect(desiredID, platform); 123 | } 124 | 125 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "The requested platform is not supported"); 126 | } 127 | 128 | return GLFW_FALSE; 129 | } 130 | 131 | ////////////////////////////////////////////////////////////////////////// 132 | ////// GLFW public API ////// 133 | ////////////////////////////////////////////////////////////////////////// 134 | 135 | GLFWAPI int glfwGetPlatform(void) 136 | { 137 | _GLFW_REQUIRE_INIT_OR_RETURN(0); 138 | return _glfw.platform.platformID; 139 | } 140 | 141 | GLFWAPI int glfwPlatformSupported(int platformID) 142 | { 143 | const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]); 144 | size_t i; 145 | 146 | if (platformID != GLFW_PLATFORM_WIN32 && 147 | platformID != GLFW_PLATFORM_COCOA && 148 | platformID != GLFW_PLATFORM_WAYLAND && 149 | platformID != GLFW_PLATFORM_X11 && 150 | platformID != GLFW_PLATFORM_NULL) 151 | { 152 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X", platformID); 153 | return GLFW_FALSE; 154 | } 155 | 156 | if (platformID == GLFW_PLATFORM_NULL) 157 | return GLFW_TRUE; 158 | 159 | for (i = 0; i < count; i++) 160 | { 161 | if (platformID == supportedPlatforms[i].ID) 162 | return GLFW_TRUE; 163 | } 164 | 165 | return GLFW_FALSE; 166 | } 167 | 168 | GLFWAPI const char* glfwGetVersionString(void) 169 | { 170 | return _GLFW_MAKE_VERSION(GLFW_VERSION_MAJOR, 171 | GLFW_VERSION_MINOR, 172 | GLFW_VERSION_REVISION) 173 | #if defined(_GLFW_WIN32) 174 | " Win32 WGL" 175 | #endif 176 | #if defined(_GLFW_COCOA) 177 | " Cocoa NSGL" 178 | #endif 179 | #if defined(_GLFW_WAYLAND) 180 | " Wayland" 181 | #endif 182 | #if defined(_GLFW_X11) 183 | " X11 GLX" 184 | #endif 185 | " Null" 186 | " EGL" 187 | " OSMesa" 188 | #if defined(__MINGW64_VERSION_MAJOR) 189 | " MinGW-w64" 190 | #elif defined(__MINGW32__) 191 | " MinGW" 192 | #elif defined(_MSC_VER) 193 | " VisualC" 194 | #endif 195 | #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG) 196 | " hybrid-GPU" 197 | #endif 198 | #if defined(_POSIX_MONOTONIC_CLOCK) 199 | " monotonic" 200 | #endif 201 | #if defined(_GLFW_BUILD_DLL) 202 | #if defined(_WIN32) 203 | " DLL" 204 | #elif defined(__APPLE__) 205 | " dynamic" 206 | #else 207 | " shared" 208 | #endif 209 | #endif 210 | ; 211 | } 212 | 213 | -------------------------------------------------------------------------------- /third-party/glfw/src/wl_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Wayland - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | #if defined(_GLFW_WAYLAND) 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "wayland-client-protocol.h" 38 | 39 | 40 | static void outputHandleGeometry(void* userData, 41 | struct wl_output* output, 42 | int32_t x, 43 | int32_t y, 44 | int32_t physicalWidth, 45 | int32_t physicalHeight, 46 | int32_t subpixel, 47 | const char* make, 48 | const char* model, 49 | int32_t transform) 50 | { 51 | struct _GLFWmonitor* monitor = userData; 52 | 53 | monitor->wl.x = x; 54 | monitor->wl.y = y; 55 | monitor->widthMM = physicalWidth; 56 | monitor->heightMM = physicalHeight; 57 | 58 | if (strlen(monitor->name) == 0) 59 | snprintf(monitor->name, sizeof(monitor->name), "%s %s", make, model); 60 | } 61 | 62 | static void outputHandleMode(void* userData, 63 | struct wl_output* output, 64 | uint32_t flags, 65 | int32_t width, 66 | int32_t height, 67 | int32_t refresh) 68 | { 69 | struct _GLFWmonitor* monitor = userData; 70 | GLFWvidmode mode; 71 | 72 | mode.width = width; 73 | mode.height = height; 74 | mode.redBits = 8; 75 | mode.greenBits = 8; 76 | mode.blueBits = 8; 77 | mode.refreshRate = (int) round(refresh / 1000.0); 78 | 79 | monitor->modeCount++; 80 | monitor->modes = 81 | _glfw_realloc(monitor->modes, monitor->modeCount * sizeof(GLFWvidmode)); 82 | monitor->modes[monitor->modeCount - 1] = mode; 83 | 84 | if (flags & WL_OUTPUT_MODE_CURRENT) 85 | monitor->wl.currentMode = monitor->modeCount - 1; 86 | } 87 | 88 | static void outputHandleDone(void* userData, struct wl_output* output) 89 | { 90 | struct _GLFWmonitor* monitor = userData; 91 | 92 | if (monitor->widthMM <= 0 || monitor->heightMM <= 0) 93 | { 94 | // If Wayland does not provide a physical size, assume the default 96 DPI 95 | const GLFWvidmode* mode = &monitor->modes[monitor->wl.currentMode]; 96 | monitor->widthMM = (int) (mode->width * 25.4f / 96.f); 97 | monitor->heightMM = (int) (mode->height * 25.4f / 96.f); 98 | } 99 | 100 | for (int i = 0; i < _glfw.monitorCount; i++) 101 | { 102 | if (_glfw.monitors[i] == monitor) 103 | return; 104 | } 105 | 106 | _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST); 107 | } 108 | 109 | static void outputHandleScale(void* userData, 110 | struct wl_output* output, 111 | int32_t factor) 112 | { 113 | struct _GLFWmonitor* monitor = userData; 114 | 115 | monitor->wl.scale = factor; 116 | 117 | for (_GLFWwindow* window = _glfw.windowListHead; window; window = window->next) 118 | { 119 | for (size_t i = 0; i < window->wl.outputScaleCount; i++) 120 | { 121 | if (window->wl.outputScales[i].output == monitor->wl.output) 122 | { 123 | window->wl.outputScales[i].factor = monitor->wl.scale; 124 | _glfwUpdateBufferScaleFromOutputsWayland(window); 125 | break; 126 | } 127 | } 128 | } 129 | } 130 | 131 | void outputHandleName(void* userData, struct wl_output* wl_output, const char* name) 132 | { 133 | struct _GLFWmonitor* monitor = userData; 134 | 135 | strncpy(monitor->name, name, sizeof(monitor->name) - 1); 136 | } 137 | 138 | void outputHandleDescription(void* userData, 139 | struct wl_output* wl_output, 140 | const char* description) 141 | { 142 | } 143 | 144 | static const struct wl_output_listener outputListener = 145 | { 146 | outputHandleGeometry, 147 | outputHandleMode, 148 | outputHandleDone, 149 | outputHandleScale, 150 | outputHandleName, 151 | outputHandleDescription, 152 | }; 153 | 154 | 155 | ////////////////////////////////////////////////////////////////////////// 156 | ////// GLFW internal API ////// 157 | ////////////////////////////////////////////////////////////////////////// 158 | 159 | void _glfwAddOutputWayland(uint32_t name, uint32_t version) 160 | { 161 | if (version < 2) 162 | { 163 | _glfwInputError(GLFW_PLATFORM_ERROR, 164 | "Wayland: Unsupported output interface version"); 165 | return; 166 | } 167 | 168 | version = _glfw_min(version, WL_OUTPUT_NAME_SINCE_VERSION); 169 | 170 | struct wl_output* output = wl_registry_bind(_glfw.wl.registry, 171 | name, 172 | &wl_output_interface, 173 | version); 174 | if (!output) 175 | return; 176 | 177 | // The actual name of this output will be set in the geometry handler 178 | _GLFWmonitor* monitor = _glfwAllocMonitor("", 0, 0); 179 | monitor->wl.scale = 1; 180 | monitor->wl.output = output; 181 | monitor->wl.name = name; 182 | 183 | wl_proxy_set_tag((struct wl_proxy*) output, &_glfw.wl.tag); 184 | wl_output_add_listener(output, &outputListener, monitor); 185 | } 186 | 187 | 188 | ////////////////////////////////////////////////////////////////////////// 189 | ////// GLFW platform API ////// 190 | ////////////////////////////////////////////////////////////////////////// 191 | 192 | void _glfwFreeMonitorWayland(_GLFWmonitor* monitor) 193 | { 194 | if (monitor->wl.output) 195 | wl_output_destroy(monitor->wl.output); 196 | } 197 | 198 | void _glfwGetMonitorPosWayland(_GLFWmonitor* monitor, int* xpos, int* ypos) 199 | { 200 | if (xpos) 201 | *xpos = monitor->wl.x; 202 | if (ypos) 203 | *ypos = monitor->wl.y; 204 | } 205 | 206 | void _glfwGetMonitorContentScaleWayland(_GLFWmonitor* monitor, 207 | float* xscale, float* yscale) 208 | { 209 | if (xscale) 210 | *xscale = (float) monitor->wl.scale; 211 | if (yscale) 212 | *yscale = (float) monitor->wl.scale; 213 | } 214 | 215 | void _glfwGetMonitorWorkareaWayland(_GLFWmonitor* monitor, 216 | int* xpos, int* ypos, 217 | int* width, int* height) 218 | { 219 | if (xpos) 220 | *xpos = monitor->wl.x; 221 | if (ypos) 222 | *ypos = monitor->wl.y; 223 | if (width) 224 | *width = monitor->modes[monitor->wl.currentMode].width; 225 | if (height) 226 | *height = monitor->modes[monitor->wl.currentMode].height; 227 | } 228 | 229 | GLFWvidmode* _glfwGetVideoModesWayland(_GLFWmonitor* monitor, int* found) 230 | { 231 | *found = monitor->modeCount; 232 | return monitor->modes; 233 | } 234 | 235 | GLFWbool _glfwGetVideoModeWayland(_GLFWmonitor* monitor, GLFWvidmode* mode) 236 | { 237 | *mode = monitor->modes[monitor->wl.currentMode]; 238 | return GLFW_TRUE; 239 | } 240 | 241 | GLFWbool _glfwGetGammaRampWayland(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 242 | { 243 | _glfwInputError(GLFW_FEATURE_UNAVAILABLE, 244 | "Wayland: Gamma ramp access is not available"); 245 | return GLFW_FALSE; 246 | } 247 | 248 | void _glfwSetGammaRampWayland(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 249 | { 250 | _glfwInputError(GLFW_FEATURE_UNAVAILABLE, 251 | "Wayland: Gamma ramp access is not available"); 252 | } 253 | 254 | 255 | ////////////////////////////////////////////////////////////////////////// 256 | ////// GLFW native API ////// 257 | ////////////////////////////////////////////////////////////////////////// 258 | 259 | GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* handle) 260 | { 261 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 262 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 263 | 264 | if (_glfw.platform.platformID != GLFW_PLATFORM_WAYLAND) 265 | { 266 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Wayland: Platform not initialized"); 267 | return NULL; 268 | } 269 | 270 | return monitor->wl.output; 271 | } 272 | 273 | #endif // _GLFW_WAYLAND 274 | 275 | -------------------------------------------------------------------------------- /third-party/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) 7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. 8 | //----------------------------------------------------------------------------- 9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp 10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. 11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 12 | // Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using. 13 | //----------------------------------------------------------------------------- 14 | 15 | #pragma once 16 | 17 | #define IMGUI_DEFINE_MATH_OPERATORS 18 | 19 | 20 | //---- Define assertion handler. Defaults to calling assert(). 21 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. 22 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 23 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 24 | 25 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows 26 | // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. 27 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() 28 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. 29 | //#define IMGUI_API __declspec( dllexport ) 30 | //#define IMGUI_API __declspec( dllimport ) 31 | 32 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. 33 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 34 | //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. 35 | 36 | //---- Disable all of Dear ImGui or don't implement standard windows. 37 | // It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp. 38 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. 39 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended. 40 | //#define IMGUI_DISABLE_METRICS_WINDOW // Disable metrics/debugger and other debug tools: ShowMetricsWindow() and ShowStackToolWindow() will be empty. 41 | 42 | //---- Don't implement some functions to reduce linkage requirements. 43 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) 44 | //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) 45 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) 46 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime). 47 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). 48 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) 49 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. 50 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies) 51 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. 52 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 53 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available 54 | 55 | //---- Include imgui_user.h at the end of imgui.h as a convenience 56 | //#define IMGUI_INCLUDE_IMGUI_USER_H 57 | 58 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 59 | //#define IMGUI_USE_BGRA_PACKED_COLOR 60 | 61 | //---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) 62 | //#define IMGUI_USE_WCHAR32 63 | 64 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 65 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. 66 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 67 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 68 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if enabled 69 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 70 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 71 | 72 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 73 | // Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h. 74 | //#define IMGUI_USE_STB_SPRINTF 75 | 76 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 77 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). 78 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 79 | //#define IMGUI_ENABLE_FREETYPE 80 | 81 | //---- Use stb_truetype to build and rasterize the font atlas (default) 82 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 83 | //#define IMGUI_ENABLE_STB_TRUETYPE 84 | 85 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 86 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 87 | /* 88 | #define IM_VEC2_CLASS_EXTRA \ 89 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ 90 | operator MyVec2() const { return MyVec2(x,y); } 91 | 92 | #define IM_VEC4_CLASS_EXTRA \ 93 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ 94 | operator MyVec4() const { return MyVec4(x,y,z,w); } 95 | */ 96 | 97 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 98 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 99 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 100 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 101 | //#define ImDrawIdx unsigned int 102 | 103 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 104 | //struct ImDrawList; 105 | //struct ImDrawCmd; 106 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 107 | //#define ImDrawCallback MyImDrawCallback 108 | 109 | //---- Debug Tools: Macro to break in Debugger 110 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 111 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 112 | //#define IM_DEBUG_BREAK __debugbreak() 113 | 114 | //---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(), 115 | // (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.) 116 | // This adds a small runtime cost which is why it is not enabled by default. 117 | //#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX 118 | 119 | //---- Debug Tools: Enable slower asserts 120 | //#define IMGUI_DEBUG_PARANOID 121 | 122 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. 123 | /* 124 | namespace ImGui 125 | { 126 | void MyFunction(const char* name, const MyMatrix44& v); 127 | } 128 | */ 129 | -------------------------------------------------------------------------------- /src/common.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 Kyle Sylvestre 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with this program. If not, see . 15 | 16 | #pragma once 17 | 18 | // sepples 19 | #include 20 | #include 21 | 22 | // cstd 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | // linoox 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #if defined(__APPLE__) 45 | int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout); 46 | #endif 47 | 48 | #if defined(__CYGWIN__) 49 | #include 50 | #endif 51 | 52 | template 53 | using Vector = std::vector; 54 | using String = std::basic_string>; 55 | 56 | #define VARGS_CHECK(fmt, ...) (0 && snprintf(NULL, 0, fmt, __VA_ARGS__)) 57 | #define StringPrintf(fmt, ...) _StringPrintf(VARGS_CHECK(fmt, __VA_ARGS__), fmt, __VA_ARGS__) 58 | String _StringPrintf(int vargs_check, const char *fmt, ...); 59 | 60 | #define ArrayCount(arr) (sizeof(arr) / sizeof(arr[0])) 61 | #define tsnprintf(buf, fmt, ...) snprintf(buf, sizeof(buf), fmt, __VA_ARGS__) 62 | #define DefaultInvalid default: PrintError("hit invalid default switch"); break; 63 | #define GetMax(a, b) (a > b) ? a : b 64 | #define GetMin(a, b) (a < b) ? a : b 65 | #define GetPinned(v, min, max) GetMin(GetMax(v, min), max) 66 | #define GetAbs(a, b) (a > b) ? a - b : b - a 67 | 68 | template 69 | inline void Zeroize(T &value) 70 | { 71 | memset(&value, 0, sizeof(value)); 72 | } 73 | 74 | // c standard wrappers 75 | #if !defined(NDEBUG) 76 | #define Assert(cond)\ 77 | if ( !(cond) )\ 78 | {\ 79 | char _gdb_buf[128]; tsnprintf(_gdb_buf, "gdb --pid %d", (int)getpid()); int _rc = system(_gdb_buf); (void)_rc; exit(1);\ 80 | } 81 | #else 82 | #define Assert(cond) (void)0; 83 | #endif 84 | 85 | #define Printf(fmt, ...) do { String _msg = StringPrintf(fmt, __VA_ARGS__); WriteToConsoleBuffer(_msg.data(), _msg.size()); } while(0) 86 | #define Print(msg) Printf("%s", msg) 87 | 88 | // log user error message 89 | #define PrintError(str) PrintErrorf("%s", str) 90 | #define PrintErrorf(fmt, ...)\ 91 | do {\ 92 | fprintf(stderr, "(%s : %s : %d) ", __FILE__, __FUNCTION__, __LINE__);\ 93 | String _msg = StringPrintf("Error " fmt, __VA_ARGS__);\ 94 | fprintf(stderr, "%s", _msg.c_str());\ 95 | WriteToConsoleBuffer(_msg.data(), _msg.size());\ 96 | /*Assert(false);*/\ 97 | } while(0) 98 | 99 | #define INVALID_LINE 0 100 | #define RECORD_ROOT_IDX 0 101 | 102 | // prefix for preventing name clashes 103 | #define GLOBAL_NAME_PREFIX "GB__" 104 | #define LOCAL_NAME_PREFIX "LC__" 105 | 106 | // values with child elements from -data-evaluate-expression 107 | // struct: value={ a = "foo", b = "bar", c = "baz" } 108 | // union: value={ a = "foo", b = "bar", c = "baz" } 109 | // array: value={1, 2, 3} 110 | #define AGGREGATE_CHAR_START '{' 111 | #define AGGREGATE_CHAR_END '}' 112 | 113 | // maximum amount of variables displayed in an expression if there 114 | // are no run length values 115 | #define AGGREGATE_MAX 200 116 | 117 | const char *const DEFAULT_REG_ARM[] = { 118 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", 119 | "r9", "r10", "r11", /*"fp",*/ "r12", "sp", "lr", "pc", "cpsr", 120 | }; 121 | 122 | const char *const DEFAULT_REG_AMD64[] = { 123 | "rax", "rbx", "rcx", "rdx", 124 | "rbp", "rsp", "rip", "rsi", 125 | "rdi", "r8", "r9", "r10", "r11", 126 | "r12", "r13", "r14", "r15" 127 | }; 128 | 129 | const char *const DEFAULT_REG_X86[] = { 130 | "eax", "ebx", "ecx", "edx", 131 | "ebp", "esp", "eip", "esi", 132 | "edi", 133 | }; 134 | 135 | // TODO: threads 136 | struct Frame 137 | { 138 | String func; 139 | uint64_t addr; // current PC/IP 140 | size_t file_idx; // in prog.files 141 | size_t line_idx; // next line to be executed - 1 142 | }; 143 | 144 | struct Breakpoint 145 | { 146 | uint64_t addr; 147 | size_t number; // ordinal assigned by GDB 148 | size_t line_idx; // file line number - 1 149 | size_t file_idx; // index in prog.files 150 | bool enabled; 151 | String cond; 152 | }; 153 | 154 | struct DisassemblyLine 155 | { 156 | uint64_t addr; 157 | String text; 158 | }; 159 | 160 | struct DisassemblySourceLine 161 | { 162 | uint64_t addr; 163 | size_t num_instructions; 164 | size_t line_idx; 165 | }; 166 | 167 | struct File 168 | { 169 | Vector lines; // offset to line within data 170 | String filename; 171 | String data; // file chars excluding line endings 172 | size_t longest_line_idx;// line with most chars, used for horizontal scrollbar 173 | }; 174 | 175 | #define INVALID_BLOCK_STRING_IDX 0 176 | 177 | enum AtomType 178 | { 179 | Atom_None, // parse state 180 | Atom_Name, // parse state 181 | Atom_Array, 182 | Atom_Struct, 183 | Atom_String, 184 | }; 185 | 186 | // range of data that lives inside another buffer 187 | struct Span 188 | { 189 | size_t index; 190 | size_t length; 191 | }; 192 | 193 | struct RecordAtom 194 | { 195 | AtomType type; 196 | 197 | // text span inside Record.buf 198 | Span name; 199 | 200 | // variant variable based upon type 201 | // array/struct= array span inside Record.atoms 202 | // string= text span inside Record.buf 203 | Span value; 204 | }; 205 | 206 | struct Record 207 | { 208 | // ordinal that gets send preceding MI-Commands that gets sent 209 | // back in the response record 210 | uint32_t id; 211 | 212 | // data describing the line elements 213 | Vector atoms; 214 | 215 | // line buffer, RecordAtom name/value strings point to data inside this 216 | String buf; 217 | }; 218 | 219 | struct RecordHolder 220 | { 221 | bool parsed; 222 | Record rec; 223 | }; 224 | 225 | struct VarObj 226 | { 227 | String name; 228 | String value; 229 | bool changed; 230 | 231 | // structs, unions, arrays 232 | Record expr; 233 | Vector expr_changed; 234 | }; 235 | 236 | // run length RecordAtom in expression value 237 | struct RecordAtomSequence 238 | { 239 | RecordAtom atom; 240 | size_t length; 241 | }; 242 | 243 | struct Thread 244 | { 245 | int id; 246 | String group_id; 247 | bool running; 248 | bool focused; // thread is included in ExecuteCommand 249 | }; 250 | 251 | 252 | // GDB MI sends output as human readable lines, starting with a symbol 253 | // * = exec-async-output contains asynchronous state change on the target 254 | // (stopped, started, disappeared) 255 | // 256 | // & = log-stream-output is debugging messages being produced by GDB’s internals. 257 | // 258 | // ^ = record 259 | // 260 | // @ = The target output stream contains any textual output from the running target. 261 | // This is only present when GDB’s event loop is truly asynchronous, 262 | // which is currently only the case for remote targets. 263 | // 264 | // ~ = console-stream-output is output that should be displayed 265 | // as is in the console. It is the textual response to a CLI command 266 | // 267 | // after the commands, it ends with signature "(gdb)" 268 | 269 | #define PREFIX_ASYNC0 '=' 270 | #define PREFIX_ASYNC1 '*' 271 | #define PREFIX_RESULT '^' 272 | #define PREFIX_DEBUG_LOG '&' 273 | #define PREFIX_TARGET_LOG '@' 274 | #define PREFIX_CONSOLE_LOG '~' 275 | 276 | const size_t BAD_INDEX = ~0; 277 | 278 | #define FILE_IDX_INVALID 0 279 | 280 | 281 | struct GDB 282 | { 283 | pid_t spawned_pid; // process running GDB 284 | String debug_filename; // debug executable filename 285 | String debug_args; // args passed to debug executable 286 | String filename; // filename of spawned GDB 287 | String args; // args passed to spawned GDB 288 | String ptty_slave; 289 | int fd_ptty_master; 290 | 291 | bool end_program; 292 | pthread_t thread_read_interp; 293 | //pthread_t thread_write_stdin; 294 | 295 | sem_t *recv_block; 296 | pthread_mutex_t modify_block; 297 | 298 | // MI command sent from GDB 299 | int fd_in_read; 300 | int fd_in_write; 301 | 302 | // commands sent to GDB 303 | int fd_out_read; 304 | int fd_out_write; 305 | 306 | // ordinal ID that gets incremented on every 307 | // GDB_SendBlocking record sent 308 | uint32_t record_id = 1; 309 | 310 | // raw data, guarded by modify_storage_lock 311 | // a block is one or more Records 312 | char block_data[1024 * 1024]; 313 | Vector block_spans; // pipe read span into block_data 314 | 315 | // capabilities of the spawned GDB process using -list-features 316 | bool has_frozen_varobj; 317 | bool has_pending_breakpoints; 318 | bool has_python_scripting_support; 319 | bool has_thread_info; 320 | bool has_data_rw_bytes; // -data-read-memory bytes and -data-write-memory-bytes 321 | bool has_async_breakpoint_notification; // bkpt changes make async record 322 | bool has_ada_task_info; 323 | bool has_language_option; 324 | bool has_gdb_mi_command; 325 | bool has_undefined_command_error_code; 326 | bool has_exec_run_start; 327 | bool has_data_disassemble_option_a; // -data-disassemble -a function 328 | 329 | // capabilities of the target using -list-target-features 330 | bool supports_async_execution; // GDB will accept further commands while the target is running. 331 | bool supports_reverse_execution; // target is capable of reverse execution 332 | 333 | bool echo_next_no_symbol_in_context; // GDB MI error "no symbol "xyz" in current context" 334 | // useful sometimes but mostly gets spammed in console 335 | }; 336 | 337 | struct Program 338 | { 339 | // console messages ordered from newest to oldest 340 | char log[64 * 1024]; 341 | bool log_scroll_to_bottom = true; 342 | size_t log_idx; 343 | 344 | // GDB console history buffer 345 | String input_cmd_data; 346 | Vector input_cmd_offsets; 347 | int input_cmd_idx = -1; 348 | 349 | Vector local_vars; // locals for the current frame 350 | Vector global_vars; // watch for entire program, -var-create name @ expr 351 | Vector watch_vars; // user defined watch for entire program 352 | bool running; 353 | bool started; 354 | bool source_out_of_date; 355 | Vector breakpoints; 356 | // TODO: threads, active_thread 357 | 358 | Vector read_recs; 359 | size_t num_recs; 360 | 361 | Vector files; 362 | Vector threads; 363 | Vector frames; 364 | size_t frame_idx = BAD_INDEX; 365 | size_t file_idx = BAD_INDEX; 366 | size_t thread_idx = BAD_INDEX; 367 | pid_t inferior_process; 368 | String stack_sig; // string of all function names combined 369 | }; 370 | 371 | extern Program prog; 372 | extern GDB gdb; 373 | 374 | const char *GetErrorString(int _errno); 375 | void WriteToConsoleBuffer(const char *raw, size_t rawsize); 376 | bool VerifyFileExecutable(const char *filename); 377 | bool DoesFileExist(const char *filename, bool print_error_on_missing = true); 378 | bool DoesProcessExist(pid_t p); 379 | bool InvokeShellCommand(String command, String &output); 380 | void TrimWhitespace(String &str); 381 | -------------------------------------------------------------------------------- /third-party/glfw/src/null_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 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 | #define GLFW_NULL_WINDOW_STATE _GLFWwindowNull null; 29 | #define GLFW_NULL_LIBRARY_WINDOW_STATE _GLFWlibraryNull null; 30 | #define GLFW_NULL_MONITOR_STATE _GLFWmonitorNull null; 31 | 32 | #define GLFW_NULL_CONTEXT_STATE 33 | #define GLFW_NULL_CURSOR_STATE 34 | #define GLFW_NULL_LIBRARY_CONTEXT_STATE 35 | 36 | #define GLFW_NULL_SC_FIRST GLFW_NULL_SC_SPACE 37 | #define GLFW_NULL_SC_SPACE 1 38 | #define GLFW_NULL_SC_APOSTROPHE 2 39 | #define GLFW_NULL_SC_COMMA 3 40 | #define GLFW_NULL_SC_MINUS 4 41 | #define GLFW_NULL_SC_PERIOD 5 42 | #define GLFW_NULL_SC_SLASH 6 43 | #define GLFW_NULL_SC_0 7 44 | #define GLFW_NULL_SC_1 8 45 | #define GLFW_NULL_SC_2 9 46 | #define GLFW_NULL_SC_3 10 47 | #define GLFW_NULL_SC_4 11 48 | #define GLFW_NULL_SC_5 12 49 | #define GLFW_NULL_SC_6 13 50 | #define GLFW_NULL_SC_7 14 51 | #define GLFW_NULL_SC_8 15 52 | #define GLFW_NULL_SC_9 16 53 | #define GLFW_NULL_SC_SEMICOLON 17 54 | #define GLFW_NULL_SC_EQUAL 18 55 | #define GLFW_NULL_SC_LEFT_BRACKET 19 56 | #define GLFW_NULL_SC_BACKSLASH 20 57 | #define GLFW_NULL_SC_RIGHT_BRACKET 21 58 | #define GLFW_NULL_SC_GRAVE_ACCENT 22 59 | #define GLFW_NULL_SC_WORLD_1 23 60 | #define GLFW_NULL_SC_WORLD_2 24 61 | #define GLFW_NULL_SC_ESCAPE 25 62 | #define GLFW_NULL_SC_ENTER 26 63 | #define GLFW_NULL_SC_TAB 27 64 | #define GLFW_NULL_SC_BACKSPACE 28 65 | #define GLFW_NULL_SC_INSERT 29 66 | #define GLFW_NULL_SC_DELETE 30 67 | #define GLFW_NULL_SC_RIGHT 31 68 | #define GLFW_NULL_SC_LEFT 32 69 | #define GLFW_NULL_SC_DOWN 33 70 | #define GLFW_NULL_SC_UP 34 71 | #define GLFW_NULL_SC_PAGE_UP 35 72 | #define GLFW_NULL_SC_PAGE_DOWN 36 73 | #define GLFW_NULL_SC_HOME 37 74 | #define GLFW_NULL_SC_END 38 75 | #define GLFW_NULL_SC_CAPS_LOCK 39 76 | #define GLFW_NULL_SC_SCROLL_LOCK 40 77 | #define GLFW_NULL_SC_NUM_LOCK 41 78 | #define GLFW_NULL_SC_PRINT_SCREEN 42 79 | #define GLFW_NULL_SC_PAUSE 43 80 | #define GLFW_NULL_SC_A 44 81 | #define GLFW_NULL_SC_B 45 82 | #define GLFW_NULL_SC_C 46 83 | #define GLFW_NULL_SC_D 47 84 | #define GLFW_NULL_SC_E 48 85 | #define GLFW_NULL_SC_F 49 86 | #define GLFW_NULL_SC_G 50 87 | #define GLFW_NULL_SC_H 51 88 | #define GLFW_NULL_SC_I 52 89 | #define GLFW_NULL_SC_J 53 90 | #define GLFW_NULL_SC_K 54 91 | #define GLFW_NULL_SC_L 55 92 | #define GLFW_NULL_SC_M 56 93 | #define GLFW_NULL_SC_N 57 94 | #define GLFW_NULL_SC_O 58 95 | #define GLFW_NULL_SC_P 59 96 | #define GLFW_NULL_SC_Q 60 97 | #define GLFW_NULL_SC_R 61 98 | #define GLFW_NULL_SC_S 62 99 | #define GLFW_NULL_SC_T 63 100 | #define GLFW_NULL_SC_U 64 101 | #define GLFW_NULL_SC_V 65 102 | #define GLFW_NULL_SC_W 66 103 | #define GLFW_NULL_SC_X 67 104 | #define GLFW_NULL_SC_Y 68 105 | #define GLFW_NULL_SC_Z 69 106 | #define GLFW_NULL_SC_F1 70 107 | #define GLFW_NULL_SC_F2 71 108 | #define GLFW_NULL_SC_F3 72 109 | #define GLFW_NULL_SC_F4 73 110 | #define GLFW_NULL_SC_F5 74 111 | #define GLFW_NULL_SC_F6 75 112 | #define GLFW_NULL_SC_F7 76 113 | #define GLFW_NULL_SC_F8 77 114 | #define GLFW_NULL_SC_F9 78 115 | #define GLFW_NULL_SC_F10 79 116 | #define GLFW_NULL_SC_F11 80 117 | #define GLFW_NULL_SC_F12 81 118 | #define GLFW_NULL_SC_F13 82 119 | #define GLFW_NULL_SC_F14 83 120 | #define GLFW_NULL_SC_F15 84 121 | #define GLFW_NULL_SC_F16 85 122 | #define GLFW_NULL_SC_F17 86 123 | #define GLFW_NULL_SC_F18 87 124 | #define GLFW_NULL_SC_F19 88 125 | #define GLFW_NULL_SC_F20 89 126 | #define GLFW_NULL_SC_F21 90 127 | #define GLFW_NULL_SC_F22 91 128 | #define GLFW_NULL_SC_F23 92 129 | #define GLFW_NULL_SC_F24 93 130 | #define GLFW_NULL_SC_F25 94 131 | #define GLFW_NULL_SC_KP_0 95 132 | #define GLFW_NULL_SC_KP_1 96 133 | #define GLFW_NULL_SC_KP_2 97 134 | #define GLFW_NULL_SC_KP_3 98 135 | #define GLFW_NULL_SC_KP_4 99 136 | #define GLFW_NULL_SC_KP_5 100 137 | #define GLFW_NULL_SC_KP_6 101 138 | #define GLFW_NULL_SC_KP_7 102 139 | #define GLFW_NULL_SC_KP_8 103 140 | #define GLFW_NULL_SC_KP_9 104 141 | #define GLFW_NULL_SC_KP_DECIMAL 105 142 | #define GLFW_NULL_SC_KP_DIVIDE 106 143 | #define GLFW_NULL_SC_KP_MULTIPLY 107 144 | #define GLFW_NULL_SC_KP_SUBTRACT 108 145 | #define GLFW_NULL_SC_KP_ADD 109 146 | #define GLFW_NULL_SC_KP_ENTER 110 147 | #define GLFW_NULL_SC_KP_EQUAL 111 148 | #define GLFW_NULL_SC_LEFT_SHIFT 112 149 | #define GLFW_NULL_SC_LEFT_CONTROL 113 150 | #define GLFW_NULL_SC_LEFT_ALT 114 151 | #define GLFW_NULL_SC_LEFT_SUPER 115 152 | #define GLFW_NULL_SC_RIGHT_SHIFT 116 153 | #define GLFW_NULL_SC_RIGHT_CONTROL 117 154 | #define GLFW_NULL_SC_RIGHT_ALT 118 155 | #define GLFW_NULL_SC_RIGHT_SUPER 119 156 | #define GLFW_NULL_SC_MENU 120 157 | #define GLFW_NULL_SC_LAST GLFW_NULL_SC_MENU 158 | 159 | // Null-specific per-window data 160 | // 161 | typedef struct _GLFWwindowNull 162 | { 163 | int xpos; 164 | int ypos; 165 | int width; 166 | int height; 167 | GLFWbool visible; 168 | GLFWbool iconified; 169 | GLFWbool maximized; 170 | GLFWbool resizable; 171 | GLFWbool decorated; 172 | GLFWbool floating; 173 | GLFWbool transparent; 174 | float opacity; 175 | } _GLFWwindowNull; 176 | 177 | // Null-specific per-monitor data 178 | // 179 | typedef struct _GLFWmonitorNull 180 | { 181 | GLFWgammaramp ramp; 182 | } _GLFWmonitorNull; 183 | 184 | // Null-specific global data 185 | // 186 | typedef struct _GLFWlibraryNull 187 | { 188 | int xcursor; 189 | int ycursor; 190 | char* clipboardString; 191 | _GLFWwindow* focusedWindow; 192 | uint16_t keycodes[GLFW_NULL_SC_LAST + 1]; 193 | uint8_t scancodes[GLFW_KEY_LAST + 1]; 194 | } _GLFWlibraryNull; 195 | 196 | void _glfwPollMonitorsNull(void); 197 | 198 | GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform); 199 | int _glfwInitNull(void); 200 | void _glfwTerminateNull(void); 201 | 202 | void _glfwFreeMonitorNull(_GLFWmonitor* monitor); 203 | void _glfwGetMonitorPosNull(_GLFWmonitor* monitor, int* xpos, int* ypos); 204 | void _glfwGetMonitorContentScaleNull(_GLFWmonitor* monitor, float* xscale, float* yscale); 205 | void _glfwGetMonitorWorkareaNull(_GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height); 206 | GLFWvidmode* _glfwGetVideoModesNull(_GLFWmonitor* monitor, int* found); 207 | GLFWbool _glfwGetVideoModeNull(_GLFWmonitor* monitor, GLFWvidmode* mode); 208 | GLFWbool _glfwGetGammaRampNull(_GLFWmonitor* monitor, GLFWgammaramp* ramp); 209 | void _glfwSetGammaRampNull(_GLFWmonitor* monitor, const GLFWgammaramp* ramp); 210 | 211 | GLFWbool _glfwCreateWindowNull(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); 212 | void _glfwDestroyWindowNull(_GLFWwindow* window); 213 | void _glfwSetWindowTitleNull(_GLFWwindow* window, const char* title); 214 | void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* images); 215 | void _glfwSetWindowMonitorNull(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); 216 | void _glfwGetWindowPosNull(_GLFWwindow* window, int* xpos, int* ypos); 217 | void _glfwSetWindowPosNull(_GLFWwindow* window, int xpos, int ypos); 218 | void _glfwGetWindowSizeNull(_GLFWwindow* window, int* width, int* height); 219 | void _glfwSetWindowSizeNull(_GLFWwindow* window, int width, int height); 220 | void _glfwSetWindowSizeLimitsNull(_GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight); 221 | void _glfwSetWindowAspectRatioNull(_GLFWwindow* window, int n, int d); 222 | void _glfwGetFramebufferSizeNull(_GLFWwindow* window, int* width, int* height); 223 | void _glfwGetWindowFrameSizeNull(_GLFWwindow* window, int* left, int* top, int* right, int* bottom); 224 | void _glfwGetWindowContentScaleNull(_GLFWwindow* window, float* xscale, float* yscale); 225 | void _glfwIconifyWindowNull(_GLFWwindow* window); 226 | void _glfwRestoreWindowNull(_GLFWwindow* window); 227 | void _glfwMaximizeWindowNull(_GLFWwindow* window); 228 | GLFWbool _glfwWindowMaximizedNull(_GLFWwindow* window); 229 | GLFWbool _glfwWindowHoveredNull(_GLFWwindow* window); 230 | GLFWbool _glfwFramebufferTransparentNull(_GLFWwindow* window); 231 | void _glfwSetWindowResizableNull(_GLFWwindow* window, GLFWbool enabled); 232 | void _glfwSetWindowDecoratedNull(_GLFWwindow* window, GLFWbool enabled); 233 | void _glfwSetWindowFloatingNull(_GLFWwindow* window, GLFWbool enabled); 234 | void _glfwSetWindowMousePassthroughNull(_GLFWwindow* window, GLFWbool enabled); 235 | float _glfwGetWindowOpacityNull(_GLFWwindow* window); 236 | void _glfwSetWindowOpacityNull(_GLFWwindow* window, float opacity); 237 | void _glfwSetRawMouseMotionNull(_GLFWwindow *window, GLFWbool enabled); 238 | GLFWbool _glfwRawMouseMotionSupportedNull(void); 239 | void _glfwShowWindowNull(_GLFWwindow* window); 240 | void _glfwRequestWindowAttentionNull(_GLFWwindow* window); 241 | void _glfwHideWindowNull(_GLFWwindow* window); 242 | void _glfwFocusWindowNull(_GLFWwindow* window); 243 | GLFWbool _glfwWindowFocusedNull(_GLFWwindow* window); 244 | GLFWbool _glfwWindowIconifiedNull(_GLFWwindow* window); 245 | GLFWbool _glfwWindowVisibleNull(_GLFWwindow* window); 246 | void _glfwPollEventsNull(void); 247 | void _glfwWaitEventsNull(void); 248 | void _glfwWaitEventsTimeoutNull(double timeout); 249 | void _glfwPostEmptyEventNull(void); 250 | void _glfwGetCursorPosNull(_GLFWwindow* window, double* xpos, double* ypos); 251 | void _glfwSetCursorPosNull(_GLFWwindow* window, double x, double y); 252 | void _glfwSetCursorModeNull(_GLFWwindow* window, int mode); 253 | GLFWbool _glfwCreateCursorNull(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot); 254 | GLFWbool _glfwCreateStandardCursorNull(_GLFWcursor* cursor, int shape); 255 | void _glfwDestroyCursorNull(_GLFWcursor* cursor); 256 | void _glfwSetCursorNull(_GLFWwindow* window, _GLFWcursor* cursor); 257 | void _glfwSetClipboardStringNull(const char* string); 258 | const char* _glfwGetClipboardStringNull(void); 259 | const char* _glfwGetScancodeNameNull(int scancode); 260 | int _glfwGetKeyScancodeNull(int key); 261 | 262 | EGLenum _glfwGetEGLPlatformNull(EGLint** attribs); 263 | EGLNativeDisplayType _glfwGetEGLNativeDisplayNull(void); 264 | EGLNativeWindowType _glfwGetEGLNativeWindowNull(_GLFWwindow* window); 265 | 266 | void _glfwGetRequiredInstanceExtensionsNull(char** extensions); 267 | GLFWbool _glfwGetPhysicalDevicePresentationSupportNull(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); 268 | VkResult _glfwCreateWindowSurfaceNull(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); 269 | 270 | void _glfwPollMonitorsNull(void); 271 | 272 | -------------------------------------------------------------------------------- /third-party/glfw/src/vulkan.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2018 Camilla Löwy 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 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #define _GLFW_FIND_LOADER 1 35 | #define _GLFW_REQUIRE_LOADER 2 36 | 37 | 38 | ////////////////////////////////////////////////////////////////////////// 39 | ////// GLFW internal API ////// 40 | ////////////////////////////////////////////////////////////////////////// 41 | 42 | GLFWbool _glfwInitVulkan(int mode) 43 | { 44 | VkResult err; 45 | VkExtensionProperties* ep; 46 | PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties; 47 | uint32_t i, count; 48 | 49 | if (_glfw.vk.available) 50 | return GLFW_TRUE; 51 | 52 | if (_glfw.hints.init.vulkanLoader) 53 | _glfw.vk.GetInstanceProcAddr = _glfw.hints.init.vulkanLoader; 54 | else 55 | { 56 | #if defined(_GLFW_VULKAN_LIBRARY) 57 | _glfw.vk.handle = _glfwPlatformLoadModule(_GLFW_VULKAN_LIBRARY); 58 | #elif defined(_GLFW_WIN32) 59 | _glfw.vk.handle = _glfwPlatformLoadModule("vulkan-1.dll"); 60 | #elif defined(_GLFW_COCOA) 61 | _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.1.dylib"); 62 | if (!_glfw.vk.handle) 63 | _glfw.vk.handle = _glfwLoadLocalVulkanLoaderCocoa(); 64 | #elif defined(__OpenBSD__) || defined(__NetBSD__) 65 | _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.so"); 66 | #else 67 | _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.so.1"); 68 | #endif 69 | if (!_glfw.vk.handle) 70 | { 71 | if (mode == _GLFW_REQUIRE_LOADER) 72 | _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: Loader not found"); 73 | 74 | return GLFW_FALSE; 75 | } 76 | 77 | _glfw.vk.GetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) 78 | _glfwPlatformGetModuleSymbol(_glfw.vk.handle, "vkGetInstanceProcAddr"); 79 | if (!_glfw.vk.GetInstanceProcAddr) 80 | { 81 | _glfwInputError(GLFW_API_UNAVAILABLE, 82 | "Vulkan: Loader does not export vkGetInstanceProcAddr"); 83 | 84 | _glfwTerminateVulkan(); 85 | return GLFW_FALSE; 86 | } 87 | } 88 | 89 | vkEnumerateInstanceExtensionProperties = (PFN_vkEnumerateInstanceExtensionProperties) 90 | vkGetInstanceProcAddr(NULL, "vkEnumerateInstanceExtensionProperties"); 91 | if (!vkEnumerateInstanceExtensionProperties) 92 | { 93 | _glfwInputError(GLFW_API_UNAVAILABLE, 94 | "Vulkan: Failed to retrieve vkEnumerateInstanceExtensionProperties"); 95 | 96 | _glfwTerminateVulkan(); 97 | return GLFW_FALSE; 98 | } 99 | 100 | err = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL); 101 | if (err) 102 | { 103 | // NOTE: This happens on systems with a loader but without any Vulkan ICD 104 | if (mode == _GLFW_REQUIRE_LOADER) 105 | { 106 | _glfwInputError(GLFW_API_UNAVAILABLE, 107 | "Vulkan: Failed to query instance extension count: %s", 108 | _glfwGetVulkanResultString(err)); 109 | } 110 | 111 | _glfwTerminateVulkan(); 112 | return GLFW_FALSE; 113 | } 114 | 115 | ep = _glfw_calloc(count, sizeof(VkExtensionProperties)); 116 | 117 | err = vkEnumerateInstanceExtensionProperties(NULL, &count, ep); 118 | if (err) 119 | { 120 | _glfwInputError(GLFW_API_UNAVAILABLE, 121 | "Vulkan: Failed to query instance extensions: %s", 122 | _glfwGetVulkanResultString(err)); 123 | 124 | _glfw_free(ep); 125 | _glfwTerminateVulkan(); 126 | return GLFW_FALSE; 127 | } 128 | 129 | for (i = 0; i < count; i++) 130 | { 131 | if (strcmp(ep[i].extensionName, "VK_KHR_surface") == 0) 132 | _glfw.vk.KHR_surface = GLFW_TRUE; 133 | else if (strcmp(ep[i].extensionName, "VK_KHR_win32_surface") == 0) 134 | _glfw.vk.KHR_win32_surface = GLFW_TRUE; 135 | else if (strcmp(ep[i].extensionName, "VK_MVK_macos_surface") == 0) 136 | _glfw.vk.MVK_macos_surface = GLFW_TRUE; 137 | else if (strcmp(ep[i].extensionName, "VK_EXT_metal_surface") == 0) 138 | _glfw.vk.EXT_metal_surface = GLFW_TRUE; 139 | else if (strcmp(ep[i].extensionName, "VK_KHR_xlib_surface") == 0) 140 | _glfw.vk.KHR_xlib_surface = GLFW_TRUE; 141 | else if (strcmp(ep[i].extensionName, "VK_KHR_xcb_surface") == 0) 142 | _glfw.vk.KHR_xcb_surface = GLFW_TRUE; 143 | else if (strcmp(ep[i].extensionName, "VK_KHR_wayland_surface") == 0) 144 | _glfw.vk.KHR_wayland_surface = GLFW_TRUE; 145 | } 146 | 147 | _glfw_free(ep); 148 | 149 | _glfw.vk.available = GLFW_TRUE; 150 | 151 | _glfw.platform.getRequiredInstanceExtensions(_glfw.vk.extensions); 152 | 153 | return GLFW_TRUE; 154 | } 155 | 156 | void _glfwTerminateVulkan(void) 157 | { 158 | if (_glfw.vk.handle) 159 | _glfwPlatformFreeModule(_glfw.vk.handle); 160 | } 161 | 162 | const char* _glfwGetVulkanResultString(VkResult result) 163 | { 164 | switch (result) 165 | { 166 | case VK_SUCCESS: 167 | return "Success"; 168 | case VK_NOT_READY: 169 | return "A fence or query has not yet completed"; 170 | case VK_TIMEOUT: 171 | return "A wait operation has not completed in the specified time"; 172 | case VK_EVENT_SET: 173 | return "An event is signaled"; 174 | case VK_EVENT_RESET: 175 | return "An event is unsignaled"; 176 | case VK_INCOMPLETE: 177 | return "A return array was too small for the result"; 178 | case VK_ERROR_OUT_OF_HOST_MEMORY: 179 | return "A host memory allocation has failed"; 180 | case VK_ERROR_OUT_OF_DEVICE_MEMORY: 181 | return "A device memory allocation has failed"; 182 | case VK_ERROR_INITIALIZATION_FAILED: 183 | return "Initialization of an object could not be completed for implementation-specific reasons"; 184 | case VK_ERROR_DEVICE_LOST: 185 | return "The logical or physical device has been lost"; 186 | case VK_ERROR_MEMORY_MAP_FAILED: 187 | return "Mapping of a memory object has failed"; 188 | case VK_ERROR_LAYER_NOT_PRESENT: 189 | return "A requested layer is not present or could not be loaded"; 190 | case VK_ERROR_EXTENSION_NOT_PRESENT: 191 | return "A requested extension is not supported"; 192 | case VK_ERROR_FEATURE_NOT_PRESENT: 193 | return "A requested feature is not supported"; 194 | case VK_ERROR_INCOMPATIBLE_DRIVER: 195 | return "The requested version of Vulkan is not supported by the driver or is otherwise incompatible"; 196 | case VK_ERROR_TOO_MANY_OBJECTS: 197 | return "Too many objects of the type have already been created"; 198 | case VK_ERROR_FORMAT_NOT_SUPPORTED: 199 | return "A requested format is not supported on this device"; 200 | case VK_ERROR_SURFACE_LOST_KHR: 201 | return "A surface is no longer available"; 202 | case VK_SUBOPTIMAL_KHR: 203 | return "A swapchain no longer matches the surface properties exactly, but can still be used"; 204 | case VK_ERROR_OUT_OF_DATE_KHR: 205 | return "A surface has changed in such a way that it is no longer compatible with the swapchain"; 206 | case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR: 207 | return "The display used by a swapchain does not use the same presentable image layout"; 208 | case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: 209 | return "The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API"; 210 | case VK_ERROR_VALIDATION_FAILED_EXT: 211 | return "A validation layer found an error"; 212 | default: 213 | return "ERROR: UNKNOWN VULKAN ERROR"; 214 | } 215 | } 216 | 217 | 218 | ////////////////////////////////////////////////////////////////////////// 219 | ////// GLFW public API ////// 220 | ////////////////////////////////////////////////////////////////////////// 221 | 222 | GLFWAPI int glfwVulkanSupported(void) 223 | { 224 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 225 | return _glfwInitVulkan(_GLFW_FIND_LOADER); 226 | } 227 | 228 | GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count) 229 | { 230 | assert(count != NULL); 231 | 232 | *count = 0; 233 | 234 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 235 | 236 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 237 | return NULL; 238 | 239 | if (!_glfw.vk.extensions[0]) 240 | return NULL; 241 | 242 | *count = 2; 243 | return (const char**) _glfw.vk.extensions; 244 | } 245 | 246 | GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, 247 | const char* procname) 248 | { 249 | GLFWvkproc proc; 250 | assert(procname != NULL); 251 | 252 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 253 | 254 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 255 | return NULL; 256 | 257 | // NOTE: Vulkan 1.0 and 1.1 vkGetInstanceProcAddr cannot return itself 258 | if (strcmp(procname, "vkGetInstanceProcAddr") == 0) 259 | return (GLFWvkproc) vkGetInstanceProcAddr; 260 | 261 | proc = (GLFWvkproc) vkGetInstanceProcAddr(instance, procname); 262 | if (!proc) 263 | { 264 | if (_glfw.vk.handle) 265 | proc = (GLFWvkproc) _glfwPlatformGetModuleSymbol(_glfw.vk.handle, procname); 266 | } 267 | 268 | return proc; 269 | } 270 | 271 | GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, 272 | VkPhysicalDevice device, 273 | uint32_t queuefamily) 274 | { 275 | assert(instance != VK_NULL_HANDLE); 276 | assert(device != VK_NULL_HANDLE); 277 | 278 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 279 | 280 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 281 | return GLFW_FALSE; 282 | 283 | if (!_glfw.vk.extensions[0]) 284 | { 285 | _glfwInputError(GLFW_API_UNAVAILABLE, 286 | "Vulkan: Window surface creation extensions not found"); 287 | return GLFW_FALSE; 288 | } 289 | 290 | return _glfw.platform.getPhysicalDevicePresentationSupport(instance, 291 | device, 292 | queuefamily); 293 | } 294 | 295 | GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, 296 | GLFWwindow* handle, 297 | const VkAllocationCallbacks* allocator, 298 | VkSurfaceKHR* surface) 299 | { 300 | _GLFWwindow* window = (_GLFWwindow*) handle; 301 | assert(instance != VK_NULL_HANDLE); 302 | assert(window != NULL); 303 | assert(surface != NULL); 304 | 305 | *surface = VK_NULL_HANDLE; 306 | 307 | _GLFW_REQUIRE_INIT_OR_RETURN(VK_ERROR_INITIALIZATION_FAILED); 308 | 309 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 310 | return VK_ERROR_INITIALIZATION_FAILED; 311 | 312 | if (!_glfw.vk.extensions[0]) 313 | { 314 | _glfwInputError(GLFW_API_UNAVAILABLE, 315 | "Vulkan: Window surface creation extensions not found"); 316 | return VK_ERROR_EXTENSION_NOT_PRESENT; 317 | } 318 | 319 | if (window->context.client != GLFW_NO_API) 320 | { 321 | _glfwInputError(GLFW_INVALID_VALUE, 322 | "Vulkan: Window surface creation requires the window to have the client API set to GLFW_NO_API"); 323 | return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; 324 | } 325 | 326 | return _glfw.platform.createWindowSurface(instance, window, allocator, surface); 327 | } 328 | 329 | -------------------------------------------------------------------------------- /third-party/glfw/src/nsgl_context.m: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2019 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | #if defined(_GLFW_COCOA) 30 | 31 | #include 32 | #include 33 | 34 | static void makeContextCurrentNSGL(_GLFWwindow* window) 35 | { 36 | @autoreleasepool { 37 | 38 | if (window) 39 | [window->context.nsgl.object makeCurrentContext]; 40 | else 41 | [NSOpenGLContext clearCurrentContext]; 42 | 43 | _glfwPlatformSetTls(&_glfw.contextSlot, window); 44 | 45 | } // autoreleasepool 46 | } 47 | 48 | static void swapBuffersNSGL(_GLFWwindow* window) 49 | { 50 | @autoreleasepool { 51 | 52 | // HACK: Simulate vsync with usleep as NSGL swap interval does not apply to 53 | // windows with a non-visible occlusion state 54 | if (window->ns.occluded) 55 | { 56 | int interval = 0; 57 | [window->context.nsgl.object getValues:&interval 58 | forParameter:NSOpenGLContextParameterSwapInterval]; 59 | 60 | if (interval > 0) 61 | { 62 | const double framerate = 60.0; 63 | const uint64_t frequency = _glfwPlatformGetTimerFrequency(); 64 | const uint64_t value = _glfwPlatformGetTimerValue(); 65 | 66 | const double elapsed = value / (double) frequency; 67 | const double period = 1.0 / framerate; 68 | const double delay = period - fmod(elapsed, period); 69 | 70 | usleep(floorl(delay * 1e6)); 71 | } 72 | } 73 | 74 | [window->context.nsgl.object flushBuffer]; 75 | 76 | } // autoreleasepool 77 | } 78 | 79 | static void swapIntervalNSGL(int interval) 80 | { 81 | @autoreleasepool { 82 | 83 | _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); 84 | assert(window != NULL); 85 | 86 | [window->context.nsgl.object setValues:&interval 87 | forParameter:NSOpenGLContextParameterSwapInterval]; 88 | 89 | } // autoreleasepool 90 | } 91 | 92 | static int extensionSupportedNSGL(const char* extension) 93 | { 94 | // There are no NSGL extensions 95 | return GLFW_FALSE; 96 | } 97 | 98 | static GLFWglproc getProcAddressNSGL(const char* procname) 99 | { 100 | CFStringRef symbolName = CFStringCreateWithCString(kCFAllocatorDefault, 101 | procname, 102 | kCFStringEncodingASCII); 103 | 104 | GLFWglproc symbol = CFBundleGetFunctionPointerForName(_glfw.nsgl.framework, 105 | symbolName); 106 | 107 | CFRelease(symbolName); 108 | 109 | return symbol; 110 | } 111 | 112 | static void destroyContextNSGL(_GLFWwindow* window) 113 | { 114 | @autoreleasepool { 115 | 116 | [window->context.nsgl.pixelFormat release]; 117 | window->context.nsgl.pixelFormat = nil; 118 | 119 | [window->context.nsgl.object release]; 120 | window->context.nsgl.object = nil; 121 | 122 | } // autoreleasepool 123 | } 124 | 125 | 126 | ////////////////////////////////////////////////////////////////////////// 127 | ////// GLFW internal API ////// 128 | ////////////////////////////////////////////////////////////////////////// 129 | 130 | // Initialize OpenGL support 131 | // 132 | GLFWbool _glfwInitNSGL(void) 133 | { 134 | if (_glfw.nsgl.framework) 135 | return GLFW_TRUE; 136 | 137 | _glfw.nsgl.framework = 138 | CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); 139 | if (_glfw.nsgl.framework == NULL) 140 | { 141 | _glfwInputError(GLFW_API_UNAVAILABLE, 142 | "NSGL: Failed to locate OpenGL framework"); 143 | return GLFW_FALSE; 144 | } 145 | 146 | return GLFW_TRUE; 147 | } 148 | 149 | // Terminate OpenGL support 150 | // 151 | void _glfwTerminateNSGL(void) 152 | { 153 | } 154 | 155 | // Create the OpenGL context 156 | // 157 | GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, 158 | const _GLFWctxconfig* ctxconfig, 159 | const _GLFWfbconfig* fbconfig) 160 | { 161 | if (ctxconfig->client == GLFW_OPENGL_ES_API) 162 | { 163 | _glfwInputError(GLFW_API_UNAVAILABLE, 164 | "NSGL: OpenGL ES is not available via NSGL"); 165 | return GLFW_FALSE; 166 | } 167 | 168 | if (ctxconfig->major > 2) 169 | { 170 | if (ctxconfig->major == 3 && ctxconfig->minor < 2) 171 | { 172 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 173 | "NSGL: The targeted version of macOS does not support OpenGL 3.0 or 3.1 but may support 3.2 and above"); 174 | return GLFW_FALSE; 175 | } 176 | } 177 | 178 | if (ctxconfig->major >= 3 && ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE) 179 | { 180 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 181 | "NSGL: The compatibility profile is not available on macOS"); 182 | return GLFW_FALSE; 183 | } 184 | 185 | // Context robustness modes (GL_KHR_robustness) are not yet supported by 186 | // macOS but are not a hard constraint, so ignore and continue 187 | 188 | // Context release behaviors (GL_KHR_context_flush_control) are not yet 189 | // supported by macOS but are not a hard constraint, so ignore and continue 190 | 191 | // Debug contexts (GL_KHR_debug) are not yet supported by macOS but are not 192 | // a hard constraint, so ignore and continue 193 | 194 | // No-error contexts (GL_KHR_no_error) are not yet supported by macOS but 195 | // are not a hard constraint, so ignore and continue 196 | 197 | #define ADD_ATTRIB(a) \ 198 | { \ 199 | assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \ 200 | attribs[index++] = a; \ 201 | } 202 | #define SET_ATTRIB(a, v) { ADD_ATTRIB(a); ADD_ATTRIB(v); } 203 | 204 | NSOpenGLPixelFormatAttribute attribs[40]; 205 | int index = 0; 206 | 207 | ADD_ATTRIB(NSOpenGLPFAAccelerated); 208 | ADD_ATTRIB(NSOpenGLPFAClosestPolicy); 209 | 210 | if (ctxconfig->nsgl.offline) 211 | { 212 | ADD_ATTRIB(NSOpenGLPFAAllowOfflineRenderers); 213 | // NOTE: This replaces the NSSupportsAutomaticGraphicsSwitching key in 214 | // Info.plist for unbundled applications 215 | // HACK: This assumes that NSOpenGLPixelFormat will remain 216 | // a straightforward wrapper of its CGL counterpart 217 | ADD_ATTRIB(kCGLPFASupportsAutomaticGraphicsSwitching); 218 | } 219 | 220 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 221 | if (ctxconfig->major >= 4) 222 | { 223 | SET_ATTRIB(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core); 224 | } 225 | else 226 | #endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ 227 | if (ctxconfig->major >= 3) 228 | { 229 | SET_ATTRIB(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core); 230 | } 231 | 232 | if (ctxconfig->major <= 2) 233 | { 234 | if (fbconfig->auxBuffers != GLFW_DONT_CARE) 235 | SET_ATTRIB(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers); 236 | 237 | if (fbconfig->accumRedBits != GLFW_DONT_CARE && 238 | fbconfig->accumGreenBits != GLFW_DONT_CARE && 239 | fbconfig->accumBlueBits != GLFW_DONT_CARE && 240 | fbconfig->accumAlphaBits != GLFW_DONT_CARE) 241 | { 242 | const int accumBits = fbconfig->accumRedBits + 243 | fbconfig->accumGreenBits + 244 | fbconfig->accumBlueBits + 245 | fbconfig->accumAlphaBits; 246 | 247 | SET_ATTRIB(NSOpenGLPFAAccumSize, accumBits); 248 | } 249 | } 250 | 251 | if (fbconfig->redBits != GLFW_DONT_CARE && 252 | fbconfig->greenBits != GLFW_DONT_CARE && 253 | fbconfig->blueBits != GLFW_DONT_CARE) 254 | { 255 | int colorBits = fbconfig->redBits + 256 | fbconfig->greenBits + 257 | fbconfig->blueBits; 258 | 259 | // macOS needs non-zero color size, so set reasonable values 260 | if (colorBits == 0) 261 | colorBits = 24; 262 | else if (colorBits < 15) 263 | colorBits = 15; 264 | 265 | SET_ATTRIB(NSOpenGLPFAColorSize, colorBits); 266 | } 267 | 268 | if (fbconfig->alphaBits != GLFW_DONT_CARE) 269 | SET_ATTRIB(NSOpenGLPFAAlphaSize, fbconfig->alphaBits); 270 | 271 | if (fbconfig->depthBits != GLFW_DONT_CARE) 272 | SET_ATTRIB(NSOpenGLPFADepthSize, fbconfig->depthBits); 273 | 274 | if (fbconfig->stencilBits != GLFW_DONT_CARE) 275 | SET_ATTRIB(NSOpenGLPFAStencilSize, fbconfig->stencilBits); 276 | 277 | if (fbconfig->stereo) 278 | { 279 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 280 | _glfwInputError(GLFW_FORMAT_UNAVAILABLE, 281 | "NSGL: Stereo rendering is deprecated"); 282 | return GLFW_FALSE; 283 | #else 284 | ADD_ATTRIB(NSOpenGLPFAStereo); 285 | #endif 286 | } 287 | 288 | if (fbconfig->doublebuffer) 289 | ADD_ATTRIB(NSOpenGLPFADoubleBuffer); 290 | 291 | if (fbconfig->samples != GLFW_DONT_CARE) 292 | { 293 | if (fbconfig->samples == 0) 294 | { 295 | SET_ATTRIB(NSOpenGLPFASampleBuffers, 0); 296 | } 297 | else 298 | { 299 | SET_ATTRIB(NSOpenGLPFASampleBuffers, 1); 300 | SET_ATTRIB(NSOpenGLPFASamples, fbconfig->samples); 301 | } 302 | } 303 | 304 | // NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB 305 | // framebuffer, so there's no need (and no way) to request it 306 | 307 | ADD_ATTRIB(0); 308 | 309 | #undef ADD_ATTRIB 310 | #undef SET_ATTRIB 311 | 312 | window->context.nsgl.pixelFormat = 313 | [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; 314 | if (window->context.nsgl.pixelFormat == nil) 315 | { 316 | _glfwInputError(GLFW_FORMAT_UNAVAILABLE, 317 | "NSGL: Failed to find a suitable pixel format"); 318 | return GLFW_FALSE; 319 | } 320 | 321 | NSOpenGLContext* share = nil; 322 | 323 | if (ctxconfig->share) 324 | share = ctxconfig->share->context.nsgl.object; 325 | 326 | window->context.nsgl.object = 327 | [[NSOpenGLContext alloc] initWithFormat:window->context.nsgl.pixelFormat 328 | shareContext:share]; 329 | if (window->context.nsgl.object == nil) 330 | { 331 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 332 | "NSGL: Failed to create OpenGL context"); 333 | return GLFW_FALSE; 334 | } 335 | 336 | if (fbconfig->transparent) 337 | { 338 | GLint opaque = 0; 339 | [window->context.nsgl.object setValues:&opaque 340 | forParameter:NSOpenGLContextParameterSurfaceOpacity]; 341 | } 342 | 343 | [window->ns.view setWantsBestResolutionOpenGLSurface:window->ns.scaleFramebuffer]; 344 | 345 | [window->context.nsgl.object setView:window->ns.view]; 346 | 347 | window->context.makeCurrent = makeContextCurrentNSGL; 348 | window->context.swapBuffers = swapBuffersNSGL; 349 | window->context.swapInterval = swapIntervalNSGL; 350 | window->context.extensionSupported = extensionSupportedNSGL; 351 | window->context.getProcAddress = getProcAddressNSGL; 352 | window->context.destroy = destroyContextNSGL; 353 | 354 | return GLFW_TRUE; 355 | } 356 | 357 | 358 | ////////////////////////////////////////////////////////////////////////// 359 | ////// GLFW native API ////// 360 | ////////////////////////////////////////////////////////////////////////// 361 | 362 | GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle) 363 | { 364 | _GLFWwindow* window = (_GLFWwindow*) handle; 365 | _GLFW_REQUIRE_INIT_OR_RETURN(nil); 366 | 367 | if (_glfw.platform.platformID != GLFW_PLATFORM_COCOA) 368 | { 369 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, 370 | "NSGL: Platform not initialized"); 371 | return nil; 372 | } 373 | 374 | if (window->context.source != GLFW_NATIVE_CONTEXT_API) 375 | { 376 | _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); 377 | return nil; 378 | } 379 | 380 | return window->context.nsgl.object; 381 | } 382 | 383 | #endif // _GLFW_COCOA 384 | 385 | -------------------------------------------------------------------------------- /third-party/glfw/src/osmesa_context.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 OSMesa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 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 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | static void makeContextCurrentOSMesa(_GLFWwindow* window) 35 | { 36 | if (window) 37 | { 38 | int width, height; 39 | _glfw.platform.getFramebufferSize(window, &width, &height); 40 | 41 | // Check to see if we need to allocate a new buffer 42 | if ((window->context.osmesa.buffer == NULL) || 43 | (width != window->context.osmesa.width) || 44 | (height != window->context.osmesa.height)) 45 | { 46 | _glfw_free(window->context.osmesa.buffer); 47 | 48 | // Allocate the new buffer (width * height * 8-bit RGBA) 49 | window->context.osmesa.buffer = _glfw_calloc(4, (size_t) width * height); 50 | window->context.osmesa.width = width; 51 | window->context.osmesa.height = height; 52 | } 53 | 54 | if (!OSMesaMakeCurrent(window->context.osmesa.handle, 55 | window->context.osmesa.buffer, 56 | GL_UNSIGNED_BYTE, 57 | width, height)) 58 | { 59 | _glfwInputError(GLFW_PLATFORM_ERROR, 60 | "OSMesa: Failed to make context current"); 61 | return; 62 | } 63 | } 64 | 65 | _glfwPlatformSetTls(&_glfw.contextSlot, window); 66 | } 67 | 68 | static GLFWglproc getProcAddressOSMesa(const char* procname) 69 | { 70 | return (GLFWglproc) OSMesaGetProcAddress(procname); 71 | } 72 | 73 | static void destroyContextOSMesa(_GLFWwindow* window) 74 | { 75 | if (window->context.osmesa.handle) 76 | { 77 | OSMesaDestroyContext(window->context.osmesa.handle); 78 | window->context.osmesa.handle = NULL; 79 | } 80 | 81 | if (window->context.osmesa.buffer) 82 | { 83 | _glfw_free(window->context.osmesa.buffer); 84 | window->context.osmesa.width = 0; 85 | window->context.osmesa.height = 0; 86 | } 87 | } 88 | 89 | static void swapBuffersOSMesa(_GLFWwindow* window) 90 | { 91 | // No double buffering on OSMesa 92 | } 93 | 94 | static void swapIntervalOSMesa(int interval) 95 | { 96 | // No swap interval on OSMesa 97 | } 98 | 99 | static int extensionSupportedOSMesa(const char* extension) 100 | { 101 | // OSMesa does not have extensions 102 | return GLFW_FALSE; 103 | } 104 | 105 | 106 | ////////////////////////////////////////////////////////////////////////// 107 | ////// GLFW internal API ////// 108 | ////////////////////////////////////////////////////////////////////////// 109 | 110 | GLFWbool _glfwInitOSMesa(void) 111 | { 112 | int i; 113 | const char* sonames[] = 114 | { 115 | #if defined(_GLFW_OSMESA_LIBRARY) 116 | _GLFW_OSMESA_LIBRARY, 117 | #elif defined(_WIN32) 118 | "libOSMesa.dll", 119 | "OSMesa.dll", 120 | #elif defined(__APPLE__) 121 | "libOSMesa.8.dylib", 122 | #elif defined(__CYGWIN__) 123 | "libOSMesa-8.so", 124 | #elif defined(__OpenBSD__) || defined(__NetBSD__) 125 | "libOSMesa.so", 126 | #else 127 | "libOSMesa.so.8", 128 | "libOSMesa.so.6", 129 | #endif 130 | NULL 131 | }; 132 | 133 | if (_glfw.osmesa.handle) 134 | return GLFW_TRUE; 135 | 136 | for (i = 0; sonames[i]; i++) 137 | { 138 | _glfw.osmesa.handle = _glfwPlatformLoadModule(sonames[i]); 139 | if (_glfw.osmesa.handle) 140 | break; 141 | } 142 | 143 | if (!_glfw.osmesa.handle) 144 | { 145 | _glfwInputError(GLFW_API_UNAVAILABLE, "OSMesa: Library not found"); 146 | return GLFW_FALSE; 147 | } 148 | 149 | _glfw.osmesa.CreateContextExt = (PFN_OSMesaCreateContextExt) 150 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaCreateContextExt"); 151 | _glfw.osmesa.CreateContextAttribs = (PFN_OSMesaCreateContextAttribs) 152 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaCreateContextAttribs"); 153 | _glfw.osmesa.DestroyContext = (PFN_OSMesaDestroyContext) 154 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaDestroyContext"); 155 | _glfw.osmesa.MakeCurrent = (PFN_OSMesaMakeCurrent) 156 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaMakeCurrent"); 157 | _glfw.osmesa.GetColorBuffer = (PFN_OSMesaGetColorBuffer) 158 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaGetColorBuffer"); 159 | _glfw.osmesa.GetDepthBuffer = (PFN_OSMesaGetDepthBuffer) 160 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaGetDepthBuffer"); 161 | _glfw.osmesa.GetProcAddress = (PFN_OSMesaGetProcAddress) 162 | _glfwPlatformGetModuleSymbol(_glfw.osmesa.handle, "OSMesaGetProcAddress"); 163 | 164 | if (!_glfw.osmesa.CreateContextExt || 165 | !_glfw.osmesa.DestroyContext || 166 | !_glfw.osmesa.MakeCurrent || 167 | !_glfw.osmesa.GetColorBuffer || 168 | !_glfw.osmesa.GetDepthBuffer || 169 | !_glfw.osmesa.GetProcAddress) 170 | { 171 | _glfwInputError(GLFW_PLATFORM_ERROR, 172 | "OSMesa: Failed to load required entry points"); 173 | 174 | _glfwTerminateOSMesa(); 175 | return GLFW_FALSE; 176 | } 177 | 178 | return GLFW_TRUE; 179 | } 180 | 181 | void _glfwTerminateOSMesa(void) 182 | { 183 | if (_glfw.osmesa.handle) 184 | { 185 | _glfwPlatformFreeModule(_glfw.osmesa.handle); 186 | _glfw.osmesa.handle = NULL; 187 | } 188 | } 189 | 190 | #define SET_ATTRIB(a, v) \ 191 | { \ 192 | assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \ 193 | attribs[index++] = a; \ 194 | attribs[index++] = v; \ 195 | } 196 | 197 | GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window, 198 | const _GLFWctxconfig* ctxconfig, 199 | const _GLFWfbconfig* fbconfig) 200 | { 201 | OSMesaContext share = NULL; 202 | const int accumBits = fbconfig->accumRedBits + 203 | fbconfig->accumGreenBits + 204 | fbconfig->accumBlueBits + 205 | fbconfig->accumAlphaBits; 206 | 207 | if (ctxconfig->client == GLFW_OPENGL_ES_API) 208 | { 209 | _glfwInputError(GLFW_API_UNAVAILABLE, 210 | "OSMesa: OpenGL ES is not available on OSMesa"); 211 | return GLFW_FALSE; 212 | } 213 | 214 | if (ctxconfig->share) 215 | share = ctxconfig->share->context.osmesa.handle; 216 | 217 | if (OSMesaCreateContextAttribs) 218 | { 219 | int index = 0, attribs[40]; 220 | 221 | SET_ATTRIB(OSMESA_FORMAT, OSMESA_RGBA); 222 | SET_ATTRIB(OSMESA_DEPTH_BITS, fbconfig->depthBits); 223 | SET_ATTRIB(OSMESA_STENCIL_BITS, fbconfig->stencilBits); 224 | SET_ATTRIB(OSMESA_ACCUM_BITS, accumBits); 225 | 226 | if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE) 227 | { 228 | SET_ATTRIB(OSMESA_PROFILE, OSMESA_CORE_PROFILE); 229 | } 230 | else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE) 231 | { 232 | SET_ATTRIB(OSMESA_PROFILE, OSMESA_COMPAT_PROFILE); 233 | } 234 | 235 | if (ctxconfig->major != 1 || ctxconfig->minor != 0) 236 | { 237 | SET_ATTRIB(OSMESA_CONTEXT_MAJOR_VERSION, ctxconfig->major); 238 | SET_ATTRIB(OSMESA_CONTEXT_MINOR_VERSION, ctxconfig->minor); 239 | } 240 | 241 | if (ctxconfig->forward) 242 | { 243 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 244 | "OSMesa: Forward-compatible contexts not supported"); 245 | return GLFW_FALSE; 246 | } 247 | 248 | SET_ATTRIB(0, 0); 249 | 250 | window->context.osmesa.handle = 251 | OSMesaCreateContextAttribs(attribs, share); 252 | } 253 | else 254 | { 255 | if (ctxconfig->profile) 256 | { 257 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 258 | "OSMesa: OpenGL profiles unavailable"); 259 | return GLFW_FALSE; 260 | } 261 | 262 | window->context.osmesa.handle = 263 | OSMesaCreateContextExt(OSMESA_RGBA, 264 | fbconfig->depthBits, 265 | fbconfig->stencilBits, 266 | accumBits, 267 | share); 268 | } 269 | 270 | if (window->context.osmesa.handle == NULL) 271 | { 272 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 273 | "OSMesa: Failed to create context"); 274 | return GLFW_FALSE; 275 | } 276 | 277 | window->context.makeCurrent = makeContextCurrentOSMesa; 278 | window->context.swapBuffers = swapBuffersOSMesa; 279 | window->context.swapInterval = swapIntervalOSMesa; 280 | window->context.extensionSupported = extensionSupportedOSMesa; 281 | window->context.getProcAddress = getProcAddressOSMesa; 282 | window->context.destroy = destroyContextOSMesa; 283 | 284 | return GLFW_TRUE; 285 | } 286 | 287 | #undef SET_ATTRIB 288 | 289 | 290 | ////////////////////////////////////////////////////////////////////////// 291 | ////// GLFW native API ////// 292 | ////////////////////////////////////////////////////////////////////////// 293 | 294 | GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* handle, int* width, 295 | int* height, int* format, void** buffer) 296 | { 297 | void* mesaBuffer; 298 | GLint mesaWidth, mesaHeight, mesaFormat; 299 | _GLFWwindow* window = (_GLFWwindow*) handle; 300 | assert(window != NULL); 301 | 302 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 303 | 304 | if (window->context.source != GLFW_OSMESA_CONTEXT_API) 305 | { 306 | _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); 307 | return GLFW_FALSE; 308 | } 309 | 310 | if (!OSMesaGetColorBuffer(window->context.osmesa.handle, 311 | &mesaWidth, &mesaHeight, 312 | &mesaFormat, &mesaBuffer)) 313 | { 314 | _glfwInputError(GLFW_PLATFORM_ERROR, 315 | "OSMesa: Failed to retrieve color buffer"); 316 | return GLFW_FALSE; 317 | } 318 | 319 | if (width) 320 | *width = mesaWidth; 321 | if (height) 322 | *height = mesaHeight; 323 | if (format) 324 | *format = mesaFormat; 325 | if (buffer) 326 | *buffer = mesaBuffer; 327 | 328 | return GLFW_TRUE; 329 | } 330 | 331 | GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* handle, 332 | int* width, int* height, 333 | int* bytesPerValue, 334 | void** buffer) 335 | { 336 | void* mesaBuffer; 337 | GLint mesaWidth, mesaHeight, mesaBytes; 338 | _GLFWwindow* window = (_GLFWwindow*) handle; 339 | assert(window != NULL); 340 | 341 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 342 | 343 | if (window->context.source != GLFW_OSMESA_CONTEXT_API) 344 | { 345 | _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); 346 | return GLFW_FALSE; 347 | } 348 | 349 | if (!OSMesaGetDepthBuffer(window->context.osmesa.handle, 350 | &mesaWidth, &mesaHeight, 351 | &mesaBytes, &mesaBuffer)) 352 | { 353 | _glfwInputError(GLFW_PLATFORM_ERROR, 354 | "OSMesa: Failed to retrieve depth buffer"); 355 | return GLFW_FALSE; 356 | } 357 | 358 | if (width) 359 | *width = mesaWidth; 360 | if (height) 361 | *height = mesaHeight; 362 | if (bytesPerValue) 363 | *bytesPerValue = mesaBytes; 364 | if (buffer) 365 | *buffer = mesaBuffer; 366 | 367 | return GLFW_TRUE; 368 | } 369 | 370 | GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* handle) 371 | { 372 | _GLFWwindow* window = (_GLFWwindow*) handle; 373 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 374 | 375 | if (window->context.source != GLFW_OSMESA_CONTEXT_API) 376 | { 377 | _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); 378 | return NULL; 379 | } 380 | 381 | return window->context.osmesa.handle; 382 | } 383 | 384 | -------------------------------------------------------------------------------- /third-party/glfw/src/cocoa_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2019 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | // NOTE: All of NSGL was deprecated in the 10.14 SDK 33 | // This disables the pointless warnings for every symbol we use 34 | #ifndef GL_SILENCE_DEPRECATION 35 | #define GL_SILENCE_DEPRECATION 36 | #endif 37 | 38 | #if defined(__OBJC__) 39 | #import 40 | #else 41 | typedef void* id; 42 | #endif 43 | 44 | // NOTE: Many Cocoa enum values have been renamed and we need to build across 45 | // SDK versions where one is unavailable or deprecated. 46 | // We use the newer names in code and replace them with the older names if 47 | // the base SDK does not provide the newer names. 48 | 49 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 101400 50 | #define NSOpenGLContextParameterSwapInterval NSOpenGLCPSwapInterval 51 | #define NSOpenGLContextParameterSurfaceOpacity NSOpenGLCPSurfaceOpacity 52 | #endif 53 | 54 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 101200 55 | #define NSBitmapFormatAlphaNonpremultiplied NSAlphaNonpremultipliedBitmapFormat 56 | #define NSEventMaskAny NSAnyEventMask 57 | #define NSEventMaskKeyUp NSKeyUpMask 58 | #define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask 59 | #define NSEventModifierFlagCommand NSCommandKeyMask 60 | #define NSEventModifierFlagControl NSControlKeyMask 61 | #define NSEventModifierFlagDeviceIndependentFlagsMask NSDeviceIndependentModifierFlagsMask 62 | #define NSEventModifierFlagOption NSAlternateKeyMask 63 | #define NSEventModifierFlagShift NSShiftKeyMask 64 | #define NSEventTypeApplicationDefined NSApplicationDefined 65 | #define NSWindowStyleMaskBorderless NSBorderlessWindowMask 66 | #define NSWindowStyleMaskClosable NSClosableWindowMask 67 | #define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask 68 | #define NSWindowStyleMaskResizable NSResizableWindowMask 69 | #define NSWindowStyleMaskTitled NSTitledWindowMask 70 | #endif 71 | 72 | // NOTE: Many Cocoa dynamically linked constants have been renamed and we need 73 | // to build across SDK versions where one is unavailable or deprecated. 74 | // We use the newer names in code and replace them with the older names if 75 | // the deployment target is older than the newer names. 76 | 77 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 101300 78 | #define NSPasteboardTypeURL NSURLPboardType 79 | #endif 80 | 81 | typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; 82 | typedef VkFlags VkMetalSurfaceCreateFlagsEXT; 83 | 84 | typedef struct VkMacOSSurfaceCreateInfoMVK 85 | { 86 | VkStructureType sType; 87 | const void* pNext; 88 | VkMacOSSurfaceCreateFlagsMVK flags; 89 | const void* pView; 90 | } VkMacOSSurfaceCreateInfoMVK; 91 | 92 | typedef struct VkMetalSurfaceCreateInfoEXT 93 | { 94 | VkStructureType sType; 95 | const void* pNext; 96 | VkMetalSurfaceCreateFlagsEXT flags; 97 | const void* pLayer; 98 | } VkMetalSurfaceCreateInfoEXT; 99 | 100 | typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*); 101 | typedef VkResult (APIENTRY *PFN_vkCreateMetalSurfaceEXT)(VkInstance,const VkMetalSurfaceCreateInfoEXT*,const VkAllocationCallbacks*,VkSurfaceKHR*); 102 | 103 | #define GLFW_COCOA_WINDOW_STATE _GLFWwindowNS ns; 104 | #define GLFW_COCOA_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns; 105 | #define GLFW_COCOA_MONITOR_STATE _GLFWmonitorNS ns; 106 | #define GLFW_COCOA_CURSOR_STATE _GLFWcursorNS ns; 107 | 108 | #define GLFW_NSGL_CONTEXT_STATE _GLFWcontextNSGL nsgl; 109 | #define GLFW_NSGL_LIBRARY_CONTEXT_STATE _GLFWlibraryNSGL nsgl; 110 | 111 | // HIToolbox.framework pointer typedefs 112 | #define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData 113 | typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void); 114 | #define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource 115 | typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef); 116 | #define TISGetInputSourceProperty _glfw.ns.tis.GetInputSourceProperty 117 | typedef UInt8 (*PFN_LMGetKbdType)(void); 118 | #define LMGetKbdType _glfw.ns.tis.GetKbdType 119 | 120 | 121 | // NSGL-specific per-context data 122 | // 123 | typedef struct _GLFWcontextNSGL 124 | { 125 | id pixelFormat; 126 | id object; 127 | } _GLFWcontextNSGL; 128 | 129 | // NSGL-specific global data 130 | // 131 | typedef struct _GLFWlibraryNSGL 132 | { 133 | // dlopen handle for OpenGL.framework (for glfwGetProcAddress) 134 | CFBundleRef framework; 135 | } _GLFWlibraryNSGL; 136 | 137 | // Cocoa-specific per-window data 138 | // 139 | typedef struct _GLFWwindowNS 140 | { 141 | id object; 142 | id delegate; 143 | id view; 144 | id layer; 145 | 146 | GLFWbool maximized; 147 | GLFWbool occluded; 148 | GLFWbool scaleFramebuffer; 149 | 150 | // Cached window properties to filter out duplicate events 151 | int width, height; 152 | int fbWidth, fbHeight; 153 | float xscale, yscale; 154 | 155 | // The total sum of the distances the cursor has been warped 156 | // since the last cursor motion event was processed 157 | // This is kept to counteract Cocoa doing the same internally 158 | double cursorWarpDeltaX, cursorWarpDeltaY; 159 | } _GLFWwindowNS; 160 | 161 | // Cocoa-specific global data 162 | // 163 | typedef struct _GLFWlibraryNS 164 | { 165 | CGEventSourceRef eventSource; 166 | id delegate; 167 | GLFWbool cursorHidden; 168 | TISInputSourceRef inputSource; 169 | IOHIDManagerRef hidManager; 170 | id unicodeData; 171 | id helper; 172 | id keyUpMonitor; 173 | id nibObjects; 174 | 175 | char keynames[GLFW_KEY_LAST + 1][17]; 176 | short int keycodes[256]; 177 | short int scancodes[GLFW_KEY_LAST + 1]; 178 | char* clipboardString; 179 | CGPoint cascadePoint; 180 | // Where to place the cursor when re-enabled 181 | double restoreCursorPosX, restoreCursorPosY; 182 | // The window whose disabled cursor mode is active 183 | _GLFWwindow* disabledCursorWindow; 184 | 185 | struct { 186 | CFBundleRef bundle; 187 | PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource; 188 | PFN_TISGetInputSourceProperty GetInputSourceProperty; 189 | PFN_LMGetKbdType GetKbdType; 190 | CFStringRef kPropertyUnicodeKeyLayoutData; 191 | } tis; 192 | } _GLFWlibraryNS; 193 | 194 | // Cocoa-specific per-monitor data 195 | // 196 | typedef struct _GLFWmonitorNS 197 | { 198 | CGDirectDisplayID displayID; 199 | CGDisplayModeRef previousMode; 200 | uint32_t unitNumber; 201 | id screen; 202 | double fallbackRefreshRate; 203 | } _GLFWmonitorNS; 204 | 205 | // Cocoa-specific per-cursor data 206 | // 207 | typedef struct _GLFWcursorNS 208 | { 209 | id object; 210 | } _GLFWcursorNS; 211 | 212 | 213 | GLFWbool _glfwConnectCocoa(int platformID, _GLFWplatform* platform); 214 | int _glfwInitCocoa(void); 215 | void _glfwTerminateCocoa(void); 216 | 217 | GLFWbool _glfwCreateWindowCocoa(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); 218 | void _glfwDestroyWindowCocoa(_GLFWwindow* window); 219 | void _glfwSetWindowTitleCocoa(_GLFWwindow* window, const char* title); 220 | void _glfwSetWindowIconCocoa(_GLFWwindow* window, int count, const GLFWimage* images); 221 | void _glfwGetWindowPosCocoa(_GLFWwindow* window, int* xpos, int* ypos); 222 | void _glfwSetWindowPosCocoa(_GLFWwindow* window, int xpos, int ypos); 223 | void _glfwGetWindowSizeCocoa(_GLFWwindow* window, int* width, int* height); 224 | void _glfwSetWindowSizeCocoa(_GLFWwindow* window, int width, int height); 225 | void _glfwSetWindowSizeLimitsCocoa(_GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight); 226 | void _glfwSetWindowAspectRatioCocoa(_GLFWwindow* window, int numer, int denom); 227 | void _glfwGetFramebufferSizeCocoa(_GLFWwindow* window, int* width, int* height); 228 | void _glfwGetWindowFrameSizeCocoa(_GLFWwindow* window, int* left, int* top, int* right, int* bottom); 229 | void _glfwGetWindowContentScaleCocoa(_GLFWwindow* window, float* xscale, float* yscale); 230 | void _glfwIconifyWindowCocoa(_GLFWwindow* window); 231 | void _glfwRestoreWindowCocoa(_GLFWwindow* window); 232 | void _glfwMaximizeWindowCocoa(_GLFWwindow* window); 233 | void _glfwShowWindowCocoa(_GLFWwindow* window); 234 | void _glfwHideWindowCocoa(_GLFWwindow* window); 235 | void _glfwRequestWindowAttentionCocoa(_GLFWwindow* window); 236 | void _glfwFocusWindowCocoa(_GLFWwindow* window); 237 | void _glfwSetWindowMonitorCocoa(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); 238 | GLFWbool _glfwWindowFocusedCocoa(_GLFWwindow* window); 239 | GLFWbool _glfwWindowIconifiedCocoa(_GLFWwindow* window); 240 | GLFWbool _glfwWindowVisibleCocoa(_GLFWwindow* window); 241 | GLFWbool _glfwWindowMaximizedCocoa(_GLFWwindow* window); 242 | GLFWbool _glfwWindowHoveredCocoa(_GLFWwindow* window); 243 | GLFWbool _glfwFramebufferTransparentCocoa(_GLFWwindow* window); 244 | void _glfwSetWindowResizableCocoa(_GLFWwindow* window, GLFWbool enabled); 245 | void _glfwSetWindowDecoratedCocoa(_GLFWwindow* window, GLFWbool enabled); 246 | void _glfwSetWindowFloatingCocoa(_GLFWwindow* window, GLFWbool enabled); 247 | float _glfwGetWindowOpacityCocoa(_GLFWwindow* window); 248 | void _glfwSetWindowOpacityCocoa(_GLFWwindow* window, float opacity); 249 | void _glfwSetWindowMousePassthroughCocoa(_GLFWwindow* window, GLFWbool enabled); 250 | 251 | void _glfwSetRawMouseMotionCocoa(_GLFWwindow *window, GLFWbool enabled); 252 | GLFWbool _glfwRawMouseMotionSupportedCocoa(void); 253 | 254 | void _glfwPollEventsCocoa(void); 255 | void _glfwWaitEventsCocoa(void); 256 | void _glfwWaitEventsTimeoutCocoa(double timeout); 257 | void _glfwPostEmptyEventCocoa(void); 258 | 259 | void _glfwGetCursorPosCocoa(_GLFWwindow* window, double* xpos, double* ypos); 260 | void _glfwSetCursorPosCocoa(_GLFWwindow* window, double xpos, double ypos); 261 | void _glfwSetCursorModeCocoa(_GLFWwindow* window, int mode); 262 | const char* _glfwGetScancodeNameCocoa(int scancode); 263 | int _glfwGetKeyScancodeCocoa(int key); 264 | GLFWbool _glfwCreateCursorCocoa(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot); 265 | GLFWbool _glfwCreateStandardCursorCocoa(_GLFWcursor* cursor, int shape); 266 | void _glfwDestroyCursorCocoa(_GLFWcursor* cursor); 267 | void _glfwSetCursorCocoa(_GLFWwindow* window, _GLFWcursor* cursor); 268 | void _glfwSetClipboardStringCocoa(const char* string); 269 | const char* _glfwGetClipboardStringCocoa(void); 270 | 271 | EGLenum _glfwGetEGLPlatformCocoa(EGLint** attribs); 272 | EGLNativeDisplayType _glfwGetEGLNativeDisplayCocoa(void); 273 | EGLNativeWindowType _glfwGetEGLNativeWindowCocoa(_GLFWwindow* window); 274 | 275 | void _glfwGetRequiredInstanceExtensionsCocoa(char** extensions); 276 | GLFWbool _glfwGetPhysicalDevicePresentationSupportCocoa(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); 277 | VkResult _glfwCreateWindowSurfaceCocoa(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); 278 | 279 | void _glfwFreeMonitorCocoa(_GLFWmonitor* monitor); 280 | void _glfwGetMonitorPosCocoa(_GLFWmonitor* monitor, int* xpos, int* ypos); 281 | void _glfwGetMonitorContentScaleCocoa(_GLFWmonitor* monitor, float* xscale, float* yscale); 282 | void _glfwGetMonitorWorkareaCocoa(_GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height); 283 | GLFWvidmode* _glfwGetVideoModesCocoa(_GLFWmonitor* monitor, int* count); 284 | GLFWbool _glfwGetVideoModeCocoa(_GLFWmonitor* monitor, GLFWvidmode* mode); 285 | GLFWbool _glfwGetGammaRampCocoa(_GLFWmonitor* monitor, GLFWgammaramp* ramp); 286 | void _glfwSetGammaRampCocoa(_GLFWmonitor* monitor, const GLFWgammaramp* ramp); 287 | 288 | void _glfwPollMonitorsCocoa(void); 289 | void _glfwSetVideoModeCocoa(_GLFWmonitor* monitor, const GLFWvidmode* desired); 290 | void _glfwRestoreVideoModeCocoa(_GLFWmonitor* monitor); 291 | 292 | float _glfwTransformYCocoa(float y); 293 | 294 | void* _glfwLoadLocalVulkanLoaderCocoa(void); 295 | 296 | GLFWbool _glfwInitNSGL(void); 297 | void _glfwTerminateNSGL(void); 298 | GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, 299 | const _GLFWctxconfig* ctxconfig, 300 | const _GLFWfbconfig* fbconfig); 301 | void _glfwDestroyContextNSGL(_GLFWwindow* window); 302 | 303 | -------------------------------------------------------------------------------- /third-party/glfw/src/linux_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 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 | #include "internal.h" 29 | 30 | #if defined(GLFW_BUILD_LINUX_JOYSTICK) 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #ifndef SYN_DROPPED // < v2.6.39 kernel headers 44 | // Workaround for CentOS-6, which is supported till 2020-11-30, but still on v2.6.32 45 | #define SYN_DROPPED 3 46 | #endif 47 | 48 | // Apply an EV_KEY event to the specified joystick 49 | // 50 | static void handleKeyEvent(_GLFWjoystick* js, int code, int value) 51 | { 52 | _glfwInputJoystickButton(js, 53 | js->linjs.keyMap[code - BTN_MISC], 54 | value ? GLFW_PRESS : GLFW_RELEASE); 55 | } 56 | 57 | // Apply an EV_ABS event to the specified joystick 58 | // 59 | static void handleAbsEvent(_GLFWjoystick* js, int code, int value) 60 | { 61 | const int index = js->linjs.absMap[code]; 62 | 63 | if (code >= ABS_HAT0X && code <= ABS_HAT3Y) 64 | { 65 | static const char stateMap[3][3] = 66 | { 67 | { GLFW_HAT_CENTERED, GLFW_HAT_UP, GLFW_HAT_DOWN }, 68 | { GLFW_HAT_LEFT, GLFW_HAT_LEFT_UP, GLFW_HAT_LEFT_DOWN }, 69 | { GLFW_HAT_RIGHT, GLFW_HAT_RIGHT_UP, GLFW_HAT_RIGHT_DOWN }, 70 | }; 71 | 72 | const int hat = (code - ABS_HAT0X) / 2; 73 | const int axis = (code - ABS_HAT0X) % 2; 74 | int* state = js->linjs.hats[hat]; 75 | 76 | // NOTE: Looking at several input drivers, it seems all hat events use 77 | // -1 for left / up, 0 for centered and 1 for right / down 78 | if (value == 0) 79 | state[axis] = 0; 80 | else if (value < 0) 81 | state[axis] = 1; 82 | else if (value > 0) 83 | state[axis] = 2; 84 | 85 | _glfwInputJoystickHat(js, index, stateMap[state[0]][state[1]]); 86 | } 87 | else 88 | { 89 | const struct input_absinfo* info = &js->linjs.absInfo[code]; 90 | float normalized = value; 91 | 92 | const int range = info->maximum - info->minimum; 93 | if (range) 94 | { 95 | // Normalize to 0.0 -> 1.0 96 | normalized = (normalized - info->minimum) / range; 97 | // Normalize to -1.0 -> 1.0 98 | normalized = normalized * 2.0f - 1.0f; 99 | } 100 | 101 | _glfwInputJoystickAxis(js, index, normalized); 102 | } 103 | } 104 | 105 | // Poll state of absolute axes 106 | // 107 | static void pollAbsState(_GLFWjoystick* js) 108 | { 109 | for (int code = 0; code < ABS_CNT; code++) 110 | { 111 | if (js->linjs.absMap[code] < 0) 112 | continue; 113 | 114 | struct input_absinfo* info = &js->linjs.absInfo[code]; 115 | 116 | if (ioctl(js->linjs.fd, EVIOCGABS(code), info) < 0) 117 | continue; 118 | 119 | handleAbsEvent(js, code, info->value); 120 | } 121 | } 122 | 123 | #define isBitSet(bit, arr) (arr[(bit) / 8] & (1 << ((bit) % 8))) 124 | 125 | // Attempt to open the specified joystick device 126 | // 127 | static GLFWbool openJoystickDevice(const char* path) 128 | { 129 | for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) 130 | { 131 | if (!_glfw.joysticks[jid].connected) 132 | continue; 133 | if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0) 134 | return GLFW_FALSE; 135 | } 136 | 137 | _GLFWjoystickLinux linjs = {0}; 138 | linjs.fd = open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC); 139 | if (linjs.fd == -1) 140 | return GLFW_FALSE; 141 | 142 | char evBits[(EV_CNT + 7) / 8] = {0}; 143 | char keyBits[(KEY_CNT + 7) / 8] = {0}; 144 | char absBits[(ABS_CNT + 7) / 8] = {0}; 145 | struct input_id id; 146 | 147 | if (ioctl(linjs.fd, EVIOCGBIT(0, sizeof(evBits)), evBits) < 0 || 148 | ioctl(linjs.fd, EVIOCGBIT(EV_KEY, sizeof(keyBits)), keyBits) < 0 || 149 | ioctl(linjs.fd, EVIOCGBIT(EV_ABS, sizeof(absBits)), absBits) < 0 || 150 | ioctl(linjs.fd, EVIOCGID, &id) < 0) 151 | { 152 | _glfwInputError(GLFW_PLATFORM_ERROR, 153 | "Linux: Failed to query input device: %s", 154 | strerror(errno)); 155 | close(linjs.fd); 156 | return GLFW_FALSE; 157 | } 158 | 159 | // Ensure this device supports the events expected of a joystick 160 | if (!isBitSet(EV_ABS, evBits)) 161 | { 162 | close(linjs.fd); 163 | return GLFW_FALSE; 164 | } 165 | 166 | char name[256] = ""; 167 | 168 | if (ioctl(linjs.fd, EVIOCGNAME(sizeof(name)), name) < 0) 169 | strncpy(name, "Unknown", sizeof(name)); 170 | 171 | char guid[33] = ""; 172 | 173 | // Generate a joystick GUID that matches the SDL 2.0.5+ one 174 | if (id.vendor && id.product && id.version) 175 | { 176 | sprintf(guid, "%02x%02x0000%02x%02x0000%02x%02x0000%02x%02x0000", 177 | id.bustype & 0xff, id.bustype >> 8, 178 | id.vendor & 0xff, id.vendor >> 8, 179 | id.product & 0xff, id.product >> 8, 180 | id.version & 0xff, id.version >> 8); 181 | } 182 | else 183 | { 184 | sprintf(guid, "%02x%02x0000%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x00", 185 | id.bustype & 0xff, id.bustype >> 8, 186 | name[0], name[1], name[2], name[3], 187 | name[4], name[5], name[6], name[7], 188 | name[8], name[9], name[10]); 189 | } 190 | 191 | int axisCount = 0, buttonCount = 0, hatCount = 0; 192 | 193 | for (int code = BTN_MISC; code < KEY_CNT; code++) 194 | { 195 | if (!isBitSet(code, keyBits)) 196 | continue; 197 | 198 | linjs.keyMap[code - BTN_MISC] = buttonCount; 199 | buttonCount++; 200 | } 201 | 202 | for (int code = 0; code < ABS_CNT; code++) 203 | { 204 | linjs.absMap[code] = -1; 205 | if (!isBitSet(code, absBits)) 206 | continue; 207 | 208 | if (code >= ABS_HAT0X && code <= ABS_HAT3Y) 209 | { 210 | linjs.absMap[code] = hatCount; 211 | hatCount++; 212 | // Skip the Y axis 213 | code++; 214 | } 215 | else 216 | { 217 | if (ioctl(linjs.fd, EVIOCGABS(code), &linjs.absInfo[code]) < 0) 218 | continue; 219 | 220 | linjs.absMap[code] = axisCount; 221 | axisCount++; 222 | } 223 | } 224 | 225 | _GLFWjoystick* js = 226 | _glfwAllocJoystick(name, guid, axisCount, buttonCount, hatCount); 227 | if (!js) 228 | { 229 | close(linjs.fd); 230 | return GLFW_FALSE; 231 | } 232 | 233 | strncpy(linjs.path, path, sizeof(linjs.path) - 1); 234 | memcpy(&js->linjs, &linjs, sizeof(linjs)); 235 | 236 | pollAbsState(js); 237 | 238 | _glfwInputJoystick(js, GLFW_CONNECTED); 239 | return GLFW_TRUE; 240 | } 241 | 242 | #undef isBitSet 243 | 244 | // Frees all resources associated with the specified joystick 245 | // 246 | static void closeJoystick(_GLFWjoystick* js) 247 | { 248 | _glfwInputJoystick(js, GLFW_DISCONNECTED); 249 | close(js->linjs.fd); 250 | _glfwFreeJoystick(js); 251 | } 252 | 253 | // Lexically compare joysticks by name; used by qsort 254 | // 255 | static int compareJoysticks(const void* fp, const void* sp) 256 | { 257 | const _GLFWjoystick* fj = fp; 258 | const _GLFWjoystick* sj = sp; 259 | return strcmp(fj->linjs.path, sj->linjs.path); 260 | } 261 | 262 | 263 | ////////////////////////////////////////////////////////////////////////// 264 | ////// GLFW internal API ////// 265 | ////////////////////////////////////////////////////////////////////////// 266 | 267 | void _glfwDetectJoystickConnectionLinux(void) 268 | { 269 | if (_glfw.linjs.inotify <= 0) 270 | return; 271 | 272 | ssize_t offset = 0; 273 | char buffer[16384]; 274 | const ssize_t size = read(_glfw.linjs.inotify, buffer, sizeof(buffer)); 275 | 276 | while (size > offset) 277 | { 278 | regmatch_t match; 279 | const struct inotify_event* e = (struct inotify_event*) (buffer + offset); 280 | 281 | offset += sizeof(struct inotify_event) + e->len; 282 | 283 | if (regexec(&_glfw.linjs.regex, e->name, 1, &match, 0) != 0) 284 | continue; 285 | 286 | char path[PATH_MAX]; 287 | snprintf(path, sizeof(path), "/dev/input/%s", e->name); 288 | 289 | if (e->mask & (IN_CREATE | IN_ATTRIB)) 290 | openJoystickDevice(path); 291 | else if (e->mask & IN_DELETE) 292 | { 293 | for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) 294 | { 295 | if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0) 296 | { 297 | closeJoystick(_glfw.joysticks + jid); 298 | break; 299 | } 300 | } 301 | } 302 | } 303 | } 304 | 305 | 306 | ////////////////////////////////////////////////////////////////////////// 307 | ////// GLFW platform API ////// 308 | ////////////////////////////////////////////////////////////////////////// 309 | 310 | GLFWbool _glfwInitJoysticksLinux(void) 311 | { 312 | const char* dirname = "/dev/input"; 313 | 314 | _glfw.linjs.inotify = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); 315 | if (_glfw.linjs.inotify > 0) 316 | { 317 | // HACK: Register for IN_ATTRIB to get notified when udev is done 318 | // This works well in practice but the true way is libudev 319 | 320 | _glfw.linjs.watch = inotify_add_watch(_glfw.linjs.inotify, 321 | dirname, 322 | IN_CREATE | IN_ATTRIB | IN_DELETE); 323 | } 324 | 325 | // Continue without device connection notifications if inotify fails 326 | 327 | _glfw.linjs.regexCompiled = (regcomp(&_glfw.linjs.regex, "^event[0-9]\\+$", 0) == 0); 328 | if (!_glfw.linjs.regexCompiled) 329 | { 330 | _glfwInputError(GLFW_PLATFORM_ERROR, "Linux: Failed to compile regex"); 331 | return GLFW_FALSE; 332 | } 333 | 334 | int count = 0; 335 | 336 | DIR* dir = opendir(dirname); 337 | if (dir) 338 | { 339 | struct dirent* entry; 340 | 341 | while ((entry = readdir(dir))) 342 | { 343 | regmatch_t match; 344 | 345 | if (regexec(&_glfw.linjs.regex, entry->d_name, 1, &match, 0) != 0) 346 | continue; 347 | 348 | char path[PATH_MAX]; 349 | 350 | snprintf(path, sizeof(path), "%s/%s", dirname, entry->d_name); 351 | 352 | if (openJoystickDevice(path)) 353 | count++; 354 | } 355 | 356 | closedir(dir); 357 | } 358 | 359 | // Continue with no joysticks if enumeration fails 360 | 361 | qsort(_glfw.joysticks, count, sizeof(_GLFWjoystick), compareJoysticks); 362 | return GLFW_TRUE; 363 | } 364 | 365 | void _glfwTerminateJoysticksLinux(void) 366 | { 367 | for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) 368 | { 369 | _GLFWjoystick* js = _glfw.joysticks + jid; 370 | if (js->connected) 371 | closeJoystick(js); 372 | } 373 | 374 | if (_glfw.linjs.inotify > 0) 375 | { 376 | if (_glfw.linjs.watch > 0) 377 | inotify_rm_watch(_glfw.linjs.inotify, _glfw.linjs.watch); 378 | 379 | close(_glfw.linjs.inotify); 380 | } 381 | 382 | if (_glfw.linjs.regexCompiled) 383 | regfree(&_glfw.linjs.regex); 384 | } 385 | 386 | GLFWbool _glfwPollJoystickLinux(_GLFWjoystick* js, int mode) 387 | { 388 | // Read all queued events (non-blocking) 389 | for (;;) 390 | { 391 | struct input_event e; 392 | 393 | errno = 0; 394 | if (read(js->linjs.fd, &e, sizeof(e)) < 0) 395 | { 396 | // Reset the joystick slot if the device was disconnected 397 | if (errno == ENODEV) 398 | closeJoystick(js); 399 | 400 | break; 401 | } 402 | 403 | if (e.type == EV_SYN) 404 | { 405 | if (e.code == SYN_DROPPED) 406 | _glfw.linjs.dropped = GLFW_TRUE; 407 | else if (e.code == SYN_REPORT) 408 | { 409 | _glfw.linjs.dropped = GLFW_FALSE; 410 | pollAbsState(js); 411 | } 412 | } 413 | 414 | if (_glfw.linjs.dropped) 415 | continue; 416 | 417 | if (e.type == EV_KEY) 418 | handleKeyEvent(js, e.code, e.value); 419 | else if (e.type == EV_ABS) 420 | handleAbsEvent(js, e.code, e.value); 421 | } 422 | 423 | return js->connected; 424 | } 425 | 426 | const char* _glfwGetMappingNameLinux(void) 427 | { 428 | return "Linux"; 429 | } 430 | 431 | void _glfwUpdateGamepadGUIDLinux(char* guid) 432 | { 433 | } 434 | 435 | #endif // GLFW_BUILD_LINUX_JOYSTICK 436 | 437 | -------------------------------------------------------------------------------- /third-party/glfw/src/null_init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 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 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW platform API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform) 39 | { 40 | const _GLFWplatform null = 41 | { 42 | .platformID = GLFW_PLATFORM_NULL, 43 | .init = _glfwInitNull, 44 | .terminate = _glfwTerminateNull, 45 | .getCursorPos = _glfwGetCursorPosNull, 46 | .setCursorPos = _glfwSetCursorPosNull, 47 | .setCursorMode = _glfwSetCursorModeNull, 48 | .setRawMouseMotion = _glfwSetRawMouseMotionNull, 49 | .rawMouseMotionSupported = _glfwRawMouseMotionSupportedNull, 50 | .createCursor = _glfwCreateCursorNull, 51 | .createStandardCursor = _glfwCreateStandardCursorNull, 52 | .destroyCursor = _glfwDestroyCursorNull, 53 | .setCursor = _glfwSetCursorNull, 54 | .getScancodeName = _glfwGetScancodeNameNull, 55 | .getKeyScancode = _glfwGetKeyScancodeNull, 56 | .setClipboardString = _glfwSetClipboardStringNull, 57 | .getClipboardString = _glfwGetClipboardStringNull, 58 | .initJoysticks = _glfwInitJoysticksNull, 59 | .terminateJoysticks = _glfwTerminateJoysticksNull, 60 | .pollJoystick = _glfwPollJoystickNull, 61 | .getMappingName = _glfwGetMappingNameNull, 62 | .updateGamepadGUID = _glfwUpdateGamepadGUIDNull, 63 | .freeMonitor = _glfwFreeMonitorNull, 64 | .getMonitorPos = _glfwGetMonitorPosNull, 65 | .getMonitorContentScale = _glfwGetMonitorContentScaleNull, 66 | .getMonitorWorkarea = _glfwGetMonitorWorkareaNull, 67 | .getVideoModes = _glfwGetVideoModesNull, 68 | .getVideoMode = _glfwGetVideoModeNull, 69 | .getGammaRamp = _glfwGetGammaRampNull, 70 | .setGammaRamp = _glfwSetGammaRampNull, 71 | .createWindow = _glfwCreateWindowNull, 72 | .destroyWindow = _glfwDestroyWindowNull, 73 | .setWindowTitle = _glfwSetWindowTitleNull, 74 | .setWindowIcon = _glfwSetWindowIconNull, 75 | .getWindowPos = _glfwGetWindowPosNull, 76 | .setWindowPos = _glfwSetWindowPosNull, 77 | .getWindowSize = _glfwGetWindowSizeNull, 78 | .setWindowSize = _glfwSetWindowSizeNull, 79 | .setWindowSizeLimits = _glfwSetWindowSizeLimitsNull, 80 | .setWindowAspectRatio = _glfwSetWindowAspectRatioNull, 81 | .getFramebufferSize = _glfwGetFramebufferSizeNull, 82 | .getWindowFrameSize = _glfwGetWindowFrameSizeNull, 83 | .getWindowContentScale = _glfwGetWindowContentScaleNull, 84 | .iconifyWindow = _glfwIconifyWindowNull, 85 | .restoreWindow = _glfwRestoreWindowNull, 86 | .maximizeWindow = _glfwMaximizeWindowNull, 87 | .showWindow = _glfwShowWindowNull, 88 | .hideWindow = _glfwHideWindowNull, 89 | .requestWindowAttention = _glfwRequestWindowAttentionNull, 90 | .focusWindow = _glfwFocusWindowNull, 91 | .setWindowMonitor = _glfwSetWindowMonitorNull, 92 | .windowFocused = _glfwWindowFocusedNull, 93 | .windowIconified = _glfwWindowIconifiedNull, 94 | .windowVisible = _glfwWindowVisibleNull, 95 | .windowMaximized = _glfwWindowMaximizedNull, 96 | .windowHovered = _glfwWindowHoveredNull, 97 | .framebufferTransparent = _glfwFramebufferTransparentNull, 98 | .getWindowOpacity = _glfwGetWindowOpacityNull, 99 | .setWindowResizable = _glfwSetWindowResizableNull, 100 | .setWindowDecorated = _glfwSetWindowDecoratedNull, 101 | .setWindowFloating = _glfwSetWindowFloatingNull, 102 | .setWindowOpacity = _glfwSetWindowOpacityNull, 103 | .setWindowMousePassthrough = _glfwSetWindowMousePassthroughNull, 104 | .pollEvents = _glfwPollEventsNull, 105 | .waitEvents = _glfwWaitEventsNull, 106 | .waitEventsTimeout = _glfwWaitEventsTimeoutNull, 107 | .postEmptyEvent = _glfwPostEmptyEventNull, 108 | .getEGLPlatform = _glfwGetEGLPlatformNull, 109 | .getEGLNativeDisplay = _glfwGetEGLNativeDisplayNull, 110 | .getEGLNativeWindow = _glfwGetEGLNativeWindowNull, 111 | .getRequiredInstanceExtensions = _glfwGetRequiredInstanceExtensionsNull, 112 | .getPhysicalDevicePresentationSupport = _glfwGetPhysicalDevicePresentationSupportNull, 113 | .createWindowSurface = _glfwCreateWindowSurfaceNull 114 | }; 115 | 116 | *platform = null; 117 | return GLFW_TRUE; 118 | } 119 | 120 | int _glfwInitNull(void) 121 | { 122 | int scancode; 123 | 124 | memset(_glfw.null.keycodes, -1, sizeof(_glfw.null.keycodes)); 125 | memset(_glfw.null.scancodes, -1, sizeof(_glfw.null.scancodes)); 126 | 127 | _glfw.null.keycodes[GLFW_NULL_SC_SPACE] = GLFW_KEY_SPACE; 128 | _glfw.null.keycodes[GLFW_NULL_SC_APOSTROPHE] = GLFW_KEY_APOSTROPHE; 129 | _glfw.null.keycodes[GLFW_NULL_SC_COMMA] = GLFW_KEY_COMMA; 130 | _glfw.null.keycodes[GLFW_NULL_SC_MINUS] = GLFW_KEY_MINUS; 131 | _glfw.null.keycodes[GLFW_NULL_SC_PERIOD] = GLFW_KEY_PERIOD; 132 | _glfw.null.keycodes[GLFW_NULL_SC_SLASH] = GLFW_KEY_SLASH; 133 | _glfw.null.keycodes[GLFW_NULL_SC_0] = GLFW_KEY_0; 134 | _glfw.null.keycodes[GLFW_NULL_SC_1] = GLFW_KEY_1; 135 | _glfw.null.keycodes[GLFW_NULL_SC_2] = GLFW_KEY_2; 136 | _glfw.null.keycodes[GLFW_NULL_SC_3] = GLFW_KEY_3; 137 | _glfw.null.keycodes[GLFW_NULL_SC_4] = GLFW_KEY_4; 138 | _glfw.null.keycodes[GLFW_NULL_SC_5] = GLFW_KEY_5; 139 | _glfw.null.keycodes[GLFW_NULL_SC_6] = GLFW_KEY_6; 140 | _glfw.null.keycodes[GLFW_NULL_SC_7] = GLFW_KEY_7; 141 | _glfw.null.keycodes[GLFW_NULL_SC_8] = GLFW_KEY_8; 142 | _glfw.null.keycodes[GLFW_NULL_SC_9] = GLFW_KEY_9; 143 | _glfw.null.keycodes[GLFW_NULL_SC_SEMICOLON] = GLFW_KEY_SEMICOLON; 144 | _glfw.null.keycodes[GLFW_NULL_SC_EQUAL] = GLFW_KEY_EQUAL; 145 | _glfw.null.keycodes[GLFW_NULL_SC_A] = GLFW_KEY_A; 146 | _glfw.null.keycodes[GLFW_NULL_SC_B] = GLFW_KEY_B; 147 | _glfw.null.keycodes[GLFW_NULL_SC_C] = GLFW_KEY_C; 148 | _glfw.null.keycodes[GLFW_NULL_SC_D] = GLFW_KEY_D; 149 | _glfw.null.keycodes[GLFW_NULL_SC_E] = GLFW_KEY_E; 150 | _glfw.null.keycodes[GLFW_NULL_SC_F] = GLFW_KEY_F; 151 | _glfw.null.keycodes[GLFW_NULL_SC_G] = GLFW_KEY_G; 152 | _glfw.null.keycodes[GLFW_NULL_SC_H] = GLFW_KEY_H; 153 | _glfw.null.keycodes[GLFW_NULL_SC_I] = GLFW_KEY_I; 154 | _glfw.null.keycodes[GLFW_NULL_SC_J] = GLFW_KEY_J; 155 | _glfw.null.keycodes[GLFW_NULL_SC_K] = GLFW_KEY_K; 156 | _glfw.null.keycodes[GLFW_NULL_SC_L] = GLFW_KEY_L; 157 | _glfw.null.keycodes[GLFW_NULL_SC_M] = GLFW_KEY_M; 158 | _glfw.null.keycodes[GLFW_NULL_SC_N] = GLFW_KEY_N; 159 | _glfw.null.keycodes[GLFW_NULL_SC_O] = GLFW_KEY_O; 160 | _glfw.null.keycodes[GLFW_NULL_SC_P] = GLFW_KEY_P; 161 | _glfw.null.keycodes[GLFW_NULL_SC_Q] = GLFW_KEY_Q; 162 | _glfw.null.keycodes[GLFW_NULL_SC_R] = GLFW_KEY_R; 163 | _glfw.null.keycodes[GLFW_NULL_SC_S] = GLFW_KEY_S; 164 | _glfw.null.keycodes[GLFW_NULL_SC_T] = GLFW_KEY_T; 165 | _glfw.null.keycodes[GLFW_NULL_SC_U] = GLFW_KEY_U; 166 | _glfw.null.keycodes[GLFW_NULL_SC_V] = GLFW_KEY_V; 167 | _glfw.null.keycodes[GLFW_NULL_SC_W] = GLFW_KEY_W; 168 | _glfw.null.keycodes[GLFW_NULL_SC_X] = GLFW_KEY_X; 169 | _glfw.null.keycodes[GLFW_NULL_SC_Y] = GLFW_KEY_Y; 170 | _glfw.null.keycodes[GLFW_NULL_SC_Z] = GLFW_KEY_Z; 171 | _glfw.null.keycodes[GLFW_NULL_SC_LEFT_BRACKET] = GLFW_KEY_LEFT_BRACKET; 172 | _glfw.null.keycodes[GLFW_NULL_SC_BACKSLASH] = GLFW_KEY_BACKSLASH; 173 | _glfw.null.keycodes[GLFW_NULL_SC_RIGHT_BRACKET] = GLFW_KEY_RIGHT_BRACKET; 174 | _glfw.null.keycodes[GLFW_NULL_SC_GRAVE_ACCENT] = GLFW_KEY_GRAVE_ACCENT; 175 | _glfw.null.keycodes[GLFW_NULL_SC_WORLD_1] = GLFW_KEY_WORLD_1; 176 | _glfw.null.keycodes[GLFW_NULL_SC_WORLD_2] = GLFW_KEY_WORLD_2; 177 | _glfw.null.keycodes[GLFW_NULL_SC_ESCAPE] = GLFW_KEY_ESCAPE; 178 | _glfw.null.keycodes[GLFW_NULL_SC_ENTER] = GLFW_KEY_ENTER; 179 | _glfw.null.keycodes[GLFW_NULL_SC_TAB] = GLFW_KEY_TAB; 180 | _glfw.null.keycodes[GLFW_NULL_SC_BACKSPACE] = GLFW_KEY_BACKSPACE; 181 | _glfw.null.keycodes[GLFW_NULL_SC_INSERT] = GLFW_KEY_INSERT; 182 | _glfw.null.keycodes[GLFW_NULL_SC_DELETE] = GLFW_KEY_DELETE; 183 | _glfw.null.keycodes[GLFW_NULL_SC_RIGHT] = GLFW_KEY_RIGHT; 184 | _glfw.null.keycodes[GLFW_NULL_SC_LEFT] = GLFW_KEY_LEFT; 185 | _glfw.null.keycodes[GLFW_NULL_SC_DOWN] = GLFW_KEY_DOWN; 186 | _glfw.null.keycodes[GLFW_NULL_SC_UP] = GLFW_KEY_UP; 187 | _glfw.null.keycodes[GLFW_NULL_SC_PAGE_UP] = GLFW_KEY_PAGE_UP; 188 | _glfw.null.keycodes[GLFW_NULL_SC_PAGE_DOWN] = GLFW_KEY_PAGE_DOWN; 189 | _glfw.null.keycodes[GLFW_NULL_SC_HOME] = GLFW_KEY_HOME; 190 | _glfw.null.keycodes[GLFW_NULL_SC_END] = GLFW_KEY_END; 191 | _glfw.null.keycodes[GLFW_NULL_SC_CAPS_LOCK] = GLFW_KEY_CAPS_LOCK; 192 | _glfw.null.keycodes[GLFW_NULL_SC_SCROLL_LOCK] = GLFW_KEY_SCROLL_LOCK; 193 | _glfw.null.keycodes[GLFW_NULL_SC_NUM_LOCK] = GLFW_KEY_NUM_LOCK; 194 | _glfw.null.keycodes[GLFW_NULL_SC_PRINT_SCREEN] = GLFW_KEY_PRINT_SCREEN; 195 | _glfw.null.keycodes[GLFW_NULL_SC_PAUSE] = GLFW_KEY_PAUSE; 196 | _glfw.null.keycodes[GLFW_NULL_SC_F1] = GLFW_KEY_F1; 197 | _glfw.null.keycodes[GLFW_NULL_SC_F2] = GLFW_KEY_F2; 198 | _glfw.null.keycodes[GLFW_NULL_SC_F3] = GLFW_KEY_F3; 199 | _glfw.null.keycodes[GLFW_NULL_SC_F4] = GLFW_KEY_F4; 200 | _glfw.null.keycodes[GLFW_NULL_SC_F5] = GLFW_KEY_F5; 201 | _glfw.null.keycodes[GLFW_NULL_SC_F6] = GLFW_KEY_F6; 202 | _glfw.null.keycodes[GLFW_NULL_SC_F7] = GLFW_KEY_F7; 203 | _glfw.null.keycodes[GLFW_NULL_SC_F8] = GLFW_KEY_F8; 204 | _glfw.null.keycodes[GLFW_NULL_SC_F9] = GLFW_KEY_F9; 205 | _glfw.null.keycodes[GLFW_NULL_SC_F10] = GLFW_KEY_F10; 206 | _glfw.null.keycodes[GLFW_NULL_SC_F11] = GLFW_KEY_F11; 207 | _glfw.null.keycodes[GLFW_NULL_SC_F12] = GLFW_KEY_F12; 208 | _glfw.null.keycodes[GLFW_NULL_SC_F13] = GLFW_KEY_F13; 209 | _glfw.null.keycodes[GLFW_NULL_SC_F14] = GLFW_KEY_F14; 210 | _glfw.null.keycodes[GLFW_NULL_SC_F15] = GLFW_KEY_F15; 211 | _glfw.null.keycodes[GLFW_NULL_SC_F16] = GLFW_KEY_F16; 212 | _glfw.null.keycodes[GLFW_NULL_SC_F17] = GLFW_KEY_F17; 213 | _glfw.null.keycodes[GLFW_NULL_SC_F18] = GLFW_KEY_F18; 214 | _glfw.null.keycodes[GLFW_NULL_SC_F19] = GLFW_KEY_F19; 215 | _glfw.null.keycodes[GLFW_NULL_SC_F20] = GLFW_KEY_F20; 216 | _glfw.null.keycodes[GLFW_NULL_SC_F21] = GLFW_KEY_F21; 217 | _glfw.null.keycodes[GLFW_NULL_SC_F22] = GLFW_KEY_F22; 218 | _glfw.null.keycodes[GLFW_NULL_SC_F23] = GLFW_KEY_F23; 219 | _glfw.null.keycodes[GLFW_NULL_SC_F24] = GLFW_KEY_F24; 220 | _glfw.null.keycodes[GLFW_NULL_SC_F25] = GLFW_KEY_F25; 221 | _glfw.null.keycodes[GLFW_NULL_SC_KP_0] = GLFW_KEY_KP_0; 222 | _glfw.null.keycodes[GLFW_NULL_SC_KP_1] = GLFW_KEY_KP_1; 223 | _glfw.null.keycodes[GLFW_NULL_SC_KP_2] = GLFW_KEY_KP_2; 224 | _glfw.null.keycodes[GLFW_NULL_SC_KP_3] = GLFW_KEY_KP_3; 225 | _glfw.null.keycodes[GLFW_NULL_SC_KP_4] = GLFW_KEY_KP_4; 226 | _glfw.null.keycodes[GLFW_NULL_SC_KP_5] = GLFW_KEY_KP_5; 227 | _glfw.null.keycodes[GLFW_NULL_SC_KP_6] = GLFW_KEY_KP_6; 228 | _glfw.null.keycodes[GLFW_NULL_SC_KP_7] = GLFW_KEY_KP_7; 229 | _glfw.null.keycodes[GLFW_NULL_SC_KP_8] = GLFW_KEY_KP_8; 230 | _glfw.null.keycodes[GLFW_NULL_SC_KP_9] = GLFW_KEY_KP_9; 231 | _glfw.null.keycodes[GLFW_NULL_SC_KP_DECIMAL] = GLFW_KEY_KP_DECIMAL; 232 | _glfw.null.keycodes[GLFW_NULL_SC_KP_DIVIDE] = GLFW_KEY_KP_DIVIDE; 233 | _glfw.null.keycodes[GLFW_NULL_SC_KP_MULTIPLY] = GLFW_KEY_KP_MULTIPLY; 234 | _glfw.null.keycodes[GLFW_NULL_SC_KP_SUBTRACT] = GLFW_KEY_KP_SUBTRACT; 235 | _glfw.null.keycodes[GLFW_NULL_SC_KP_ADD] = GLFW_KEY_KP_ADD; 236 | _glfw.null.keycodes[GLFW_NULL_SC_KP_ENTER] = GLFW_KEY_KP_ENTER; 237 | _glfw.null.keycodes[GLFW_NULL_SC_KP_EQUAL] = GLFW_KEY_KP_EQUAL; 238 | _glfw.null.keycodes[GLFW_NULL_SC_LEFT_SHIFT] = GLFW_KEY_LEFT_SHIFT; 239 | _glfw.null.keycodes[GLFW_NULL_SC_LEFT_CONTROL] = GLFW_KEY_LEFT_CONTROL; 240 | _glfw.null.keycodes[GLFW_NULL_SC_LEFT_ALT] = GLFW_KEY_LEFT_ALT; 241 | _glfw.null.keycodes[GLFW_NULL_SC_LEFT_SUPER] = GLFW_KEY_LEFT_SUPER; 242 | _glfw.null.keycodes[GLFW_NULL_SC_RIGHT_SHIFT] = GLFW_KEY_RIGHT_SHIFT; 243 | _glfw.null.keycodes[GLFW_NULL_SC_RIGHT_CONTROL] = GLFW_KEY_RIGHT_CONTROL; 244 | _glfw.null.keycodes[GLFW_NULL_SC_RIGHT_ALT] = GLFW_KEY_RIGHT_ALT; 245 | _glfw.null.keycodes[GLFW_NULL_SC_RIGHT_SUPER] = GLFW_KEY_RIGHT_SUPER; 246 | _glfw.null.keycodes[GLFW_NULL_SC_MENU] = GLFW_KEY_MENU; 247 | 248 | for (scancode = GLFW_NULL_SC_FIRST; scancode < GLFW_NULL_SC_LAST; scancode++) 249 | { 250 | if (_glfw.null.keycodes[scancode] > 0) 251 | _glfw.null.scancodes[_glfw.null.keycodes[scancode]] = scancode; 252 | } 253 | 254 | _glfwPollMonitorsNull(); 255 | return GLFW_TRUE; 256 | } 257 | 258 | void _glfwTerminateNull(void) 259 | { 260 | free(_glfw.null.clipboardString); 261 | _glfwTerminateOSMesa(); 262 | _glfwTerminateEGL(); 263 | } 264 | 265 | --------------------------------------------------------------------------------