mirror of
https://github.com/glfw/glfw.git
synced 2026-09-23 00:59:48 +00:00
Added context sharing.
This commit is contained in:
@@ -631,9 +631,14 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
NSOpenGLContext* share = NULL;
|
||||
|
||||
if (wndconfig->share)
|
||||
share = wndconfig->share->NSGL.context;
|
||||
|
||||
window->NSGL.context =
|
||||
[[NSOpenGLContext alloc] initWithFormat:window->NSGL.pixelFormat
|
||||
shareContext:nil];
|
||||
shareContext:share];
|
||||
if (window->NSGL.context == nil)
|
||||
{
|
||||
_glfwSetError(GLFW_INTERNAL_ERROR);
|
||||
|
||||
+27
-19
@@ -60,13 +60,20 @@
|
||||
#include "platform.h"
|
||||
|
||||
|
||||
typedef struct _GLFWhints _GLFWhints;
|
||||
typedef struct _GLFWwndconfig _GLFWwndconfig;
|
||||
typedef struct _GLFWfbconfig _GLFWfbconfig;
|
||||
typedef struct _GLFWwindow _GLFWwindow;
|
||||
typedef struct _GLFWlibrary _GLFWlibrary;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Window hints, set by glfwOpenWindowHint and consumed by glfwOpenWindow
|
||||
// A bucket of semi-random stuff lumped together for historical reasons
|
||||
// This is used only by the platform independent code and only to store
|
||||
// parameters passed to us by glfwOpenWindowHint
|
||||
//------------------------------------------------------------------------
|
||||
typedef struct _GLFWhints
|
||||
struct _GLFWhints
|
||||
{
|
||||
int redBits;
|
||||
int greenBits;
|
||||
@@ -88,7 +95,7 @@ typedef struct _GLFWhints
|
||||
int glForward;
|
||||
int glDebug;
|
||||
int glProfile;
|
||||
} _GLFWhints;
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
@@ -97,18 +104,19 @@ typedef struct _GLFWhints
|
||||
// This is used to pass window and context creation parameters from the
|
||||
// platform independent code to the platform specific code
|
||||
//------------------------------------------------------------------------
|
||||
typedef struct _GLFWwndconfig
|
||||
struct _GLFWwndconfig
|
||||
{
|
||||
int mode;
|
||||
const char* title;
|
||||
int refreshRate;
|
||||
int windowNoResize;
|
||||
int glMajor;
|
||||
int glMinor;
|
||||
int glForward;
|
||||
int glDebug;
|
||||
int glProfile;
|
||||
} _GLFWwndconfig;
|
||||
int mode;
|
||||
const char* title;
|
||||
int refreshRate;
|
||||
int windowNoResize;
|
||||
int glMajor;
|
||||
int glMinor;
|
||||
int glForward;
|
||||
int glDebug;
|
||||
int glProfile;
|
||||
_GLFWwindow* share;
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
@@ -118,7 +126,7 @@ typedef struct _GLFWwndconfig
|
||||
// code to the platform specific code, and also to enumerate and select
|
||||
// available framebuffer configurations
|
||||
//------------------------------------------------------------------------
|
||||
typedef struct _GLFWfbconfig
|
||||
struct _GLFWfbconfig
|
||||
{
|
||||
int redBits;
|
||||
int greenBits;
|
||||
@@ -134,13 +142,13 @@ typedef struct _GLFWfbconfig
|
||||
int stereo;
|
||||
int samples;
|
||||
GLFWintptr platformID;
|
||||
} _GLFWfbconfig;
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Window structure
|
||||
//------------------------------------------------------------------------
|
||||
typedef struct _GLFWwindow
|
||||
struct _GLFWwindow
|
||||
{
|
||||
struct _GLFWwindow* next;
|
||||
|
||||
@@ -199,13 +207,13 @@ typedef struct _GLFWwindow
|
||||
|
||||
_GLFW_PLATFORM_WINDOW_STATE;
|
||||
_GLFW_PLATFORM_CONTEXT_STATE;
|
||||
} _GLFWwindow;
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Library global data
|
||||
//------------------------------------------------------------------------
|
||||
typedef struct _GLFWlibrary
|
||||
struct _GLFWlibrary
|
||||
{
|
||||
_GLFWhints hints;
|
||||
|
||||
@@ -215,7 +223,7 @@ typedef struct _GLFWlibrary
|
||||
_GLFWwindow* cursorLockWindow;
|
||||
|
||||
_GLFW_PLATFORM_LIBRARY_STATE;
|
||||
} _GLFWlibrary;
|
||||
};
|
||||
|
||||
|
||||
//========================================================================
|
||||
|
||||
+25
-12
@@ -315,20 +315,23 @@ static HGLRC createContext(_GLFWwindow* window,
|
||||
const _GLFWwndconfig* wndconfig,
|
||||
int pixelFormat)
|
||||
{
|
||||
HGLRC context;
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
int flags, i = 0, attribs[7];
|
||||
HGLRC share = NULL;
|
||||
|
||||
if (wndconfig->share)
|
||||
share = wndconfig->share->WGL.context;
|
||||
|
||||
if (!_glfw_DescribePixelFormat(window->WGL.DC, pixelFormat, sizeof(pfd), &pfd))
|
||||
{
|
||||
_glfwSetError(GLFW_INTERNAL_ERROR);
|
||||
return NULL;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (!_glfw_SetPixelFormat(window->WGL.DC, pixelFormat, &pfd))
|
||||
{
|
||||
_glfwSetError(GLFW_INTERNAL_ERROR);
|
||||
return NULL;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (window->WGL.has_WGL_ARB_create_context)
|
||||
@@ -372,24 +375,35 @@ static HGLRC createContext(_GLFWwindow* window,
|
||||
|
||||
attribs[i++] = 0;
|
||||
|
||||
context = window->WGL.CreateContextAttribsARB(window->WGL.DC, NULL, attribs);
|
||||
if (!context)
|
||||
window->WGL.context = window->WGL.CreateContextAttribsARB(window->WGL.DC,
|
||||
share,
|
||||
attribs);
|
||||
if (!window->WGL.context)
|
||||
{
|
||||
_glfwSetError(GLFW_INTERNAL_ERROR);
|
||||
return NULL;
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
context = wglCreateContext(window->WGL.DC);
|
||||
if (!context)
|
||||
window->WGL.context = wglCreateContext(window->WGL.DC);
|
||||
if (!window->WGL.context)
|
||||
{
|
||||
_glfwSetError(GLFW_INTERNAL_ERROR);
|
||||
return NULL;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (share)
|
||||
{
|
||||
if (!wglShareLists(share, window->WGL.context))
|
||||
{
|
||||
_glfwSetError(GLFW_INTERNAL_ERROR);
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return context;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1201,8 +1215,7 @@ static int createWindow(_GLFWwindow* window,
|
||||
if (!pixelFormat)
|
||||
return GL_FALSE;
|
||||
|
||||
window->WGL.context = createContext(window, wndconfig, pixelFormat);
|
||||
if (!window->WGL.context)
|
||||
if (!createContext(window, wndconfig, pixelFormat))
|
||||
return GL_FALSE;
|
||||
|
||||
glfwMakeWindowCurrent(window);
|
||||
|
||||
+3
-1
@@ -409,7 +409,8 @@ const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||
int mode, const char* title)
|
||||
int mode, const char* title,
|
||||
GLFWwindow share)
|
||||
{
|
||||
_GLFWfbconfig fbconfig;
|
||||
_GLFWwndconfig wndconfig;
|
||||
@@ -458,6 +459,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||
wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE;
|
||||
wndconfig.glDebug = _glfwLibrary.hints.glDebug ? GL_TRUE : GL_FALSE;
|
||||
wndconfig.glProfile = _glfwLibrary.hints.glProfile;
|
||||
wndconfig.share = share;
|
||||
|
||||
// Clear for next open call
|
||||
_glfwClearWindowHints();
|
||||
|
||||
+17
-11
@@ -483,6 +483,10 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
|
||||
int attribs[40];
|
||||
int flags, dummy, index;
|
||||
GLXFBConfig* fbconfig;
|
||||
GLXContext share = NULL;
|
||||
|
||||
if (wndconfig->share)
|
||||
share = wndconfig->share->GLX.context;
|
||||
|
||||
// Retrieve the previously selected GLXFBConfig
|
||||
{
|
||||
@@ -580,28 +584,30 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
|
||||
|
||||
setGLXattrib(attribs, index, None, None);
|
||||
|
||||
window->GLX.context = window->GLX.CreateContextAttribsARB(_glfwLibrary.X11.display,
|
||||
*fbconfig,
|
||||
NULL,
|
||||
True,
|
||||
attribs);
|
||||
window->GLX.context =
|
||||
window->GLX.CreateContextAttribsARB(_glfwLibrary.X11.display,
|
||||
*fbconfig,
|
||||
share,
|
||||
True,
|
||||
attribs);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (window->GLX.has_GLX_SGIX_fbconfig)
|
||||
{
|
||||
window->GLX.context = window->GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display,
|
||||
*fbconfig,
|
||||
GLX_RGBA_TYPE,
|
||||
NULL,
|
||||
True);
|
||||
window->GLX.context =
|
||||
window->GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display,
|
||||
*fbconfig,
|
||||
GLX_RGBA_TYPE,
|
||||
share,
|
||||
True);
|
||||
}
|
||||
else
|
||||
{
|
||||
window->GLX.context = glXCreateNewContext(_glfwLibrary.X11.display,
|
||||
*fbconfig,
|
||||
GLX_RGBA_TYPE,
|
||||
NULL,
|
||||
share,
|
||||
True);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user