Browse Source

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
pull/168/head
Matthias Melcher 22 years ago
parent
commit
6293dd5558
  1. 61
      src/Fl_Gl_Choice.cxx

61
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). // 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; 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; i<nContext; i++) {
if (context_list[i]==ctx) {
memmove(context_list+i, context_list+i+1,
(nContext-i-1) * sizeof(GLContext));
context_list[--nContext] = 0;
break;
}
}
}
#ifdef WIN32 #ifdef WIN32
@ -234,17 +258,19 @@ GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int lay
GLContext context = GLContext context =
layer ? wglCreateLayerContext(hdc, layer) : wglCreateContext(hdc); layer ? wglCreateLayerContext(hdc, layer) : wglCreateContext(hdc);
if (context) { if (context) {
if (first_context) wglShareLists(first_context, context); if (context_list && context_list[0])
else first_context = context; wglShareLists(context_list[0], context);
add_context(context);
} }
return context; return context;
} }
#elif defined(__APPLE__) #elif defined(__APPLE__)
GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer) { GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer) {
GLContext context; GLContext context, shared_ctx = context_list ? context_list[0] : 0;
context = aglCreateContext( g->pixelformat, first_context); context = aglCreateContext( g->pixelformat, shared_ctx);
if ( !first_context ) first_context = (GLContext)context; if (!context) return 0;
add_context((GLContext)context);
if ( window->parent() ) { if ( window->parent() ) {
Rect wrect; GetWindowPortBounds( fl_xid(window), &wrect ); Rect wrect; GetWindowPortBounds( fl_xid(window), &wrect );
GLint rect[] = { window->x(), wrect.bottom-window->h()-window->y(), window->w(), window->h() }; 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 #else
GLContext fl_create_gl_context(XVisualInfo* vis) { GLContext fl_create_gl_context(XVisualInfo* vis) {
GLContext context = glXCreateContext(fl_display, vis, first_context, 1); GLContext shared_ctx = context_list ? context_list[0] : 0;
if (!first_context) first_context = context; GLContext context = glXCreateContext(fl_display, vis, shared_ctx, 1);
if (context)
add_context(context);
return context; return context;
} }
@ -302,21 +330,20 @@ void fl_no_gl_context() {
void fl_delete_gl_context(GLContext context) { void fl_delete_gl_context(GLContext context) {
if (cached_context == context) fl_no_gl_context(); if (cached_context == context) fl_no_gl_context();
if (context != first_context) {
#ifdef WIN32 #ifdef WIN32
wglDeleteContext(context); wglDeleteContext(context);
#elif defined(__APPLE__) #elif defined(__APPLE__)
aglSetCurrentContext( NULL ); aglSetCurrentContext( NULL );
aglSetDrawable( context, NULL ); aglSetDrawable( context, NULL );
aglDestroyContext( context ); aglDestroyContext( context );
#else #else
glXDestroyContext(fl_display, context); glXDestroyContext(fl_display, context);
#endif #endif
} del_context(context);
} }
#endif #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 $".
// //

Loading…
Cancel
Save