internal.h 35.7 KB
Newer Older
Camilla Berglund's avatar
Camilla Berglund committed
1
//========================================================================
Camilla Berglund's avatar
Camilla Berglund committed
2
// GLFW 3.3 - www.glfw.org
Camilla Berglund's avatar
Camilla Berglund committed
3
4
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
Camilla Löwy's avatar
Camilla Löwy committed
5
// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org>
Camilla Berglund's avatar
Camilla Berglund committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
//    claim that you wrote the original software. If you use this software
//    in a product, an acknowledgment in the product documentation would
//    be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
//    be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
//    distribution.
//
//========================================================================

28
29
30
#if defined(_GLFW_USE_CONFIG_H)
 #include "glfw_config.h"
#endif
Camilla Berglund's avatar
Camilla Berglund committed
31

32
33
34
35
#if defined(GLFW_INCLUDE_GLCOREARB) || \
    defined(GLFW_INCLUDE_ES1)       || \
    defined(GLFW_INCLUDE_ES2)       || \
    defined(GLFW_INCLUDE_ES3)       || \
Camilla Löwy's avatar
Camilla Löwy committed
36
37
    defined(GLFW_INCLUDE_ES31)      || \
    defined(GLFW_INCLUDE_ES32)      || \
38
39
40
    defined(GLFW_INCLUDE_NONE)      || \
    defined(GLFW_INCLUDE_GLEXT)     || \
    defined(GLFW_INCLUDE_GLU)       || \
41
    defined(GLFW_INCLUDE_VULKAN)    || \
42
    defined(GLFW_DLL)
43
 #error "You must not define any header option macros when compiling GLFW"
44
45
#endif

46
#define GLFW_INCLUDE_NONE
47
#include "../include/GLFW/glfw3.h"
Camilla Berglund's avatar
Camilla Berglund committed
48

49
50
51
#define _GLFW_INSERT_FIRST      0
#define _GLFW_INSERT_LAST       1

52
53
54
#define _GLFW_POLL_PRESENCE     0
#define _GLFW_POLL_AXES         1
#define _GLFW_POLL_BUTTONS      2
55
#define _GLFW_POLL_ALL          (_GLFW_POLL_AXES | _GLFW_POLL_BUTTONS)
56

57
58
#define _GLFW_MESSAGE_SIZE      1024

Camilla Berglund's avatar
Camilla Berglund committed
59
60
typedef int GLFWbool;

61
typedef struct _GLFWerror       _GLFWerror;
Camilla Löwy's avatar
Camilla Löwy committed
62
typedef struct _GLFWinitconfig  _GLFWinitconfig;
Camilla Berglund's avatar
Camilla Berglund committed
63
64
65
66
67
68
69
70
typedef struct _GLFWwndconfig   _GLFWwndconfig;
typedef struct _GLFWctxconfig   _GLFWctxconfig;
typedef struct _GLFWfbconfig    _GLFWfbconfig;
typedef struct _GLFWcontext     _GLFWcontext;
typedef struct _GLFWwindow      _GLFWwindow;
typedef struct _GLFWlibrary     _GLFWlibrary;
typedef struct _GLFWmonitor     _GLFWmonitor;
typedef struct _GLFWcursor      _GLFWcursor;
71
72
typedef struct _GLFWmapelement  _GLFWmapelement;
typedef struct _GLFWmapping     _GLFWmapping;
73
typedef struct _GLFWjoystick    _GLFWjoystick;
Camilla Löwy's avatar
Camilla Löwy committed
74
typedef struct _GLFWtls         _GLFWtls;
75
typedef struct _GLFWmutex       _GLFWmutex;
Camilla Berglund's avatar
Camilla Berglund committed
76

77
78
79
80
81
82
83
typedef void (* _GLFWmakecontextcurrentfun)(_GLFWwindow*);
typedef void (* _GLFWswapbuffersfun)(_GLFWwindow*);
typedef void (* _GLFWswapintervalfun)(int);
typedef int (* _GLFWextensionsupportedfun)(const char*);
typedef GLFWglproc (* _GLFWgetprocaddressfun)(const char*);
typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*);

84
85
86
#define GL_VERSION 0x1f02
#define GL_NONE	0
#define GL_COLOR_BUFFER_BIT	0x00004000
Camilla Berglund's avatar
Camilla Berglund committed
87
#define GL_UNSIGNED_BYTE 0x1401
88
89
90
91
92
93
94
95
96
97
98
99
100
#define GL_EXTENSIONS 0x1f03
#define GL_NUM_EXTENSIONS 0x821d
#define GL_CONTEXT_FLAGS 0x821e
#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x00000001
#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002
#define GL_CONTEXT_PROFILE_MASK 0x9126
#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001
#define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
#define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
#define GL_NO_RESET_NOTIFICATION_ARB 0x8261
#define GL_CONTEXT_RELEASE_BEHAVIOR 0x82fb
#define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82fc
101
#define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008
102
103
104
105
106
107

typedef int	GLint;
typedef unsigned int GLuint;
typedef unsigned int GLenum;
typedef unsigned int GLbitfield;
typedef unsigned char GLubyte;
Camilla Berglund's avatar
Camilla Berglund committed
108

109
110
111
typedef void (APIENTRY * PFNGLCLEARPROC)(GLbitfield);
typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGPROC)(GLenum);
typedef void (APIENTRY * PFNGLGETINTEGERVPROC)(GLenum,GLint*);
112
typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGIPROC)(GLenum,GLuint);
113

Camilla Berglund's avatar
Camilla Berglund committed
114
#define VK_NULL_HANDLE 0
Camilla Berglund's avatar
Camilla Berglund committed
115

116
117
typedef void* VkInstance;
typedef void* VkPhysicalDevice;
118
typedef uint64_t VkSurfaceKHR;
119
120
typedef uint32_t VkFlags;
typedef uint32_t VkBool32;
Camilla Berglund's avatar
Camilla Berglund committed
121
122
123
124
125
126
127
128

typedef enum VkStructureType
{
    VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000,
    VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR = 1000005000,
    VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000,
    VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR = 1000007000,
    VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
129
    VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000053000,
Camilla Berglund's avatar
Camilla Berglund committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
    VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
} VkStructureType;

typedef enum VkResult
{
    VK_SUCCESS = 0,
    VK_NOT_READY = 1,
    VK_TIMEOUT = 2,
    VK_EVENT_SET = 3,
    VK_EVENT_RESET = 4,
    VK_INCOMPLETE = 5,
    VK_ERROR_OUT_OF_HOST_MEMORY = -1,
    VK_ERROR_OUT_OF_DEVICE_MEMORY = -2,
    VK_ERROR_INITIALIZATION_FAILED = -3,
    VK_ERROR_DEVICE_LOST = -4,
    VK_ERROR_MEMORY_MAP_FAILED = -5,
    VK_ERROR_LAYER_NOT_PRESENT = -6,
    VK_ERROR_EXTENSION_NOT_PRESENT = -7,
    VK_ERROR_FEATURE_NOT_PRESENT = -8,
    VK_ERROR_INCOMPATIBLE_DRIVER = -9,
    VK_ERROR_TOO_MANY_OBJECTS = -10,
    VK_ERROR_FORMAT_NOT_SUPPORTED = -11,
    VK_ERROR_SURFACE_LOST_KHR = -1000000000,
    VK_SUBOPTIMAL_KHR = 1000001003,
    VK_ERROR_OUT_OF_DATE_KHR = -1000001004,
    VK_ERROR_INCOMPATIBLE_DISPLAY_KHR = -1000003001,
    VK_ERROR_NATIVE_WINDOW_IN_USE_KHR = -1000000001,
    VK_ERROR_VALIDATION_FAILED_EXT = -1000011001,
    VK_RESULT_MAX_ENUM = 0x7FFFFFFF
} VkResult;

typedef struct VkAllocationCallbacks VkAllocationCallbacks;

typedef struct VkExtensionProperties
{
    char            extensionName[256];
166
    uint32_t        specVersion;
Camilla Berglund's avatar
Camilla Berglund committed
167
168
169
170
} VkExtensionProperties;

typedef void (APIENTRY * PFN_vkVoidFunction)(void);

171
172
173
174
175
176
177
178
179
#if defined(_GLFW_VULKAN_STATIC)
  PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance,const char*);
  VkResult vkEnumerateInstanceExtensionProperties(const char*,uint32_t*,VkExtensionProperties*);
#else
  typedef PFN_vkVoidFunction (APIENTRY * PFN_vkGetInstanceProcAddr)(VkInstance,const char*);
  typedef VkResult (APIENTRY * PFN_vkEnumerateInstanceExtensionProperties)(const char*,uint32_t*,VkExtensionProperties*);
  #define vkEnumerateInstanceExtensionProperties _glfw.vk.EnumerateInstanceExtensionProperties
  #define vkGetInstanceProcAddr _glfw.vk.GetInstanceProcAddr
#endif
180

Camilla Berglund's avatar
Camilla Berglund committed
181
182
183
184
185
186
#if defined(_GLFW_COCOA)
 #include "cocoa_platform.h"
#elif defined(_GLFW_WIN32)
 #include "win32_platform.h"
#elif defined(_GLFW_X11)
 #include "x11_platform.h"
187
#elif defined(_GLFW_WAYLAND)
188
 #include "wl_platform.h"
189
190
#elif defined(_GLFW_MIR)
 #include "mir_platform.h"
Jason Daly's avatar
Jason Daly committed
191
#elif defined(_GLFW_OSMESA)
192
 #include "null_platform.h"
Camilla Berglund's avatar
Camilla Berglund committed
193
194
195
196
197
#else
 #error "No supported window creation API selected"
#endif


198
199
200
201
//========================================================================
// Doxygen group definitions
//========================================================================

Camilla Berglund's avatar
Camilla Berglund committed
202
203
/*! @defgroup platform Platform interface
 *  @brief The interface implemented by the platform-specific code.
204
205
206
207
208
 *
 *  The platform API is the interface exposed by the platform-specific code for
 *  each platform and is called by the shared code of the public API It mirrors
 *  the public API except it uses objects instead of handles.
 */
Camilla Berglund's avatar
Camilla Berglund committed
209
210
/*! @defgroup event Event interface
 *  @brief The interface used by the platform-specific code to report events.
211
212
213
214
215
216
 *
 *  The event API is used by the platform-specific code to notify the shared
 *  code of events that can be translated into state changes and/or callback
 *  calls.
 */
/*! @defgroup utility Utility functions
Camilla Berglund's avatar
Camilla Berglund committed
217
 *  @brief Various utility functions for internal use.
218
219
 *
 *  These functions are shared code and may be used by any part of GLFW
220
 *  Each platform may add its own utility functions, but those must only be
221
222
223
224
 *  called by the platform-specific code
 */


Camilla Berglund's avatar
Camilla Berglund committed
225
//========================================================================
Camilla Berglund's avatar
Camilla Berglund committed
226
// Helper macros
Camilla Berglund's avatar
Camilla Berglund committed
227
228
//========================================================================

229
230
231
232
233
234
235
// Constructs a version number string from the public header macros
#define _GLFW_CONCAT_VERSION(m, n, r) #m "." #n "." #r
#define _GLFW_MAKE_VERSION(m, n, r) _GLFW_CONCAT_VERSION(m, n, r)
#define _GLFW_VERSION_NUMBER _GLFW_MAKE_VERSION(GLFW_VERSION_MAJOR, \
                                                GLFW_VERSION_MINOR, \
                                                GLFW_VERSION_REVISION)

236
// Checks for whether the library has been initialized
237
#define _GLFW_REQUIRE_INIT()                         \
238
    if (!_glfw.initialized)                          \
239
240
241
242
243
    {                                                \
        _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
        return;                                      \
    }
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)              \
244
    if (!_glfw.initialized)                          \
245
246
247
248
249
    {                                                \
        _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
        return x;                                    \
    }

250
251
252
253
254
255
256
257
258
// Swaps the provided pointers
#define _GLFW_SWAP_POINTERS(x, y) \
    {                             \
        void* t;                  \
        t = x;                    \
        x = y;                    \
        y = t;                    \
    }

Camilla Berglund's avatar
Camilla Berglund committed
259

260
//========================================================================
Camilla Berglund's avatar
Camilla Berglund committed
261
// Platform-independent structures
262
263
//========================================================================

264
265
266
267
struct _GLFWerror
{
    _GLFWerror*     next;
    int             code;
268
    char            description[_GLFW_MESSAGE_SIZE];
269
270
};

Camilla Löwy's avatar
Camilla Löwy committed
271
272
273
274
275
276
/*! @brief Initialization configuration.
 *
 *  Parameters relating to the initialization of the library.
 */
struct _GLFWinitconfig
{
Camilla Löwy's avatar
Camilla Löwy committed
277
    GLFWbool      hatButtons;
Camilla Löwy's avatar
Camilla Löwy committed
278
279
280
281
    struct {
        GLFWbool  menubar;
        GLFWbool  chdir;
    } ns;
Camilla Löwy's avatar
Camilla Löwy committed
282
283
284
285
    struct {
        char      className[256];
        char      classClass[256];
    } x11;
Camilla Löwy's avatar
Camilla Löwy committed
286
287
};

288
/*! @brief Window configuration.
289
 *
290
 *  Parameters relating to the creation of the window but not directly related
Camilla Berglund's avatar
Camilla Berglund committed
291
 *  to the framebuffer.  This is used to pass window creation parameters from
292
 *  shared code to the platform API.
293
 */
Camilla Berglund's avatar
Camilla Berglund committed
294
struct _GLFWwndconfig
295
{
296
297
    int           width;
    int           height;
Camilla Berglund's avatar
Camilla Berglund committed
298
    const char*   title;
299
300
301
302
303
304
    GLFWbool      resizable;
    GLFWbool      visible;
    GLFWbool      decorated;
    GLFWbool      focused;
    GLFWbool      autoIconify;
    GLFWbool      floating;
305
    GLFWbool      maximized;
Liam Middlebrook's avatar
Liam Middlebrook committed
306
    GLFWbool      centerCursor;
307
308
    struct {
        GLFWbool  retina;
Camilla Löwy's avatar
Camilla Löwy committed
309
        GLFWbool  frame;
310
    } ns;
311
312
313
314
315
316
317
318
319
320
};

/*! @brief Context configuration.
 *
 *  Parameters relating to the creation of the context but not directly related
 *  to the framebuffer.  This is used to pass context creation parameters from
 *  shared code to the platform API.
 */
struct _GLFWctxconfig
{
321
322
    int           client;
    int           source;
323
324
    int           major;
    int           minor;
325
326
    GLFWbool      forward;
    GLFWbool      debug;
327
    GLFWbool      noerror;
328
329
    int           profile;
    int           robustness;
330
    int           release;
Camilla Berglund's avatar
Camilla Berglund committed
331
    _GLFWwindow*  share;
332
333
334
    struct {
        GLFWbool  offline;
    } nsgl;
Camilla Berglund's avatar
Camilla Berglund committed
335
};
Camilla Berglund's avatar
Camilla Berglund committed
336

337
338
/*! @brief Framebuffer configuration.
 *
339
 *  This describes buffers and their sizes.  It also contains
340
 *  a platform-specific ID used to map back to the backend API object.
341
342
343
 *
 *  It is used to pass framebuffer parameters from shared code to the platform
 *  API and also to enumerate and select available framebuffer configs.
344
 */
Camilla Berglund's avatar
Camilla Berglund committed
345
struct _GLFWfbconfig
346
{
Camilla Berglund's avatar
Camilla Berglund committed
347
348
349
350
351
352
353
354
355
356
357
    int         redBits;
    int         greenBits;
    int         blueBits;
    int         alphaBits;
    int         depthBits;
    int         stencilBits;
    int         accumRedBits;
    int         accumGreenBits;
    int         accumBlueBits;
    int         accumAlphaBits;
    int         auxBuffers;
Camilla Berglund's avatar
Camilla Berglund committed
358
    GLFWbool    stereo;
Camilla Berglund's avatar
Camilla Berglund committed
359
    int         samples;
Camilla Berglund's avatar
Camilla Berglund committed
360
361
    GLFWbool    sRGB;
    GLFWbool    doublebuffer;
Bailey Cosier's avatar
Cleanup    
Bailey Cosier committed
362
    GLFWbool    transparent;
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
363
    uintptr_t   handle;
Camilla Berglund's avatar
Camilla Berglund committed
364
};
Camilla Berglund's avatar
Camilla Berglund committed
365

366
367
368
369
/*! @brief Context structure.
 */
struct _GLFWcontext
{
370
371
    int                 client;
    int                 source;
372
373
374
375
376
377
378
379
380
381
    int                 major, minor, revision;
    GLFWbool            forward, debug, noerror;
    int                 profile;
    int                 robustness;
    int                 release;

    PFNGLGETSTRINGIPROC GetStringi;
    PFNGLGETINTEGERVPROC GetIntegerv;
    PFNGLGETSTRINGPROC  GetString;

Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
382
    _GLFWmakecontextcurrentfun  makeCurrent;
383
384
385
386
    _GLFWswapbuffersfun         swapBuffers;
    _GLFWswapintervalfun        swapInterval;
    _GLFWextensionsupportedfun  extensionSupported;
    _GLFWgetprocaddressfun      getProcAddress;
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
387
    _GLFWdestroycontextfun      destroy;
388

389
390
    // This is defined in the context API's context.h
    _GLFW_PLATFORM_CONTEXT_STATE;
391
392
    // This is defined in egl_context.h
    _GLFW_EGL_CONTEXT_STATE;
Camilla Löwy's avatar
Camilla Löwy committed
393
394
    // This is defined in osmesa_context.h
    _GLFW_OSMESA_CONTEXT_STATE;
395
396
};

397
398
/*! @brief Window and context structure.
 */
Camilla Berglund's avatar
Camilla Berglund committed
399
struct _GLFWwindow
400
{
401
402
    struct _GLFWwindow* next;

403
    // Window settings and state
404
405
406
407
    GLFWbool            resizable;
    GLFWbool            decorated;
    GLFWbool            autoIconify;
    GLFWbool            floating;
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
408
    GLFWbool            shouldClose;
Camilla Berglund's avatar
Camilla Berglund committed
409
    void*               userPointer;
410
    GLFWvidmode         videoMode;
Camilla Berglund's avatar
Camilla Berglund committed
411
    _GLFWmonitor*       monitor;
412
    _GLFWcursor*        cursor;
413

Camilla Berglund's avatar
Camilla Berglund committed
414
415
416
417
    int                 minwidth, minheight;
    int                 maxwidth, maxheight;
    int                 numer, denom;

418
419
    GLFWbool            stickyKeys;
    GLFWbool            stickyMouseButtons;
Camilla Berglund's avatar
Camilla Berglund committed
420
    int                 cursorMode;
421
422
    char                mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
    char                keys[GLFW_KEY_LAST + 1];
423
424
    // Virtual cursor position when cursor is disabled
    double              virtualCursorPosX, virtualCursorPosY;
425

426
    _GLFWcontext        context;
427

428
    struct {
429
430
431
432
433
434
        GLFWwindowposfun        pos;
        GLFWwindowsizefun       size;
        GLFWwindowclosefun      close;
        GLFWwindowrefreshfun    refresh;
        GLFWwindowfocusfun      focus;
        GLFWwindowiconifyfun    iconify;
435
        GLFWwindowmaximizefun   maximize;
436
437
438
439
440
441
442
        GLFWframebuffersizefun  fbsize;
        GLFWmousebuttonfun      mouseButton;
        GLFWcursorposfun        cursorPos;
        GLFWcursorenterfun      cursorEnter;
        GLFWscrollfun           scroll;
        GLFWkeyfun              key;
        GLFWcharfun             character;
443
        GLFWcharmodsfun         charmods;
arturo's avatar
arturo committed
444
        GLFWdropfun             drop;
445
    } callbacks;
446

447
    // This is defined in the window API's platform.h
448
    _GLFW_PLATFORM_WINDOW_STATE;
Camilla Berglund's avatar
Camilla Berglund committed
449
};
450

451
452
/*! @brief Monitor structure.
 */
453
struct _GLFWmonitor
454
{
Camilla Berglund's avatar
Camilla Berglund committed
455
    char*           name;
456

Camilla Berglund's avatar
Camilla Berglund committed
457
458
    // Physical dimensions in millimeters.
    int             widthMM, heightMM;
459

460
461
462
    // The window whose video mode is current on this monitor
    _GLFWwindow*    window;

Camilla Berglund's avatar
Camilla Berglund committed
463
464
    GLFWvidmode*    modes;
    int             modeCount;
465
    GLFWvidmode     currentMode;
466

467
    GLFWgammaramp   originalRamp;
Camilla Berglund's avatar
Camilla Berglund committed
468
    GLFWgammaramp   currentRamp;
469

470
    // This is defined in the window API's platform.h
471
    _GLFW_PLATFORM_MONITOR_STATE;
472
473
};

474
475
476
477
478
479
480
481
482
483
/*! @brief Cursor structure
 */
struct _GLFWcursor
{
    _GLFWcursor*    next;

    // This is defined in the window API's platform.h
    _GLFW_PLATFORM_CURSOR_STATE;
};

484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
/*! @brief Gamepad mapping element structure
 */
struct _GLFWmapelement
{
    uint8_t         type;
    uint8_t         value;
};

/*! @brief Gamepad mapping structure
 */
struct _GLFWmapping
{
    char            name[128];
    char            guid[33];
    _GLFWmapelement buttons[15];
    _GLFWmapelement axes[6];
};

502
503
504
505
506
507
508
509
510
/*! @brief Joystick structure
 */
struct _GLFWjoystick
{
    GLFWbool        present;
    float*          axes;
    int             axisCount;
    unsigned char*  buttons;
    int             buttonCount;
Camilla Löwy's avatar
Camilla Löwy committed
511
512
    unsigned char*  hats;
    int             hatCount;
513
    char*           name;
514
515
    char            guid[33];
    _GLFWmapping*   mapping;
516
517
518
519
520

    // This is defined in the joystick API's joystick.h
    _GLFW_PLATFORM_JOYSTICK_STATE;
};

Camilla Löwy's avatar
Camilla Löwy committed
521
522
523
524
/*! @brief Thread local storage structure.
 */
struct _GLFWtls
{
Camilla Löwy's avatar
Camilla Löwy committed
525
    // This is defined in the platform's thread.h
Camilla Löwy's avatar
Camilla Löwy committed
526
527
528
    _GLFW_PLATFORM_TLS_STATE;
};

529
530
531
532
/*! @brief Mutex structure.
 */
struct _GLFWmutex
{
Camilla Löwy's avatar
Camilla Löwy committed
533
    // This is defined in the platform's thread.h
534
535
536
    _GLFW_PLATFORM_MUTEX_STATE;
};

537
538
/*! @brief Library global data.
 */
Camilla Berglund's avatar
Camilla Berglund committed
539
struct _GLFWlibrary
540
{
541
542
    GLFWbool            initialized;

543
    struct {
Camilla Löwy's avatar
Camilla Löwy committed
544
        _GLFWinitconfig init;
Camilla Berglund's avatar
Camilla Berglund committed
545
546
547
548
        _GLFWfbconfig   framebuffer;
        _GLFWwndconfig  window;
        _GLFWctxconfig  context;
        int             refreshRate;
549
    } hints;
550

551
    _GLFWerror*         errorListHead;
Camilla Berglund's avatar
Camilla Berglund committed
552
553
    _GLFWcursor*        cursorListHead;
    _GLFWwindow*        windowListHead;
Camilla Berglund's avatar
Camilla Berglund committed
554

Camilla Berglund's avatar
Camilla Berglund committed
555
556
    _GLFWmonitor**      monitors;
    int                 monitorCount;
557

558
    _GLFWjoystick       joysticks[GLFW_JOYSTICK_LAST + 1];
559
560
    _GLFWmapping*       mappings;
    int                 mappingCount;
561

562
563
564
    _GLFWtls            errorSlot;
    _GLFWtls            contextSlot;
    _GLFWmutex          errorLock;
Camilla Löwy's avatar
Camilla Löwy committed
565

Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
566
567
568
569
570
571
    struct {
        uint64_t        offset;
        // This is defined in the platform's time.h
        _GLFW_PLATFORM_LIBRARY_TIMER_STATE;
    } timer;

Camilla Berglund's avatar
Camilla Berglund committed
572
573
574
    struct {
        GLFWbool        available;
        void*           handle;
575
        char*           extensions[2];
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
576
577
578
579
#if !defined(_GLFW_VULKAN_STATIC)
        PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties;
        PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
#endif
Camilla Berglund's avatar
Camilla Berglund committed
580
        GLFWbool        KHR_surface;
581
#if defined(_GLFW_WIN32)
Camilla Berglund's avatar
Camilla Berglund committed
582
        GLFWbool        KHR_win32_surface;
583
584
#elif defined(_GLFW_COCOA)
        GLFWbool        MVK_macos_surface;
585
#elif defined(_GLFW_X11)
Camilla Berglund's avatar
Camilla Berglund committed
586
587
        GLFWbool        KHR_xlib_surface;
        GLFWbool        KHR_xcb_surface;
588
#elif defined(_GLFW_WAYLAND)
Camilla Berglund's avatar
Camilla Berglund committed
589
        GLFWbool        KHR_wayland_surface;
590
#elif defined(_GLFW_MIR)
Camilla Berglund's avatar
Camilla Berglund committed
591
        GLFWbool        KHR_mir_surface;
592
#endif
Camilla Berglund's avatar
Camilla Berglund committed
593
594
    } vk;

595
596
    struct {
        GLFWmonitorfun  monitor;
Camilla Berglund's avatar
Camilla Berglund committed
597
        GLFWjoystickfun joystick;
598
    } callbacks;
599

600
    // This is defined in the window API's platform.h
601
    _GLFW_PLATFORM_LIBRARY_WINDOW_STATE;
602
    // This is defined in the context API's context.h
603
    _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE;
604
605
    // This is defined in the platform's joystick.h
    _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE;
606
607
    // This is defined in egl_context.h
    _GLFW_EGL_LIBRARY_CONTEXT_STATE;
Camilla Löwy's avatar
Camilla Löwy committed
608
609
    // This is defined in osmesa_context.h
    _GLFW_OSMESA_LIBRARY_CONTEXT_STATE;
Camilla Berglund's avatar
Camilla Berglund committed
610
};
611
612


613
//========================================================================
Camilla Berglund's avatar
Camilla Berglund committed
614
// Global state shared between compilation units of GLFW
615
616
//========================================================================

617
/*! @brief All global data shared between compilation units.
618
 */
619
extern _GLFWlibrary _glfw;
620

Camilla Berglund's avatar
Camilla Berglund committed
621
622

//========================================================================
623
// Platform API functions
Camilla Berglund's avatar
Camilla Berglund committed
624
625
//========================================================================

626
/*! @addtogroup platform @{ */
627

628
int _glfwPlatformInit(void);
629
void _glfwPlatformTerminate(void);
Camilla Berglund's avatar
Camilla Berglund committed
630
const char* _glfwPlatformGetVersionString(void);
631

632
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos);
633
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos);
634
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
635
636
637
638
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot);
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape);
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor);
Camilla Berglund's avatar
Camilla Berglund committed
639

Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
640
const char* _glfwPlatformGetScancodeName(int scancode);
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
641
int _glfwPlatformGetKeyScancode(int key);
Michael Stocker's avatar
Michael Stocker committed
642

643
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos);
Camilla Löwy's avatar
Camilla Löwy committed
644
void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, float* xscale, float* yscale);
645
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count);
646
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode);
647
648
void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp);
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);
649

650
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string);
Camilla Berglund's avatar
Camilla Berglund committed
651
const char* _glfwPlatformGetClipboardString(_GLFWwindow* window);
Ralph Eastwood's avatar
Ralph Eastwood committed
652

Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
653
int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode);
654
void _glfwPlatformUpdateGamepadGUID(char* guid);
Camilla Berglund's avatar
Camilla Berglund committed
655

656
657
uint64_t _glfwPlatformGetTimerValue(void);
uint64_t _glfwPlatformGetTimerFrequency(void);
Camilla Berglund's avatar
Camilla Berglund committed
658

659
660
int _glfwPlatformCreateWindow(_GLFWwindow* window,
                              const _GLFWwndconfig* wndconfig,
661
                              const _GLFWctxconfig* ctxconfig,
662
                              const _GLFWfbconfig* fbconfig);
663
void _glfwPlatformDestroyWindow(_GLFWwindow* window);
664
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
Camilla Berglund's avatar
Camilla Berglund committed
665
void _glfwPlatformSetWindowIcon(_GLFWwindow* window, int count, const GLFWimage* images);
666
667
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos);
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos);
668
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height);
669
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
670
671
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight);
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom);
672
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height);
673
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, int* left, int* top, int* right, int* bottom);
Camilla Löwy's avatar
Camilla Löwy committed
674
void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, float* xscale, float* yscale);
675
676
void _glfwPlatformIconifyWindow(_GLFWwindow* window);
void _glfwPlatformRestoreWindow(_GLFWwindow* window);
677
void _glfwPlatformMaximizeWindow(_GLFWwindow* window);
678
679
void _glfwPlatformShowWindow(_GLFWwindow* window);
void _glfwPlatformHideWindow(_GLFWwindow* window);
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
680
void _glfwPlatformRequestWindowAttention(_GLFWwindow* window);
Camilla Berglund's avatar
Camilla Berglund committed
681
void _glfwPlatformFocusWindow(_GLFWwindow* window);
Camilla Berglund's avatar
Camilla Berglund committed
682
void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate);
683
684
685
int _glfwPlatformWindowFocused(_GLFWwindow* window);
int _glfwPlatformWindowIconified(_GLFWwindow* window);
int _glfwPlatformWindowVisible(_GLFWwindow* window);
686
int _glfwPlatformWindowMaximized(_GLFWwindow* window);
687
int _glfwPlatformFramebufferTransparent(_GLFWwindow* window);
Camilla Löwy's avatar
Camilla Löwy committed
688
689
690
691
void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled);
void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled);
void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled);

692
693
void _glfwPlatformPollEvents(void);
void _glfwPlatformWaitEvents(void);
Camilla Berglund's avatar
Camilla Berglund committed
694
void _glfwPlatformWaitEventsTimeout(double timeout);
Camilla Berglund's avatar
Camilla Berglund committed
695
696
void _glfwPlatformPostEmptyEvent(void);

697
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions);
698
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
Camilla Berglund's avatar
Camilla Berglund committed
699
700
VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);

Camilla Löwy's avatar
Camilla Löwy committed
701
702
703
704
GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls);
void _glfwPlatformDestroyTls(_GLFWtls* tls);
void* _glfwPlatformGetTls(_GLFWtls* tls);
void _glfwPlatformSetTls(_GLFWtls* tls, void* value);
705
706
707
708
709

GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex);
void _glfwPlatformDestroyMutex(_GLFWmutex* mutex);
void _glfwPlatformLockMutex(_GLFWmutex* mutex);
void _glfwPlatformUnlockMutex(_GLFWmutex* mutex);
Camilla Löwy's avatar
Camilla Löwy committed
710

711
712
/*! @} */

Camilla Berglund's avatar
Camilla Berglund committed
713

Camilla Berglund's avatar
Camilla Berglund committed
714
//========================================================================
715
// Event API functions
Camilla Berglund's avatar
Camilla Berglund committed
716
717
//========================================================================

Camilla Löwy's avatar
Camilla Löwy committed
718
/*! @brief Notifies shared code that a window has lost or received input focus.
719
 *  @param[in] window The window that received the event.
720
 *  @param[in] focused `GLFW_TRUE` if the window received focus, or `GLFW_FALSE`
721
722
723
 *  if it lost focus.
 *  @ingroup event
 */
724
void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused);
725

Camilla Löwy's avatar
Camilla Löwy committed
726
/*! @brief Notifies shared code that a window has moved.
727
 *  @param[in] window The window that received the event.
Camilla Berglund's avatar
Camilla Berglund committed
728
729
 *  @param[in] xpos The new x-coordinate of the client area of the window.
 *  @param[in] ypos The new y-coordinate of the client area of the window.
730
731
 *  @ingroup event
 */
Camilla Berglund's avatar
Camilla Berglund committed
732
void _glfwInputWindowPos(_GLFWwindow* window, int xpos, int ypos);
733

Camilla Löwy's avatar
Camilla Löwy committed
734
/*! @brief Notifies shared code that a window has been resized.
735
736
737
738
739
 *  @param[in] window The window that received the event.
 *  @param[in] width The new width of the client area of the window.
 *  @param[in] height The new height of the client area of the window.
 *  @ingroup event
 */
740
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
741

Camilla Löwy's avatar
Camilla Löwy committed
742
/*! @brief Notifies shared code that a window framebuffer has been resized.
743
744
745
746
747
748
749
 *  @param[in] window The window that received the event.
 *  @param[in] width The new width, in pixels, of the framebuffer.
 *  @param[in] height The new height, in pixels, of the framebuffer.
 *  @ingroup event
 */
void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height);

Camilla Löwy's avatar
Camilla Löwy committed
750
/*! @brief Notifies shared code that a window has been iconified or restored.
751
 *  @param[in] window The window that received the event.
752
753
 *  @param[in] iconified `GLFW_TRUE` if the window was iconified, or
 *  `GLFW_FALSE` if it was restored.
754
755
 *  @ingroup event
 */
Camilla Berglund's avatar
Camilla Berglund committed
756
void _glfwInputWindowIconify(_GLFWwindow* window, GLFWbool iconified);
757

Camilla Löwy's avatar
Camilla Löwy committed
758
/*! @brief Notifies shared code that a window has been maximized or restored.
759
760
761
762
763
764
765
 *  @param[in] window The window that received the event.
 *  @param[in] maximized `GLFW_TRUE` if the window was maximized, or
 *  `GLFW_FALSE` if it was restored.
 *  @ingroup event
 */
void _glfwInputWindowMaximize(_GLFWwindow* window, GLFWbool maximized);

Camilla Löwy's avatar
Camilla Löwy committed
766
/*! @brief Notifies shared code that a window's contents needs updating.
767
768
 *  @param[in] window The window that received the event.
 */
769
void _glfwInputWindowDamage(_GLFWwindow* window);
770

Camilla Löwy's avatar
Camilla Löwy committed
771
/*! @brief Notifies shared code that the user wishes to close a window.
772
773
774
 *  @param[in] window The window that received the event.
 *  @ingroup event
 */
775
void _glfwInputWindowCloseRequest(_GLFWwindow* window);
776

Camilla Löwy's avatar
Camilla Löwy committed
777
778
779
780
781
/*! @brief Notifies shared code that a window has changed its desired monitor.
 *  @param[in] window The window that received the event.
 *  @param[in] monitor The new desired monitor, or `NULL`.
 *  @ingroup event
 */
Camilla Berglund's avatar
Camilla Berglund committed
782
783
void _glfwInputWindowMonitorChange(_GLFWwindow* window, _GLFWmonitor* monitor);

784
785
786
/*! @brief Notifies shared code of a physical key event.
 *  @param[in] window The window that received the event.
 *  @param[in] key The key that was pressed or released.
787
 *  @param[in] scancode The system-specific scan code of the key.
788
 *  @param[in] action @ref GLFW_PRESS or @ref GLFW_RELEASE.
789
 *  @param[in] mods The modifiers pressed when the event was generated.
790
791
 *  @ingroup event
 */
792
void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int mods);
793
794
795

/*! @brief Notifies shared code of a Unicode character input event.
 *  @param[in] window The window that received the event.
796
 *  @param[in] codepoint The Unicode code point of the input character.
797
 *  @param[in] mods Bit field describing which modifier keys were held down.
798
799
 *  @param[in] plain `GLFW_TRUE` if the character is regular text input, or
 *  `GLFW_FALSE` otherwise.
800
801
 *  @ingroup event
 */
Camilla Berglund's avatar
Camilla Berglund committed
802
void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods, GLFWbool plain);
803
804
805

/*! @brief Notifies shared code of a scroll event.
 *  @param[in] window The window that received the event.
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
806
807
 *  @param[in] xoffset The scroll offset along the x-axis.
 *  @param[in] yoffset The scroll offset along the y-axis.
808
809
 *  @ingroup event
 */
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
810
void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset);
811
812
813
814
815

/*! @brief Notifies shared code of a mouse button click event.
 *  @param[in] window The window that received the event.
 *  @param[in] button The button that was pressed or released.
 *  @param[in] action @ref GLFW_PRESS or @ref GLFW_RELEASE.
Camilla Löwy's avatar
Camilla Löwy committed
816
 *  @param[in] mods The modifiers pressed when the event was generated.
817
818
 *  @ingroup event
 */
819
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods);
820
821
822

/*! @brief Notifies shared code of a cursor motion event.
 *  @param[in] window The window that received the event.
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
823
824
825
 *  @param[in] xpos The new x-coordinate of the cursor, relative to the left
 *  edge of the client area of the window.
 *  @param[in] ypos The new y-coordinate of the cursor, relative to the top edge
826
827
828
 *  of the client area of the window.
 *  @ingroup event
 */
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
829
void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos);
830
831
832

/*! @brief Notifies shared code of a cursor enter/leave event.
 *  @param[in] window The window that received the event.
833
834
 *  @param[in] entered `GLFW_TRUE` if the cursor entered the client area of the
 *  window, or `GLFW_FALSE` if it left it.
835
836
 *  @ingroup event
 */
Camilla Berglund's avatar
Camilla Berglund committed
837
void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered);
Camilla Berglund's avatar
Camilla Berglund committed
838

Camilla Löwy's avatar
Camilla Löwy committed
839
840
841
842
843
/*! @brief Notifies shared code of a monitor connection or disconnection.
 *  @param[in] monitor The monitor that was connected or disconnected.
 *  @param[in] action One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`.
 *  @param[in] placement `_GLFW_INSERT_FIRST` or `_GLFW_INSERT_LAST`.
 *  @ingroup event
844
 */
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
845
void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement);
Camilla Berglund's avatar
Camilla Berglund committed
846

Camilla Löwy's avatar
Camilla Löwy committed
847
848
849
850
851
/*! @brief Notifies shared code that a full screen window has acquired or
 *  released a monitor.
 *  @param[in] monitor The monitor that was acquired or released.
 *  @param[in] window The window that acquired the monitor, or `NULL`.
 *  @ingroup event
852
 */
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
853
void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window);
854

855
/*! @brief Notifies shared code of an error.
856
 *  @param[in] code The error code most suitable for the error.
857
 *  @param[in] format The `printf` style format string of the error
858
859
860
 *  description.
 *  @ingroup event
 */
861
#if defined(__GNUC__)
862
void _glfwInputError(int code, const char* format, ...) __attribute__((format(printf, 2, 3)));
863
#else
864
void _glfwInputError(int code, const char* format, ...);
865
#endif
866

Camilla Löwy's avatar
Camilla Löwy committed
867
/*! @brief Notifies shared code of files or directories dropped on a window.
arturo's avatar
arturo committed
868
 *  @param[in] window The window that received the event.
869
870
 *  @param[in] count The number of dropped objects.
 *  @param[in] names The names of the dropped objects.
arturo's avatar
arturo committed
871
872
 *  @ingroup event
 */
873
void _glfwInputDrop(_GLFWwindow* window, int count, const char** names);
arturo's avatar
arturo committed
874

Camilla Löwy's avatar
Camilla Löwy committed
875
/*! @brief Notifies shared code of a joystick connection or disconnection.
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
876
 *  @param[in] js The joystick that was connected or disconnected.
Camilla Berglund's avatar
Camilla Berglund committed
877
878
879
 *  @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`.
 *  @ingroup event
 */
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
880
void _glfwInputJoystick(_GLFWjoystick* js, int event);
881
882

/*! @brief Notifies shared code of the new value of a joystick axis.
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
883
 *  @param[in] js The joystick whose axis to update.
884
885
886
 *  @param[in] axis The index of the axis to update.
 *  @param[in] value The new value of the axis.
 */
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
887
void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value);
888
889

/*! @brief Notifies shared code of the new value of a joystick button.
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
890
 *  @param[in] js The joystick whose button to update.
891
892
893
 *  @param[in] button The index of the button to update.
 *  @param[in] value The new value of the button.
 */
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
894
void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value);
Camilla Berglund's avatar
Camilla Berglund committed
895

Camilla Löwy's avatar
Camilla Löwy committed
896
/*! @brief Notifies shared code of the new value of a joystick hat.
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
897
 *  @param[in] js The joystick whose hat to update.
Camilla Löwy's avatar
Camilla Löwy committed
898
899
900
 *  @param[in] button The index of the hat to update.
 *  @param[in] value The new value of the hat.
 */
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
901
void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value);
Camilla Löwy's avatar
Camilla Löwy committed
902

903
904

//========================================================================
905
// Utility functions
906
907
//========================================================================

Camilla Löwy's avatar
Camilla Löwy committed
908
909
/*! @brief Chooses the video mode most closely matching the desired one.
 *  @ingroup utility
910
 */
911
912
const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor,
                                        const GLFWvidmode* desired);
913
914
915
916

/*! @brief Performs lexical comparison between two @ref GLFWvidmode structures.
 *  @ingroup utility
 */
917
int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second);
918
919
920
921

/*! @brief Splits a color depth into red, green and blue bit depths.
 *  @ingroup utility
 */
922
923
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);

924
925
/*! @brief Searches an extension string for the specified extension.
 *  @param[in] string The extension string to search.
Camilla Berglund's avatar
Camilla Berglund committed
926
 *  @param[in] extensions The extension to search for.
927
 *  @return `GLFW_TRUE` if the extension was found, or `GLFW_FALSE` otherwise.
928
929
 *  @ingroup utility
 */
Camilla Berglund's avatar
Camilla Berglund committed
930
GLFWbool _glfwStringInExtensionString(const char* string, const char* extensions);
931

932
933
934
935
936
937
938
939
940
941
942
943
/*! @brief Chooses the framebuffer config that best matches the desired one.
 *  @param[in] desired The desired framebuffer config.
 *  @param[in] alternatives The framebuffer configs supported by the system.
 *  @param[in] count The number of entries in the alternatives array.
 *  @return The framebuffer config most closely matching the desired one, or @c
 *  NULL if none fulfilled the hard constraints of the desired values.
 *  @ingroup utility
 */
const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
                                         const _GLFWfbconfig* alternatives,
                                         unsigned int count);

944
/*! @brief Retrieves the attributes of the current context.
945
 *  @param[in] ctxconfig The desired context attributes.
946
947
 *  @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if the context is
 *  unusable.
948
949
 *  @ingroup utility
 */
950
GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig);
951

952
/*! @brief Checks whether the desired context attributes are valid.
953
 *  @param[in] ctxconfig The context attributes to check.
954
 *  @return `GLFW_TRUE` if the context attributes are valid, or `GLFW_FALSE`
955
956
957
958
959
960
961
 *  otherwise.
 *  @ingroup utility
 *
 *  This function checks things like whether the specified client API version
 *  exists and whether all relevant options have supported and non-conflicting
 *  values.
 */
962
GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig);
963

Camilla Löwy's avatar
Camilla Löwy committed
964
965
/*! @brief Allocates red, green and blue value arrays of the specified size.
 *  @ingroup utility
Camilla Berglund's avatar
Camilla Berglund committed
966
 */
967
void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size);
Camilla Berglund's avatar
Camilla Berglund committed
968

Camilla Löwy's avatar
Camilla Löwy committed
969
970
/*! @brief Frees the red, green and blue value arrays and clears the struct.
 *  @ingroup utility
Camilla Berglund's avatar
Camilla Berglund committed
971
 */
972
void _glfwFreeGammaArrays(GLFWgammaramp* ramp);
Camilla Berglund's avatar
Camilla Berglund committed
973

974
975
976
977
978
979
980
/*! @brief Allocates and returns a monitor object with the specified name
 *  and dimensions.
 *  @param[in] name The name of the monitor.
 *  @param[in] widthMM The width, in mm, of the monitor's display area.
 *  @param[in] heightMM The height, in mm, of the monitor's display area.
 *  @return The newly created object.
 *  @ingroup utility
981
 */
982
_GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM);
983

984
985
/*! @brief Frees a monitor object and any data associated with it.
 *  @ingroup utility
Camilla Berglund's avatar