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.
Files changed (68) hide show
  1. package/GLFW/CMakeLists.txt +368 -0
  2. package/GLFW/cocoa_init.m +694 -0
  3. package/GLFW/cocoa_joystick.h +49 -0
  4. package/GLFW/cocoa_joystick.m +485 -0
  5. package/GLFW/cocoa_monitor.m +643 -0
  6. package/GLFW/cocoa_platform.h +302 -0
  7. package/GLFW/cocoa_time.c +57 -0
  8. package/GLFW/cocoa_time.h +35 -0
  9. package/GLFW/cocoa_window.m +2072 -0
  10. package/GLFW/context.c +765 -0
  11. package/GLFW/egl_context.c +911 -0
  12. package/GLFW/glfw.rc.in +30 -0
  13. package/GLFW/glfw3.c +109 -0
  14. package/GLFW/glfw3.h +6564 -0
  15. package/GLFW/glfw3native.h +663 -0
  16. package/GLFW/glx_context.c +719 -0
  17. package/GLFW/init.c +528 -0
  18. package/GLFW/input.c +1505 -0
  19. package/GLFW/internal.h +1022 -0
  20. package/GLFW/linux_joystick.c +436 -0
  21. package/GLFW/linux_joystick.h +64 -0
  22. package/GLFW/mappings.h +1001 -0
  23. package/GLFW/mappings.h.in +82 -0
  24. package/GLFW/monitor.c +548 -0
  25. package/GLFW/nsgl_context.m +384 -0
  26. package/GLFW/null_init.c +264 -0
  27. package/GLFW/null_joystick.c +56 -0
  28. package/GLFW/null_joystick.h +32 -0
  29. package/GLFW/null_monitor.c +160 -0
  30. package/GLFW/null_platform.h +271 -0
  31. package/GLFW/null_window.c +719 -0
  32. package/GLFW/osmesa_context.c +383 -0
  33. package/GLFW/platform.c +214 -0
  34. package/GLFW/platform.h +212 -0
  35. package/GLFW/posix_module.c +53 -0
  36. package/GLFW/posix_poll.c +83 -0
  37. package/GLFW/posix_poll.h +30 -0
  38. package/GLFW/posix_thread.c +107 -0
  39. package/GLFW/posix_thread.h +49 -0
  40. package/GLFW/posix_time.c +65 -0
  41. package/GLFW/posix_time.h +41 -0
  42. package/GLFW/vulkan.c +328 -0
  43. package/GLFW/wgl_context.c +798 -0
  44. package/GLFW/win32_init.c +731 -0
  45. package/GLFW/win32_joystick.c +767 -0
  46. package/GLFW/win32_joystick.h +51 -0
  47. package/GLFW/win32_module.c +51 -0
  48. package/GLFW/win32_monitor.c +569 -0
  49. package/GLFW/win32_platform.h +631 -0
  50. package/GLFW/win32_thread.c +100 -0
  51. package/GLFW/win32_thread.h +53 -0
  52. package/GLFW/win32_time.c +54 -0
  53. package/GLFW/win32_time.h +43 -0
  54. package/GLFW/win32_window.c +2592 -0
  55. package/GLFW/window.c +1172 -0
  56. package/GLFW/wl_init.c +1003 -0
  57. package/GLFW/wl_monitor.c +274 -0
  58. package/GLFW/wl_platform.h +691 -0
  59. package/GLFW/wl_window.c +3308 -0
  60. package/GLFW/x11_init.c +1656 -0
  61. package/GLFW/x11_monitor.c +641 -0
  62. package/GLFW/x11_platform.h +1004 -0
  63. package/GLFW/x11_window.c +3357 -0
  64. package/GLFW/xkb_unicode.c +943 -0
  65. package/GLFW/xkb_unicode.h +30 -0
  66. package/LICENSE +22 -0
  67. package/README.md +236 -0
  68. package/package.json +32 -0
@@ -0,0 +1,383 @@
1
+ //========================================================================
2
+ // GLFW 3.4 OSMesa - www.glfw.org
3
+ //------------------------------------------------------------------------
4
+ // Copyright (c) 2016 Google Inc.
5
+ // Copyright (c) 2016-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
+ #include <stdlib.h>
31
+ #include <string.h>
32
+ #include <assert.h>
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
+
@@ -0,0 +1,214 @@
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
+ #include "internal.h"
29
+
30
+ #include <string.h>
31
+ #include <stdlib.h>
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 !defined(_GLFW_WIN32) && !defined(_GLFW_COCOA) && !defined(_GLFW_X11) && !defined(_GLFW_WAYLAND)
79
+ if (desiredID == GLFW_PLATFORM_NULL)
80
+ return _glfwConnectNull(desiredID, platform);
81
+ else
82
+ #endif
83
+ if (count == 0)
84
+ {
85
+ _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "This binary only supports the Null platform");
86
+ return GLFW_FALSE;
87
+ }
88
+
89
+ #if defined(_GLFW_WAYLAND) && defined(_GLFW_X11)
90
+ if (desiredID == GLFW_ANY_PLATFORM)
91
+ {
92
+ const char* const session = getenv("XDG_SESSION_TYPE");
93
+ if (session)
94
+ {
95
+ // Only follow XDG_SESSION_TYPE if it is set correctly and the
96
+ // environment looks plausble; otherwise fall back to detection
97
+ if (strcmp(session, "wayland") == 0 && getenv("WAYLAND_DISPLAY"))
98
+ desiredID = GLFW_PLATFORM_WAYLAND;
99
+ else if (strcmp(session, "x11") == 0 && getenv("DISPLAY"))
100
+ desiredID = GLFW_PLATFORM_X11;
101
+ }
102
+ }
103
+ #endif
104
+
105
+ if (desiredID == GLFW_ANY_PLATFORM)
106
+ {
107
+ // If there is exactly one platform available for auto-selection, let it emit the
108
+ // error on failure as the platform-specific error description may be more helpful
109
+ if (count == 1)
110
+ return supportedPlatforms[0].connect(supportedPlatforms[0].ID, platform);
111
+
112
+ for (i = 0; i < count; i++)
113
+ {
114
+ if (supportedPlatforms[i].connect(desiredID, platform))
115
+ return GLFW_TRUE;
116
+ }
117
+
118
+ _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Failed to detect any supported platform");
119
+ }
120
+ else
121
+ {
122
+ for (i = 0; i < count; i++)
123
+ {
124
+ if (supportedPlatforms[i].ID == desiredID)
125
+ return supportedPlatforms[i].connect(desiredID, platform);
126
+ }
127
+
128
+ _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "The requested platform is not supported");
129
+ }
130
+
131
+ return GLFW_FALSE;
132
+ }
133
+
134
+ //////////////////////////////////////////////////////////////////////////
135
+ ////// GLFW public API //////
136
+ //////////////////////////////////////////////////////////////////////////
137
+
138
+ GLFWAPI int glfwGetPlatform(void)
139
+ {
140
+ _GLFW_REQUIRE_INIT_OR_RETURN(0);
141
+ return _glfw.platform.platformID;
142
+ }
143
+
144
+ GLFWAPI int glfwPlatformSupported(int platformID)
145
+ {
146
+ const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]);
147
+ size_t i;
148
+
149
+ if (platformID != GLFW_PLATFORM_WIN32 &&
150
+ platformID != GLFW_PLATFORM_COCOA &&
151
+ platformID != GLFW_PLATFORM_WAYLAND &&
152
+ platformID != GLFW_PLATFORM_X11 &&
153
+ platformID != GLFW_PLATFORM_NULL)
154
+ {
155
+ _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X", platformID);
156
+ return GLFW_FALSE;
157
+ }
158
+
159
+ if (platformID == GLFW_PLATFORM_NULL)
160
+ return GLFW_TRUE;
161
+
162
+ for (i = 0; i < count; i++)
163
+ {
164
+ if (platformID == supportedPlatforms[i].ID)
165
+ return GLFW_TRUE;
166
+ }
167
+
168
+ return GLFW_FALSE;
169
+ }
170
+
171
+ GLFWAPI const char* glfwGetVersionString(void)
172
+ {
173
+ return _GLFW_MAKE_VERSION(GLFW_VERSION_MAJOR,
174
+ GLFW_VERSION_MINOR,
175
+ GLFW_VERSION_REVISION)
176
+ #if defined(_GLFW_WIN32)
177
+ " Win32 WGL"
178
+ #endif
179
+ #if defined(_GLFW_COCOA)
180
+ " Cocoa NSGL"
181
+ #endif
182
+ #if defined(_GLFW_WAYLAND)
183
+ " Wayland"
184
+ #endif
185
+ #if defined(_GLFW_X11)
186
+ " X11 GLX"
187
+ #endif
188
+ " Null"
189
+ " EGL"
190
+ " OSMesa"
191
+ #if defined(__MINGW64_VERSION_MAJOR)
192
+ " MinGW-w64"
193
+ #elif defined(__MINGW32__)
194
+ " MinGW"
195
+ #elif defined(_MSC_VER)
196
+ " VisualC"
197
+ #endif
198
+ #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG)
199
+ " hybrid-GPU"
200
+ #endif
201
+ #if defined(_POSIX_MONOTONIC_CLOCK)
202
+ " monotonic"
203
+ #endif
204
+ #if defined(_GLFW_BUILD_DLL)
205
+ #if defined(_WIN32)
206
+ " DLL"
207
+ #elif defined(__APPLE__)
208
+ " dynamic"
209
+ #else
210
+ " shared"
211
+ #endif
212
+ #endif
213
+ ;
214
+ }