internal.h 27.8 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-2019 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
#pragma once

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

34
35
36
37
#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
38
39
    defined(GLFW_INCLUDE_ES31)      || \
    defined(GLFW_INCLUDE_ES32)      || \
40
41
42
    defined(GLFW_INCLUDE_NONE)      || \
    defined(GLFW_INCLUDE_GLEXT)     || \
    defined(GLFW_INCLUDE_GLU)       || \
43
    defined(GLFW_INCLUDE_VULKAN)    || \
44
    defined(GLFW_DLL)
45
 #error "You must not define any header option macros when compiling GLFW"
46
47
#endif

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

51
52
53
#define _GLFW_INSERT_FIRST      0
#define _GLFW_INSERT_LAST       1

54
55
56
#define _GLFW_POLL_PRESENCE     0
#define _GLFW_POLL_AXES         1
#define _GLFW_POLL_BUTTONS      2
57
#define _GLFW_POLL_ALL          (_GLFW_POLL_AXES | _GLFW_POLL_BUTTONS)
58

59
60
#define _GLFW_MESSAGE_SIZE      1024

Camilla Berglund's avatar
Camilla Berglund committed
61
62
typedef int GLFWbool;

63
typedef struct _GLFWerror       _GLFWerror;
Camilla Löwy's avatar
Camilla Löwy committed
64
typedef struct _GLFWinitconfig  _GLFWinitconfig;
Camilla Berglund's avatar
Camilla Berglund committed
65
66
67
68
69
70
71
72
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;
73
74
typedef struct _GLFWmapelement  _GLFWmapelement;
typedef struct _GLFWmapping     _GLFWmapping;
75
typedef struct _GLFWjoystick    _GLFWjoystick;
Camilla Löwy's avatar
Camilla Löwy committed
76
typedef struct _GLFWtls         _GLFWtls;
77
typedef struct _GLFWmutex       _GLFWmutex;
78
typedef struct _GLFWusercontext _GLFWusercontext;
Camilla Berglund's avatar
Camilla Berglund committed
79

80
81
82
83
84
85
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*);
86
87
typedef void (* _GLFWmakeusercontextcurrentfun)(_GLFWusercontext* context);
typedef void (* _GLFWdestroyusercontextfun)(_GLFWusercontext* context);
88

89
#define GL_VERSION 0x1f02
Luflosi's avatar
Luflosi committed
90
91
#define GL_NONE 0
#define GL_COLOR_BUFFER_BIT 0x00004000
Camilla Berglund's avatar
Camilla Berglund committed
92
#define GL_UNSIGNED_BYTE 0x1401
93
94
95
96
97
98
99
100
101
102
103
104
105
#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
106
#define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008
107

Luflosi's avatar
Luflosi committed
108
typedef int GLint;
109
110
111
112
typedef unsigned int GLuint;
typedef unsigned int GLenum;
typedef unsigned int GLbitfield;
typedef unsigned char GLubyte;
Camilla Berglund's avatar
Camilla Berglund committed
113

114
115
116
typedef void (APIENTRY * PFNGLCLEARPROC)(GLbitfield);
typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGPROC)(GLenum);
typedef void (APIENTRY * PFNGLGETINTEGERVPROC)(GLenum,GLint*);
117
typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGIPROC)(GLenum,GLuint);
118

Camilla Berglund's avatar
Camilla Berglund committed
119
#define VK_NULL_HANDLE 0
Camilla Berglund's avatar
Camilla Berglund committed
120

121
122
typedef void* VkInstance;
typedef void* VkPhysicalDevice;
123
typedef uint64_t VkSurfaceKHR;
124
125
typedef uint32_t VkFlags;
typedef uint32_t VkBool32;
Camilla Berglund's avatar
Camilla Berglund committed
126
127
128
129
130
131
132

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_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
133
    VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000,
134
    VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT = 1000217000,
Camilla Berglund's avatar
Camilla Berglund committed
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
166
167
168
169
170
    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];
171
    uint32_t        specVersion;
Camilla Berglund's avatar
Camilla Berglund committed
172
173
174
175
} VkExtensionProperties;

typedef void (APIENTRY * PFN_vkVoidFunction)(void);

176
177
178
179
180
181
182
183
184
#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
185

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

200
201
202
203
204
205
206
// 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)

207
// Checks for whether the library has been initialized
208
#define _GLFW_REQUIRE_INIT()                         \
209
    if (!_glfw.initialized)                          \
210
211
212
213
214
    {                                                \
        _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
        return;                                      \
    }
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)              \
215
    if (!_glfw.initialized)                          \
216
217
218
219
220
    {                                                \
        _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
        return x;                                    \
    }

221
222
223
224
225
226
227
228
229
// Swaps the provided pointers
#define _GLFW_SWAP_POINTERS(x, y) \
    {                             \
        void* t;                  \
        t = x;                    \
        x = y;                    \
        y = t;                    \
    }

230
231
// Per-thread error structure
//
232
233
234
235
struct _GLFWerror
{
    _GLFWerror*     next;
    int             code;
236
    char            description[_GLFW_MESSAGE_SIZE];
237
238
};

239
240
241
242
// Initialization configuration
//
// Parameters relating to the initialization of the library
//
Camilla Löwy's avatar
Camilla Löwy committed
243
244
struct _GLFWinitconfig
{
Camilla Löwy's avatar
Camilla Löwy committed
245
    GLFWbool      hatButtons;
Camilla Löwy's avatar
Camilla Löwy committed
246
247
248
249
250
251
    struct {
        GLFWbool  menubar;
        GLFWbool  chdir;
    } ns;
};

252
253
254
255
256
257
// Window configuration
//
// Parameters relating to the creation of the window but not directly related
// to the framebuffer.  This is used to pass window creation parameters from
// shared code to the platform API.
//
Camilla Berglund's avatar
Camilla Berglund committed
258
struct _GLFWwndconfig
259
{
260
261
    int           width;
    int           height;
Camilla Berglund's avatar
Camilla Berglund committed
262
    const char*   title;
263
264
265
266
267
268
    GLFWbool      resizable;
    GLFWbool      visible;
    GLFWbool      decorated;
    GLFWbool      focused;
    GLFWbool      autoIconify;
    GLFWbool      floating;
269
    GLFWbool      maximized;
Liam Middlebrook's avatar
Liam Middlebrook committed
270
    GLFWbool      centerCursor;
271
    GLFWbool      focusOnShow;
Camilla Löwy's avatar
Camilla Löwy committed
272
    GLFWbool      scaleToMonitor;
273
274
    struct {
        GLFWbool  retina;
275
        char      frameName[256];
276
    } ns;
277
278
279
280
    struct {
        char      className[256];
        char      instanceName[256];
    } x11;
281
282
};

283
284
285
286
287
288
// 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.
//
289
290
struct _GLFWctxconfig
{
291
292
    int           client;
    int           source;
293
294
    int           major;
    int           minor;
295
296
    GLFWbool      forward;
    GLFWbool      debug;
297
    GLFWbool      noerror;
298
299
    int           profile;
    int           robustness;
300
    int           release;
Camilla Berglund's avatar
Camilla Berglund committed
301
    _GLFWwindow*  share;
302
303
304
    struct {
        GLFWbool  offline;
    } nsgl;
Camilla Berglund's avatar
Camilla Berglund committed
305
};
Camilla Berglund's avatar
Camilla Berglund committed
306

307
308
309
310
311
312
313
314
// Framebuffer configuration
//
// This describes buffers and their sizes.  It also contains
// a platform-specific ID used to map back to the backend API object.
//
// It is used to pass framebuffer parameters from shared code to the platform
// API and also to enumerate and select available framebuffer configs.
//
Camilla Berglund's avatar
Camilla Berglund committed
315
struct _GLFWfbconfig
316
{
Camilla Berglund's avatar
Camilla Berglund committed
317
318
319
320
321
322
323
324
325
326
327
    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
328
    GLFWbool    stereo;
Camilla Berglund's avatar
Camilla Berglund committed
329
    int         samples;
Camilla Berglund's avatar
Camilla Berglund committed
330
331
    GLFWbool    sRGB;
    GLFWbool    doublebuffer;
Bailey Cosier's avatar
Cleanup    
Bailey Cosier committed
332
    GLFWbool    transparent;
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
333
    uintptr_t   handle;
Camilla Berglund's avatar
Camilla Berglund committed
334
};
Camilla Berglund's avatar
Camilla Berglund committed
335

336
337
// Context structure
//
338
339
struct _GLFWcontext
{
340
341
    int                 client;
    int                 source;
342
343
344
345
346
347
348
349
350
351
    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
352
    _GLFWmakecontextcurrentfun  makeCurrent;
353
354
355
356
    _GLFWswapbuffersfun         swapBuffers;
    _GLFWswapintervalfun        swapInterval;
    _GLFWextensionsupportedfun  extensionSupported;
    _GLFWgetprocaddressfun      getProcAddress;
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
357
    _GLFWdestroycontextfun      destroy;
358

359
360
    // This is defined in the context API's context.h
    _GLFW_PLATFORM_CONTEXT_STATE;
361
362
    // This is defined in egl_context.h
    _GLFW_EGL_CONTEXT_STATE;
Camilla Löwy's avatar
Camilla Löwy committed
363
364
    // This is defined in osmesa_context.h
    _GLFW_OSMESA_CONTEXT_STATE;
365
366
};

367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384

// User Context structure
//
struct _GLFWusercontext
{
    _GLFWwindow* window;

    // This is defined in the context API's context.h
    _GLFW_PLATFORM_USER_CONTEXT_STATE;
    // This is defined in egl_context.h
    _GLFWusercontextEGL egl;
    // This is defined in osmesa_context.h
    _GLFWusercontextOSMesa osmesa;

    _GLFWmakeusercontextcurrentfun makeCurrent;
    _GLFWdestroyusercontextfun destroy;
};

385
386
// Window and context structure
//
Camilla Berglund's avatar
Camilla Berglund committed
387
struct _GLFWwindow
388
{
389
390
    struct _GLFWwindow* next;

391
    // Window settings and state
392
393
394
395
    GLFWbool            resizable;
    GLFWbool            decorated;
    GLFWbool            autoIconify;
    GLFWbool            floating;
396
    GLFWbool            focusOnShow;
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
397
    GLFWbool            shouldClose;
Camilla Berglund's avatar
Camilla Berglund committed
398
    void*               userPointer;
399
    GLFWvidmode         videoMode;
Camilla Berglund's avatar
Camilla Berglund committed
400
    _GLFWmonitor*       monitor;
401
    _GLFWcursor*        cursor;
402

Camilla Berglund's avatar
Camilla Berglund committed
403
404
405
406
    int                 minwidth, minheight;
    int                 maxwidth, maxheight;
    int                 numer, denom;

407
408
    GLFWbool            stickyKeys;
    GLFWbool            stickyMouseButtons;
409
    GLFWbool            lockKeyMods;
Camilla Berglund's avatar
Camilla Berglund committed
410
    int                 cursorMode;
411
412
    char                mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
    char                keys[GLFW_KEY_LAST + 1];
413
414
    // Virtual cursor position when cursor is disabled
    double              virtualCursorPosX, virtualCursorPosY;
415
    GLFWbool            rawMouseMotion;
416

417
    _GLFWcontext        context;
418

419
    struct {
420
421
422
423
424
425
        GLFWwindowposfun        pos;
        GLFWwindowsizefun       size;
        GLFWwindowclosefun      close;
        GLFWwindowrefreshfun    refresh;
        GLFWwindowfocusfun      focus;
        GLFWwindowiconifyfun    iconify;
426
        GLFWwindowmaximizefun   maximize;
427
        GLFWframebuffersizefun  fbsize;
428
        GLFWwindowcontentscalefun scale;
429
430
431
432
433
434
        GLFWmousebuttonfun      mouseButton;
        GLFWcursorposfun        cursorPos;
        GLFWcursorenterfun      cursorEnter;
        GLFWscrollfun           scroll;
        GLFWkeyfun              key;
        GLFWcharfun             character;
435
        GLFWcharmodsfun         charmods;
arturo's avatar
arturo committed
436
        GLFWdropfun             drop;
437
    } callbacks;
438

439
    // This is defined in the window API's platform.h
440
    _GLFW_PLATFORM_WINDOW_STATE;
Camilla Berglund's avatar
Camilla Berglund committed
441
};
442

443
444
// Monitor structure
//
445
struct _GLFWmonitor
446
{
Camilla Berglund's avatar
Camilla Berglund committed
447
    char*           name;
448
    void*           userPointer;
449

Camilla Berglund's avatar
Camilla Berglund committed
450
451
    // Physical dimensions in millimeters.
    int             widthMM, heightMM;
452

453
454
455
    // The window whose video mode is current on this monitor
    _GLFWwindow*    window;

Camilla Berglund's avatar
Camilla Berglund committed
456
457
    GLFWvidmode*    modes;
    int             modeCount;
458
    GLFWvidmode     currentMode;
459

460
    GLFWgammaramp   originalRamp;
Camilla Berglund's avatar
Camilla Berglund committed
461
    GLFWgammaramp   currentRamp;
462

463
    // This is defined in the window API's platform.h
464
    _GLFW_PLATFORM_MONITOR_STATE;
465
466
};

467
468
// Cursor structure
//
469
470
471
472
473
474
475
476
struct _GLFWcursor
{
    _GLFWcursor*    next;

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

477
478
// Gamepad mapping element structure
//
479
480
481
struct _GLFWmapelement
{
    uint8_t         type;
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
482
    uint8_t         index;
483
484
    int8_t          axisScale;
    int8_t          axisOffset;
485
486
};

487
488
// Gamepad mapping structure
//
489
490
491
492
493
494
495
496
struct _GLFWmapping
{
    char            name[128];
    char            guid[33];
    _GLFWmapelement buttons[15];
    _GLFWmapelement axes[6];
};

497
498
// Joystick structure
//
499
500
501
502
503
504
505
struct _GLFWjoystick
{
    GLFWbool        present;
    float*          axes;
    int             axisCount;
    unsigned char*  buttons;
    int             buttonCount;
Camilla Löwy's avatar
Camilla Löwy committed
506
507
    unsigned char*  hats;
    int             hatCount;
508
    char*           name;
509
    void*           userPointer;
510
511
    char            guid[33];
    _GLFWmapping*   mapping;
512
513
514
515
516

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

517
518
// Thread local storage structure
//
Camilla Löwy's avatar
Camilla Löwy committed
519
520
struct _GLFWtls
{
Camilla Löwy's avatar
Camilla Löwy committed
521
    // This is defined in the platform's thread.h
Camilla Löwy's avatar
Camilla Löwy committed
522
523
524
    _GLFW_PLATFORM_TLS_STATE;
};

525
526
// Mutex structure
//
527
528
struct _GLFWmutex
{
Camilla Löwy's avatar
Camilla Löwy committed
529
    // This is defined in the platform's thread.h
530
531
532
    _GLFW_PLATFORM_MUTEX_STATE;
};

533
534
// Library global data
//
Camilla Berglund's avatar
Camilla Berglund committed
535
struct _GLFWlibrary
536
{
537
538
    GLFWbool            initialized;

539
    struct {
Camilla Löwy's avatar
Camilla Löwy committed
540
        _GLFWinitconfig init;
Camilla Berglund's avatar
Camilla Berglund committed
541
542
543
544
        _GLFWfbconfig   framebuffer;
        _GLFWwndconfig  window;
        _GLFWctxconfig  context;
        int             refreshRate;
545
    } hints;
546

547
    _GLFWerror*         errorListHead;
Camilla Berglund's avatar
Camilla Berglund committed
548
549
    _GLFWcursor*        cursorListHead;
    _GLFWwindow*        windowListHead;
Camilla Berglund's avatar
Camilla Berglund committed
550

Camilla Berglund's avatar
Camilla Berglund committed
551
552
    _GLFWmonitor**      monitors;
    int                 monitorCount;
553

554
    _GLFWjoystick       joysticks[GLFW_JOYSTICK_LAST + 1];
555
556
    _GLFWmapping*       mappings;
    int                 mappingCount;
557

558
559
560
    _GLFWtls            errorSlot;
    _GLFWtls            contextSlot;
    _GLFWmutex          errorLock;
Camilla Löwy's avatar
Camilla Löwy committed
561

Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
562
563
564
565
566
567
    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
568
569
570
    struct {
        GLFWbool        available;
        void*           handle;
571
        char*           extensions[2];
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
572
573
574
575
#if !defined(_GLFW_VULKAN_STATIC)
        PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties;
        PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
#endif
Camilla Berglund's avatar
Camilla Berglund committed
576
        GLFWbool        KHR_surface;
577
#if defined(_GLFW_WIN32)
Camilla Berglund's avatar
Camilla Berglund committed
578
        GLFWbool        KHR_win32_surface;
579
580
#elif defined(_GLFW_COCOA)
        GLFWbool        MVK_macos_surface;
581
        GLFWbool        EXT_metal_surface;
582
#elif defined(_GLFW_X11)
Camilla Berglund's avatar
Camilla Berglund committed
583
584
        GLFWbool        KHR_xlib_surface;
        GLFWbool        KHR_xcb_surface;
585
#elif defined(_GLFW_WAYLAND)
Camilla Berglund's avatar
Camilla Berglund committed
586
        GLFWbool        KHR_wayland_surface;
587
#endif
Camilla Berglund's avatar
Camilla Berglund committed
588
589
    } vk;

590
591
    struct {
        GLFWmonitorfun  monitor;
Camilla Berglund's avatar
Camilla Berglund committed
592
        GLFWjoystickfun joystick;
593
    } callbacks;
594

595
    // This is defined in the window API's platform.h
596
    _GLFW_PLATFORM_LIBRARY_WINDOW_STATE;
597
    // This is defined in the context API's context.h
598
    _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE;
599
600
    // This is defined in the platform's joystick.h
    _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE;
601
602
    // This is defined in egl_context.h
    _GLFW_EGL_LIBRARY_CONTEXT_STATE;
Camilla Löwy's avatar
Camilla Löwy committed
603
604
    // This is defined in osmesa_context.h
    _GLFW_OSMESA_LIBRARY_CONTEXT_STATE;
Camilla Berglund's avatar
Camilla Berglund committed
605
};
606

Camilla Berglund's avatar
Camilla Berglund committed
607
// Global state shared between compilation units of GLFW
608
//
609
extern _GLFWlibrary _glfw;
610

Camilla Berglund's avatar
Camilla Berglund committed
611

612
613
614
//////////////////////////////////////////////////////////////////////////
//////                       GLFW platform API                      //////
//////////////////////////////////////////////////////////////////////////
615

616
int _glfwPlatformInit(void);
617
void _glfwPlatformTerminate(void);
Camilla Berglund's avatar
Camilla Berglund committed
618
const char* _glfwPlatformGetVersionString(void);
619

620
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos);
621
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos);
622
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
623
624
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled);
GLFWbool _glfwPlatformRawMouseMotionSupported(void);
Camilla Löwy's avatar
Camilla Löwy committed
625
626
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
                              const GLFWimage* image, int xhot, int yhot);
627
628
629
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape);
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor);
Camilla Berglund's avatar
Camilla Berglund committed
630

Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
631
const char* _glfwPlatformGetScancodeName(int scancode);
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
632
int _glfwPlatformGetKeyScancode(int key);
Michael Stocker's avatar
Michael Stocker committed
633

634
void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor);
635
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos);
Camilla Löwy's avatar
Camilla Löwy committed
636
637
void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor,
                                         float* xscale, float* yscale);
638
void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, int* xpos, int* ypos, int *width, int *height);
639
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count);
640
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode);
641
GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp);
642
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);
643

644
645
void _glfwPlatformSetClipboardString(const char* string);
const char* _glfwPlatformGetClipboardString(void);
Ralph Eastwood's avatar
Ralph Eastwood committed
646

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

650
651
uint64_t _glfwPlatformGetTimerValue(void);
uint64_t _glfwPlatformGetTimerFrequency(void);
Camilla Berglund's avatar
Camilla Berglund committed
652

653
654
int _glfwPlatformCreateWindow(_GLFWwindow* window,
                              const _GLFWwndconfig* wndconfig,
655
                              const _GLFWctxconfig* ctxconfig,
656
                              const _GLFWfbconfig* fbconfig);
657
void _glfwPlatformDestroyWindow(_GLFWwindow* window);
658
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
Camilla Löwy's avatar
Camilla Löwy committed
659
660
void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
                                int count, const GLFWimage* images);
661
662
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos);
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos);
663
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height);
664
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
Camilla Löwy's avatar
Camilla Löwy committed
665
666
667
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
                                      int minwidth, int minheight,
                                      int maxwidth, int maxheight);
668
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom);
669
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height);
Camilla Löwy's avatar
Camilla Löwy committed
670
671
672
673
674
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
                                     int* left, int* top,
                                     int* right, int* bottom);
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 Löwy's avatar
Camilla Löwy committed
682
683
684
void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor,
                                   int xpos, int ypos, int width, int height,
                                   int refreshRate);
685
686
687
int _glfwPlatformWindowFocused(_GLFWwindow* window);
int _glfwPlatformWindowIconified(_GLFWwindow* window);
int _glfwPlatformWindowVisible(_GLFWwindow* window);
688
int _glfwPlatformWindowMaximized(_GLFWwindow* window);
689
int _glfwPlatformWindowHovered(_GLFWwindow* window);
690
int _glfwPlatformFramebufferTransparent(_GLFWwindow* window);
691
float _glfwPlatformGetWindowOpacity(_GLFWwindow* window);
Camilla Löwy's avatar
Camilla Löwy committed
692
693
694
void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled);
void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled);
void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled);
695
void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity);
Camilla Löwy's avatar
Camilla Löwy committed
696

697
698
void _glfwPlatformPollEvents(void);
void _glfwPlatformWaitEvents(void);
Camilla Berglund's avatar
Camilla Berglund committed
699
void _glfwPlatformWaitEventsTimeout(double timeout);
Camilla Berglund's avatar
Camilla Berglund committed
700
701
void _glfwPlatformPostEmptyEvent(void);

702
703
704
_GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window);


705
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions);
Camilla Löwy's avatar
Camilla Löwy committed
706
707
708
709
710
711
712
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
                                                      VkPhysicalDevice device,
                                                      uint32_t queuefamily);
VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
                                          _GLFWwindow* window,
                                          const VkAllocationCallbacks* allocator,
                                          VkSurfaceKHR* surface);
Camilla Berglund's avatar
Camilla Berglund committed
713

Camilla Löwy's avatar
Camilla Löwy committed
714
715
716
717
GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls);
void _glfwPlatformDestroyTls(_GLFWtls* tls);
void* _glfwPlatformGetTls(_GLFWtls* tls);
void _glfwPlatformSetTls(_GLFWtls* tls, void* value);
718
719
720
721
722

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
723

724

725
726
727
//////////////////////////////////////////////////////////////////////////
//////                         GLFW event API                       //////
//////////////////////////////////////////////////////////////////////////
Camilla Berglund's avatar
Camilla Berglund committed
728

729
void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused);
Camilla Berglund's avatar
Camilla Berglund committed
730
void _glfwInputWindowPos(_GLFWwindow* window, int xpos, int ypos);
731
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
732
void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height);
Camilla Löwy's avatar
Camilla Löwy committed
733
734
void _glfwInputWindowContentScale(_GLFWwindow* window,
                                  float xscale, float yscale);
Camilla Berglund's avatar
Camilla Berglund committed
735
void _glfwInputWindowIconify(_GLFWwindow* window, GLFWbool iconified);
736
void _glfwInputWindowMaximize(_GLFWwindow* window, GLFWbool maximized);
737
void _glfwInputWindowDamage(_GLFWwindow* window);
738
void _glfwInputWindowCloseRequest(_GLFWwindow* window);
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
739
void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor);
Camilla Berglund's avatar
Camilla Berglund committed
740

Camilla Löwy's avatar
Camilla Löwy committed
741
742
743
744
void _glfwInputKey(_GLFWwindow* window,
                   int key, int scancode, int action, int mods);
void _glfwInputChar(_GLFWwindow* window,
                    unsigned int codepoint, int mods, GLFWbool plain);
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
745
void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset);
746
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods);
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
747
void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos);
Camilla Berglund's avatar
Camilla Berglund committed
748
void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered);
749
750
751
752
753
void _glfwInputDrop(_GLFWwindow* window, int count, const char** names);
void _glfwInputJoystick(_GLFWjoystick* js, int event);
void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value);
void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value);
void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value);
Camilla Berglund's avatar
Camilla Berglund committed
754

Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
755
756
void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement);
void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window);
757

758
#if defined(__GNUC__)
Camilla Löwy's avatar
Camilla Löwy committed
759
760
void _glfwInputError(int code, const char* format, ...)
    __attribute__((format(printf, 2, 3)));
761
#else
762
void _glfwInputError(int code, const char* format, ...);
763
#endif
764

765

766
767
768
//////////////////////////////////////////////////////////////////////////
//////                       GLFW internal API                      //////
//////////////////////////////////////////////////////////////////////////
769

Camilla Berglund's avatar
Camilla Berglund committed
770
GLFWbool _glfwStringInExtensionString(const char* string, const char* extensions);
771
772
773
const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
                                         const _GLFWfbconfig* alternatives,
                                         unsigned int count);
774
775
GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window,
                                    const _GLFWctxconfig* ctxconfig);
776
GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig);
777

778
779
780
const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor,
                                        const GLFWvidmode* desired);
int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second);
781
782
_GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM);
void _glfwFreeMonitor(_GLFWmonitor* monitor);
783
784
785
void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size);
void _glfwFreeGammaArrays(GLFWgammaramp* ramp);
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
786

787
788
789
790
791
_GLFWjoystick* _glfwAllocJoystick(const char* name,
                                  const char* guid,
                                  int axisCount,
                                  int buttonCount,
                                  int hatCount);
792
void _glfwFreeJoystick(_GLFWjoystick* js);
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
793
void _glfwCenterCursorInContentArea(_GLFWwindow* window);
794

795
GLFWbool _glfwInitVulkan(int mode);
Camilla Berglund's avatar
Camilla Berglund committed
796
797
798
void _glfwTerminateVulkan(void);
const char* _glfwGetVulkanResultString(VkResult result);

799
char* _glfw_strdup(const char* source);
800
801
float _glfw_fminf(float a, float b);
float _glfw_fmaxf(float a, float b);
802