glfw3.c 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GLFW/CMakeLists.txt +368 -0
- package/GLFW/cocoa_init.m +694 -0
- package/GLFW/cocoa_joystick.h +49 -0
- package/GLFW/cocoa_joystick.m +485 -0
- package/GLFW/cocoa_monitor.m +643 -0
- package/GLFW/cocoa_platform.h +302 -0
- package/GLFW/cocoa_time.c +57 -0
- package/GLFW/cocoa_time.h +35 -0
- package/GLFW/cocoa_window.m +2072 -0
- package/GLFW/context.c +765 -0
- package/GLFW/egl_context.c +911 -0
- package/GLFW/glfw.rc.in +30 -0
- package/GLFW/glfw3.c +109 -0
- package/GLFW/glfw3.h +6564 -0
- package/GLFW/glfw3native.h +663 -0
- package/GLFW/glx_context.c +719 -0
- package/GLFW/init.c +528 -0
- package/GLFW/input.c +1505 -0
- package/GLFW/internal.h +1022 -0
- package/GLFW/linux_joystick.c +436 -0
- package/GLFW/linux_joystick.h +64 -0
- package/GLFW/mappings.h +1001 -0
- package/GLFW/mappings.h.in +82 -0
- package/GLFW/monitor.c +548 -0
- package/GLFW/nsgl_context.m +384 -0
- package/GLFW/null_init.c +264 -0
- package/GLFW/null_joystick.c +56 -0
- package/GLFW/null_joystick.h +32 -0
- package/GLFW/null_monitor.c +160 -0
- package/GLFW/null_platform.h +271 -0
- package/GLFW/null_window.c +719 -0
- package/GLFW/osmesa_context.c +383 -0
- package/GLFW/platform.c +214 -0
- package/GLFW/platform.h +212 -0
- package/GLFW/posix_module.c +53 -0
- package/GLFW/posix_poll.c +83 -0
- package/GLFW/posix_poll.h +30 -0
- package/GLFW/posix_thread.c +107 -0
- package/GLFW/posix_thread.h +49 -0
- package/GLFW/posix_time.c +65 -0
- package/GLFW/posix_time.h +41 -0
- package/GLFW/vulkan.c +328 -0
- package/GLFW/wgl_context.c +798 -0
- package/GLFW/win32_init.c +731 -0
- package/GLFW/win32_joystick.c +767 -0
- package/GLFW/win32_joystick.h +51 -0
- package/GLFW/win32_module.c +51 -0
- package/GLFW/win32_monitor.c +569 -0
- package/GLFW/win32_platform.h +631 -0
- package/GLFW/win32_thread.c +100 -0
- package/GLFW/win32_thread.h +53 -0
- package/GLFW/win32_time.c +54 -0
- package/GLFW/win32_time.h +43 -0
- package/GLFW/win32_window.c +2592 -0
- package/GLFW/window.c +1172 -0
- package/GLFW/wl_init.c +1003 -0
- package/GLFW/wl_monitor.c +274 -0
- package/GLFW/wl_platform.h +691 -0
- package/GLFW/wl_window.c +3308 -0
- package/GLFW/x11_init.c +1656 -0
- package/GLFW/x11_monitor.c +641 -0
- package/GLFW/x11_platform.h +1004 -0
- package/GLFW/x11_window.c +3357 -0
- package/GLFW/xkb_unicode.c +943 -0
- package/GLFW/xkb_unicode.h +30 -0
- package/LICENSE +22 -0
- package/README.md +236 -0
- package/package.json +32 -0
package/GLFW/platform.h
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
//========================================================================
|
|
2
|
+
// GLFW 3.4 - www.glfw.org
|
|
3
|
+
//------------------------------------------------------------------------
|
|
4
|
+
// Copyright (c) 2002-2006 Marcus Geelnard
|
|
5
|
+
// Copyright (c) 2006-2018 Camilla Löwy <elmindreda@glfw.org>
|
|
6
|
+
//
|
|
7
|
+
// This software is provided 'as-is', without any express or implied
|
|
8
|
+
// warranty. In no event will the authors be held liable for any damages
|
|
9
|
+
// arising from the use of this software.
|
|
10
|
+
//
|
|
11
|
+
// Permission is granted to anyone to use this software for any purpose,
|
|
12
|
+
// including commercial applications, and to alter it and redistribute it
|
|
13
|
+
// freely, subject to the following restrictions:
|
|
14
|
+
//
|
|
15
|
+
// 1. The origin of this software must not be misrepresented; you must not
|
|
16
|
+
// claim that you wrote the original software. If you use this software
|
|
17
|
+
// in a product, an acknowledgment in the product documentation would
|
|
18
|
+
// be appreciated but is not required.
|
|
19
|
+
//
|
|
20
|
+
// 2. Altered source versions must be plainly marked as such, and must not
|
|
21
|
+
// be misrepresented as being the original software.
|
|
22
|
+
//
|
|
23
|
+
// 3. This notice may not be removed or altered from any source
|
|
24
|
+
// distribution.
|
|
25
|
+
//
|
|
26
|
+
//========================================================================
|
|
27
|
+
|
|
28
|
+
#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_<platform> 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
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//========================================================================
|
|
2
|
+
// GLFW 3.4 POSIX - www.glfw.org
|
|
3
|
+
//------------------------------------------------------------------------
|
|
4
|
+
// Copyright (c) 2021 Camilla Löwy <elmindreda@glfw.org>
|
|
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 <dlfcn.h>
|
|
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
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//========================================================================
|
|
2
|
+
// GLFW 3.4 POSIX - www.glfw.org
|
|
3
|
+
//------------------------------------------------------------------------
|
|
4
|
+
// Copyright (c) 2022 Camilla Löwy <elmindreda@glfw.org>
|
|
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 <signal.h>
|
|
34
|
+
#include <time.h>
|
|
35
|
+
#include <errno.h>
|
|
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
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//========================================================================
|
|
2
|
+
// GLFW 3.4 POSIX - www.glfw.org
|
|
3
|
+
//------------------------------------------------------------------------
|
|
4
|
+
// Copyright (c) 2022 Camilla Löwy <elmindreda@glfw.org>
|
|
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 <poll.h>
|
|
28
|
+
|
|
29
|
+
GLFWbool _glfwPollPOSIX(struct pollfd* fds, nfds_t count, double* timeout);
|
|
30
|
+
|
|
@@ -0,0 +1,107 @@
|
|
|
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 <elmindreda@glfw.org>
|
|
6
|
+
//
|
|
7
|
+
// This software is provided 'as-is', without any express or implied
|
|
8
|
+
// warranty. In no event will the authors be held liable for any damages
|
|
9
|
+
// arising from the use of this software.
|
|
10
|
+
//
|
|
11
|
+
// Permission is granted to anyone to use this software for any purpose,
|
|
12
|
+
// including commercial applications, and to alter it and redistribute it
|
|
13
|
+
// freely, subject to the following restrictions:
|
|
14
|
+
//
|
|
15
|
+
// 1. The origin of this software must not be misrepresented; you must not
|
|
16
|
+
// claim that you wrote the original software. If you use this software
|
|
17
|
+
// in a product, an acknowledgment in the product documentation would
|
|
18
|
+
// be appreciated but is not required.
|
|
19
|
+
//
|
|
20
|
+
// 2. Altered source versions must be plainly marked as such, and must not
|
|
21
|
+
// be misrepresented as being the original software.
|
|
22
|
+
//
|
|
23
|
+
// 3. This notice may not be removed or altered from any source
|
|
24
|
+
// distribution.
|
|
25
|
+
//
|
|
26
|
+
//========================================================================
|
|
27
|
+
|
|
28
|
+
#include "internal.h"
|
|
29
|
+
|
|
30
|
+
#if defined(GLFW_BUILD_POSIX_THREAD)
|
|
31
|
+
|
|
32
|
+
#include <assert.h>
|
|
33
|
+
#include <string.h>
|
|
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
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
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 <elmindreda@glfw.org>
|
|
6
|
+
//
|
|
7
|
+
// This software is provided 'as-is', without any express or implied
|
|
8
|
+
// warranty. In no event will the authors be held liable for any damages
|
|
9
|
+
// arising from the use of this software.
|
|
10
|
+
//
|
|
11
|
+
// Permission is granted to anyone to use this software for any purpose,
|
|
12
|
+
// including commercial applications, and to alter it and redistribute it
|
|
13
|
+
// freely, subject to the following restrictions:
|
|
14
|
+
//
|
|
15
|
+
// 1. The origin of this software must not be misrepresented; you must not
|
|
16
|
+
// claim that you wrote the original software. If you use this software
|
|
17
|
+
// in a product, an acknowledgment in the product documentation would
|
|
18
|
+
// be appreciated but is not required.
|
|
19
|
+
//
|
|
20
|
+
// 2. Altered source versions must be plainly marked as such, and must not
|
|
21
|
+
// be misrepresented as being the original software.
|
|
22
|
+
//
|
|
23
|
+
// 3. This notice may not be removed or altered from any source
|
|
24
|
+
// distribution.
|
|
25
|
+
//
|
|
26
|
+
//========================================================================
|
|
27
|
+
|
|
28
|
+
#include <pthread.h>
|
|
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
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
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 <elmindreda@glfw.org>
|
|
6
|
+
//
|
|
7
|
+
// This software is provided 'as-is', without any express or implied
|
|
8
|
+
// warranty. In no event will the authors be held liable for any damages
|
|
9
|
+
// arising from the use of this software.
|
|
10
|
+
//
|
|
11
|
+
// Permission is granted to anyone to use this software for any purpose,
|
|
12
|
+
// including commercial applications, and to alter it and redistribute it
|
|
13
|
+
// freely, subject to the following restrictions:
|
|
14
|
+
//
|
|
15
|
+
// 1. The origin of this software must not be misrepresented; you must not
|
|
16
|
+
// claim that you wrote the original software. If you use this software
|
|
17
|
+
// in a product, an acknowledgment in the product documentation would
|
|
18
|
+
// be appreciated but is not required.
|
|
19
|
+
//
|
|
20
|
+
// 2. Altered source versions must be plainly marked as such, and must not
|
|
21
|
+
// be misrepresented as being the original software.
|
|
22
|
+
//
|
|
23
|
+
// 3. This notice may not be removed or altered from any source
|
|
24
|
+
// distribution.
|
|
25
|
+
//
|
|
26
|
+
//========================================================================
|
|
27
|
+
|
|
28
|
+
#include "internal.h"
|
|
29
|
+
|
|
30
|
+
#if defined(GLFW_BUILD_POSIX_TIMER)
|
|
31
|
+
|
|
32
|
+
#include <unistd.h>
|
|
33
|
+
#include <sys/time.h>
|
|
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
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
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 <elmindreda@glfw.org>
|
|
6
|
+
//
|
|
7
|
+
// This software is provided 'as-is', without any express or implied
|
|
8
|
+
// warranty. In no event will the authors be held liable for any damages
|
|
9
|
+
// arising from the use of this software.
|
|
10
|
+
//
|
|
11
|
+
// Permission is granted to anyone to use this software for any purpose,
|
|
12
|
+
// including commercial applications, and to alter it and redistribute it
|
|
13
|
+
// freely, subject to the following restrictions:
|
|
14
|
+
//
|
|
15
|
+
// 1. The origin of this software must not be misrepresented; you must not
|
|
16
|
+
// claim that you wrote the original software. If you use this software
|
|
17
|
+
// in a product, an acknowledgment in the product documentation would
|
|
18
|
+
// be appreciated but is not required.
|
|
19
|
+
//
|
|
20
|
+
// 2. Altered source versions must be plainly marked as such, and must not
|
|
21
|
+
// be misrepresented as being the original software.
|
|
22
|
+
//
|
|
23
|
+
// 3. This notice may not be removed or altered from any source
|
|
24
|
+
// distribution.
|
|
25
|
+
//
|
|
26
|
+
//========================================================================
|
|
27
|
+
|
|
28
|
+
#define GLFW_POSIX_LIBRARY_TIMER_STATE _GLFWtimerPOSIX posix;
|
|
29
|
+
|
|
30
|
+
#include <stdint.h>
|
|
31
|
+
#include <time.h>
|
|
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
|
+
|