2
0

glfw3native.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /*************************************************************************
  2. * GLFW 3.4 - www.glfw.org
  3. * A library for OpenGL, window and input
  4. *------------------------------------------------------------------------
  5. * Copyright (c) 2002-2006 Marcus Geelnard
  6. * Copyright (c) 2006-2018 Camilla Löwy <[email protected]>
  7. *
  8. * This software is provided 'as-is', without any express or implied
  9. * warranty. In no event will the authors be held liable for any damages
  10. * arising from the use of this software.
  11. *
  12. * Permission is granted to anyone to use this software for any purpose,
  13. * including commercial applications, and to alter it and redistribute it
  14. * freely, subject to the following restrictions:
  15. *
  16. * 1. The origin of this software must not be misrepresented; you must not
  17. * claim that you wrote the original software. If you use this software
  18. * in a product, an acknowledgment in the product documentation would
  19. * be appreciated but is not required.
  20. *
  21. * 2. Altered source versions must be plainly marked as such, and must not
  22. * be misrepresented as being the original software.
  23. *
  24. * 3. This notice may not be removed or altered from any source
  25. * distribution.
  26. *
  27. *************************************************************************/
  28. #ifndef _glfw3_native_h_
  29. #define _glfw3_native_h_
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /*************************************************************************
  34. * Doxygen documentation
  35. *************************************************************************/
  36. /*! @file glfw3native.h
  37. * @brief The header of the native access functions.
  38. *
  39. * This is the header file of the native access functions. See @ref native for
  40. * more information.
  41. */
  42. /*! @defgroup native Native access
  43. * @brief Functions related to accessing native handles.
  44. *
  45. * **By using the native access functions you assert that you know what you're
  46. * doing and how to fix problems caused by using them. If you don't, you
  47. * shouldn't be using them.**
  48. *
  49. * Before the inclusion of @ref glfw3native.h, you may define zero or more
  50. * window system API macro and zero or more context creation API macros.
  51. *
  52. * The chosen backends must match those the library was compiled for. Failure
  53. * to do this will cause a link-time error.
  54. *
  55. * The available window API macros are:
  56. * * `GLFW_EXPOSE_NATIVE_WIN32`
  57. * * `GLFW_EXPOSE_NATIVE_COCOA`
  58. * * `GLFW_EXPOSE_NATIVE_X11`
  59. * * `GLFW_EXPOSE_NATIVE_WAYLAND`
  60. *
  61. * The available context API macros are:
  62. * * `GLFW_EXPOSE_NATIVE_WGL`
  63. * * `GLFW_EXPOSE_NATIVE_NSGL`
  64. * * `GLFW_EXPOSE_NATIVE_GLX`
  65. * * `GLFW_EXPOSE_NATIVE_EGL`
  66. * * `GLFW_EXPOSE_NATIVE_OSMESA`
  67. *
  68. * These macros select which of the native access functions that are declared
  69. * and which platform-specific headers to include. It is then up your (by
  70. * definition platform-specific) code to handle which of these should be
  71. * defined.
  72. */
  73. /*************************************************************************
  74. * System headers and types
  75. *************************************************************************/
  76. #if defined(GLFW_EXPOSE_NATIVE_WIN32) || defined(GLFW_EXPOSE_NATIVE_WGL)
  77. // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
  78. // example to allow applications to correctly declare a GL_ARB_debug_output
  79. // callback) but windows.h assumes no one will define APIENTRY before it does
  80. #if defined(GLFW_APIENTRY_DEFINED)
  81. #undef APIENTRY
  82. #undef GLFW_APIENTRY_DEFINED
  83. #endif
  84. #include <windows.h>
  85. #elif defined(GLFW_EXPOSE_NATIVE_COCOA) || defined(GLFW_EXPOSE_NATIVE_NSGL)
  86. #if defined(__OBJC__)
  87. #import <Cocoa/Cocoa.h>
  88. #else
  89. #include <ApplicationServices/ApplicationServices.h>
  90. typedef void* id;
  91. #endif
  92. #elif defined(GLFW_EXPOSE_NATIVE_X11) || defined(GLFW_EXPOSE_NATIVE_GLX)
  93. #include <X11/Xlib.h>
  94. #include <X11/extensions/Xrandr.h>
  95. #elif defined(GLFW_EXPOSE_NATIVE_WAYLAND)
  96. #include <wayland-client.h>
  97. #endif
  98. #if defined(GLFW_EXPOSE_NATIVE_WGL)
  99. /* WGL is declared by windows.h */
  100. #endif
  101. #if defined(GLFW_EXPOSE_NATIVE_NSGL)
  102. /* NSGL is declared by Cocoa.h */
  103. #endif
  104. #if defined(GLFW_EXPOSE_NATIVE_GLX)
  105. #include <GL/glx.h>
  106. #endif
  107. #if defined(GLFW_EXPOSE_NATIVE_EGL)
  108. #include <EGL/egl.h>
  109. #endif
  110. #if defined(GLFW_EXPOSE_NATIVE_OSMESA)
  111. #include <GL/osmesa.h>
  112. #endif
  113. /*************************************************************************
  114. * Functions
  115. *************************************************************************/
  116. #if defined(GLFW_EXPOSE_NATIVE_WIN32)
  117. /*! @brief Returns the adapter device name of the specified monitor.
  118. *
  119. * @return The UTF-8 encoded adapter device name (for example `\\.\DISPLAY1`)
  120. * of the specified monitor, or `NULL` if an [error](@ref error_handling)
  121. * occurred.
  122. *
  123. * @thread_safety This function may be called from any thread. Access is not
  124. * synchronized.
  125. *
  126. * @since Added in version 3.1.
  127. *
  128. * @ingroup native
  129. */
  130. GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor);
  131. /*! @brief Returns the display device name of the specified monitor.
  132. *
  133. * @return The UTF-8 encoded display device name (for example
  134. * `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an
  135. * [error](@ref error_handling) occurred.
  136. *
  137. * @thread_safety This function may be called from any thread. Access is not
  138. * synchronized.
  139. *
  140. * @since Added in version 3.1.
  141. *
  142. * @ingroup native
  143. */
  144. GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor);
  145. /*! @brief Returns the `HWND` of the specified window.
  146. *
  147. * @return The `HWND` of the specified window, or `NULL` if an
  148. * [error](@ref error_handling) occurred.
  149. *
  150. * @thread_safety This function may be called from any thread. Access is not
  151. * synchronized.
  152. *
  153. * @since Added in version 3.0.
  154. *
  155. * @ingroup native
  156. */
  157. GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window);
  158. #endif
  159. #if defined(GLFW_EXPOSE_NATIVE_WGL)
  160. /*! @brief Returns the `HGLRC` of the specified window.
  161. *
  162. * @return The `HGLRC` of the specified window, or `NULL` if an
  163. * [error](@ref error_handling) occurred.
  164. *
  165. * @thread_safety This function may be called from any thread. Access is not
  166. * synchronized.
  167. *
  168. * @since Added in version 3.0.
  169. *
  170. * @ingroup native
  171. */
  172. GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window);
  173. #endif
  174. #if defined(GLFW_EXPOSE_NATIVE_COCOA)
  175. /*! @brief Returns the `CGDirectDisplayID` of the specified monitor.
  176. *
  177. * @return The `CGDirectDisplayID` of the specified monitor, or
  178. * `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred.
  179. *
  180. * @thread_safety This function may be called from any thread. Access is not
  181. * synchronized.
  182. *
  183. * @since Added in version 3.1.
  184. *
  185. * @ingroup native
  186. */
  187. GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
  188. /*! @brief Returns the `NSWindow` of the specified window.
  189. *
  190. * @return The `NSWindow` of the specified window, or `nil` if an
  191. * [error](@ref error_handling) occurred.
  192. *
  193. * @thread_safety This function may be called from any thread. Access is not
  194. * synchronized.
  195. *
  196. * @since Added in version 3.0.
  197. *
  198. * @ingroup native
  199. */
  200. GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window);
  201. #endif
  202. #if defined(GLFW_EXPOSE_NATIVE_NSGL)
  203. /*! @brief Returns the `NSOpenGLContext` of the specified window.
  204. *
  205. * @return The `NSOpenGLContext` of the specified window, or `nil` if an
  206. * [error](@ref error_handling) occurred.
  207. *
  208. * @thread_safety This function may be called from any thread. Access is not
  209. * synchronized.
  210. *
  211. * @since Added in version 3.0.
  212. *
  213. * @ingroup native
  214. */
  215. GLFWAPI id glfwGetNSGLContext(GLFWwindow* window);
  216. #endif
  217. #if defined(GLFW_EXPOSE_NATIVE_X11)
  218. /*! @brief Returns the `Display` used by GLFW.
  219. *
  220. * @return The `Display` used by GLFW, or `NULL` if an
  221. * [error](@ref error_handling) occurred.
  222. *
  223. * @thread_safety This function may be called from any thread. Access is not
  224. * synchronized.
  225. *
  226. * @since Added in version 3.0.
  227. *
  228. * @ingroup native
  229. */
  230. GLFWAPI Display* glfwGetX11Display(void);
  231. /*! @brief Returns the `RRCrtc` of the specified monitor.
  232. *
  233. * @return The `RRCrtc` of the specified monitor, or `None` if an
  234. * [error](@ref error_handling) occurred.
  235. *
  236. * @thread_safety This function may be called from any thread. Access is not
  237. * synchronized.
  238. *
  239. * @since Added in version 3.1.
  240. *
  241. * @ingroup native
  242. */
  243. GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor);
  244. /*! @brief Returns the `RROutput` of the specified monitor.
  245. *
  246. * @return The `RROutput` of the specified monitor, or `None` if an
  247. * [error](@ref error_handling) occurred.
  248. *
  249. * @thread_safety This function may be called from any thread. Access is not
  250. * synchronized.
  251. *
  252. * @since Added in version 3.1.
  253. *
  254. * @ingroup native
  255. */
  256. GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor);
  257. /*! @brief Returns the `Window` of the specified window.
  258. *
  259. * @return The `Window` of the specified window, or `None` if an
  260. * [error](@ref error_handling) occurred.
  261. *
  262. * @thread_safety This function may be called from any thread. Access is not
  263. * synchronized.
  264. *
  265. * @since Added in version 3.0.
  266. *
  267. * @ingroup native
  268. */
  269. GLFWAPI Window glfwGetX11Window(GLFWwindow* window);
  270. /*! @brief Sets the current primary selection to the specified string.
  271. *
  272. * @param[in] string A UTF-8 encoded string.
  273. *
  274. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
  275. * GLFW_PLATFORM_ERROR.
  276. *
  277. * @pointer_lifetime The specified string is copied before this function
  278. * returns.
  279. *
  280. * @thread_safety This function must only be called from the main thread.
  281. *
  282. * @sa @ref clipboard
  283. * @sa glfwGetX11SelectionString
  284. * @sa glfwSetClipboardString
  285. *
  286. * @since Added in version 3.3.
  287. *
  288. * @ingroup native
  289. */
  290. GLFWAPI void glfwSetX11SelectionString(const char* string);
  291. /*! @brief Returns the contents of the current primary selection as a string.
  292. *
  293. * If the selection is empty or if its contents cannot be converted, `NULL`
  294. * is returned and a @ref GLFW_FORMAT_UNAVAILABLE error is generated.
  295. *
  296. * @return The contents of the selection as a UTF-8 encoded string, or `NULL`
  297. * if an [error](@ref error_handling) occurred.
  298. *
  299. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
  300. * GLFW_PLATFORM_ERROR.
  301. *
  302. * @pointer_lifetime The returned string is allocated and freed by GLFW. You
  303. * should not free it yourself. It is valid until the next call to @ref
  304. * glfwGetX11SelectionString or @ref glfwSetX11SelectionString, or until the
  305. * library is terminated.
  306. *
  307. * @thread_safety This function must only be called from the main thread.
  308. *
  309. * @sa @ref clipboard
  310. * @sa glfwSetX11SelectionString
  311. * @sa glfwGetClipboardString
  312. *
  313. * @since Added in version 3.3.
  314. *
  315. * @ingroup native
  316. */
  317. GLFWAPI const char* glfwGetX11SelectionString(void);
  318. #endif
  319. #if defined(GLFW_EXPOSE_NATIVE_GLX)
  320. /*! @brief Returns the `GLXContext` of the specified window.
  321. *
  322. * @return The `GLXContext` of the specified window, or `NULL` if an
  323. * [error](@ref error_handling) occurred.
  324. *
  325. * @thread_safety This function may be called from any thread. Access is not
  326. * synchronized.
  327. *
  328. * @since Added in version 3.0.
  329. *
  330. * @ingroup native
  331. */
  332. GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window);
  333. /*! @brief Returns the `GLXWindow` of the specified window.
  334. *
  335. * @return The `GLXWindow` of the specified window, or `None` if an
  336. * [error](@ref error_handling) occurred.
  337. *
  338. * @thread_safety This function may be called from any thread. Access is not
  339. * synchronized.
  340. *
  341. * @since Added in version 3.2.
  342. *
  343. * @ingroup native
  344. */
  345. GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* window);
  346. #endif
  347. #if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
  348. /*! @brief Returns the `struct wl_display*` used by GLFW.
  349. *
  350. * @return The `struct wl_display*` used by GLFW, or `NULL` if an
  351. * [error](@ref error_handling) occurred.
  352. *
  353. * @thread_safety This function may be called from any thread. Access is not
  354. * synchronized.
  355. *
  356. * @since Added in version 3.2.
  357. *
  358. * @ingroup native
  359. */
  360. GLFWAPI struct wl_display* glfwGetWaylandDisplay(void);
  361. /*! @brief Returns the `struct wl_output*` of the specified monitor.
  362. *
  363. * @return The `struct wl_output*` of the specified monitor, or `NULL` if an
  364. * [error](@ref error_handling) occurred.
  365. *
  366. * @thread_safety This function may be called from any thread. Access is not
  367. * synchronized.
  368. *
  369. * @since Added in version 3.2.
  370. *
  371. * @ingroup native
  372. */
  373. GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor);
  374. /*! @brief Returns the main `struct wl_surface*` of the specified window.
  375. *
  376. * @return The main `struct wl_surface*` of the specified window, or `NULL` if
  377. * an [error](@ref error_handling) occurred.
  378. *
  379. * @thread_safety This function may be called from any thread. Access is not
  380. * synchronized.
  381. *
  382. * @since Added in version 3.2.
  383. *
  384. * @ingroup native
  385. */
  386. GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window);
  387. #endif
  388. #if defined(GLFW_EXPOSE_NATIVE_EGL)
  389. /*! @brief Returns the `EGLDisplay` used by GLFW.
  390. *
  391. * @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an
  392. * [error](@ref error_handling) occurred.
  393. *
  394. * @thread_safety This function may be called from any thread. Access is not
  395. * synchronized.
  396. *
  397. * @since Added in version 3.0.
  398. *
  399. * @ingroup native
  400. */
  401. GLFWAPI EGLDisplay glfwGetEGLDisplay(void);
  402. /*! @brief Returns the `EGLContext` of the specified window.
  403. *
  404. * @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an
  405. * [error](@ref error_handling) occurred.
  406. *
  407. * @thread_safety This function may be called from any thread. Access is not
  408. * synchronized.
  409. *
  410. * @since Added in version 3.0.
  411. *
  412. * @ingroup native
  413. */
  414. GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window);
  415. /*! @brief Returns the `EGLSurface` of the specified window.
  416. *
  417. * @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an
  418. * [error](@ref error_handling) occurred.
  419. *
  420. * @thread_safety This function may be called from any thread. Access is not
  421. * synchronized.
  422. *
  423. * @since Added in version 3.0.
  424. *
  425. * @ingroup native
  426. */
  427. GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window);
  428. #endif
  429. #if defined(GLFW_EXPOSE_NATIVE_OSMESA)
  430. /*! @brief Retrieves the color buffer associated with the specified window.
  431. *
  432. * @param[in] window The window whose color buffer to retrieve.
  433. * @param[out] width Where to store the width of the color buffer, or `NULL`.
  434. * @param[out] height Where to store the height of the color buffer, or `NULL`.
  435. * @param[out] format Where to store the OSMesa pixel format of the color
  436. * buffer, or `NULL`.
  437. * @param[out] buffer Where to store the address of the color buffer, or
  438. * `NULL`.
  439. * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an
  440. * [error](@ref error_handling) occurred.
  441. *
  442. * @thread_safety This function may be called from any thread. Access is not
  443. * synchronized.
  444. *
  445. * @since Added in version 3.3.
  446. *
  447. * @ingroup native
  448. */
  449. GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* window, int* width, int* height, int* format, void** buffer);
  450. /*! @brief Retrieves the depth buffer associated with the specified window.
  451. *
  452. * @param[in] window The window whose depth buffer to retrieve.
  453. * @param[out] width Where to store the width of the depth buffer, or `NULL`.
  454. * @param[out] height Where to store the height of the depth buffer, or `NULL`.
  455. * @param[out] bytesPerValue Where to store the number of bytes per depth
  456. * buffer element, or `NULL`.
  457. * @param[out] buffer Where to store the address of the depth buffer, or
  458. * `NULL`.
  459. * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an
  460. * [error](@ref error_handling) occurred.
  461. *
  462. * @thread_safety This function may be called from any thread. Access is not
  463. * synchronized.
  464. *
  465. * @since Added in version 3.3.
  466. *
  467. * @ingroup native
  468. */
  469. GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* window, int* width, int* height, int* bytesPerValue, void** buffer);
  470. /*! @brief Returns the `OSMesaContext` of the specified window.
  471. *
  472. * @return The `OSMesaContext` of the specified window, or `NULL` if an
  473. * [error](@ref error_handling) occurred.
  474. *
  475. * @thread_safety This function may be called from any thread. Access is not
  476. * synchronized.
  477. *
  478. * @since Added in version 3.3.
  479. *
  480. * @ingroup native
  481. */
  482. GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* window);
  483. #endif
  484. #ifdef __cplusplus
  485. }
  486. #endif
  487. #endif /* _glfw3_native_h_ */