diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h
index 1c8c4e1c..6e70e59c 100644
--- a/include/GL/glfw3.h
+++ b/include/GL/glfw3.h
@@ -583,6 +583,7 @@ GLFWAPI void glfwSwapInterval(int interval);
GLFWAPI int glfwExtensionSupported(const char* extension);
GLFWAPI void* glfwGetProcAddress(const char* procname);
GLFWAPI void glfwGetGLVersion(int* major, int* minor, int* rev);
+GLFWAPI void glfwCopyGLState(GLFWwindow src, GLFWwindow dst, unsigned long mask);
/* Enable/disable functions */
GLFWAPI void glfwEnable(GLFWwindow window, int token);
diff --git a/readme.html b/readme.html
index 314b1cdd..31cc03ed 100644
--- a/readme.html
+++ b/readme.html
@@ -273,6 +273,7 @@ version of GLFW.
Added glfwSetWindowIconifyCallback
function and GLFWwindowiconifyfun
type for receiving window iconification events
Added glfwGetCurrentWindow
function for retrieving the window whose OpenGL context is current
Added glfwInitWithModels
function and GLFWallocator
and GLFWthreadmodel
types for pluggable memory allocation and threading models
+ Added glfwCopyGLState
function for copying OpenGL state categories between contexts
Added GLFW_OPENGL_ES2_PROFILE
profile for creating OpenGL ES 2.0 contexts using the GLX_EXT_create_context_es2_profile
and WGL_EXT_create_context_es2_profile
extensions
Added GLFW_OPENGL_ROBUSTNESS
window hint and associated strategy tokens for GL_ARB_robustness
support
Added windows
simple multi-window test program
diff --git a/src/cocoa/cocoa_opengl.m b/src/cocoa/cocoa_opengl.m
index b633d472..6d93ed9f 100644
--- a/src/cocoa/cocoa_opengl.m
+++ b/src/cocoa/cocoa_opengl.m
@@ -86,3 +86,12 @@ void* _glfwPlatformGetProcAddress(const char* procname)
return symbol;
}
+//========================================================================
+// Copies the specified OpenGL state categories from src to dst
+//========================================================================
+
+void _glfwPlatformCopyGLState(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask)
+{
+ [dst->NSGL.context copyAttributesFromContext:src->NSGL.context withMask:mask];
+}
+
diff --git a/src/internal.h b/src/internal.h
index c942707b..4a39b9c9 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -310,6 +310,7 @@ void _glfwPlatformSwapInterval(int interval);
void _glfwPlatformRefreshWindowParams(void);
int _glfwPlatformExtensionSupported(const char* extension);
void* _glfwPlatformGetProcAddress(const char* procname);
+void _glfwPlatformCopyGLState(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask);
//========================================================================
diff --git a/src/opengl.c b/src/opengl.c
index a08f97f9..2e5e287d 100644
--- a/src/opengl.c
+++ b/src/opengl.c
@@ -587,3 +587,25 @@ GLFWAPI void glfwGetGLVersion(int* major, int* minor, int* rev)
*rev = window->glRevision;
}
+
+//========================================================================
+// Copies the specified OpenGL state categories from src to dst
+//========================================================================
+
+GLFWAPI void glfwCopyGLState(GLFWwindow hsrc, GLFWwindow hdst, unsigned long mask)
+{
+ _GLFWwindow* src;
+ _GLFWwindow* dst;
+
+ if (!_glfwInitialized)
+ {
+ _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
+ return;
+ }
+
+ src = (_GLFWwindow*) hsrc;
+ dst = (_GLFWwindow*) hdst;
+
+ _glfwPlatformCopyGLState(src, dst, mask);
+}
+
diff --git a/src/win32/win32_opengl.c b/src/win32/win32_opengl.c
index efce1531..d729fb51 100644
--- a/src/win32/win32_opengl.c
+++ b/src/win32/win32_opengl.c
@@ -103,3 +103,14 @@ void* _glfwPlatformGetProcAddress(const char* procname)
return (void*) wglGetProcAddress(procname);
}
+
+//========================================================================
+// Copies the specified OpenGL state categories from src to dst
+//========================================================================
+
+void _glfwPlatformCopyGLState(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask)
+{
+ if (!wglCopyContext(src->WGL.context, dst->WGL.context, mask))
+ _glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to copy OpenGL context attributes");
+}
+
diff --git a/src/x11/x11_opengl.c b/src/x11/x11_opengl.c
index 33b19ff9..0442209b 100644
--- a/src/x11/x11_opengl.c
+++ b/src/x11/x11_opengl.c
@@ -116,3 +116,16 @@ void* _glfwPlatformGetProcAddress(const char* procname)
return (void*) _glfw_glXGetProcAddress((const GLubyte*) procname);
}
+
+//========================================================================
+// Copies the specified OpenGL state categories from src to dst
+//========================================================================
+
+void _glfwPlatformCopyGLState(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask)
+{
+ glXCopyContext(_glfwLibrary.X11.display,
+ src->GLX.context,
+ dst->GLX.context,
+ mask);
+}
+