1 /*************************************************************************
2  * GLFW 3.1 - www.glfw.org
3  * A library for OpenGL, window and input
4  *------------------------------------------------------------------------
5  * Copyright (c) 2002-2006 Marcus Geelnard
6  * Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.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 
29 #ifndef _glfw3_native_h_
30 #define _glfw3_native_h_
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 
37 /*************************************************************************
38  * Doxygen documentation
39  *************************************************************************/
40 
41 /*! @defgroup native Native access
42  *
43  *  **By using the native access functions you assert that you know what you're
44  *  doing and how to fix problems caused by using them.  If you don't, you
45  *  shouldn't be using them.**
46  *
47  *  Before the inclusion of @ref glfw3native.h, you must define exactly one
48  *  window system API macro and exactly one context creation API macro.  Failure
49  *  to do this will cause a compile-time error.
50  *
51  *  The available window API macros are:
52  *  * `GLFW_EXPOSE_NATIVE_WIN32`
53  *  * `GLFW_EXPOSE_NATIVE_COCOA`
54  *  * `GLFW_EXPOSE_NATIVE_X11`
55  *
56  *  The available context API macros are:
57  *  * `GLFW_EXPOSE_NATIVE_WGL`
58  *  * `GLFW_EXPOSE_NATIVE_NSGL`
59  *  * `GLFW_EXPOSE_NATIVE_GLX`
60  *  * `GLFW_EXPOSE_NATIVE_EGL`
61  *
62  *  These macros select which of the native access functions that are declared
63  *  and which platform-specific headers to include.  It is then up your (by
64  *  definition platform-specific) code to handle which of these should be
65  *  defined.
66  */
67 
68 
69 /*************************************************************************
70  * System headers and types
71  *************************************************************************/
72 
73 #if defined(GLFW_EXPOSE_NATIVE_WIN32)
74  // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
75  // example to allow applications to correctly declare a GL_ARB_debug_output
76  // callback) but windows.h assumes no one will define APIENTRY before it does
77  #undef APIENTRY
78  #include <windows.h>
79 #elif defined(GLFW_EXPOSE_NATIVE_COCOA)
80  #include <ApplicationServices/ApplicationServices.h>
81  #if defined(__OBJC__)
82   #import <Cocoa/Cocoa.h>
83  #else
84   typedef void* id;
85  #endif
86 #elif defined(GLFW_EXPOSE_NATIVE_X11)
87  #include <X11/Xlib.h>
88  #include <X11/extensions/Xrandr.h>
89 #else
90  #error "No window API selected"
91 #endif
92 
93 #if defined(GLFW_EXPOSE_NATIVE_WGL)
94  /* WGL is declared by windows.h */
95 #elif defined(GLFW_EXPOSE_NATIVE_NSGL)
96  /* NSGL is declared by Cocoa.h */
97 #elif defined(GLFW_EXPOSE_NATIVE_GLX)
98  #include <GL/glx.h>
99 #elif defined(GLFW_EXPOSE_NATIVE_EGL)
100  #include <EGL/egl.h>
101 #else
102  #error "No context API selected"
103 #endif
104 
105 
106 /*************************************************************************
107  * Functions
108  *************************************************************************/
109 
110 #if defined(GLFW_EXPOSE_NATIVE_WIN32)
111 /*! @brief Returns the adapter device name of the specified monitor.
112  *
113  *  @return The UTF-8 encoded adapter device name (for example `\\.\DISPLAY1`)
114  *  of the specified monitor, or `NULL` if an [error](@ref error_handling)
115  *  occurred.
116  *
117  *  @par Thread Safety
118  *  This function may be called from any thread.  Access is not synchronized.
119  *
120  *  @par History
121  *  Added in GLFW 3.1.
122  *
123  *  @ingroup native
124  */
125 GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor);
126 
127 /*! @brief Returns the display device name of the specified monitor.
128  *
129  *  @return The UTF-8 encoded display device name (for example
130  *  `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an
131  *  [error](@ref error_handling) occurred.
132  *
133  *  @par Thread Safety
134  *  This function may be called from any thread.  Access is not synchronized.
135  *
136  *  @par History
137  *  Added in GLFW 3.1.
138  *
139  *  @ingroup native
140  */
141 GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor);
142 
143 /*! @brief Returns the `HWND` of the specified window.
144  *
145  *  @return The `HWND` of the specified window, or `NULL` if an
146  *  [error](@ref error_handling) occurred.
147  *
148  *  @par Thread Safety
149  *  This function may be called from any thread.  Access is not synchronized.
150  *
151  *  @par History
152  *  Added in GLFW 3.0.
153  *
154  *  @ingroup native
155  */
156 GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window);
157 #endif
158 
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  *  @par Thread Safety
166  *  This function may be called from any thread.  Access is not synchronized.
167  *
168  *  @par History
169  *  Added in GLFW 3.0.
170  *
171  *  @ingroup native
172  */
173 GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window);
174 #endif
175 
176 #if defined(GLFW_EXPOSE_NATIVE_COCOA)
177 /*! @brief Returns the `CGDirectDisplayID` of the specified monitor.
178  *
179  *  @return The `CGDirectDisplayID` of the specified monitor, or
180  *  `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred.
181  *
182  *  @par Thread Safety
183  *  This function may be called from any thread.  Access is not synchronized.
184  *
185  *  @par History
186  *  Added in GLFW 3.1.
187  *
188  *  @ingroup native
189  */
190 GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
191 
192 /*! @brief Returns the `NSWindow` of the specified window.
193  *
194  *  @return The `NSWindow` of the specified window, or `nil` if an
195  *  [error](@ref error_handling) occurred.
196  *
197  *  @par Thread Safety
198  *  This function may be called from any thread.  Access is not synchronized.
199  *
200  *  @par History
201  *  Added in GLFW 3.0.
202  *
203  *  @ingroup native
204  */
205 GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window);
206 #endif
207 
208 #if defined(GLFW_EXPOSE_NATIVE_NSGL)
209 /*! @brief Returns the `NSOpenGLContext` of the specified window.
210  *
211  *  @return The `NSOpenGLContext` of the specified window, or `nil` if an
212  *  [error](@ref error_handling) occurred.
213  *
214  *  @par Thread Safety
215  *  This function may be called from any thread.  Access is not synchronized.
216  *
217  *  @par History
218  *  Added in GLFW 3.0.
219  *
220  *  @ingroup native
221  */
222 GLFWAPI id glfwGetNSGLContext(GLFWwindow* window);
223 #endif
224 
225 #if defined(GLFW_EXPOSE_NATIVE_X11)
226 /*! @brief Returns the `Display` used by GLFW.
227  *
228  *  @return The `Display` used by GLFW, or `NULL` if an
229  *  [error](@ref error_handling) occurred.
230  *
231  *  @par Thread Safety
232  *  This function may be called from any thread.  Access is not synchronized.
233  *
234  *  @par History
235  *  Added in GLFW 3.0.
236  *
237  *  @ingroup native
238  */
239 GLFWAPI Display* glfwGetX11Display(void);
240 
241 /*! @brief Returns the `RRCrtc` of the specified monitor.
242  *
243  *  @return The `RRCrtc` of the specified monitor, or `None` if an
244  *  [error](@ref error_handling) occurred.
245  *
246  *  @par Thread Safety
247  *  This function may be called from any thread.  Access is not synchronized.
248  *
249  *  @par History
250  *  Added in GLFW 3.1.
251  *
252  *  @ingroup native
253  */
254 GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor);
255 
256 /*! @brief Returns the `RROutput` of the specified monitor.
257  *
258  *  @return The `RROutput` of the specified monitor, or `None` if an
259  *  [error](@ref error_handling) occurred.
260  *
261  *  @par Thread Safety
262  *  This function may be called from any thread.  Access is not synchronized.
263  *
264  *  @par History
265  *  Added in GLFW 3.1.
266  *
267  *  @ingroup native
268  */
269 GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor);
270 
271 /*! @brief Returns the `Window` of the specified window.
272  *
273  *  @return The `Window` of the specified window, or `None` if an
274  *  [error](@ref error_handling) occurred.
275  *
276  *  @par Thread Safety
277  *  This function may be called from any thread.  Access is not synchronized.
278  *
279  *  @par History
280  *  Added in GLFW 3.0.
281  *
282  *  @ingroup native
283  */
284 GLFWAPI Window glfwGetX11Window(GLFWwindow* window);
285 #endif
286 
287 #if defined(GLFW_EXPOSE_NATIVE_GLX)
288 /*! @brief Returns the `GLXContext` of the specified window.
289  *
290  *  @return The `GLXContext` of the specified window, or `NULL` if an
291  *  [error](@ref error_handling) occurred.
292  *
293  *  @par Thread Safety
294  *  This function may be called from any thread.  Access is not synchronized.
295  *
296  *  @par History
297  *  Added in GLFW 3.0.
298  *
299  *  @ingroup native
300  */
301 GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window);
302 #endif
303 
304 #if defined(GLFW_EXPOSE_NATIVE_EGL)
305 /*! @brief Returns the `EGLDisplay` used by GLFW.
306  *
307  *  @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an
308  *  [error](@ref error_handling) occurred.
309  *
310  *  @par Thread Safety
311  *  This function may be called from any thread.  Access is not synchronized.
312  *
313  *  @par History
314  *  Added in GLFW 3.0.
315  *
316  *  @ingroup native
317  */
318 GLFWAPI EGLDisplay glfwGetEGLDisplay(void);
319 
320 /*! @brief Returns the `EGLContext` of the specified window.
321  *
322  *  @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an
323  *  [error](@ref error_handling) occurred.
324  *
325  *  @par Thread Safety
326  *  This function may be called from any thread.  Access is not synchronized.
327  *
328  *  @par History
329  *  Added in GLFW 3.0.
330  *
331  *  @ingroup native
332  */
333 GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window);
334 
335 /*! @brief Returns the `EGLSurface` of the specified window.
336  *
337  *  @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an
338  *  [error](@ref error_handling) occurred.
339  *
340  *  @par Thread Safety
341  *  This function may be called from any thread.  Access is not synchronized.
342  *
343  *  @par History
344  *  Added in GLFW 3.0.
345  *
346  *  @ingroup native
347  */
348 GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window);
349 #endif
350 
351 #ifdef __cplusplus
352 }
353 #endif
354 
355 #endif /* _glfw3_native_h_ */
356 
357