diff --git a/mrv2/lib/mrvGL/mrvGLOffscreenContext.cpp b/mrv2/lib/mrvGL/mrvGLOffscreenContext.cpp index 23a236484..5af12c518 100644 --- a/mrv2/lib/mrvGL/mrvGLOffscreenContext.cpp +++ b/mrv2/lib/mrvGL/mrvGLOffscreenContext.cpp @@ -141,7 +141,6 @@ namespace mrv TLRENDER_P(); #if defined(_WIN32) - ///! Note: Is this is not thread safe? Not sure p.win->context(nullptr, true); p.win->make_current(); if (!p.win->context()) diff --git a/mrv2/lib/mrvGL/mrvGLViewport.cpp b/mrv2/lib/mrvGL/mrvGLViewport.cpp index aa4d6618f..d2182426b 100644 --- a/mrv2/lib/mrvGL/mrvGLViewport.cpp +++ b/mrv2/lib/mrvGL/mrvGLViewport.cpp @@ -41,6 +41,18 @@ #include "mrvApp/mrvSettingsObject.h" +#include +#undef None + +#ifdef FLTK_USE_X11 +# include +# include +#endif + +#ifdef FLTK_USE_WAYLAND +# include +#endif + namespace { const char* kModule = "view"; @@ -179,11 +191,66 @@ namespace mrv return TimelineViewport::handle(event); } + void Viewport::make_current() + { + GLContext ctx = this->context(); + if (!ctx) + return TimelineViewport::make_current(); + +#ifdef _WIN32 + HGLRC cur_hglrc = wglGetCurrentContext(); + HGLRC hglrc = fl_win32_glcontext(ctx); + if (hglrc == cur_hglrc) + return; + + HWND hwnd = fl_win32_xid(this); + assert(hwnd); + HDC hdc = fl_GetDC(hwnd); + assert(hdc); + assert(hglrc); + wglMakeCurrent(hdc, hglrc); +#endif + +#ifdef __linux__ +# ifdef FLTK_USE_X11 + auto dpy = fl_x11_display(); + if (dpy) + { + auto win = fl_x11_xid(this); + assert(win); + glXMakeCurrent(dpy, win, (GLXContext)ctx); + } +# endif +# ifdef FLTK_USE_WAYLAND + auto wldpy = fl_wl_display(); + if (wldpy) + { + auto eglctx = fl_wl_glcontext(ctx); + EGLContext currentContext = eglGetCurrentContext(); + if (currentContext == eglctx) + return; + + auto win = fl_wl_xid(this); + assert(win); + + auto surface = fl_wl_surface(win); + eglMakeCurrent(wldpy, surface, surface, eglctx); + } +# endif +#endif + +#ifdef __APPLE__ + // CGLSetCurrentContext(ctx); +#endif + } + void Viewport::draw() { TLRENDER_P(); MRV2_GL(); + make_current(); + if (!valid()) { _initializeGL(); diff --git a/mrv2/lib/mrvGL/mrvGLViewport.h b/mrv2/lib/mrvGL/mrvGLViewport.h index dcdd9dec0..c2b289cd1 100644 --- a/mrv2/lib/mrvGL/mrvGLViewport.h +++ b/mrv2/lib/mrvGL/mrvGLViewport.h @@ -37,6 +37,9 @@ namespace mrv //! Refresh window by clearing the associated resources. void refresh() override; + //! Force context to be made current, unlike FLTK's optimized approach. + void make_current(); + protected: void _initializeGL(); void _initializeGLResources(); diff --git a/tlRender b/tlRender index 691841ce3..2db1edafa 160000 --- a/tlRender +++ b/tlRender @@ -1 +1 @@ -Subproject commit 691841ce3500f9456ca30c2d05d005c2c1ee8ea6 +Subproject commit 2db1edafacb7e0ed4c8121aded37d485750bf13b