From 6293dd5558644b6562524c3bfa328a35bedeb661 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 17 Jul 2003 05:52:47 +0000 Subject: STR #77: all GL Contexts are now managed in a list, so that if the firts context is hidden, there is still information with shareable GL Contexts. Depending on the implementation of the OpenGL driver, this may not work. It would be great if folks could do stress testing on multiple platforms with different drivers. The test would be to create 3 Contexts, delete the firts one, and create another one or two. It seems to work on my OS X Mac... . git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@3046 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Gl_Choice.cxx | 61 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/Fl_Gl_Choice.cxx b/src/Fl_Gl_Choice.cxx index 2805a6978..2d2cd633b 100644 --- a/src/Fl_Gl_Choice.cxx +++ b/src/Fl_Gl_Choice.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Gl_Choice.cxx,v 1.5.2.7.2.13 2003/01/30 21:41:48 easysw Exp $" +// "$Id: Fl_Gl_Choice.cxx,v 1.5.2.7.2.14 2003/07/17 05:52:47 matthiaswm Exp $" // // OpenGL visual selection code for the Fast Light Tool Kit (FLTK). // @@ -217,7 +217,31 @@ Fl_Gl_Choice *Fl_Gl_Choice::find(int m, const int *alistp) { return g; } -static GLContext first_context; +static GLContext *context_list = 0; +static int nContext = 0, NContext = 0; + +static void add_context(GLContext ctx) { + if (!ctx) return; + if (nContext==NContext) { + if (!NContext) NContext = 8; + NContext *= 2; + context_list = (GLContext*)realloc( + context_list, NContext*sizeof(GLContext)); + } + context_list[nContext++] = ctx; +} + +static void del_context(GLContext ctx) { + int i; + for (i=0; ipixelformat, first_context); - if ( !first_context ) first_context = (GLContext)context; + GLContext context, shared_ctx = context_list ? context_list[0] : 0; + context = aglCreateContext( g->pixelformat, shared_ctx); + if (!context) return 0; + add_context((GLContext)context); if ( window->parent() ) { Rect wrect; GetWindowPortBounds( fl_xid(window), &wrect ); GLint rect[] = { window->x(), wrect.bottom-window->h()-window->y(), window->w(), window->h() }; @@ -257,8 +283,10 @@ GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int lay #else GLContext fl_create_gl_context(XVisualInfo* vis) { - GLContext context = glXCreateContext(fl_display, vis, first_context, 1); - if (!first_context) first_context = context; + GLContext shared_ctx = context_list ? context_list[0] : 0; + GLContext context = glXCreateContext(fl_display, vis, shared_ctx, 1); + if (context) + add_context(context); return context; } @@ -302,21 +330,20 @@ void fl_no_gl_context() { void fl_delete_gl_context(GLContext context) { if (cached_context == context) fl_no_gl_context(); - if (context != first_context) { #ifdef WIN32 - wglDeleteContext(context); + wglDeleteContext(context); #elif defined(__APPLE__) - aglSetCurrentContext( NULL ); - aglSetDrawable( context, NULL ); - aglDestroyContext( context ); + aglSetCurrentContext( NULL ); + aglSetDrawable( context, NULL ); + aglDestroyContext( context ); #else - glXDestroyContext(fl_display, context); + glXDestroyContext(fl_display, context); #endif - } + del_context(context); } #endif // -// End of "$Id: Fl_Gl_Choice.cxx,v 1.5.2.7.2.13 2003/01/30 21:41:48 easysw Exp $". +// End of "$Id: Fl_Gl_Choice.cxx,v 1.5.2.7.2.14 2003/07/17 05:52:47 matthiaswm Exp $". // -- cgit v1.2.3