medfall

A super great game engine
Log | Files | Refs

internal.h (36240B)


      1 //========================================================================
      2 // GLFW 3.3 - www.glfw.org
      3 //------------------------------------------------------------------------
      4 // Copyright (c) 2002-2006 Marcus Geelnard
      5 // Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org>
      6 //
      7 // This software is provided 'as-is', without any express or implied
      8 // warranty. In no event will the authors be held liable for any damages
      9 // arising from the use of this software.
     10 //
     11 // Permission is granted to anyone to use this software for any purpose,
     12 // including commercial applications, and to alter it and redistribute it
     13 // freely, subject to the following restrictions:
     14 //
     15 // 1. The origin of this software must not be misrepresented; you must not
     16 //    claim that you wrote the original software. If you use this software
     17 //    in a product, an acknowledgment in the product documentation would
     18 //    be appreciated but is not required.
     19 //
     20 // 2. Altered source versions must be plainly marked as such, and must not
     21 //    be misrepresented as being the original software.
     22 //
     23 // 3. This notice may not be removed or altered from any source
     24 //    distribution.
     25 //
     26 //========================================================================
     27 
     28 #if defined(_GLFW_USE_CONFIG_H)
     29  #include "glfw_config.h"
     30 #endif
     31 
     32 #if defined(GLFW_INCLUDE_GLCOREARB) || \
     33     defined(GLFW_INCLUDE_ES1)       || \
     34     defined(GLFW_INCLUDE_ES2)       || \
     35     defined(GLFW_INCLUDE_ES3)       || \
     36     defined(GLFW_INCLUDE_ES31)      || \
     37     defined(GLFW_INCLUDE_ES32)      || \
     38     defined(GLFW_INCLUDE_NONE)      || \
     39     defined(GLFW_INCLUDE_GLEXT)     || \
     40     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 #endif
     45 
     46 #define GLFW_INCLUDE_NONE
     47 #include "../include/GLFW/glfw3.h"
     48 
     49 #define _GLFW_INSERT_FIRST      0
     50 #define _GLFW_INSERT_LAST       1
     51 
     52 #define _GLFW_POLL_PRESENCE     0
     53 #define _GLFW_POLL_AXES         1
     54 #define _GLFW_POLL_BUTTONS      2
     55 #define _GLFW_POLL_ALL          (_GLFW_POLL_AXES | _GLFW_POLL_BUTTONS)
     56 
     57 #define _GLFW_MESSAGE_SIZE      1024
     58 
     59 typedef int GLFWbool;
     60 
     61 typedef struct _GLFWerror       _GLFWerror;
     62 typedef struct _GLFWinitconfig  _GLFWinitconfig;
     63 typedef struct _GLFWwndconfig   _GLFWwndconfig;
     64 typedef struct _GLFWctxconfig   _GLFWctxconfig;
     65 typedef struct _GLFWfbconfig    _GLFWfbconfig;
     66 typedef struct _GLFWcontext     _GLFWcontext;
     67 typedef struct _GLFWwindow      _GLFWwindow;
     68 typedef struct _GLFWlibrary     _GLFWlibrary;
     69 typedef struct _GLFWmonitor     _GLFWmonitor;
     70 typedef struct _GLFWcursor      _GLFWcursor;
     71 typedef struct _GLFWmapelement  _GLFWmapelement;
     72 typedef struct _GLFWmapping     _GLFWmapping;
     73 typedef struct _GLFWjoystick    _GLFWjoystick;
     74 typedef struct _GLFWtls         _GLFWtls;
     75 typedef struct _GLFWmutex       _GLFWmutex;
     76 
     77 typedef void (* _GLFWmakecontextcurrentfun)(_GLFWwindow*);
     78 typedef void (* _GLFWswapbuffersfun)(_GLFWwindow*);
     79 typedef void (* _GLFWswapintervalfun)(int);
     80 typedef int (* _GLFWextensionsupportedfun)(const char*);
     81 typedef GLFWglproc (* _GLFWgetprocaddressfun)(const char*);
     82 typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*);
     83 
     84 #define GL_VERSION 0x1f02
     85 #define GL_NONE	0
     86 #define GL_COLOR_BUFFER_BIT	0x00004000
     87 #define GL_UNSIGNED_BYTE 0x1401
     88 #define GL_EXTENSIONS 0x1f03
     89 #define GL_NUM_EXTENSIONS 0x821d
     90 #define GL_CONTEXT_FLAGS 0x821e
     91 #define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x00000001
     92 #define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002
     93 #define GL_CONTEXT_PROFILE_MASK 0x9126
     94 #define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
     95 #define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001
     96 #define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
     97 #define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
     98 #define GL_NO_RESET_NOTIFICATION_ARB 0x8261
     99 #define GL_CONTEXT_RELEASE_BEHAVIOR 0x82fb
    100 #define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82fc
    101 #define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008
    102 
    103 typedef int	GLint;
    104 typedef unsigned int GLuint;
    105 typedef unsigned int GLenum;
    106 typedef unsigned int GLbitfield;
    107 typedef unsigned char GLubyte;
    108 
    109 typedef void (APIENTRY * PFNGLCLEARPROC)(GLbitfield);
    110 typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGPROC)(GLenum);
    111 typedef void (APIENTRY * PFNGLGETINTEGERVPROC)(GLenum,GLint*);
    112 typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGIPROC)(GLenum,GLuint);
    113 
    114 #define VK_NULL_HANDLE 0
    115 
    116 typedef void* VkInstance;
    117 typedef void* VkPhysicalDevice;
    118 typedef uint64_t VkSurfaceKHR;
    119 typedef uint32_t VkFlags;
    120 typedef uint32_t VkBool32;
    121 
    122 typedef enum VkStructureType
    123 {
    124     VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000,
    125     VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR = 1000005000,
    126     VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000,
    127     VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR = 1000007000,
    128     VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
    129     VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000053000,
    130     VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
    131 } VkStructureType;
    132 
    133 typedef enum VkResult
    134 {
    135     VK_SUCCESS = 0,
    136     VK_NOT_READY = 1,
    137     VK_TIMEOUT = 2,
    138     VK_EVENT_SET = 3,
    139     VK_EVENT_RESET = 4,
    140     VK_INCOMPLETE = 5,
    141     VK_ERROR_OUT_OF_HOST_MEMORY = -1,
    142     VK_ERROR_OUT_OF_DEVICE_MEMORY = -2,
    143     VK_ERROR_INITIALIZATION_FAILED = -3,
    144     VK_ERROR_DEVICE_LOST = -4,
    145     VK_ERROR_MEMORY_MAP_FAILED = -5,
    146     VK_ERROR_LAYER_NOT_PRESENT = -6,
    147     VK_ERROR_EXTENSION_NOT_PRESENT = -7,
    148     VK_ERROR_FEATURE_NOT_PRESENT = -8,
    149     VK_ERROR_INCOMPATIBLE_DRIVER = -9,
    150     VK_ERROR_TOO_MANY_OBJECTS = -10,
    151     VK_ERROR_FORMAT_NOT_SUPPORTED = -11,
    152     VK_ERROR_SURFACE_LOST_KHR = -1000000000,
    153     VK_SUBOPTIMAL_KHR = 1000001003,
    154     VK_ERROR_OUT_OF_DATE_KHR = -1000001004,
    155     VK_ERROR_INCOMPATIBLE_DISPLAY_KHR = -1000003001,
    156     VK_ERROR_NATIVE_WINDOW_IN_USE_KHR = -1000000001,
    157     VK_ERROR_VALIDATION_FAILED_EXT = -1000011001,
    158     VK_RESULT_MAX_ENUM = 0x7FFFFFFF
    159 } VkResult;
    160 
    161 typedef struct VkAllocationCallbacks VkAllocationCallbacks;
    162 
    163 typedef struct VkExtensionProperties
    164 {
    165     char            extensionName[256];
    166     uint32_t        specVersion;
    167 } VkExtensionProperties;
    168 
    169 typedef void (APIENTRY * PFN_vkVoidFunction)(void);
    170 
    171 #if defined(_GLFW_VULKAN_STATIC)
    172   PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance,const char*);
    173   VkResult vkEnumerateInstanceExtensionProperties(const char*,uint32_t*,VkExtensionProperties*);
    174 #else
    175   typedef PFN_vkVoidFunction (APIENTRY * PFN_vkGetInstanceProcAddr)(VkInstance,const char*);
    176   typedef VkResult (APIENTRY * PFN_vkEnumerateInstanceExtensionProperties)(const char*,uint32_t*,VkExtensionProperties*);
    177   #define vkEnumerateInstanceExtensionProperties _glfw.vk.EnumerateInstanceExtensionProperties
    178   #define vkGetInstanceProcAddr _glfw.vk.GetInstanceProcAddr
    179 #endif
    180 
    181 #if defined(_GLFW_COCOA)
    182  #include "cocoa_platform.h"
    183 #elif defined(_GLFW_WIN32)
    184  #include "win32_platform.h"
    185 #elif defined(_GLFW_X11)
    186  #include "x11_platform.h"
    187 #elif defined(_GLFW_WAYLAND)
    188  #include "wl_platform.h"
    189 #elif defined(_GLFW_MIR)
    190  #include "mir_platform.h"
    191 #elif defined(_GLFW_OSMESA)
    192  #include "null_platform.h"
    193 #else
    194  #error "No supported window creation API selected"
    195 #endif
    196 
    197 
    198 //========================================================================
    199 // Doxygen group definitions
    200 //========================================================================
    201 
    202 /*! @defgroup platform Platform interface
    203  *  @brief The interface implemented by the platform-specific code.
    204  *
    205  *  The platform API is the interface exposed by the platform-specific code for
    206  *  each platform and is called by the shared code of the public API It mirrors
    207  *  the public API except it uses objects instead of handles.
    208  */
    209 /*! @defgroup event Event interface
    210  *  @brief The interface used by the platform-specific code to report events.
    211  *
    212  *  The event API is used by the platform-specific code to notify the shared
    213  *  code of events that can be translated into state changes and/or callback
    214  *  calls.
    215  */
    216 /*! @defgroup utility Utility functions
    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  *  called by the platform-specific code
    222  */
    223 
    224 
    225 //========================================================================
    226 // Helper macros
    227 //========================================================================
    228 
    229 // Constructs a version number string from the public header macros
    230 #define _GLFW_CONCAT_VERSION(m, n, r) #m "." #n "." #r
    231 #define _GLFW_MAKE_VERSION(m, n, r) _GLFW_CONCAT_VERSION(m, n, r)
    232 #define _GLFW_VERSION_NUMBER _GLFW_MAKE_VERSION(GLFW_VERSION_MAJOR, \
    233                                                 GLFW_VERSION_MINOR, \
    234                                                 GLFW_VERSION_REVISION)
    235 
    236 // Checks for whether the library has been initialized
    237 #define _GLFW_REQUIRE_INIT()                         \
    238     if (!_glfw.initialized)                          \
    239     {                                                \
    240         _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
    241         return;                                      \
    242     }
    243 #define _GLFW_REQUIRE_INIT_OR_RETURN(x)              \
    244     if (!_glfw.initialized)                          \
    245     {                                                \
    246         _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
    247         return x;                                    \
    248     }
    249 
    250 // Swaps the provided pointers
    251 #define _GLFW_SWAP_POINTERS(x, y) \
    252     {                             \
    253         void* t;                  \
    254         t = x;                    \
    255         x = y;                    \
    256         y = t;                    \
    257     }
    258 
    259 
    260 //========================================================================
    261 // Platform-independent structures
    262 //========================================================================
    263 
    264 struct _GLFWerror
    265 {
    266     _GLFWerror*     next;
    267     int             code;
    268     char            description[_GLFW_MESSAGE_SIZE];
    269 };
    270 
    271 /*! @brief Initialization configuration.
    272  *
    273  *  Parameters relating to the initialization of the library.
    274  */
    275 struct _GLFWinitconfig
    276 {
    277     GLFWbool      hatButtons;
    278     struct {
    279         GLFWbool  menubar;
    280         GLFWbool  chdir;
    281     } ns;
    282     struct {
    283         char      className[256];
    284         char      classClass[256];
    285     } x11;
    286 };
    287 
    288 /*! @brief Window configuration.
    289  *
    290  *  Parameters relating to the creation of the window but not directly related
    291  *  to the framebuffer.  This is used to pass window creation parameters from
    292  *  shared code to the platform API.
    293  */
    294 struct _GLFWwndconfig
    295 {
    296     int           width;
    297     int           height;
    298     const char*   title;
    299     GLFWbool      resizable;
    300     GLFWbool      visible;
    301     GLFWbool      decorated;
    302     GLFWbool      focused;
    303     GLFWbool      autoIconify;
    304     GLFWbool      floating;
    305     GLFWbool      maximized;
    306     GLFWbool      centerCursor;
    307     struct {
    308         GLFWbool  retina;
    309         GLFWbool  frame;
    310     } ns;
    311 };
    312 
    313 /*! @brief Context configuration.
    314  *
    315  *  Parameters relating to the creation of the context but not directly related
    316  *  to the framebuffer.  This is used to pass context creation parameters from
    317  *  shared code to the platform API.
    318  */
    319 struct _GLFWctxconfig
    320 {
    321     int           client;
    322     int           source;
    323     int           major;
    324     int           minor;
    325     GLFWbool      forward;
    326     GLFWbool      debug;
    327     GLFWbool      noerror;
    328     int           profile;
    329     int           robustness;
    330     int           release;
    331     _GLFWwindow*  share;
    332     struct {
    333         GLFWbool  offline;
    334     } nsgl;
    335 };
    336 
    337 /*! @brief Framebuffer configuration.
    338  *
    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  *  It is used to pass framebuffer parameters from shared code to the platform
    343  *  API and also to enumerate and select available framebuffer configs.
    344  */
    345 struct _GLFWfbconfig
    346 {
    347     int         redBits;
    348     int         greenBits;
    349     int         blueBits;
    350     int         alphaBits;
    351     int         depthBits;
    352     int         stencilBits;
    353     int         accumRedBits;
    354     int         accumGreenBits;
    355     int         accumBlueBits;
    356     int         accumAlphaBits;
    357     int         auxBuffers;
    358     GLFWbool    stereo;
    359     int         samples;
    360     GLFWbool    sRGB;
    361     GLFWbool    doublebuffer;
    362     uintptr_t   handle;
    363 };
    364 
    365 /*! @brief Context structure.
    366  */
    367 struct _GLFWcontext
    368 {
    369     int                 client;
    370     int                 source;
    371     int                 major, minor, revision;
    372     GLFWbool            forward, debug, noerror;
    373     int                 profile;
    374     int                 robustness;
    375     int                 release;
    376 
    377     PFNGLGETSTRINGIPROC GetStringi;
    378     PFNGLGETINTEGERVPROC GetIntegerv;
    379     PFNGLGETSTRINGPROC  GetString;
    380 
    381     _GLFWmakecontextcurrentfun  makeCurrent;
    382     _GLFWswapbuffersfun         swapBuffers;
    383     _GLFWswapintervalfun        swapInterval;
    384     _GLFWextensionsupportedfun  extensionSupported;
    385     _GLFWgetprocaddressfun      getProcAddress;
    386     _GLFWdestroycontextfun      destroy;
    387 
    388     // This is defined in the context API's context.h
    389     _GLFW_PLATFORM_CONTEXT_STATE;
    390     // This is defined in egl_context.h
    391     _GLFW_EGL_CONTEXT_STATE;
    392     // This is defined in osmesa_context.h
    393     _GLFW_OSMESA_CONTEXT_STATE;
    394 };
    395 
    396 /*! @brief Window and context structure.
    397  */
    398 struct _GLFWwindow
    399 {
    400     struct _GLFWwindow* next;
    401 
    402     // Window settings and state
    403     GLFWbool            resizable;
    404     GLFWbool            decorated;
    405     GLFWbool            autoIconify;
    406     GLFWbool            floating;
    407     GLFWbool            shouldClose;
    408     void*               userPointer;
    409     GLFWvidmode         videoMode;
    410     _GLFWmonitor*       monitor;
    411     _GLFWcursor*        cursor;
    412 
    413     int                 minwidth, minheight;
    414     int                 maxwidth, maxheight;
    415     int                 numer, denom;
    416 
    417     GLFWbool            stickyKeys;
    418     GLFWbool            stickyMouseButtons;
    419     int                 cursorMode;
    420     char                mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
    421     char                keys[GLFW_KEY_LAST + 1];
    422     // Virtual cursor position when cursor is disabled
    423     double              virtualCursorPosX, virtualCursorPosY;
    424 
    425     _GLFWcontext        context;
    426 
    427     struct {
    428         GLFWwindowposfun        pos;
    429         GLFWwindowsizefun       size;
    430         GLFWwindowclosefun      close;
    431         GLFWwindowrefreshfun    refresh;
    432         GLFWwindowfocusfun      focus;
    433         GLFWwindowiconifyfun    iconify;
    434         GLFWwindowmaximizefun   maximize;
    435         GLFWframebuffersizefun  fbsize;
    436         GLFWmousebuttonfun      mouseButton;
    437         GLFWcursorposfun        cursorPos;
    438         GLFWcursorenterfun      cursorEnter;
    439         GLFWscrollfun           scroll;
    440         GLFWkeyfun              key;
    441         GLFWcharfun             character;
    442         GLFWcharmodsfun         charmods;
    443         GLFWdropfun             drop;
    444     } callbacks;
    445 
    446     // This is defined in the window API's platform.h
    447     _GLFW_PLATFORM_WINDOW_STATE;
    448 };
    449 
    450 /*! @brief Monitor structure.
    451  */
    452 struct _GLFWmonitor
    453 {
    454     char*           name;
    455 
    456     // Physical dimensions in millimeters.
    457     int             widthMM, heightMM;
    458 
    459     // The window whose video mode is current on this monitor
    460     _GLFWwindow*    window;
    461 
    462     GLFWvidmode*    modes;
    463     int             modeCount;
    464     GLFWvidmode     currentMode;
    465 
    466     GLFWgammaramp   originalRamp;
    467     GLFWgammaramp   currentRamp;
    468 
    469     // This is defined in the window API's platform.h
    470     _GLFW_PLATFORM_MONITOR_STATE;
    471 };
    472 
    473 /*! @brief Cursor structure
    474  */
    475 struct _GLFWcursor
    476 {
    477     _GLFWcursor*    next;
    478 
    479     // This is defined in the window API's platform.h
    480     _GLFW_PLATFORM_CURSOR_STATE;
    481 };
    482 
    483 /*! @brief Gamepad mapping element structure
    484  */
    485 struct _GLFWmapelement
    486 {
    487     uint8_t         type;
    488     uint8_t         value;
    489 };
    490 
    491 /*! @brief Gamepad mapping structure
    492  */
    493 struct _GLFWmapping
    494 {
    495     char            name[128];
    496     char            guid[33];
    497     _GLFWmapelement buttons[15];
    498     _GLFWmapelement axes[6];
    499 };
    500 
    501 /*! @brief Joystick structure
    502  */
    503 struct _GLFWjoystick
    504 {
    505     GLFWbool        present;
    506     float*          axes;
    507     int             axisCount;
    508     unsigned char*  buttons;
    509     int             buttonCount;
    510     unsigned char*  hats;
    511     int             hatCount;
    512     char*           name;
    513     char            guid[33];
    514     _GLFWmapping*   mapping;
    515 
    516     // This is defined in the joystick API's joystick.h
    517     _GLFW_PLATFORM_JOYSTICK_STATE;
    518 };
    519 
    520 /*! @brief Thread local storage structure.
    521  */
    522 struct _GLFWtls
    523 {
    524     // This is defined in the platform's thread.h
    525     _GLFW_PLATFORM_TLS_STATE;
    526 };
    527 
    528 /*! @brief Mutex structure.
    529  */
    530 struct _GLFWmutex
    531 {
    532     // This is defined in the platform's thread.h
    533     _GLFW_PLATFORM_MUTEX_STATE;
    534 };
    535 
    536 /*! @brief Library global data.
    537  */
    538 struct _GLFWlibrary
    539 {
    540     GLFWbool            initialized;
    541 
    542     struct {
    543         _GLFWinitconfig init;
    544         _GLFWfbconfig   framebuffer;
    545         _GLFWwndconfig  window;
    546         _GLFWctxconfig  context;
    547         int             refreshRate;
    548     } hints;
    549 
    550     _GLFWerror*         errorListHead;
    551     _GLFWcursor*        cursorListHead;
    552     _GLFWwindow*        windowListHead;
    553 
    554     _GLFWmonitor**      monitors;
    555     int                 monitorCount;
    556 
    557     _GLFWjoystick       joysticks[GLFW_JOYSTICK_LAST + 1];
    558     _GLFWmapping*       mappings;
    559     int                 mappingCount;
    560 
    561     _GLFWtls            errorSlot;
    562     _GLFWtls            contextSlot;
    563     _GLFWmutex          errorLock;
    564 
    565     struct {
    566         uint64_t        offset;
    567         // This is defined in the platform's time.h
    568         _GLFW_PLATFORM_LIBRARY_TIMER_STATE;
    569     } timer;
    570 
    571     struct {
    572         GLFWbool        available;
    573         void*           handle;
    574         char*           extensions[2];
    575 #if !defined(_GLFW_VULKAN_STATIC)
    576         PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties;
    577         PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
    578 #endif
    579         GLFWbool        KHR_surface;
    580 #if defined(_GLFW_WIN32)
    581         GLFWbool        KHR_win32_surface;
    582 #elif defined(_GLFW_COCOA)
    583         GLFWbool        MVK_macos_surface;
    584 #elif defined(_GLFW_X11)
    585         GLFWbool        KHR_xlib_surface;
    586         GLFWbool        KHR_xcb_surface;
    587 #elif defined(_GLFW_WAYLAND)
    588         GLFWbool        KHR_wayland_surface;
    589 #elif defined(_GLFW_MIR)
    590         GLFWbool        KHR_mir_surface;
    591 #endif
    592     } vk;
    593 
    594     struct {
    595         GLFWmonitorfun  monitor;
    596         GLFWjoystickfun joystick;
    597     } callbacks;
    598 
    599     // This is defined in the window API's platform.h
    600     _GLFW_PLATFORM_LIBRARY_WINDOW_STATE;
    601     // This is defined in the context API's context.h
    602     _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE;
    603     // This is defined in the platform's joystick.h
    604     _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE;
    605     // This is defined in egl_context.h
    606     _GLFW_EGL_LIBRARY_CONTEXT_STATE;
    607     // This is defined in osmesa_context.h
    608     _GLFW_OSMESA_LIBRARY_CONTEXT_STATE;
    609 };
    610 
    611 
    612 //========================================================================
    613 // Global state shared between compilation units of GLFW
    614 //========================================================================
    615 
    616 /*! @brief All global data shared between compilation units.
    617  */
    618 extern _GLFWlibrary _glfw;
    619 
    620 
    621 //========================================================================
    622 // Platform API functions
    623 //========================================================================
    624 
    625 /*! @addtogroup platform @{ */
    626 
    627 int _glfwPlatformInit(void);
    628 void _glfwPlatformTerminate(void);
    629 const char* _glfwPlatformGetVersionString(void);
    630 
    631 void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos);
    632 void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos);
    633 void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
    634 int _glfwPlatformCreateCursor(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot);
    635 int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape);
    636 void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
    637 void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor);
    638 
    639 const char* _glfwPlatformGetScancodeName(int scancode);
    640 int _glfwPlatformGetKeyScancode(int key);
    641 
    642 void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos);
    643 GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count);
    644 void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode);
    645 void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp);
    646 void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);
    647 
    648 void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string);
    649 const char* _glfwPlatformGetClipboardString(_GLFWwindow* window);
    650 
    651 int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode);
    652 void _glfwPlatformUpdateGamepadGUID(char* guid);
    653 
    654 uint64_t _glfwPlatformGetTimerValue(void);
    655 uint64_t _glfwPlatformGetTimerFrequency(void);
    656 
    657 int _glfwPlatformCreateWindow(_GLFWwindow* window,
    658                               const _GLFWwndconfig* wndconfig,
    659                               const _GLFWctxconfig* ctxconfig,
    660                               const _GLFWfbconfig* fbconfig);
    661 void _glfwPlatformDestroyWindow(_GLFWwindow* window);
    662 void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
    663 void _glfwPlatformSetWindowIcon(_GLFWwindow* window, int count, const GLFWimage* images);
    664 void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos);
    665 void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos);
    666 void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height);
    667 void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
    668 void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight);
    669 void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom);
    670 void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height);
    671 void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, int* left, int* top, int* right, int* bottom);
    672 void _glfwPlatformIconifyWindow(_GLFWwindow* window);
    673 void _glfwPlatformRestoreWindow(_GLFWwindow* window);
    674 void _glfwPlatformMaximizeWindow(_GLFWwindow* window);
    675 void _glfwPlatformShowWindow(_GLFWwindow* window);
    676 void _glfwPlatformHideWindow(_GLFWwindow* window);
    677 void _glfwPlatformRequestWindowAttention(_GLFWwindow* window);
    678 void _glfwPlatformFocusWindow(_GLFWwindow* window);
    679 void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate);
    680 int _glfwPlatformWindowFocused(_GLFWwindow* window);
    681 int _glfwPlatformWindowIconified(_GLFWwindow* window);
    682 int _glfwPlatformWindowVisible(_GLFWwindow* window);
    683 int _glfwPlatformWindowMaximized(_GLFWwindow* window);
    684 void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled);
    685 void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled);
    686 void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled);
    687 
    688 void _glfwPlatformPollEvents(void);
    689 void _glfwPlatformWaitEvents(void);
    690 void _glfwPlatformWaitEventsTimeout(double timeout);
    691 void _glfwPlatformPostEmptyEvent(void);
    692 
    693 void _glfwPlatformGetRequiredInstanceExtensions(char** extensions);
    694 int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
    695 VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
    696 
    697 GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls);
    698 void _glfwPlatformDestroyTls(_GLFWtls* tls);
    699 void* _glfwPlatformGetTls(_GLFWtls* tls);
    700 void _glfwPlatformSetTls(_GLFWtls* tls, void* value);
    701 
    702 GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex);
    703 void _glfwPlatformDestroyMutex(_GLFWmutex* mutex);
    704 void _glfwPlatformLockMutex(_GLFWmutex* mutex);
    705 void _glfwPlatformUnlockMutex(_GLFWmutex* mutex);
    706 
    707 /*! @} */
    708 
    709 
    710 //========================================================================
    711 // Event API functions
    712 //========================================================================
    713 
    714 /*! @brief Notifies shared code that a window has lost or received input focus.
    715  *  @param[in] window The window that received the event.
    716  *  @param[in] focused `GLFW_TRUE` if the window received focus, or `GLFW_FALSE`
    717  *  if it lost focus.
    718  *  @ingroup event
    719  */
    720 void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused);
    721 
    722 /*! @brief Notifies shared code that a window has moved.
    723  *  @param[in] window The window that received the event.
    724  *  @param[in] xpos The new x-coordinate of the client area of the window.
    725  *  @param[in] ypos The new y-coordinate of the client area of the window.
    726  *  @ingroup event
    727  */
    728 void _glfwInputWindowPos(_GLFWwindow* window, int xpos, int ypos);
    729 
    730 /*! @brief Notifies shared code that a window has been resized.
    731  *  @param[in] window The window that received the event.
    732  *  @param[in] width The new width of the client area of the window.
    733  *  @param[in] height The new height of the client area of the window.
    734  *  @ingroup event
    735  */
    736 void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
    737 
    738 /*! @brief Notifies shared code that a window framebuffer has been resized.
    739  *  @param[in] window The window that received the event.
    740  *  @param[in] width The new width, in pixels, of the framebuffer.
    741  *  @param[in] height The new height, in pixels, of the framebuffer.
    742  *  @ingroup event
    743  */
    744 void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height);
    745 
    746 /*! @brief Notifies shared code that a window has been iconified or restored.
    747  *  @param[in] window The window that received the event.
    748  *  @param[in] iconified `GLFW_TRUE` if the window was iconified, or
    749  *  `GLFW_FALSE` if it was restored.
    750  *  @ingroup event
    751  */
    752 void _glfwInputWindowIconify(_GLFWwindow* window, GLFWbool iconified);
    753 
    754 /*! @brief Notifies shared code that a window has been maximized or restored.
    755  *  @param[in] window The window that received the event.
    756  *  @param[in] maximized `GLFW_TRUE` if the window was maximized, or
    757  *  `GLFW_FALSE` if it was restored.
    758  *  @ingroup event
    759  */
    760 void _glfwInputWindowMaximize(_GLFWwindow* window, GLFWbool maximized);
    761 
    762 /*! @brief Notifies shared code that a window's contents needs updating.
    763  *  @param[in] window The window that received the event.
    764  */
    765 void _glfwInputWindowDamage(_GLFWwindow* window);
    766 
    767 /*! @brief Notifies shared code that the user wishes to close a window.
    768  *  @param[in] window The window that received the event.
    769  *  @ingroup event
    770  */
    771 void _glfwInputWindowCloseRequest(_GLFWwindow* window);
    772 
    773 /*! @brief Notifies shared code that a window has changed its desired monitor.
    774  *  @param[in] window The window that received the event.
    775  *  @param[in] monitor The new desired monitor, or `NULL`.
    776  *  @ingroup event
    777  */
    778 void _glfwInputWindowMonitorChange(_GLFWwindow* window, _GLFWmonitor* monitor);
    779 
    780 /*! @brief Notifies shared code of a physical key event.
    781  *  @param[in] window The window that received the event.
    782  *  @param[in] key The key that was pressed or released.
    783  *  @param[in] scancode The system-specific scan code of the key.
    784  *  @param[in] action @ref GLFW_PRESS or @ref GLFW_RELEASE.
    785  *  @param[in] mods The modifiers pressed when the event was generated.
    786  *  @ingroup event
    787  */
    788 void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int mods);
    789 
    790 /*! @brief Notifies shared code of a Unicode character input event.
    791  *  @param[in] window The window that received the event.
    792  *  @param[in] codepoint The Unicode code point of the input character.
    793  *  @param[in] mods Bit field describing which modifier keys were held down.
    794  *  @param[in] plain `GLFW_TRUE` if the character is regular text input, or
    795  *  `GLFW_FALSE` otherwise.
    796  *  @ingroup event
    797  */
    798 void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods, GLFWbool plain);
    799 
    800 /*! @brief Notifies shared code of a scroll event.
    801  *  @param[in] window The window that received the event.
    802  *  @param[in] xoffset The scroll offset along the x-axis.
    803  *  @param[in] yoffset The scroll offset along the y-axis.
    804  *  @ingroup event
    805  */
    806 void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset);
    807 
    808 /*! @brief Notifies shared code of a mouse button click event.
    809  *  @param[in] window The window that received the event.
    810  *  @param[in] button The button that was pressed or released.
    811  *  @param[in] action @ref GLFW_PRESS or @ref GLFW_RELEASE.
    812  *  @param[in] mods The modifiers pressed when the event was generated.
    813  *  @ingroup event
    814  */
    815 void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods);
    816 
    817 /*! @brief Notifies shared code of a cursor motion event.
    818  *  @param[in] window The window that received the event.
    819  *  @param[in] xpos The new x-coordinate of the cursor, relative to the left
    820  *  edge of the client area of the window.
    821  *  @param[in] ypos The new y-coordinate of the cursor, relative to the top edge
    822  *  of the client area of the window.
    823  *  @ingroup event
    824  */
    825 void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos);
    826 
    827 /*! @brief Notifies shared code of a cursor enter/leave event.
    828  *  @param[in] window The window that received the event.
    829  *  @param[in] entered `GLFW_TRUE` if the cursor entered the client area of the
    830  *  window, or `GLFW_FALSE` if it left it.
    831  *  @ingroup event
    832  */
    833 void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered);
    834 
    835 /*! @brief Notifies shared code of a monitor connection or disconnection.
    836  *  @param[in] monitor The monitor that was connected or disconnected.
    837  *  @param[in] action One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`.
    838  *  @param[in] placement `_GLFW_INSERT_FIRST` or `_GLFW_INSERT_LAST`.
    839  *  @ingroup event
    840  */
    841 void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement);
    842 
    843 /*! @brief Notifies shared code that a full screen window has acquired or
    844  *  released a monitor.
    845  *  @param[in] monitor The monitor that was acquired or released.
    846  *  @param[in] window The window that acquired the monitor, or `NULL`.
    847  *  @ingroup event
    848  */
    849 void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window);
    850 
    851 /*! @brief Notifies shared code of an error.
    852  *  @param[in] code The error code most suitable for the error.
    853  *  @param[in] format The `printf` style format string of the error
    854  *  description.
    855  *  @ingroup event
    856  */
    857 #if defined(__GNUC__)
    858 void _glfwInputError(int code, const char* format, ...) __attribute__((format(printf, 2, 3)));
    859 #else
    860 void _glfwInputError(int code, const char* format, ...);
    861 #endif
    862 
    863 /*! @brief Notifies shared code of files or directories dropped on a window.
    864  *  @param[in] window The window that received the event.
    865  *  @param[in] count The number of dropped objects.
    866  *  @param[in] names The names of the dropped objects.
    867  *  @ingroup event
    868  */
    869 void _glfwInputDrop(_GLFWwindow* window, int count, const char** names);
    870 
    871 /*! @brief Notifies shared code of a joystick connection or disconnection.
    872  *  @param[in] js The joystick that was connected or disconnected.
    873  *  @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`.
    874  *  @ingroup event
    875  */
    876 void _glfwInputJoystick(_GLFWjoystick* js, int event);
    877 
    878 /*! @brief Notifies shared code of the new value of a joystick axis.
    879  *  @param[in] js The joystick whose axis to update.
    880  *  @param[in] axis The index of the axis to update.
    881  *  @param[in] value The new value of the axis.
    882  */
    883 void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value);
    884 
    885 /*! @brief Notifies shared code of the new value of a joystick button.
    886  *  @param[in] js The joystick whose button to update.
    887  *  @param[in] button The index of the button to update.
    888  *  @param[in] value The new value of the button.
    889  */
    890 void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value);
    891 
    892 /*! @brief Notifies shared code of the new value of a joystick hat.
    893  *  @param[in] js The joystick whose hat to update.
    894  *  @param[in] button The index of the hat to update.
    895  *  @param[in] value The new value of the hat.
    896  */
    897 void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value);
    898 
    899 
    900 //========================================================================
    901 // Utility functions
    902 //========================================================================
    903 
    904 /*! @brief Chooses the video mode most closely matching the desired one.
    905  *  @ingroup utility
    906  */
    907 const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor,
    908                                         const GLFWvidmode* desired);
    909 
    910 /*! @brief Performs lexical comparison between two @ref GLFWvidmode structures.
    911  *  @ingroup utility
    912  */
    913 int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second);
    914 
    915 /*! @brief Splits a color depth into red, green and blue bit depths.
    916  *  @ingroup utility
    917  */
    918 void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
    919 
    920 /*! @brief Searches an extension string for the specified extension.
    921  *  @param[in] string The extension string to search.
    922  *  @param[in] extensions The extension to search for.
    923  *  @return `GLFW_TRUE` if the extension was found, or `GLFW_FALSE` otherwise.
    924  *  @ingroup utility
    925  */
    926 GLFWbool _glfwStringInExtensionString(const char* string, const char* extensions);
    927 
    928 /*! @brief Chooses the framebuffer config that best matches the desired one.
    929  *  @param[in] desired The desired framebuffer config.
    930  *  @param[in] alternatives The framebuffer configs supported by the system.
    931  *  @param[in] count The number of entries in the alternatives array.
    932  *  @return The framebuffer config most closely matching the desired one, or @c
    933  *  NULL if none fulfilled the hard constraints of the desired values.
    934  *  @ingroup utility
    935  */
    936 const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
    937                                          const _GLFWfbconfig* alternatives,
    938                                          unsigned int count);
    939 
    940 /*! @brief Retrieves the attributes of the current context.
    941  *  @param[in] ctxconfig The desired context attributes.
    942  *  @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if the context is
    943  *  unusable.
    944  *  @ingroup utility
    945  */
    946 GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig);
    947 
    948 /*! @brief Checks whether the desired context attributes are valid.
    949  *  @param[in] ctxconfig The context attributes to check.
    950  *  @return `GLFW_TRUE` if the context attributes are valid, or `GLFW_FALSE`
    951  *  otherwise.
    952  *  @ingroup utility
    953  *
    954  *  This function checks things like whether the specified client API version
    955  *  exists and whether all relevant options have supported and non-conflicting
    956  *  values.
    957  */
    958 GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig);
    959 
    960 /*! @brief Allocates red, green and blue value arrays of the specified size.
    961  *  @ingroup utility
    962  */
    963 void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size);
    964 
    965 /*! @brief Frees the red, green and blue value arrays and clears the struct.
    966  *  @ingroup utility
    967  */
    968 void _glfwFreeGammaArrays(GLFWgammaramp* ramp);
    969 
    970 /*! @brief Allocates and returns a monitor object with the specified name
    971  *  and dimensions.
    972  *  @param[in] name The name of the monitor.
    973  *  @param[in] widthMM The width, in mm, of the monitor's display area.
    974  *  @param[in] heightMM The height, in mm, of the monitor's display area.
    975  *  @return The newly created object.
    976  *  @ingroup utility
    977  */
    978 _GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM);
    979 
    980 /*! @brief Frees a monitor object and any data associated with it.
    981  *  @ingroup utility
    982   */
    983 void _glfwFreeMonitor(_GLFWmonitor* monitor);
    984 
    985 /*! @brief Returns an available joystick object with arrays and name allocated.
    986  *  @ingroup utility
    987   */
    988 _GLFWjoystick* _glfwAllocJoystick(const char* name,
    989                                   const char* guid,
    990                                   int axisCount,
    991                                   int buttonCount,
    992                                   int hatCount);
    993 
    994 /*! @brief Frees arrays and name and flags the joystick object as unused.
    995  *  @ingroup utility
    996   */
    997 void _glfwFreeJoystick(_GLFWjoystick* js);
    998 
    999 /*! @ingroup utility
   1000  */
   1001 GLFWbool _glfwInitVulkan(int mode);
   1002 
   1003 /*! @ingroup utility
   1004  */
   1005 void _glfwTerminateVulkan(void);
   1006 
   1007 /*! @ingroup utility
   1008  */
   1009 const char* _glfwGetVulkanResultString(VkResult result);
   1010