From 2d1a98136ef876ba6548cf9acb3fea3aae695718 Mon Sep 17 00:00:00 2001 From: Matthew Henry Date: Sun, 12 Jan 2014 12:16:36 +1000 Subject: [PATCH] Added support for CGL context access in glfw3native.h This allows access to the underlying context on OSX without dropping into ObjC as CGL is an entirely C-based API --- .gitignore | 1 + include/GLFW/glfw3native.h | 13 ++++++++++++- src/nsgl_context.m | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4f8ddbc9..9e330a9b 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ src/glfw_config.h src/glfw3.pc src/glfwConfig.cmake src/glfwConfigVersion.cmake +install_manifest.txt # Compiled binaries src/libglfw.so diff --git a/include/GLFW/glfw3native.h b/include/GLFW/glfw3native.h index d570f587..5117d4cc 100644 --- a/include/GLFW/glfw3native.h +++ b/include/GLFW/glfw3native.h @@ -55,7 +55,8 @@ extern "C" { * * The available context API macros are: * * `GLFW_EXPOSE_NATIVE_WGL` - * * `GLFW_EXPOSE_NATIVE_NSGL` + * * `GLFW_EXPOSE_NATIVE_NSGL` (OSX, ObjC required to do anything useful) + * * `GLFW_EXPOSE_NATIVE_CGL` * * `GLFW_EXPOSE_NATIVE_GLX` * * `GLFW_EXPOSE_NATIVE_EGL` * @@ -88,6 +89,8 @@ extern "C" { /* WGL is declared by windows.h */ #elif defined(GLFW_EXPOSE_NATIVE_NSGL) /* NSGL is declared by Cocoa.h */ +#elif defined(GLFW_EXPOSE_NATIVE_CGL) + #include #elif defined(GLFW_EXPOSE_NATIVE_GLX) #include #elif defined(GLFW_EXPOSE_NATIVE_EGL) @@ -133,6 +136,14 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window); GLFWAPI id glfwGetNSGLContext(GLFWwindow* window); #endif +#if defined(GLFW_EXPOSE_NATIVE_CGL) +/*! @brief Returns the `CGLContextObj` of the specified window. + * @return The `CGLContextObj` of the specified window. + * @ingroup native + */ +GLFWAPI CGLContextObj glfwGetCGLContext(GLFWwindow* window); +#endif + #if defined(GLFW_EXPOSE_NATIVE_X11) /*! @brief Returns the `Display` used by GLFW. * @return The `Display` used by GLFW. diff --git a/src/nsgl_context.m b/src/nsgl_context.m index 71638ad1..3a6b75c0 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -289,3 +289,9 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle) return window->nsgl.context; } +GLFWAPI CGLContextObj glfwGetCGLContext(GLFWwindow* handle) +{ + NSOpenGLContext* ctx = glfwGetNSGLContext(handle); + return [ctx CGLContextObj]; +} +