mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-26 20:28:49 -05:00
Added context sharing.
This commit is contained in:
parent
7a0be0f2eb
commit
99ddce3214
|
@ -577,7 +577,7 @@ int main( void )
|
|||
|
||||
glfwOpenWindowHint(GLFW_DEPTH_BITS, 16);
|
||||
|
||||
window = glfwOpenWindow( 400, 400, GLFW_WINDOWED, "Boing (classic Amiga demo)" );
|
||||
window = glfwOpenWindow( 400, 400, GLFW_WINDOWED, "Boing (classic Amiga demo)", NULL );
|
||||
if (!window)
|
||||
{
|
||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||
|
|
|
@ -331,7 +331,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
glfwOpenWindowHint(GLFW_DEPTH_BITS, 16);
|
||||
|
||||
window = glfwOpenWindow( 300, 300, GLFW_WINDOWED, "Gears" );
|
||||
window = glfwOpenWindow( 300, 300, GLFW_WINDOWED, "Gears", NULL );
|
||||
if (!window)
|
||||
{
|
||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||
|
|
|
@ -587,7 +587,7 @@ int main(int argc, char** argv)
|
|||
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE);
|
||||
|
||||
window = glfwOpenWindow(800, 600, GLFW_WINDOWED, "GLFW OpenGL3 Heightmap demo");
|
||||
window = glfwOpenWindow(800, 600, GLFW_WINDOWED, "GLFW OpenGL3 Heightmap demo", NULL);
|
||||
if (! window )
|
||||
{
|
||||
fprintf(stderr, "ERROR: Unable to create the OpenGL context and associated window\n");
|
||||
|
|
|
@ -460,7 +460,7 @@ int main( void )
|
|||
glfwOpenWindowHint(GLFW_DEPTH_BITS, 16);
|
||||
|
||||
// Open OpenGL window
|
||||
window = glfwOpenWindow( 500, 500, GLFW_WINDOWED, "Split view demo" );
|
||||
window = glfwOpenWindow( 500, 500, GLFW_WINDOWED, "Split view demo", NULL );
|
||||
if (!window)
|
||||
{
|
||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||
|
|
|
@ -23,7 +23,7 @@ int main( void )
|
|||
}
|
||||
|
||||
// Open a window and create its OpenGL context
|
||||
window = glfwOpenWindow( 640, 480, GLFW_WINDOWED, "Spinning Triangle" );
|
||||
window = glfwOpenWindow( 640, 480, GLFW_WINDOWED, "Spinning Triangle", NULL );
|
||||
if (!window)
|
||||
{
|
||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||
|
|
|
@ -337,7 +337,7 @@ int main(int argc, char* argv[])
|
|||
glfwOpenWindowHint(GLFW_DEPTH_BITS, 16);
|
||||
|
||||
/* Open window */
|
||||
window = glfwOpenWindow(width, height, mode, "Wave Simulation");
|
||||
window = glfwOpenWindow(width, height, mode, "Wave Simulation", NULL);
|
||||
if (!window)
|
||||
{
|
||||
fprintf(stderr, "Could not open window\n");
|
||||
|
|
|
@ -413,7 +413,7 @@ GLFWAPI int glfwGetVideoModes(GLFWvidmode* list, int maxcount);
|
|||
GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode);
|
||||
|
||||
/* Window handling */
|
||||
GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode, const char* title);
|
||||
GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode, const char* title, GLFWwindow share);
|
||||
GLFWAPI void glfwOpenWindowHint(int target, int hint);
|
||||
GLFWAPI void glfwMakeWindowCurrent(GLFWwindow window);
|
||||
GLFWAPI int glfwIsWindow(GLFWwindow window);
|
||||
|
|
|
@ -271,6 +271,7 @@ version of GLFW.</p>
|
|||
<li>Added <code>glfwSetWindowFocusCallback</code> function and <code>GLFWwindowfocusfun</code> type for receiving window focus events</li>
|
||||
<li>Added <code>glfwSetWindowIconifyCallback</code> function and <code>GLFWwindowiconifyfun</code> type for receiving window iconification events</li>
|
||||
<li>Added <code>windows</code> simple multi-window test program</li>
|
||||
<li>Added a parameter to <code>glfwOpenWindow</code> for specifying a context the new window's context will share objects with</li>
|
||||
<li>Added initial window title parameter to <code>glfwOpenWindow</code></li>
|
||||
<li>Changed buffer bit depth parameters of <code>glfwOpenWindow</code> to window hints</li>
|
||||
<li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</li>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,7 +104,7 @@ 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;
|
||||
|
@ -108,7 +115,8 @@ typedef struct _GLFWwndconfig
|
|||
int glForward;
|
||||
int glDebug;
|
||||
int glProfile;
|
||||
} _GLFWwndconfig;
|
||||
_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;
|
||||
};
|
||||
|
||||
|
||||
//========================================================================
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,9 +584,10 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
|
|||
|
||||
setGLXattrib(attribs, index, None, None);
|
||||
|
||||
window->GLX.context = window->GLX.CreateContextAttribsARB(_glfwLibrary.X11.display,
|
||||
window->GLX.context =
|
||||
window->GLX.CreateContextAttribsARB(_glfwLibrary.X11.display,
|
||||
*fbconfig,
|
||||
NULL,
|
||||
share,
|
||||
True,
|
||||
attribs);
|
||||
}
|
||||
|
@ -590,10 +595,11 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
|
|||
{
|
||||
if (window->GLX.has_GLX_SGIX_fbconfig)
|
||||
{
|
||||
window->GLX.context = window->GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display,
|
||||
window->GLX.context =
|
||||
window->GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display,
|
||||
*fbconfig,
|
||||
GLX_RGBA_TYPE,
|
||||
NULL,
|
||||
share,
|
||||
True);
|
||||
}
|
||||
else
|
||||
|
@ -601,7 +607,7 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
|
|||
window->GLX.context = glXCreateNewContext(_glfwLibrary.X11.display,
|
||||
*fbconfig,
|
||||
GLX_RGBA_TYPE,
|
||||
NULL,
|
||||
share,
|
||||
True);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ int main(void)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
window = glfwOpenWindow(window_width, window_height, GLFW_WINDOWED, "Cursor Inaccuracy Detector");
|
||||
window = glfwOpenWindow(window_width, window_height, GLFW_WINDOWED, "Cursor Inaccuracy Detector", NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
|
|
|
@ -75,7 +75,7 @@ int main(void)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Defaults");
|
||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Defaults", NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
|
|
|
@ -290,7 +290,7 @@ int main(void)
|
|||
|
||||
printf("Library initialized\n");
|
||||
|
||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Event Linter");
|
||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Event Linter", NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
|
|
|
@ -56,7 +56,7 @@ int main(void)
|
|||
|
||||
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
|
||||
|
||||
window = glfwOpenWindow(400, 400, GLFW_WINDOWED, "Aliasing Detector");
|
||||
window = glfwOpenWindow(400, 400, GLFW_WINDOWED, "Aliasing Detector", NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
|
|
|
@ -81,7 +81,7 @@ int main(void)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
window = glfwOpenWindow(640, 480, GLFW_FULLSCREEN, "Fullscreen focus");
|
||||
window = glfwOpenWindow(640, 480, GLFW_FULLSCREEN, "Fullscreen focus", NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
|
|
|
@ -109,7 +109,7 @@ int main(int argc, char** argv)
|
|||
height = 0;
|
||||
}
|
||||
|
||||
window = glfwOpenWindow(width, height, mode, "Iconify");
|
||||
window = glfwOpenWindow(width, height, mode, "Iconify", NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
|
|
|
@ -89,7 +89,7 @@ static GLboolean open_window(void)
|
|||
{
|
||||
int x, y;
|
||||
|
||||
window_handle = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Peter Detector");
|
||||
window_handle = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Peter Detector", NULL);
|
||||
if (!window_handle)
|
||||
return GL_FALSE;
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ static int open_window(int width, int height, int mode)
|
|||
{
|
||||
double base = glfwGetTime();
|
||||
|
||||
window_handle = glfwOpenWindow(width, height, mode, "Window Re-opener");
|
||||
window_handle = glfwOpenWindow(width, height, mode, "Window Re-opener", NULL);
|
||||
if (!window_handle)
|
||||
{
|
||||
fprintf(stderr, "Failed to open %s mode GLFW window: %s\n", get_mode_name(mode), glfwErrorString(glfwGetError()));
|
||||
|
|
|
@ -50,7 +50,7 @@ int main(void)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Tearing Detector");
|
||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Tearing Detector", NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
|
|
|
@ -180,7 +180,7 @@ int main(int argc, char** argv)
|
|||
// We assume here that we stand a better chance of success by leaving all
|
||||
// possible details of pixel format selection to GLFW
|
||||
|
||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Version");
|
||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Version", NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
|
|
|
@ -55,7 +55,7 @@ int main(void)
|
|||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
windows[i] = glfwOpenWindow(200, 200, GLFW_WINDOWED, titles[i]);
|
||||
windows[i] = glfwOpenWindow(200, 200, GLFW_WINDOWED, titles[i], NULL);
|
||||
if (!windows[i])
|
||||
{
|
||||
fprintf(stderr, "Failed to open GLFW window: %s\n",
|
||||
|
|
Loading…
Reference in New Issue
Block a user