internal.h 27 KB

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