Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

572 righe
17 KiB

  1. /*************************************************************************
  2. * GLFW 3.3 - www.glfw.org
  3. * A library for OpenGL, window and input
  4. *------------------------------------------------------------------------
  5. * Copyright (c) 2002-2006 Marcus Geelnard
  6. * Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org>
  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. * * `GLFW_EXPOSE_NATIVE_MIR`
  61. *
  62. * The available context API macros are:
  63. * * `GLFW_EXPOSE_NATIVE_WGL`
  64. * * `GLFW_EXPOSE_NATIVE_NSGL`
  65. * * `GLFW_EXPOSE_NATIVE_GLX`
  66. * * `GLFW_EXPOSE_NATIVE_EGL`
  67. * * `GLFW_EXPOSE_NATIVE_OSMESA`
  68. *
  69. * These macros select which of the native access functions that are declared
  70. * and which platform-specific headers to include. It is then up your (by
  71. * definition platform-specific) code to handle which of these should be
  72. * defined.
  73. */
  74. /*************************************************************************
  75. * System headers and types
  76. *************************************************************************/
  77. #if defined(GLFW_EXPOSE_NATIVE_WIN32)
  78. // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
  79. // example to allow applications to correctly declare a GL_ARB_debug_output
  80. // callback) but windows.h assumes no one will define APIENTRY before it does
  81. #if defined(GLFW_APIENTRY_DEFINED)
  82. #undef APIENTRY
  83. #undef GLFW_APIENTRY_DEFINED
  84. #endif
  85. #include <windows.h>
  86. #elif defined(GLFW_EXPOSE_NATIVE_COCOA)
  87. #include <ApplicationServices/ApplicationServices.h>
  88. #if defined(__OBJC__)
  89. #import <Cocoa/Cocoa.h>
  90. #else
  91. typedef void* id;
  92. #endif
  93. #elif defined(GLFW_EXPOSE_NATIVE_X11)
  94. #include <X11/Xlib.h>
  95. #include <X11/extensions/Xrandr.h>
  96. #elif defined(GLFW_EXPOSE_NATIVE_WAYLAND)
  97. #include <wayland-client.h>
  98. #elif defined(GLFW_EXPOSE_NATIVE_MIR)
  99. #include <mir_toolkit/mir_client_library.h>
  100. #endif
  101. #if defined(GLFW_EXPOSE_NATIVE_WGL)
  102. /* WGL is declared by windows.h */
  103. #endif
  104. #if defined(GLFW_EXPOSE_NATIVE_NSGL)
  105. /* NSGL is declared by Cocoa.h */
  106. #endif
  107. #if defined(GLFW_EXPOSE_NATIVE_GLX)
  108. #include <GL/glx.h>
  109. #endif
  110. #if defined(GLFW_EXPOSE_NATIVE_EGL)
  111. #include <EGL/egl.h>
  112. #endif
  113. #if defined(GLFW_EXPOSE_NATIVE_OSMESA)
  114. #include <GL/osmesa.h>
  115. #endif
  116. /*************************************************************************
  117. * Functions
  118. *************************************************************************/
  119. #if defined(GLFW_EXPOSE_NATIVE_WIN32)
  120. /*! @brief Returns the adapter device name of the specified monitor.
  121. *
  122. * @return The UTF-8 encoded adapter device name (for example `\\.\DISPLAY1`)
  123. * of the specified monitor, or `NULL` if an [error](@ref error_handling)
  124. * occurred.
  125. *
  126. * @thread_safety This function may be called from any thread. Access is not
  127. * synchronized.
  128. *
  129. * @since Added in version 3.1.
  130. *
  131. * @ingroup native
  132. */
  133. GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor);
  134. /*! @brief Returns the display device name of the specified monitor.
  135. *
  136. * @return The UTF-8 encoded display device name (for example
  137. * `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an
  138. * [error](@ref error_handling) occurred.
  139. *
  140. * @thread_safety This function may be called from any thread. Access is not
  141. * synchronized.
  142. *
  143. * @since Added in version 3.1.
  144. *
  145. * @ingroup native
  146. */
  147. GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor);
  148. /*! @brief Returns the `HWND` of the specified window.
  149. *
  150. * @return The `HWND` of the specified window, or `NULL` if an
  151. * [error](@ref error_handling) occurred.
  152. *
  153. * @thread_safety This function may be called from any thread. Access is not
  154. * synchronized.
  155. *
  156. * @since Added in version 3.0.
  157. *
  158. * @ingroup native
  159. */
  160. GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window);
  161. #endif
  162. #if defined(GLFW_EXPOSE_NATIVE_WGL)
  163. /*! @brief Returns the `HGLRC` of the specified window.
  164. *
  165. * @return The `HGLRC` of the specified window, or `NULL` if an
  166. * [error](@ref error_handling) occurred.
  167. *
  168. * @thread_safety This function may be called from any thread. Access is not
  169. * synchronized.
  170. *
  171. * @since Added in version 3.0.
  172. *
  173. * @ingroup native
  174. */
  175. GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window);
  176. #endif
  177. #if defined(GLFW_EXPOSE_NATIVE_COCOA)
  178. /*! @brief Returns the `CGDirectDisplayID` of the specified monitor.
  179. *
  180. * @return The `CGDirectDisplayID` of the specified monitor, or
  181. * `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred.
  182. *
  183. * @thread_safety This function may be called from any thread. Access is not
  184. * synchronized.
  185. *
  186. * @since Added in version 3.1.
  187. *
  188. * @ingroup native
  189. */
  190. GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
  191. /*! @brief Returns the `NSWindow` of the specified window.
  192. *
  193. * @return The `NSWindow` of the specified window, or `nil` if an
  194. * [error](@ref error_handling) occurred.
  195. *
  196. * @thread_safety This function may be called from any thread. Access is not
  197. * synchronized.
  198. *
  199. * @since Added in version 3.0.
  200. *
  201. * @ingroup native
  202. */
  203. GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window);
  204. #endif
  205. #if defined(GLFW_EXPOSE_NATIVE_NSGL)
  206. /*! @brief Returns the `NSOpenGLContext` of the specified window.
  207. *
  208. * @return The `NSOpenGLContext` of the specified window, or `nil` if an
  209. * [error](@ref error_handling) occurred.
  210. *
  211. * @thread_safety This function may be called from any thread. Access is not
  212. * synchronized.
  213. *
  214. * @since Added in version 3.0.
  215. *
  216. * @ingroup native
  217. */
  218. GLFWAPI id glfwGetNSGLContext(GLFWwindow* window);
  219. #endif
  220. #if defined(GLFW_EXPOSE_NATIVE_X11)
  221. /*! @brief Returns the `Display` used by GLFW.
  222. *
  223. * @return The `Display` used by GLFW, or `NULL` if an
  224. * [error](@ref error_handling) occurred.
  225. *
  226. * @thread_safety This function may be called from any thread. Access is not
  227. * synchronized.
  228. *
  229. * @since Added in version 3.0.
  230. *
  231. * @ingroup native
  232. */
  233. GLFWAPI Display* glfwGetX11Display(void);
  234. /*! @brief Returns the `RRCrtc` of the specified monitor.
  235. *
  236. * @return The `RRCrtc` of the specified monitor, or `None` if an
  237. * [error](@ref error_handling) occurred.
  238. *
  239. * @thread_safety This function may be called from any thread. Access is not
  240. * synchronized.
  241. *
  242. * @since Added in version 3.1.
  243. *
  244. * @ingroup native
  245. */
  246. GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor);
  247. /*! @brief Returns the `RROutput` of the specified monitor.
  248. *
  249. * @return The `RROutput` of the specified monitor, or `None` if an
  250. * [error](@ref error_handling) occurred.
  251. *
  252. * @thread_safety This function may be called from any thread. Access is not
  253. * synchronized.
  254. *
  255. * @since Added in version 3.1.
  256. *
  257. * @ingroup native
  258. */
  259. GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor);
  260. /*! @brief Returns the `Window` of the specified window.
  261. *
  262. * @return The `Window` of the specified window, or `None` if an
  263. * [error](@ref error_handling) occurred.
  264. *
  265. * @thread_safety This function may be called from any thread. Access is not
  266. * synchronized.
  267. *
  268. * @since Added in version 3.0.
  269. *
  270. * @ingroup native
  271. */
  272. GLFWAPI Window glfwGetX11Window(GLFWwindow* window);
  273. /*! @brief Sets the current primary selection to the specified string.
  274. *
  275. * @param[in] string A UTF-8 encoded string.
  276. *
  277. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
  278. * GLFW_PLATFORM_ERROR.
  279. *
  280. * @pointer_lifetime The specified string is copied before this function
  281. * returns.
  282. *
  283. * @thread_safety This function must only be called from the main thread.
  284. *
  285. * @sa @ref clipboard
  286. * @sa glfwGetX11SelectionString
  287. * @sa glfwSetClipboardString
  288. *
  289. * @since Added in version 3.3.
  290. *
  291. * @ingroup native
  292. */
  293. GLFWAPI void glfwSetX11SelectionString(const char* string);
  294. /*! @brief Returns the contents of the current primary selection as a string.
  295. *
  296. * If the selection is empty or if its contents cannot be converted, `NULL`
  297. * is returned and a @ref GLFW_FORMAT_UNAVAILABLE error is generated.
  298. *
  299. * @return The contents of the selection as a UTF-8 encoded string, or `NULL`
  300. * if an [error](@ref error_handling) occurred.
  301. *
  302. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
  303. * GLFW_PLATFORM_ERROR.
  304. *
  305. * @pointer_lifetime The returned string is allocated and freed by GLFW. You
  306. * should not free it yourself. It is valid until the next call to @ref
  307. * glfwGetX11SelectionString or @ref glfwSetX11SelectionString, or until the
  308. * library is terminated.
  309. *
  310. * @thread_safety This function must only be called from the main thread.
  311. *
  312. * @sa @ref clipboard
  313. * @sa glfwSetX11SelectionString
  314. * @sa glfwGetClipboardString
  315. *
  316. * @since Added in version 3.3.
  317. *
  318. * @ingroup native
  319. */
  320. GLFWAPI const char* glfwGetX11SelectionString(void);
  321. #endif
  322. #if defined(GLFW_EXPOSE_NATIVE_GLX)
  323. /*! @brief Returns the `GLXContext` of the specified window.
  324. *
  325. * @return The `GLXContext` of the specified window, or `NULL` if an
  326. * [error](@ref error_handling) occurred.
  327. *
  328. * @thread_safety This function may be called from any thread. Access is not
  329. * synchronized.
  330. *
  331. * @since Added in version 3.0.
  332. *
  333. * @ingroup native
  334. */
  335. GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window);
  336. /*! @brief Returns the `GLXWindow` of the specified window.
  337. *
  338. * @return The `GLXWindow` of the specified window, or `None` if an
  339. * [error](@ref error_handling) occurred.
  340. *
  341. * @thread_safety This function may be called from any thread. Access is not
  342. * synchronized.
  343. *
  344. * @since Added in version 3.2.
  345. *
  346. * @ingroup native
  347. */
  348. GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* window);
  349. #endif
  350. #if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
  351. /*! @brief Returns the `struct wl_display*` used by GLFW.
  352. *
  353. * @return The `struct wl_display*` used by GLFW, or `NULL` if an
  354. * [error](@ref error_handling) occurred.
  355. *
  356. * @thread_safety This function may be called from any thread. Access is not
  357. * synchronized.
  358. *
  359. * @since Added in version 3.2.
  360. *
  361. * @ingroup native
  362. */
  363. GLFWAPI struct wl_display* glfwGetWaylandDisplay(void);
  364. /*! @brief Returns the `struct wl_output*` of the specified monitor.
  365. *
  366. * @return The `struct wl_output*` of the specified monitor, or `NULL` if an
  367. * [error](@ref error_handling) occurred.
  368. *
  369. * @thread_safety This function may be called from any thread. Access is not
  370. * synchronized.
  371. *
  372. * @since Added in version 3.2.
  373. *
  374. * @ingroup native
  375. */
  376. GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor);
  377. /*! @brief Returns the main `struct wl_surface*` of the specified window.
  378. *
  379. * @return The main `struct wl_surface*` of the specified window, or `NULL` if
  380. * an [error](@ref error_handling) occurred.
  381. *
  382. * @thread_safety This function may be called from any thread. Access is not
  383. * synchronized.
  384. *
  385. * @since Added in version 3.2.
  386. *
  387. * @ingroup native
  388. */
  389. GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window);
  390. #endif
  391. #if defined(GLFW_EXPOSE_NATIVE_MIR)
  392. /*! @brief Returns the `MirConnection*` used by GLFW.
  393. *
  394. * @return The `MirConnection*` used by GLFW, or `NULL` if an
  395. * [error](@ref error_handling) occurred.
  396. *
  397. * @thread_safety This function may be called from any thread. Access is not
  398. * synchronized.
  399. *
  400. * @since Added in version 3.2.
  401. *
  402. * @ingroup native
  403. */
  404. GLFWAPI MirConnection* glfwGetMirDisplay(void);
  405. /*! @brief Returns the Mir output ID of the specified monitor.
  406. *
  407. * @return The Mir output ID of the specified monitor, or zero if an
  408. * [error](@ref error_handling) occurred.
  409. *
  410. * @thread_safety This function may be called from any thread. Access is not
  411. * synchronized.
  412. *
  413. * @since Added in version 3.2.
  414. *
  415. * @ingroup native
  416. */
  417. GLFWAPI int glfwGetMirMonitor(GLFWmonitor* monitor);
  418. /*! @brief Returns the `MirWindow*` of the specified window.
  419. *
  420. * @return The `MirWindow*` of the specified window, or `NULL` if an
  421. * [error](@ref error_handling) occurred.
  422. *
  423. * @thread_safety This function may be called from any thread. Access is not
  424. * synchronized.
  425. *
  426. * @since Added in version 3.2.
  427. *
  428. * @ingroup native
  429. */
  430. GLFWAPI MirWindow* glfwGetMirWindow(GLFWwindow* window);
  431. #endif
  432. #if defined(GLFW_EXPOSE_NATIVE_EGL)
  433. /*! @brief Returns the `EGLDisplay` used by GLFW.
  434. *
  435. * @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an
  436. * [error](@ref error_handling) occurred.
  437. *
  438. * @thread_safety This function may be called from any thread. Access is not
  439. * synchronized.
  440. *
  441. * @since Added in version 3.0.
  442. *
  443. * @ingroup native
  444. */
  445. GLFWAPI EGLDisplay glfwGetEGLDisplay(void);
  446. /*! @brief Returns the `EGLContext` of the specified window.
  447. *
  448. * @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an
  449. * [error](@ref error_handling) occurred.
  450. *
  451. * @thread_safety This function may be called from any thread. Access is not
  452. * synchronized.
  453. *
  454. * @since Added in version 3.0.
  455. *
  456. * @ingroup native
  457. */
  458. GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window);
  459. /*! @brief Returns the `EGLSurface` of the specified window.
  460. *
  461. * @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an
  462. * [error](@ref error_handling) occurred.
  463. *
  464. * @thread_safety This function may be called from any thread. Access is not
  465. * synchronized.
  466. *
  467. * @since Added in version 3.0.
  468. *
  469. * @ingroup native
  470. */
  471. GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window);
  472. #endif
  473. #if defined(GLFW_EXPOSE_NATIVE_OSMESA)
  474. /*! @brief Retrieves the color buffer associated with the specified window.
  475. *
  476. * @param[in] window The window whose color buffer to retrieve.
  477. * @param[out] width Where to store the width of the color buffer, or `NULL`.
  478. * @param[out] height Where to store the height of the color buffer, or `NULL`.
  479. * @param[out] format Where to store the OSMesa pixel format of the color
  480. * buffer, or `NULL`.
  481. * @param[out] buffer Where to store the address of the color buffer, or
  482. * `NULL`.
  483. * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an
  484. * [error](@ref error_handling) occurred.
  485. *
  486. * @thread_safety This function may be called from any thread. Access is not
  487. * synchronized.
  488. *
  489. * @since Added in version 3.3.
  490. *
  491. * @ingroup native
  492. */
  493. GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* window, int* width, int* height, int* format, void** buffer);
  494. /*! @brief Retrieves the depth buffer associated with the specified window.
  495. *
  496. * @param[in] window The window whose depth buffer to retrieve.
  497. * @param[out] width Where to store the width of the depth buffer, or `NULL`.
  498. * @param[out] height Where to store the height of the depth buffer, or `NULL`.
  499. * @param[out] bytesPerValue Where to store the number of bytes per depth
  500. * buffer element, or `NULL`.
  501. * @param[out] buffer Where to store the address of the depth buffer, or
  502. * `NULL`.
  503. * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an
  504. * [error](@ref error_handling) occurred.
  505. *
  506. * @thread_safety This function may be called from any thread. Access is not
  507. * synchronized.
  508. *
  509. * @since Added in version 3.3.
  510. *
  511. * @ingroup native
  512. */
  513. GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* window, int* width, int* height, int* bytesPerValue, void** buffer);
  514. /*! @brief Returns the `OSMesaContext` of the specified window.
  515. *
  516. * @return The `OSMesaContext` of the specified window, or `NULL` if an
  517. * [error](@ref error_handling) occurred.
  518. *
  519. * @thread_safety This function may be called from any thread. Access is not
  520. * synchronized.
  521. *
  522. * @since Added in version 3.3.
  523. *
  524. * @ingroup native
  525. */
  526. GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* window);
  527. #endif
  528. #ifdef __cplusplus
  529. }
  530. #endif
  531. #endif /* _glfw3_native_h_ */