Skip to content

Commit

Permalink
OpenGL fix (missing macOS).
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Oct 25, 2023
1 parent 601ad2d commit 3c03b82
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
1 change: 0 additions & 1 deletion mrv2/lib/mrvGL/mrvGLOffscreenContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
67 changes: 67 additions & 0 deletions mrv2/lib/mrvGL/mrvGLViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@

#include "mrvApp/mrvSettingsObject.h"

#include <FL/platform.H>
#undef None

#ifdef FLTK_USE_X11
# include <X11/Xlib.h>
# include <GL/glx.h>
#endif

#ifdef FLTK_USE_WAYLAND
# include <EGL/egl.h>
#endif

namespace
{
const char* kModule = "view";
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions mrv2/lib/mrvGL/mrvGLViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3c03b82

Please sign in to comment.