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-2018 Camilla Löwy <elmindreda@glfw.org>
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.
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:
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.
21 * 2. Altered source versions must be plainly marked as such, and must not
22 * be misrepresented as being the original software.
24 * 3. This notice may not be removed or altered from any source
27 *************************************************************************/
29 #ifndef _glfw3_native_h_
30 #define _glfw3_native_h_
37 /*************************************************************************
38 * Doxygen documentation
39 *************************************************************************/
41 /*! @file glfw3native.h
42 * @brief The header of the native access functions.
44 * This is the header file of the native access functions. See @ref native for
47 /*! @defgroup native Native access
48 * @brief Functions related to accessing native handles.
50 * **By using the native access functions you assert that you know what you're
51 * doing and how to fix problems caused by using them. If you don't, you
52 * shouldn't be using them.**
54 * Before the inclusion of @ref glfw3native.h, you may define zero or more
55 * window system API macro and zero or more context creation API macros.
57 * The chosen backends must match those the library was compiled for. Failure
58 * to do this will cause a link-time error.
60 * The available window API macros are:
61 * * `GLFW_EXPOSE_NATIVE_WIN32`
62 * * `GLFW_EXPOSE_NATIVE_COCOA`
63 * * `GLFW_EXPOSE_NATIVE_X11`
64 * * `GLFW_EXPOSE_NATIVE_WAYLAND`
66 * The available context API macros are:
67 * * `GLFW_EXPOSE_NATIVE_WGL`
68 * * `GLFW_EXPOSE_NATIVE_NSGL`
69 * * `GLFW_EXPOSE_NATIVE_GLX`
70 * * `GLFW_EXPOSE_NATIVE_EGL`
71 * * `GLFW_EXPOSE_NATIVE_OSMESA`
73 * These macros select which of the native access functions that are declared
74 * and which platform-specific headers to include. It is then up your (by
75 * definition platform-specific) code to handle which of these should be
80 /*************************************************************************
81 * System headers and types
82 *************************************************************************/
84 #if defined(GLFW_EXPOSE_NATIVE_WIN32) || defined(GLFW_EXPOSE_NATIVE_WGL)
85 // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
86 // example to allow applications to correctly declare a GL_ARB_debug_output
87 // callback) but windows.h assumes no one will define APIENTRY before it does
88 #if defined(GLFW_APIENTRY_DEFINED)
90 #undef GLFW_APIENTRY_DEFINED
93 #elif defined(GLFW_EXPOSE_NATIVE_COCOA) || defined(GLFW_EXPOSE_NATIVE_NSGL)
95 #import <Cocoa/Cocoa.h>
97 #include <ApplicationServices/ApplicationServices.h>
100 #elif defined(GLFW_EXPOSE_NATIVE_X11) || defined(GLFW_EXPOSE_NATIVE_GLX)
101 #include <X11/Xlib.h>
102 #include <X11/extensions/Xrandr.h>
103 #elif defined(GLFW_EXPOSE_NATIVE_WAYLAND)
104 #include <wayland-client.h>
107 #if defined(GLFW_EXPOSE_NATIVE_WGL)
108 /* WGL is declared by windows.h */
110 #if defined(GLFW_EXPOSE_NATIVE_NSGL)
111 /* NSGL is declared by Cocoa.h */
113 #if defined(GLFW_EXPOSE_NATIVE_GLX)
116 #if defined(GLFW_EXPOSE_NATIVE_EGL)
119 #if defined(GLFW_EXPOSE_NATIVE_OSMESA)
120 #include <GL/osmesa.h>
124 /*************************************************************************
126 *************************************************************************/
128 #if defined(GLFW_EXPOSE_NATIVE_WIN32)
129 /*! @brief Returns the adapter device name of the specified monitor.
131 * @return The UTF-8 encoded adapter device name (for example `\\.\DISPLAY1`)
132 * of the specified monitor, or `NULL` if an [error](@ref error_handling)
135 * @thread_safety This function may be called from any thread. Access is not
138 * @since Added in version 3.1.
142 GLFWAPI
const char* glfwGetWin32Adapter(GLFWmonitor
* monitor
);
144 /*! @brief Returns the display device name of the specified monitor.
146 * @return The UTF-8 encoded display device name (for example
147 * `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an
148 * [error](@ref error_handling) occurred.
150 * @thread_safety This function may be called from any thread. Access is not
153 * @since Added in version 3.1.
157 GLFWAPI
const char* glfwGetWin32Monitor(GLFWmonitor
* monitor
);
159 /*! @brief Returns the `HWND` of the specified window.
161 * @return The `HWND` of the specified window, or `NULL` if an
162 * [error](@ref error_handling) occurred.
164 * @thread_safety This function may be called from any thread. Access is not
167 * @since Added in version 3.0.
171 GLFWAPI HWND
glfwGetWin32Window(GLFWwindow
* window
);
174 #if defined(GLFW_EXPOSE_NATIVE_WGL)
175 /*! @brief Returns the `HGLRC` of the specified window.
177 * @return The `HGLRC` of the specified window, or `NULL` if an
178 * [error](@ref error_handling) occurred.
180 * @thread_safety This function may be called from any thread. Access is not
183 * @since Added in version 3.0.
187 GLFWAPI HGLRC
glfwGetWGLContext(GLFWwindow
* window
);
190 #if defined(GLFW_EXPOSE_NATIVE_COCOA)
191 /*! @brief Returns the `CGDirectDisplayID` of the specified monitor.
193 * @return The `CGDirectDisplayID` of the specified monitor, or
194 * `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred.
196 * @thread_safety This function may be called from any thread. Access is not
199 * @since Added in version 3.1.
203 GLFWAPI CGDirectDisplayID
glfwGetCocoaMonitor(GLFWmonitor
* monitor
);
205 /*! @brief Returns the `NSWindow` of the specified window.
207 * @return The `NSWindow` of the specified window, or `nil` if an
208 * [error](@ref error_handling) occurred.
210 * @thread_safety This function may be called from any thread. Access is not
213 * @since Added in version 3.0.
217 GLFWAPI id
glfwGetCocoaWindow(GLFWwindow
* window
);
220 #if defined(GLFW_EXPOSE_NATIVE_NSGL)
221 /*! @brief Returns the `NSOpenGLContext` of the specified window.
223 * @return The `NSOpenGLContext` of the specified window, or `nil` if an
224 * [error](@ref error_handling) occurred.
226 * @thread_safety This function may be called from any thread. Access is not
229 * @since Added in version 3.0.
233 GLFWAPI id
glfwGetNSGLContext(GLFWwindow
* window
);
236 #if defined(GLFW_EXPOSE_NATIVE_X11)
237 /*! @brief Returns the `Display` used by GLFW.
239 * @return The `Display` used by GLFW, or `NULL` if an
240 * [error](@ref error_handling) occurred.
242 * @thread_safety This function may be called from any thread. Access is not
245 * @since Added in version 3.0.
249 GLFWAPI Display
* glfwGetX11Display(void);
251 /*! @brief Returns the `RRCrtc` of the specified monitor.
253 * @return The `RRCrtc` of the specified monitor, or `None` if an
254 * [error](@ref error_handling) occurred.
256 * @thread_safety This function may be called from any thread. Access is not
259 * @since Added in version 3.1.
263 GLFWAPI RRCrtc
glfwGetX11Adapter(GLFWmonitor
* monitor
);
265 /*! @brief Returns the `RROutput` of the specified monitor.
267 * @return The `RROutput` of the specified monitor, or `None` if an
268 * [error](@ref error_handling) occurred.
270 * @thread_safety This function may be called from any thread. Access is not
273 * @since Added in version 3.1.
277 GLFWAPI RROutput
glfwGetX11Monitor(GLFWmonitor
* monitor
);
279 /*! @brief Returns the `Window` of the specified window.
281 * @return The `Window` of the specified window, or `None` if an
282 * [error](@ref error_handling) occurred.
284 * @thread_safety This function may be called from any thread. Access is not
287 * @since Added in version 3.0.
291 GLFWAPI Window
glfwGetX11Window(GLFWwindow
* window
);
293 /*! @brief Sets the current primary selection to the specified string.
295 * @param[in] string A UTF-8 encoded string.
297 * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
298 * GLFW_PLATFORM_ERROR.
300 * @pointer_lifetime The specified string is copied before this function
303 * @thread_safety This function must only be called from the main thread.
306 * @sa glfwGetX11SelectionString
307 * @sa glfwSetClipboardString
309 * @since Added in version 3.3.
313 GLFWAPI
void glfwSetX11SelectionString(const char* string
);
315 /*! @brief Returns the contents of the current primary selection as a string.
317 * If the selection is empty or if its contents cannot be converted, `NULL`
318 * is returned and a @ref GLFW_FORMAT_UNAVAILABLE error is generated.
320 * @return The contents of the selection as a UTF-8 encoded string, or `NULL`
321 * if an [error](@ref error_handling) occurred.
323 * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
324 * GLFW_PLATFORM_ERROR.
326 * @pointer_lifetime The returned string is allocated and freed by GLFW. You
327 * should not free it yourself. It is valid until the next call to @ref
328 * glfwGetX11SelectionString or @ref glfwSetX11SelectionString, or until the
329 * library is terminated.
331 * @thread_safety This function must only be called from the main thread.
334 * @sa glfwSetX11SelectionString
335 * @sa glfwGetClipboardString
337 * @since Added in version 3.3.
341 GLFWAPI
const char* glfwGetX11SelectionString(void);
344 #if defined(GLFW_EXPOSE_NATIVE_GLX)
345 /*! @brief Returns the `GLXContext` of the specified window.
347 * @return The `GLXContext` of the specified window, or `NULL` if an
348 * [error](@ref error_handling) occurred.
350 * @thread_safety This function may be called from any thread. Access is not
353 * @since Added in version 3.0.
357 GLFWAPI GLXContext
glfwGetGLXContext(GLFWwindow
* window
);
359 /*! @brief Returns the `GLXWindow` of the specified window.
361 * @return The `GLXWindow` of the specified window, or `None` if an
362 * [error](@ref error_handling) occurred.
364 * @thread_safety This function may be called from any thread. Access is not
367 * @since Added in version 3.2.
371 GLFWAPI GLXWindow
glfwGetGLXWindow(GLFWwindow
* window
);
374 #if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
375 /*! @brief Returns the `struct wl_display*` used by GLFW.
377 * @return The `struct wl_display*` used by GLFW, or `NULL` if an
378 * [error](@ref error_handling) occurred.
380 * @thread_safety This function may be called from any thread. Access is not
383 * @since Added in version 3.2.
387 GLFWAPI
struct wl_display
* glfwGetWaylandDisplay(void);
389 /*! @brief Returns the `struct wl_output*` of the specified monitor.
391 * @return The `struct wl_output*` of the specified monitor, or `NULL` if an
392 * [error](@ref error_handling) occurred.
394 * @thread_safety This function may be called from any thread. Access is not
397 * @since Added in version 3.2.
401 GLFWAPI
struct wl_output
* glfwGetWaylandMonitor(GLFWmonitor
* monitor
);
403 /*! @brief Returns the main `struct wl_surface*` of the specified window.
405 * @return The main `struct wl_surface*` of the specified window, or `NULL` if
406 * an [error](@ref error_handling) occurred.
408 * @thread_safety This function may be called from any thread. Access is not
411 * @since Added in version 3.2.
415 GLFWAPI
struct wl_surface
* glfwGetWaylandWindow(GLFWwindow
* window
);
418 #if defined(GLFW_EXPOSE_NATIVE_EGL)
419 /*! @brief Returns the `EGLDisplay` used by GLFW.
421 * @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an
422 * [error](@ref error_handling) occurred.
424 * @thread_safety This function may be called from any thread. Access is not
427 * @since Added in version 3.0.
431 GLFWAPI EGLDisplay
glfwGetEGLDisplay(void);
433 /*! @brief Returns the `EGLContext` of the specified window.
435 * @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an
436 * [error](@ref error_handling) occurred.
438 * @thread_safety This function may be called from any thread. Access is not
441 * @since Added in version 3.0.
445 GLFWAPI EGLContext
glfwGetEGLContext(GLFWwindow
* window
);
447 /*! @brief Returns the `EGLSurface` of the specified window.
449 * @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an
450 * [error](@ref error_handling) occurred.
452 * @thread_safety This function may be called from any thread. Access is not
455 * @since Added in version 3.0.
459 GLFWAPI EGLSurface
glfwGetEGLSurface(GLFWwindow
* window
);
462 #if defined(GLFW_EXPOSE_NATIVE_OSMESA)
463 /*! @brief Retrieves the color buffer associated with the specified window.
465 * @param[in] window The window whose color buffer to retrieve.
466 * @param[out] width Where to store the width of the color buffer, or `NULL`.
467 * @param[out] height Where to store the height of the color buffer, or `NULL`.
468 * @param[out] format Where to store the OSMesa pixel format of the color
470 * @param[out] buffer Where to store the address of the color buffer, or
472 * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an
473 * [error](@ref error_handling) occurred.
475 * @thread_safety This function may be called from any thread. Access is not
478 * @since Added in version 3.3.
482 GLFWAPI
int glfwGetOSMesaColorBuffer(GLFWwindow
* window
, int* width
, int* height
, int* format
, void** buffer
);
484 /*! @brief Retrieves the depth buffer associated with the specified window.
486 * @param[in] window The window whose depth buffer to retrieve.
487 * @param[out] width Where to store the width of the depth buffer, or `NULL`.
488 * @param[out] height Where to store the height of the depth buffer, or `NULL`.
489 * @param[out] bytesPerValue Where to store the number of bytes per depth
490 * buffer element, or `NULL`.
491 * @param[out] buffer Where to store the address of the depth buffer, or
493 * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an
494 * [error](@ref error_handling) occurred.
496 * @thread_safety This function may be called from any thread. Access is not
499 * @since Added in version 3.3.
503 GLFWAPI
int glfwGetOSMesaDepthBuffer(GLFWwindow
* window
, int* width
, int* height
, int* bytesPerValue
, void** buffer
);
505 /*! @brief Returns the `OSMesaContext` of the specified window.
507 * @return The `OSMesaContext` of the specified window, or `NULL` if an
508 * [error](@ref error_handling) occurred.
510 * @thread_safety This function may be called from any thread. Access is not
513 * @since Added in version 3.3.
517 GLFWAPI OSMesaContext
glfwGetOSMesaContext(GLFWwindow
* window
);
524 #endif /* _glfw3_native_h_ */