From 98557d0f89f6b2dd61c1eb06440fe51d1f6da2e6 Mon Sep 17 00:00:00 2001 From: endre Date: Sun, 10 May 2015 15:06:22 +0200 Subject: [PATCH] Added ability to reuse a context of another window instead of creating a new one with sharing (implementation only for Windows). --- include/GLFW/glfw3.h | 1 + src/internal.h | 2 ++ src/wgl_context.c | 6 +++++- src/window.c | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index b5d00cd79..58e09def1 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -623,6 +623,7 @@ extern "C" { #define GLFW_OPENGL_DEBUG_CONTEXT 0x00022007 #define GLFW_OPENGL_PROFILE 0x00022008 #define GLFW_CONTEXT_RELEASE_BEHAVIOR 0x00022009 +#define GLFW_REUSE_CONTEXT 0x0002200A #define GLFW_OPENGL_API 0x00030001 #define GLFW_OPENGL_ES_API 0x00030002 diff --git a/src/internal.h b/src/internal.h index 979b83cc6..ce10c412c 100644 --- a/src/internal.h +++ b/src/internal.h @@ -189,6 +189,7 @@ struct _GLFWctxconfig int robustness; int release; _GLFWwindow* share; + int reuseContext; }; @@ -353,6 +354,7 @@ struct _GLFWlibrary int profile; int robustness; int release; + int reuseContext; } hints; double cursorPosX, cursorPosY; diff --git a/src/wgl_context.c b/src/wgl_context.c index b43cc1930..127840361 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -338,7 +338,11 @@ int _glfwCreateContext(_GLFWwindow* window, return GL_FALSE; } - if (window->wgl.ARB_create_context) + if (share && ctxconfig->reuseContext) + { + window->wgl.context = share; + } + else if (window->wgl.ARB_create_context) { int index = 0, mask = 0, flags = 0; diff --git a/src/window.c b/src/window.c index 3acd48c48..3f866bbf8 100644 --- a/src/window.c +++ b/src/window.c @@ -171,6 +171,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, ctxconfig.robustness = _glfw.hints.robustness; ctxconfig.release = _glfw.hints.release; ctxconfig.share = (_GLFWwindow*) share; + ctxconfig.reuseContext = _glfw.hints.reuseContext; // Check the OpenGL bits of the window config if (!_glfwIsValidContextConfig(&ctxconfig)) @@ -295,6 +296,7 @@ void glfwDefaultWindowHints(void) _glfw.hints.depthBits = 24; _glfw.hints.stencilBits = 8; _glfw.hints.doublebuffer = GL_TRUE; + _glfw.hints.reuseContext = GL_FALSE; } GLFWAPI void glfwWindowHint(int target, int hint) @@ -393,6 +395,8 @@ GLFWAPI void glfwWindowHint(int target, int hint) case GLFW_CONTEXT_RELEASE_BEHAVIOR: _glfw.hints.release = hint; break; + case GLFW_REUSE_CONTEXT: + _glfw.hints.reuseContext = hint; default: _glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint"); break;