From c8794e2f58b4bd0f6d7324546c7492849065ad66 Mon Sep 17 00:00:00 2001 From: Bill Spitzak Date: Thu, 16 Sep 1999 05:34:27 +0000 Subject: Fixed some WIN32 bugs found in 1.0.5: FL_MOUSELEAVE had an extra underscore call to toupper() removed const char* cast added to fl_draw_pixmap Change to Fl_Gl_Window that did not get in in time for 1.0.5, it caches the current gl context and does not call glXMakeCurrent (wglMakeCurrent on WIN32) if not needed. This distinctly speeds up Mesa, Irix, and Windows opengl, although I am stumped why such a test is not built into those libraries already. If you use other code that sets the current OpenGL context fltk will get confused because it does not know it changed. To fix such programs you must call fl_no_gl_context() to clear the cache. There is a report that this causes the fractals demo to crash on some Linux and Irix machines, although I can't reproduce it. I suspect the problem is the fractals demo and not fltk, but this change may be making it more likely to fail. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@726 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Gl_Choice.H | 20 ++++++++++++++------ src/Fl_Gl_Choice.cxx | 31 +++++++++++++++++++++++++++++-- src/Fl_Gl_Overlay.cxx | 11 ++++------- src/Fl_Gl_Window.cxx | 40 ++++++++++++++-------------------------- src/Fl_get_key_win32.cxx | 6 +++--- src/Fl_win32.cxx | 6 +++--- src/fl_draw_pixmap.cxx | 6 +++--- src/gl_start.cxx | 13 +++++++------ 8 files changed, 77 insertions(+), 56 deletions(-) (limited to 'src') diff --git a/src/Fl_Gl_Choice.H b/src/Fl_Gl_Choice.H index 34fa3fc07..e49eff019 100644 --- a/src/Fl_Gl_Choice.H +++ b/src/Fl_Gl_Choice.H @@ -1,5 +1,5 @@ // -// "$Id: Fl_Gl_Choice.H,v 1.4 1999/01/07 19:17:20 mike Exp $" +// "$Id: Fl_Gl_Choice.H,v 1.4.2.1 1999/09/16 05:34:24 bill Exp $" // // OpenGL definitions for the Fast Light Tool Kit (FLTK). // @@ -68,19 +68,27 @@ public: Colormap colormap; // a colormap to use #endif uchar r,d,o; // rgb mode, double buffered, overlay flags - // either use mode flags from gl_draw.H or a literal glX int list. - // one of the two arguments must be zero! + // Return one of these structures for a given gl mode. + // The second argument is a glX attribute list, and is used if mode is + // zero. This is not supported on Win32: static Fl_Gl_Choice *find(int mode, const int *); }; -#ifdef WIN32 -// function to create and init the dc needed to draw OpenGL: +extern GLXContext fl_first_context; // used to make all contexts share +extern GLXContext fl_current_context; + class Fl_Window; + +#ifdef WIN32 +// This must be called before fl_set_gl_context works: HDC fl_private_dc(Fl_Window*, int, Fl_Gl_Choice **gp); #endif +void fl_set_gl_context(Fl_Window*, GLXContext); +void fl_no_gl_context(); + #endif // -// End of "$Id: Fl_Gl_Choice.H,v 1.4 1999/01/07 19:17:20 mike Exp $". +// End of "$Id: Fl_Gl_Choice.H,v 1.4.2.1 1999/09/16 05:34:24 bill Exp $". // diff --git a/src/Fl_Gl_Choice.cxx b/src/Fl_Gl_Choice.cxx index cfd07a5b1..ed6f93ffc 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 1999/01/07 19:17:20 mike Exp $" +// "$Id: Fl_Gl_Choice.cxx,v 1.5.2.1 1999/09/16 05:34:25 bill Exp $" // // OpenGL visual selection code for the Fast Light Tool Kit (FLTK). // @@ -174,10 +174,37 @@ HDC fl_private_dc(Fl_Window* w, int mode, Fl_Gl_Choice **gp) { } return i->private_dc; } + +#endif + +static GLXContext cached_context; + +static Fl_Window* cached_window; + +void fl_set_gl_context(Fl_Window* w, GLXContext c) { + if (c != cached_context || w != cached_window) { + cached_context = c; + cached_window = w; +#ifdef WIN32 + wglMakeCurrent(Fl_X::i(w)->private_dc, c); +#else + glXMakeCurrent(fl_display, fl_xid(w), c); #endif + } +} + +void fl_no_gl_context() { + cached_context = 0; + cached_window = 0; +#ifdef WIN32 + wglMakeCurrent(0, 0); +#else + glXMakeCurrent(fl_display, 0, 0); +#endif +} #endif // -// End of "$Id: Fl_Gl_Choice.cxx,v 1.5 1999/01/07 19:17:20 mike Exp $". +// End of "$Id: Fl_Gl_Choice.cxx,v 1.5.2.1 1999/09/16 05:34:25 bill Exp $". // diff --git a/src/Fl_Gl_Overlay.cxx b/src/Fl_Gl_Overlay.cxx index 8a7d995b3..8c8cf3428 100644 --- a/src/Fl_Gl_Overlay.cxx +++ b/src/Fl_Gl_Overlay.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Gl_Overlay.cxx,v 1.5 1999/01/07 19:17:20 mike Exp $" +// "$Id: Fl_Gl_Overlay.cxx,v 1.5.2.1 1999/09/16 05:34:25 bill Exp $" // // OpenGL overlay code for the Fast Light Tool Kit (FLTK). // @@ -110,8 +110,6 @@ int Fl_Gl_Window::can_do_overlay() { return 1; } -extern GLXContext fl_first_context; - #endif #else @@ -175,10 +173,9 @@ void Fl_Gl_Window::make_overlay_current() { #if HAVE_GL_OVERLAY if (overlay != this) { #ifdef WIN32 - wglMakeCurrent(Fl_X::i(this)->private_dc, (GLXContext)overlay); + fl_set_gl_context(this, (GLXContext)overlay); #else - Fl_Gl_Window* w = (Fl_Gl_Window*)overlay; - w->make_current(); + ((Fl_Gl_Window*)overlay)->make_current(); #endif } else #endif @@ -198,5 +195,5 @@ void Fl_Gl_Window::hide_overlay() { #endif // -// End of "$Id: Fl_Gl_Overlay.cxx,v 1.5 1999/01/07 19:17:20 mike Exp $". +// End of "$Id: Fl_Gl_Overlay.cxx,v 1.5.2.1 1999/09/16 05:34:25 bill Exp $". // diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx index 7b1a21ebb..5b20d60d2 100644 --- a/src/Fl_Gl_Window.cxx +++ b/src/Fl_Gl_Window.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Gl_Window.cxx,v 1.12.2.2 1999/08/09 06:19:32 bill Exp $" +// "$Id: Fl_Gl_Window.cxx,v 1.12.2.3 1999/09/16 05:34:25 bill Exp $" // // OpenGL window code for the Fast Light Tool Kit (FLTK). // @@ -107,8 +107,6 @@ void Fl_Gl_Window::invalidate() { #endif } -extern GLXContext fl_first_context; // in Fl_Gl_Choice.C - int Fl_Gl_Window::mode(int m, const int *a) { if (m == mode_ && a == alist) return 0; mode_ = m; alist = a; @@ -129,33 +127,25 @@ int Fl_Gl_Window::mode(int m, const int *a) { } void Fl_Gl_Window::make_current() { -#ifdef WIN32 - HDC hdc = fl_private_dc(this, mode_,&g); - if (!context) { - context = wglCreateContext(hdc); +#ifdef WIN32 + context = wglCreateContext(fl_private_dc(this, mode_,&g)); if (fl_first_context) wglShareLists(fl_first_context, (GLXContext)context); else fl_first_context = (GLXContext)context; +#else + context = glXCreateContext(fl_display, g->vis, fl_first_context, 1); + if (!fl_first_context) fl_first_context = (GLXContext)context; +#endif valid(0); } - wglMakeCurrent(hdc, (GLXContext)context); - -# if USE_COLORMAP + fl_set_gl_context(this, (GLXContext)context); +#if defined(WIN32) && USE_COLORMAP if (fl_palette) { fl_GetDC(fl_xid(this)); SelectPalette(fl_gc, fl_palette, FALSE); RealizePalette(fl_gc); } -# endif // USE_COLORMAP -#else - if (!context) { - context = glXCreateContext(fl_display, g->vis, fl_first_context, 1); - if (!fl_first_context) fl_first_context = (GLXContext)context; - valid(0); - } - glXMakeCurrent(fl_display, fl_xid(this), (GLXContext)context); -#endif - +#endif // USE_COLORMAP glDrawBuffer(GL_BACK); } @@ -215,12 +205,11 @@ void Fl_Gl_Window::flush() { int init = !ortho_context; #ifdef WIN32 if (init) ortho_context = wglCreateContext(Fl_X::i(this)->private_dc); - wglMakeCurrent(Fl_X::i(this)->private_dc, ortho_context); #else if (init) ortho_context = glXCreateContext(fl_display,g->vis,fl_first_context,1); - glXMakeCurrent(fl_display, fl_xid(this), ortho_context); #endif + fl_set_gl_context(this, ortho_context); if (init) { glDisable(GL_DEPTH_TEST); glReadBuffer(GL_BACK); @@ -266,7 +255,7 @@ void Fl_Gl_Window::flush() { if (overlay && overlay != this) { DRAW_OVERLAY_ONLY: valid_ = save_valid; - wglMakeCurrent(Fl_X::i(this)->private_dc, (GLXContext)overlay); + fl_set_gl_context(this, (GLXContext)overlay); glDisable(GL_SCISSOR_TEST); fl_overlay = 1; glClear(GL_COLOR_BUFFER_BIT); @@ -287,13 +276,12 @@ void Fl_Gl_Window::resize(int X,int Y,int W,int H) { void Fl_Gl_Window::hide() { if (context) { + fl_no_gl_context(); #ifdef WIN32 - wglMakeCurrent(0, 0); if (context && context != fl_first_context) wglDeleteContext((GLXContext)context); g = 0; #else - glXMakeCurrent(fl_display, 0, 0); if (context != fl_first_context) glXDestroyContext(fl_display, (GLXContext)context); #ifdef GLX_MESA_release_buffers @@ -326,5 +314,5 @@ void Fl_Gl_Window::draw_overlay() {} #endif // -// End of "$Id: Fl_Gl_Window.cxx,v 1.12.2.2 1999/08/09 06:19:32 bill Exp $". +// End of "$Id: Fl_Gl_Window.cxx,v 1.12.2.3 1999/09/16 05:34:25 bill Exp $". // diff --git a/src/Fl_get_key_win32.cxx b/src/Fl_get_key_win32.cxx index e909fb682..d2d364112 100755 --- a/src/Fl_get_key_win32.cxx +++ b/src/Fl_get_key_win32.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_get_key_win32.cxx,v 1.4.2.1 1999/05/06 06:20:47 bill Exp $" +// "$Id: Fl_get_key_win32.cxx,v 1.4.2.2 1999/09/16 05:34:26 bill Exp $" // // WIN32 keyboard state routines for the Fast Light Tool Kit (FLTK). // @@ -108,7 +108,7 @@ static const struct {unsigned short vk, fltk;} vktab[] = { static int fltk2ms(int fltk) { if (fltk >= '0' && fltk <= '9') return fltk; if (fltk >= 'A' && fltk <= 'Z') return fltk; - if (fltk >= 'a' && fltk <= 'z') return toupper(fltk); + if (fltk >= 'a' && fltk <= 'z') return fltk-('a'-'A'); if (fltk > FL_F && fltk <= FL_F+16) return fltk-(FL_F-(VK_F1-1)); if (fltk >= FL_KP+'0' && fltk<=FL_KP+'9') return fltk-(FL_KP+'0'-VK_NUMPAD0); int a = 0; @@ -132,5 +132,5 @@ int Fl::get_key(int k) { } // -// End of "$Id: Fl_get_key_win32.cxx,v 1.4.2.1 1999/05/06 06:20:47 bill Exp $". +// End of "$Id: Fl_get_key_win32.cxx,v 1.4.2.2 1999/09/16 05:34:26 bill Exp $". // diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index 042a7e53e..0f857f63c 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_win32.cxx,v 1.33.2.13 1999/07/22 07:27:11 bill Exp $" +// "$Id: Fl_win32.cxx,v 1.33.2.14 1999/09/16 05:34:26 bill Exp $" // // WIN32-specific code for the Fast Light Tool Kit (FLTK). // @@ -48,7 +48,7 @@ #endif /* !WM_SYNCPAINT */ #ifndef WM_MOUSELEAVE -# define WM_MOUSE_LEAVE 0x02a3 +# define WM_MOUSELEAVE 0x02a3 #endif //////////////////////////////////////////////////////////////// @@ -949,5 +949,5 @@ void Fl_Window::make_current() { } // -// End of "$Id: Fl_win32.cxx,v 1.33.2.13 1999/07/22 07:27:11 bill Exp $". +// End of "$Id: Fl_win32.cxx,v 1.33.2.14 1999/09/16 05:34:26 bill Exp $". // diff --git a/src/fl_draw_pixmap.cxx b/src/fl_draw_pixmap.cxx index 85f5eebba..0fe0d96fe 100644 --- a/src/fl_draw_pixmap.cxx +++ b/src/fl_draw_pixmap.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_draw_pixmap.cxx,v 1.4.2.2 1999/08/25 05:37:40 bill Exp $" +// "$Id: fl_draw_pixmap.cxx,v 1.4.2.3 1999/09/16 05:34:27 bill Exp $" // // Pixmap drawing code for the Fast Light Tool Kit (FLTK). // @@ -210,7 +210,7 @@ int fl_draw_pixmap(/*const*/char*const* di, int x, int y, Fl_Color bg) { #endif #endif #ifdef WIN32 - if (fl_parse_color(p, c[0], c[1], c[2])) {; + if (fl_parse_color((const char*)p, c[0], c[1], c[2])) {; #else XColor x; if (XParseColor(fl_display, fl_colormap, (const char*)p, &x)) { @@ -264,5 +264,5 @@ int fl_draw_pixmap(/*const*/char*const* di, int x, int y, Fl_Color bg) { } // -// End of "$Id: fl_draw_pixmap.cxx,v 1.4.2.2 1999/08/25 05:37:40 bill Exp $". +// End of "$Id: fl_draw_pixmap.cxx,v 1.4.2.3 1999/09/16 05:34:27 bill Exp $". // diff --git a/src/gl_start.cxx b/src/gl_start.cxx index 6a2513243..7d9af09d9 100644 --- a/src/gl_start.cxx +++ b/src/gl_start.cxx @@ -1,5 +1,5 @@ // -// "$Id: gl_start.cxx,v 1.6 1999/01/07 19:17:46 mike Exp $" +// "$Id: gl_start.cxx,v 1.6.2.1 1999/09/16 05:34:27 bill Exp $" // // OpenGL context routines for the Fast Light Tool Kit (FLTK). // @@ -61,19 +61,20 @@ Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.C void gl_start() { #ifdef WIN32 HDC hdc = fl_private_dc(Fl_Window::current(), default_mode,0); +#endif if (!context) { +#ifdef WIN32 context = wglCreateContext(hdc); if (!fl_first_context) fl_first_context = context; else wglShareLists(fl_first_context, context); - } - wglMakeCurrent(hdc, context); #else - if (!context) { context = glXCreateContext(fl_display, fl_visual, fl_first_context, 1); if (!context) Fl::fatal("OpenGL does not support this visual"); if (!fl_first_context) fl_first_context = context; +#endif } - glXMakeCurrent(fl_display, fl_window, context); + fl_set_gl_context(Fl_Window::current(), context); +#ifndef WIN32 glXWaitX(); #endif if (pw != Fl_Window::current()->w() || ph != Fl_Window::current()->h()) { @@ -121,5 +122,5 @@ int Fl::gl_visual(int mode, int *alist) { #endif // -// End of "$Id: gl_start.cxx,v 1.6 1999/01/07 19:17:46 mike Exp $". +// End of "$Id: gl_start.cxx,v 1.6.2.1 1999/09/16 05:34:27 bill Exp $". // -- cgit v1.2.3