Added option 'GLFW_OPENGL_SINGLE_GLRC' to make GLFW use only a single GLRC.

This commit is contained in:
Lukas Hermanns 2018-04-05 13:08:04 +02:00
parent 0a3c4f5d80
commit fe890e5e26
3 changed files with 34 additions and 3 deletions

View File

@ -30,6 +30,7 @@ option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON)
option(GLFW_BUILD_DOCS "Build the GLFW documentation" ON)
option(GLFW_INSTALL "Generate installation target" ON)
option(GLFW_VULKAN_STATIC "Use the Vulkan loader statically linked into application" OFF)
option(GLFW_OPENGL_SINGLE_GLRC "Build the GLFW to use only a single OpenGL render context" OFF)
if (UNIX)
option(GLFW_USE_OSMESA "Use OSMesa for offscreen context creation" OFF)
@ -73,6 +74,10 @@ if (GLFW_BUILD_DOCS)
find_package(Doxygen)
endif()
if (GLFW_OPENGL_SINGLE_GLRC)
add_definitions(-D_GLFW_OPENGL_SINGLE_GLRC)
endif()
#--------------------------------------------------------------------
# Set compiler specific flags
#--------------------------------------------------------------------

View File

@ -341,6 +341,11 @@ struct _GLFWcontext
int profile;
int robustness;
int release;
#ifdef _GLFW_OPENGL_SINGLE_GLRC
// Specifies whether this _GLFWcontext has its own GLRC object.
// If not, it must not delete the GLRC object on destruction.
GLFWbool customctx;
#endif
PFNGLGETSTRINGIPROC GetStringi;
PFNGLGETINTEGERVPROC GetIntegerv;

View File

@ -324,7 +324,14 @@ static void destroyContextWGL(_GLFWwindow* window)
{
if (window->context.wgl.handle)
{
#ifdef _GLFW_OPENGL_SINGLE_GLRC
if (window->context.customctx)
{
wglDeleteContext(window->context.wgl.handle);
}
#else
wglDeleteContext(window->context.wgl.handle);
#endif
window->context.wgl.handle = NULL;
}
}
@ -623,9 +630,23 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
setAttrib(0, 0);
window->context.wgl.handle =
_glfw.wgl.CreateContextAttribsARB(window->context.wgl.dc,
share, attribs);
#ifdef _GLFW_OPENGL_SINGLE_GLRC
if (share)
{
// Use shared context instead of creating a new one
window->context.wgl.handle = share;
window->context.customctx = GLFW_FALSE;
}
else
{
// Create new GL render context
window->context.wgl.handle = _glfw.wgl.CreateContextAttribsARB(window->context.wgl.dc, NULL, attribs);
window->context.customctx = GLFW_TRUE;
}
#else
window->context.wgl.handle = _glfw.wgl.CreateContextAttribsARB(window->context.wgl.dc, share, attribs);
#endif
if (!window->context.wgl.handle)
{
const DWORD error = GetLastError();