hs

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | LICENSE

internal.h (28054B)


      1 //========================================================================
      2 // GLFW 3.4 - www.glfw.org
      3 //------------------------------------------------------------------------
      4 // Copyright (c) 2002-2006 Marcus Geelnard
      5 // Copyright (c) 2006-2019 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 #pragma once
     29 
     30 #if defined(_GLFW_USE_CONFIG_H)
     31  #include "glfw_config.h"
     32 #endif
     33 
     34 #if defined(GLFW_INCLUDE_GLCOREARB) || \
     35     defined(GLFW_INCLUDE_ES1)       || \
     36     defined(GLFW_INCLUDE_ES2)       || \
     37     defined(GLFW_INCLUDE_ES3)       || \
     38     defined(GLFW_INCLUDE_ES31)      || \
     39     defined(GLFW_INCLUDE_ES32)      || \
     40     defined(GLFW_INCLUDE_NONE)      || \
     41     defined(GLFW_INCLUDE_GLEXT)     || \
     42     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 #endif
     47 
     48 #define GLFW_INCLUDE_NONE
     49 #include "glfw3.h"
     50 
     51 #define _GLFW_INSERT_FIRST      0
     52 #define _GLFW_INSERT_LAST       1
     53 
     54 #define _GLFW_POLL_PRESENCE     0
     55 #define _GLFW_POLL_AXES         1
     56 #define _GLFW_POLL_BUTTONS      2
     57 #define _GLFW_POLL_ALL          (_GLFW_POLL_AXES | _GLFW_POLL_BUTTONS)
     58 
     59 #define _GLFW_MESSAGE_SIZE      1024
     60 
     61 typedef int GLFWbool;
     62 
     63 typedef struct _GLFWerror       _GLFWerror;
     64 typedef struct _GLFWinitconfig  _GLFWinitconfig;
     65 typedef struct _GLFWwndconfig   _GLFWwndconfig;
     66 typedef struct _GLFWctxconfig   _GLFWctxconfig;
     67 typedef struct _GLFWfbconfig    _GLFWfbconfig;
     68 typedef struct _GLFWcontext     _GLFWcontext;
     69 typedef struct _GLFWwindow      _GLFWwindow;
     70 typedef struct _GLFWlibrary     _GLFWlibrary;
     71 typedef struct _GLFWmonitor     _GLFWmonitor;
     72 typedef struct _GLFWcursor      _GLFWcursor;
     73 typedef struct _GLFWmapelement  _GLFWmapelement;
     74 typedef struct _GLFWmapping     _GLFWmapping;
     75 typedef struct _GLFWjoystick    _GLFWjoystick;
     76 typedef struct _GLFWtls         _GLFWtls;
     77 typedef struct _GLFWmutex       _GLFWmutex;
     78 
     79 typedef void (* _GLFWmakecontextcurrentfun)(_GLFWwindow*);
     80 typedef void (* _GLFWswapbuffersfun)(_GLFWwindow*);
     81 typedef void (* _GLFWswapintervalfun)(int);
     82 typedef int (* _GLFWextensionsupportedfun)(const char*);
     83 typedef GLFWglproc (* _GLFWgetprocaddressfun)(const char*);
     84 typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*);
     85 
     86 #ifndef GL_VERSION
     87     #define GL_VERSION 0x1f02
     88 #endif
     89 
     90 #define GL_NONE 0
     91 #define GL_COLOR_BUFFER_BIT 0x00004000
     92 #define GL_UNSIGNED_BYTE 0x1401
     93 
     94 #ifndef GL_EXTENSIONS
     95     #define GL_EXTENSIONS 0x1f03
     96 #endif
     97 
     98 #ifndef GL_NUM_EXTENSIONS
     99     #define GL_NUM_EXTENSIONS 0x821d
    100 #endif
    101 
    102 #ifndef GL_CONTEXT_FLAGS
    103     #define GL_CONTEXT_FLAGS 0x821e
    104 #endif
    105 
    106 #define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x00000001
    107 #define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002
    108 #define GL_CONTEXT_PROFILE_MASK 0x9126
    109 #define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
    110 #define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001
    111 #define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
    112 #define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
    113 #define GL_NO_RESET_NOTIFICATION_ARB 0x8261
    114 
    115 #ifndef GL_CONTEXT_RELEASE_BEHAVIOR
    116     #define GL_CONTEXT_RELEASE_BEHAVIOR 0x82fb
    117 #endif
    118 
    119 #ifndef GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH
    120     #define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82fc
    121 #endif
    122 
    123 #define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008
    124 
    125 typedef int GLint;
    126 typedef unsigned int GLuint;
    127 typedef unsigned int GLenum;
    128 typedef unsigned int GLbitfield;
    129 typedef unsigned char GLubyte;
    130 
    131 typedef void (APIENTRY * PFNGLCLEARPROC)(GLbitfield);
    132 typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGPROC)(GLenum);
    133 typedef void (APIENTRY * PFNGLGETINTEGERVPROC)(GLenum,GLint*);
    134 typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGIPROC)(GLenum,GLuint);
    135 
    136 #define VK_NULL_HANDLE 0
    137 
    138 typedef void* VkInstance;
    139 typedef void* VkPhysicalDevice;
    140 typedef uint64_t VkSurfaceKHR;
    141 typedef uint32_t VkFlags;
    142 typedef uint32_t VkBool32;
    143 
    144 typedef enum VkStructureType
    145 {
    146     VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000,
    147     VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR = 1000005000,
    148     VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000,
    149     VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
    150     VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000,
    151     VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT = 1000217000,
    152     VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
    153 } VkStructureType;
    154 
    155 typedef enum VkResult
    156 {
    157     VK_SUCCESS = 0,
    158     VK_NOT_READY = 1,
    159     VK_TIMEOUT = 2,
    160     VK_EVENT_SET = 3,
    161     VK_EVENT_RESET = 4,
    162     VK_INCOMPLETE = 5,
    163     VK_ERROR_OUT_OF_HOST_MEMORY = -1,
    164     VK_ERROR_OUT_OF_DEVICE_MEMORY = -2,
    165     VK_ERROR_INITIALIZATION_FAILED = -3,
    166     VK_ERROR_DEVICE_LOST = -4,
    167     VK_ERROR_MEMORY_MAP_FAILED = -5,
    168     VK_ERROR_LAYER_NOT_PRESENT = -6,
    169     VK_ERROR_EXTENSION_NOT_PRESENT = -7,
    170     VK_ERROR_FEATURE_NOT_PRESENT = -8,
    171     VK_ERROR_INCOMPATIBLE_DRIVER = -9,
    172     VK_ERROR_TOO_MANY_OBJECTS = -10,
    173     VK_ERROR_FORMAT_NOT_SUPPORTED = -11,
    174     VK_ERROR_SURFACE_LOST_KHR = -1000000000,
    175     VK_SUBOPTIMAL_KHR = 1000001003,
    176     VK_ERROR_OUT_OF_DATE_KHR = -1000001004,
    177     VK_ERROR_INCOMPATIBLE_DISPLAY_KHR = -1000003001,
    178     VK_ERROR_NATIVE_WINDOW_IN_USE_KHR = -1000000001,
    179     VK_ERROR_VALIDATION_FAILED_EXT = -1000011001,
    180     VK_RESULT_MAX_ENUM = 0x7FFFFFFF
    181 } VkResult;
    182 
    183 typedef struct VkAllocationCallbacks VkAllocationCallbacks;
    184 
    185 typedef struct VkExtensionProperties
    186 {
    187     char            extensionName[256];
    188     uint32_t        specVersion;
    189 } VkExtensionProperties;
    190 
    191 typedef void (APIENTRY * PFN_vkVoidFunction)(void);
    192 
    193 #if defined(_GLFW_VULKAN_STATIC)
    194   PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance,const char*);
    195   VkResult vkEnumerateInstanceExtensionProperties(const char*,uint32_t*,VkExtensionProperties*);
    196 #else
    197   typedef PFN_vkVoidFunction (APIENTRY * PFN_vkGetInstanceProcAddr)(VkInstance,const char*);
    198   typedef VkResult (APIENTRY * PFN_vkEnumerateInstanceExtensionProperties)(const char*,uint32_t*,VkExtensionProperties*);
    199   #define vkEnumerateInstanceExtensionProperties _glfw.vk.EnumerateInstanceExtensionProperties
    200   #define vkGetInstanceProcAddr _glfw.vk.GetInstanceProcAddr
    201 #endif
    202 
    203 #if defined(_GLFW_COCOA)
    204  #include "cocoa_platform.h"
    205 #elif defined(_GLFW_WIN32)
    206  #include "win32_platform.h"
    207 #elif defined(_GLFW_X11)
    208  #include "x11_platform.h"
    209 #elif defined(_GLFW_WAYLAND)
    210  #include "wl_platform.h"
    211 #elif defined(_GLFW_OSMESA)
    212  #include "null_platform.h"
    213 #else
    214  #error "No supported window creation API selected"
    215 #endif
    216 
    217 // Constructs a version number string from the public header macros
    218 #define _GLFW_CONCAT_VERSION(m, n, r) #m "." #n "." #r
    219 #define _GLFW_MAKE_VERSION(m, n, r) _GLFW_CONCAT_VERSION(m, n, r)
    220 #define _GLFW_VERSION_NUMBER _GLFW_MAKE_VERSION(GLFW_VERSION_MAJOR, \
    221                                                 GLFW_VERSION_MINOR, \
    222                                                 GLFW_VERSION_REVISION)
    223 
    224 // Checks for whether the library has been initialized
    225 #define _GLFW_REQUIRE_INIT()                         \
    226     if (!_glfw.initialized)                          \
    227     {                                                \
    228         _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
    229         return;                                      \
    230     }
    231 #define _GLFW_REQUIRE_INIT_OR_RETURN(x)              \
    232     if (!_glfw.initialized)                          \
    233     {                                                \
    234         _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
    235         return x;                                    \
    236     }
    237 
    238 // Swaps the provided pointers
    239 #define _GLFW_SWAP_POINTERS(T, x, y) \
    240     {                             \
    241         T t;                      \
    242         t = x;                    \
    243         x = y;                    \
    244         y = t;                    \
    245     }
    246 
    247 // Per-thread error structure
    248 //
    249 struct _GLFWerror
    250 {
    251     _GLFWerror*     next;
    252     int             code;
    253     char            description[_GLFW_MESSAGE_SIZE];
    254 };
    255 
    256 // Initialization configuration
    257 //
    258 // Parameters relating to the initialization of the library
    259 //
    260 struct _GLFWinitconfig
    261 {
    262     GLFWbool      hatButtons;
    263     struct {
    264         GLFWbool  menubar;
    265         GLFWbool  chdir;
    266     } ns;
    267 };
    268 
    269 // Window configuration
    270 //
    271 // Parameters relating to the creation of the window but not directly related
    272 // to the framebuffer.  This is used to pass window creation parameters from
    273 // shared code to the platform API.
    274 //
    275 struct _GLFWwndconfig
    276 {
    277     int           width;
    278     int           height;
    279     const char*   title;
    280     GLFWbool      resizable;
    281     GLFWbool      visible;
    282     GLFWbool      decorated;
    283     GLFWbool      focused;
    284     GLFWbool      autoIconify;
    285     GLFWbool      floating;
    286     GLFWbool      maximized;
    287     GLFWbool      centerCursor;
    288     GLFWbool      focusOnShow;
    289     GLFWbool      scaleToMonitor;
    290     struct {
    291         GLFWbool  retina;
    292         char      frameName[256];
    293     } ns;
    294     struct {
    295         char      className[256];
    296         char      instanceName[256];
    297     } x11;
    298     struct {
    299         GLFWbool  keymenu;
    300     } win32;
    301 };
    302 
    303 // Context configuration
    304 //
    305 // Parameters relating to the creation of the context but not directly related
    306 // to the framebuffer.  This is used to pass context creation parameters from
    307 // shared code to the platform API.
    308 //
    309 struct _GLFWctxconfig
    310 {
    311     int           client;
    312     int           source;
    313     int           major;
    314     int           minor;
    315     GLFWbool      forward;
    316     GLFWbool      debug;
    317     GLFWbool      noerror;
    318     int           profile;
    319     int           robustness;
    320     int           release;
    321     _GLFWwindow*  share;
    322     struct {
    323         GLFWbool  offline;
    324     } nsgl;
    325 };
    326 
    327 // Framebuffer configuration
    328 //
    329 // This describes buffers and their sizes.  It also contains
    330 // a platform-specific ID used to map back to the backend API object.
    331 //
    332 // It is used to pass framebuffer parameters from shared code to the platform
    333 // API and also to enumerate and select available framebuffer configs.
    334 //
    335 struct _GLFWfbconfig
    336 {
    337     int         redBits;
    338     int         greenBits;
    339     int         blueBits;
    340     int         alphaBits;
    341     int         depthBits;
    342     int         stencilBits;
    343     int         accumRedBits;
    344     int         accumGreenBits;
    345     int         accumBlueBits;
    346     int         accumAlphaBits;
    347     int         auxBuffers;
    348     GLFWbool    stereo;
    349     int         samples;
    350     GLFWbool    sRGB;
    351     GLFWbool    doublebuffer;
    352     GLFWbool    transparent;
    353     uintptr_t   handle;
    354 };
    355 
    356 // Context structure
    357 //
    358 struct _GLFWcontext
    359 {
    360     int                 client;
    361     int                 source;
    362     int                 major, minor, revision;
    363     GLFWbool            forward, debug, noerror;
    364     int                 profile;
    365     int                 robustness;
    366     int                 release;
    367 
    368     PFNGLGETSTRINGIPROC GetStringi;
    369     PFNGLGETINTEGERVPROC GetIntegerv;
    370     PFNGLGETSTRINGPROC  GetString;
    371 
    372     _GLFWmakecontextcurrentfun  makeCurrent;
    373     _GLFWswapbuffersfun         swapBuffers;
    374     _GLFWswapintervalfun        swapInterval;
    375     _GLFWextensionsupportedfun  extensionSupported;
    376     _GLFWgetprocaddressfun      getProcAddress;
    377     _GLFWdestroycontextfun      destroy;
    378 
    379     // This is defined in the context API's context.h
    380     _GLFW_PLATFORM_CONTEXT_STATE;
    381     // This is defined in egl_context.h
    382     _GLFW_EGL_CONTEXT_STATE;
    383     // This is defined in osmesa_context.h
    384     _GLFW_OSMESA_CONTEXT_STATE;
    385 };
    386 
    387 // Window and context structure
    388 //
    389 struct _GLFWwindow
    390 {
    391     struct _GLFWwindow* next;
    392 
    393     // Window settings and state
    394     GLFWbool            resizable;
    395     GLFWbool            decorated;
    396     GLFWbool            autoIconify;
    397     GLFWbool            floating;
    398     GLFWbool            focusOnShow;
    399     GLFWbool            shouldClose;
    400     void*               userPointer;
    401     GLFWvidmode         videoMode;
    402     _GLFWmonitor*       monitor;
    403     _GLFWcursor*        cursor;
    404 
    405     int                 minwidth, minheight;
    406     int                 maxwidth, maxheight;
    407     int                 numer, denom;
    408 
    409     GLFWbool            stickyKeys;
    410     GLFWbool            stickyMouseButtons;
    411     GLFWbool            lockKeyMods;
    412     int                 cursorMode;
    413     char                mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
    414     char                keys[GLFW_KEY_LAST + 1];
    415     // Virtual cursor position when cursor is disabled
    416     double              virtualCursorPosX, virtualCursorPosY;
    417     GLFWbool            rawMouseMotion;
    418 
    419     _GLFWcontext        context;
    420 
    421     struct {
    422         GLFWwindowposfun        pos;
    423         GLFWwindowsizefun       size;
    424         GLFWwindowclosefun      close;
    425         GLFWwindowrefreshfun    refresh;
    426         GLFWwindowfocusfun      focus;
    427         GLFWwindowiconifyfun    iconify;
    428         GLFWwindowmaximizefun   maximize;
    429         GLFWframebuffersizefun  fbsize;
    430         GLFWwindowcontentscalefun scale;
    431         GLFWmousebuttonfun      mouseButton;
    432         GLFWcursorposfun        cursorPos;
    433         GLFWcursorenterfun      cursorEnter;
    434         GLFWscrollfun           scroll;
    435         GLFWkeyfun              key;
    436         GLFWcharfun             character;
    437         GLFWcharmodsfun         charmods;
    438         GLFWdropfun             drop;
    439     } callbacks;
    440 
    441     // This is defined in the window API's platform.h
    442     _GLFW_PLATFORM_WINDOW_STATE;
    443 };
    444 
    445 // Monitor structure
    446 //
    447 struct _GLFWmonitor
    448 {
    449     char*           name;
    450     void*           userPointer;
    451 
    452     // Physical dimensions in millimeters.
    453     int             widthMM, heightMM;
    454 
    455     // The window whose video mode is current on this monitor
    456     _GLFWwindow*    window;
    457 
    458     GLFWvidmode*    modes;
    459     int             modeCount;
    460     GLFWvidmode     currentMode;
    461 
    462     GLFWgammaramp   originalRamp;
    463     GLFWgammaramp   currentRamp;
    464 
    465     // This is defined in the window API's platform.h
    466     _GLFW_PLATFORM_MONITOR_STATE;
    467 };
    468 
    469 // Cursor structure
    470 //
    471 struct _GLFWcursor
    472 {
    473     _GLFWcursor*    next;
    474 
    475     // This is defined in the window API's platform.h
    476     _GLFW_PLATFORM_CURSOR_STATE;
    477 };
    478 
    479 // Gamepad mapping element structure
    480 //
    481 struct _GLFWmapelement
    482 {
    483     uint8_t         type;
    484     uint8_t         index;
    485     int8_t          axisScale;
    486     int8_t          axisOffset;
    487 };
    488 
    489 // Gamepad mapping structure
    490 //
    491 struct _GLFWmapping
    492 {
    493     char            name[128];
    494     char            guid[33];
    495     _GLFWmapelement buttons[15];
    496     _GLFWmapelement axes[6];
    497 };
    498 
    499 // Joystick structure
    500 //
    501 struct _GLFWjoystick
    502 {
    503     GLFWbool        present;
    504     float*          axes;
    505     int             axisCount;
    506     unsigned char*  buttons;
    507     int             buttonCount;
    508     unsigned char*  hats;
    509     int             hatCount;
    510     char*           name;
    511     void*           userPointer;
    512     char            guid[33];
    513     _GLFWmapping*   mapping;
    514 
    515     // This is defined in the joystick API's joystick.h
    516     _GLFW_PLATFORM_JOYSTICK_STATE;
    517 };
    518 
    519 // Thread local storage structure
    520 //
    521 struct _GLFWtls
    522 {
    523     // This is defined in the platform's thread.h
    524     _GLFW_PLATFORM_TLS_STATE;
    525 };
    526 
    527 // Mutex structure
    528 //
    529 struct _GLFWmutex
    530 {
    531     // This is defined in the platform's thread.h
    532     _GLFW_PLATFORM_MUTEX_STATE;
    533 };
    534 
    535 // Library global data
    536 //
    537 struct _GLFWlibrary
    538 {
    539     GLFWbool            initialized;
    540 
    541     struct {
    542         _GLFWinitconfig init;
    543         _GLFWfbconfig   framebuffer;
    544         _GLFWwndconfig  window;
    545         _GLFWctxconfig  context;
    546         int             refreshRate;
    547     } hints;
    548 
    549     _GLFWerror*         errorListHead;
    550     _GLFWcursor*        cursorListHead;
    551     _GLFWwindow*        windowListHead;
    552 
    553     _GLFWmonitor**      monitors;
    554     int                 monitorCount;
    555 
    556     _GLFWjoystick       joysticks[GLFW_JOYSTICK_LAST + 1];
    557     _GLFWmapping*       mappings;
    558     int                 mappingCount;
    559 
    560     _GLFWtls            errorSlot;
    561     _GLFWtls            contextSlot;
    562     _GLFWmutex          errorLock;
    563 
    564     struct {
    565         uint64_t        offset;
    566         // This is defined in the platform's time.h
    567         _GLFW_PLATFORM_LIBRARY_TIMER_STATE;
    568     } timer;
    569 
    570     struct {
    571         GLFWbool        available;
    572         void*           handle;
    573         char*           extensions[2];
    574 #if !defined(_GLFW_VULKAN_STATIC)
    575         PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties;
    576         PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
    577 #endif
    578         GLFWbool        KHR_surface;
    579 #if defined(_GLFW_WIN32)
    580         GLFWbool        KHR_win32_surface;
    581 #elif defined(_GLFW_COCOA)
    582         GLFWbool        MVK_macos_surface;
    583         GLFWbool        EXT_metal_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 #endif
    590     } vk;
    591 
    592     struct {
    593         GLFWmonitorfun  monitor;
    594         GLFWjoystickfun joystick;
    595     } callbacks;
    596 
    597     // This is defined in the window API's platform.h
    598     _GLFW_PLATFORM_LIBRARY_WINDOW_STATE;
    599     // This is defined in the context API's context.h
    600     _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE;
    601     // This is defined in the platform's joystick.h
    602     _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE;
    603     // This is defined in egl_context.h
    604     _GLFW_EGL_LIBRARY_CONTEXT_STATE;
    605     // This is defined in osmesa_context.h
    606     _GLFW_OSMESA_LIBRARY_CONTEXT_STATE;
    607 };
    608 
    609 // Global state shared between compilation units of GLFW
    610 //
    611 extern _GLFWlibrary _glfw;
    612 
    613 
    614 //////////////////////////////////////////////////////////////////////////
    615 //////                       GLFW platform API                      //////
    616 //////////////////////////////////////////////////////////////////////////
    617 
    618 int _glfwPlatformInit(void);
    619 void _glfwPlatformTerminate(void);
    620 const char* _glfwPlatformGetVersionString(void);
    621 
    622 void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos);
    623 void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos);
    624 void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
    625 void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled);
    626 GLFWbool _glfwPlatformRawMouseMotionSupported(void);
    627 int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
    628                               const GLFWimage* image, int xhot, int yhot);
    629 int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape);
    630 void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
    631 void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor);
    632 
    633 const char* _glfwPlatformGetScancodeName(int scancode);
    634 int _glfwPlatformGetKeyScancode(int key);
    635 
    636 void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor);
    637 void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos);
    638 void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor,
    639                                          float* xscale, float* yscale);
    640 void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, int* xpos, int* ypos, int *width, int *height);
    641 GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count);
    642 void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode);
    643 GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp);
    644 void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);
    645 
    646 void _glfwPlatformSetClipboardString(const char* string);
    647 const char* _glfwPlatformGetClipboardString(void);
    648 
    649 int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode);
    650 void _glfwPlatformUpdateGamepadGUID(char* guid);
    651 
    652 uint64_t _glfwPlatformGetTimerValue(void);
    653 uint64_t _glfwPlatformGetTimerFrequency(void);
    654 
    655 int _glfwPlatformCreateWindow(_GLFWwindow* window,
    656                               const _GLFWwndconfig* wndconfig,
    657                               const _GLFWctxconfig* ctxconfig,
    658                               const _GLFWfbconfig* fbconfig);
    659 void _glfwPlatformDestroyWindow(_GLFWwindow* window);
    660 void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
    661 void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
    662                                 int count, const GLFWimage* images);
    663 void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos);
    664 void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos);
    665 void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height);
    666 void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
    667 void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
    668                                       int minwidth, int minheight,
    669                                       int maxwidth, int maxheight);
    670 void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom);
    671 void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height);
    672 void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
    673                                      int* left, int* top,
    674                                      int* right, int* bottom);
    675 void _glfwPlatformGetWindowContentScale(_GLFWwindow* window,
    676                                         float* xscale, float* yscale);
    677 void _glfwPlatformIconifyWindow(_GLFWwindow* window);
    678 void _glfwPlatformRestoreWindow(_GLFWwindow* window);
    679 void _glfwPlatformMaximizeWindow(_GLFWwindow* window);
    680 void _glfwPlatformShowWindow(_GLFWwindow* window);
    681 void _glfwPlatformHideWindow(_GLFWwindow* window);
    682 void _glfwPlatformRequestWindowAttention(_GLFWwindow* window);
    683 void _glfwPlatformFocusWindow(_GLFWwindow* window);
    684 void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor,
    685                                    int xpos, int ypos, int width, int height,
    686                                    int refreshRate);
    687 int _glfwPlatformWindowFocused(_GLFWwindow* window);
    688 int _glfwPlatformWindowIconified(_GLFWwindow* window);
    689 int _glfwPlatformWindowVisible(_GLFWwindow* window);
    690 int _glfwPlatformWindowMaximized(_GLFWwindow* window);
    691 int _glfwPlatformWindowHovered(_GLFWwindow* window);
    692 int _glfwPlatformFramebufferTransparent(_GLFWwindow* window);
    693 float _glfwPlatformGetWindowOpacity(_GLFWwindow* window);
    694 void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled);
    695 void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled);
    696 void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled);
    697 void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity);
    698 
    699 void _glfwPlatformPollEvents(void);
    700 void _glfwPlatformWaitEvents(void);
    701 void _glfwPlatformWaitEventsTimeout(double timeout);
    702 void _glfwPlatformPostEmptyEvent(void);
    703 
    704 void _glfwPlatformGetRequiredInstanceExtensions(char** extensions);
    705 int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
    706                                                       VkPhysicalDevice device,
    707                                                       uint32_t queuefamily);
    708 VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
    709                                           _GLFWwindow* window,
    710                                           const VkAllocationCallbacks* allocator,
    711                                           VkSurfaceKHR* surface);
    712 
    713 GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls);
    714 void _glfwPlatformDestroyTls(_GLFWtls* tls);
    715 void* _glfwPlatformGetTls(_GLFWtls* tls);
    716 void _glfwPlatformSetTls(_GLFWtls* tls, void* value);
    717 
    718 GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex);
    719 void _glfwPlatformDestroyMutex(_GLFWmutex* mutex);
    720 void _glfwPlatformLockMutex(_GLFWmutex* mutex);
    721 void _glfwPlatformUnlockMutex(_GLFWmutex* mutex);
    722 
    723 
    724 //////////////////////////////////////////////////////////////////////////
    725 //////                         GLFW event API                       //////
    726 //////////////////////////////////////////////////////////////////////////
    727 
    728 void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused);
    729 void _glfwInputWindowPos(_GLFWwindow* window, int xpos, int ypos);
    730 void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
    731 void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height);
    732 void _glfwInputWindowContentScale(_GLFWwindow* window,
    733                                   float xscale, float yscale);
    734 void _glfwInputWindowIconify(_GLFWwindow* window, GLFWbool iconified);
    735 void _glfwInputWindowMaximize(_GLFWwindow* window, GLFWbool maximized);
    736 void _glfwInputWindowDamage(_GLFWwindow* window);
    737 void _glfwInputWindowCloseRequest(_GLFWwindow* window);
    738 void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor);
    739 
    740 void _glfwInputKey(_GLFWwindow* window,
    741                    int key, int scancode, int action, int mods);
    742 void _glfwInputChar(_GLFWwindow* window,
    743                     unsigned int codepoint, int mods, GLFWbool plain);
    744 void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset);
    745 void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods);
    746 void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos);
    747 void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered);
    748 void _glfwInputDrop(_GLFWwindow* window, int count, const char** names);
    749 void _glfwInputJoystick(_GLFWjoystick* js, int event);
    750 void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value);
    751 void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value);
    752 void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value);
    753 
    754 void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement);
    755 void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window);
    756 
    757 #if defined(__GNUC__)
    758 void _glfwInputError(int code, const char* format, ...)
    759     __attribute__((format(printf, 2, 3)));
    760 #else
    761 void _glfwInputError(int code, const char* format, ...);
    762 #endif
    763 
    764 
    765 //////////////////////////////////////////////////////////////////////////
    766 //////                       GLFW internal API                      //////
    767 //////////////////////////////////////////////////////////////////////////
    768 
    769 GLFWbool _glfwStringInExtensionString(const char* string, const char* extensions);
    770 const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
    771                                          const _GLFWfbconfig* alternatives,
    772                                          unsigned int count);
    773 GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window,
    774                                     const _GLFWctxconfig* ctxconfig);
    775 GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig);
    776 
    777 const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor,
    778                                         const GLFWvidmode* desired);
    779 int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second);
    780 _GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM);
    781 void _glfwFreeMonitor(_GLFWmonitor* monitor);
    782 void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size);
    783 void _glfwFreeGammaArrays(GLFWgammaramp* ramp);
    784 void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
    785 
    786 _GLFWjoystick* _glfwAllocJoystick(const char* name,
    787                                   const char* guid,
    788                                   int axisCount,
    789                                   int buttonCount,
    790                                   int hatCount);
    791 void _glfwFreeJoystick(_GLFWjoystick* js);
    792 void _glfwCenterCursorInContentArea(_GLFWwindow* window);
    793 
    794 GLFWbool _glfwInitVulkan(int mode);
    795 void _glfwTerminateVulkan(void);
    796 const char* _glfwGetVulkanResultString(VkResult result);
    797 
    798 char* _glfw_strdup(const char* source);
    799 float _glfw_fminf(float a, float b);
    800 float _glfw_fmaxf(float a, float b);
    801