From 1fe6118654fa36e1db617f4637790e40386a5d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Garramu=C3=B1o?= Date: Wed, 25 Oct 2023 13:31:11 -0300 Subject: [PATCH] Fixed OpenGL error. --- .gitattributes | 1 + mrv2/docs/HISTORY.md | 6 +- mrv2/lib/mrvFl/mrvPreferences.cpp | 9 ++- mrv2/lib/mrvGL/CMakeLists.txt | 8 ++- mrv2/lib/mrvGL/mrvGLViewport.cpp | 55 +----------------- mrv2/lib/mrvGL/mrvGLViewport.h | 3 - mrv2/lib/mrvGL/mrvGLWindow.cpp | 87 ++++++++++++++++++++++++++++ mrv2/lib/mrvGL/mrvGLWindow.h | 24 ++++++++ mrv2/lib/mrvGL/mrvGLWindow.mm | 13 +++++ mrv2/lib/mrvGL/mrvTimelineViewport.h | 6 +- mrv2/lib/mrvGL/mrvTimelineWidget.cpp | 5 +- mrv2/lib/mrvGL/mrvTimelineWidget.h | 9 ++- 12 files changed, 157 insertions(+), 69 deletions(-) create mode 100644 mrv2/lib/mrvGL/mrvGLWindow.cpp create mode 100644 mrv2/lib/mrvGL/mrvGLWindow.h create mode 100644 mrv2/lib/mrvGL/mrvGLWindow.mm diff --git a/.gitattributes b/.gitattributes index 8a0884948..61edaa48b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,6 +6,7 @@ *.i text eol=lf *.fl text eol=lf *.md text eol=lf +*.mm text eol=lf *.po text eol=lf *.pot text eol=lf *.py text eol=lf diff --git a/mrv2/docs/HISTORY.md b/mrv2/docs/HISTORY.md index f19494959..8e74ace7d 100644 --- a/mrv2/docs/HISTORY.md +++ b/mrv2/docs/HISTORY.md @@ -44,10 +44,12 @@ v0.8.2 - Fixed EDL creation for movies that did not have audio. - Fixed selecting the wrong clip when loading a session from the command-line. - Added Background panel to change solid color, checker size and checker colors. -- Made session files try to store relative paths to clips so as to be able to - use them on different platforms. +- Made session files try to store relative paths to clips and OCIO config so + as to be able to use them on different platforms. - Made routine for relative paths return the original path if the path could not be translated into a relative path. +- Fixed the annoying macOS bug where the timeline viewport elements would not + get drawn sometimes. v0.8.1 diff --git a/mrv2/lib/mrvFl/mrvPreferences.cpp b/mrv2/lib/mrvFl/mrvPreferences.cpp index 3720f3ca0..1e2cae838 100644 --- a/mrv2/lib/mrvFl/mrvPreferences.cpp +++ b/mrv2/lib/mrvFl/mrvPreferences.cpp @@ -135,7 +135,8 @@ namespace mrv LOG_INFO(msg); - Fl_Preferences base(prefspath().c_str(), "filmaura", "mrv2"); + Fl_Preferences base( + prefspath().c_str(), "filmaura", "mrv2", (Fl_Preferences::Root)0); base.get("version", version, kPreferencesVersion); @@ -715,7 +716,8 @@ namespace mrv char key[256]; Fl_Preferences path_mapping( - prefspath().c_str(), "filmaura", "mrv2.paths"); + prefspath().c_str(), "filmaura", "mrv2.paths", + (Fl_Preferences::Root)0); num = path_mapping.entries(); for (int i = 0; i < num; ++i) { @@ -1757,7 +1759,8 @@ namespace mrv } } - Fl_Preferences base(prefspath().c_str(), "filmaura", "mrv2"); + Fl_Preferences base( + prefspath().c_str(), "filmaura", "mrv2", (Fl_Preferences::Root)0); Fl_Preferences gui(base, "ui"); gui.set("single_instance", uiPrefs->uiPrefsSingleInstance->value()); gui.set( diff --git a/mrv2/lib/mrvGL/CMakeLists.txt b/mrv2/lib/mrvGL/CMakeLists.txt index 44059e3bc..bc756dbe7 100644 --- a/mrv2/lib/mrvGL/CMakeLists.txt +++ b/mrv2/lib/mrvGL/CMakeLists.txt @@ -15,6 +15,7 @@ set(HEADERS mrvGLUtil.h mrvGLViewport.h mrvGLViewportPrivate.h + mrvGLWindow.h mrvThumbnailCreator.h mrvThumbnailWindow.h mrvTimelineViewport.h @@ -36,12 +37,17 @@ set(SOURCES mrvGLViewport.cpp mrvGLViewportDraw.cpp mrvGLViewportPrims.cpp + mrvGLWindow.cpp mrvThumbnailCreator.cpp mrvTimelineViewportEvents.cpp mrvTimelineViewport.cpp mrvTimelineWidget.cpp - ) +) +if(APPLE) + list(APPEND SOURCES mrvGLWindow.mm) +endif() + add_definitions( -DGL_SILENCE_DEPRECATION ) set(LIBRARIES tlGL tlTimeline tlTimelineUI tlUI glfw) diff --git a/mrv2/lib/mrvGL/mrvGLViewport.cpp b/mrv2/lib/mrvGL/mrvGLViewport.cpp index d2182426b..da2d17c7e 100644 --- a/mrv2/lib/mrvGL/mrvGLViewport.cpp +++ b/mrv2/lib/mrvGL/mrvGLViewport.cpp @@ -191,65 +191,12 @@ 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(); + make_current(); // needed to work with GLFW if (!valid()) { diff --git a/mrv2/lib/mrvGL/mrvGLViewport.h b/mrv2/lib/mrvGL/mrvGLViewport.h index c2b289cd1..dcdd9dec0 100644 --- a/mrv2/lib/mrvGL/mrvGLViewport.h +++ b/mrv2/lib/mrvGL/mrvGLViewport.h @@ -37,9 +37,6 @@ 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/mrv2/lib/mrvGL/mrvGLWindow.cpp b/mrv2/lib/mrvGL/mrvGLWindow.cpp new file mode 100644 index 000000000..a0feba637 --- /dev/null +++ b/mrv2/lib/mrvGL/mrvGLWindow.cpp @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: BSD-3-Clause +// mrv2 +// Copyright Contributors to the mrv2 Project. All rights reserved. + +#include + +#ifdef FLTK_USE_X11 +# include +# include +#endif + +#ifdef FLTK_USE_WAYLAND +# include +#endif + +#include "mrvGL/mrvGLWindow.h" + +namespace +{ + const char* kModule = "gl"; +} + +namespace mrv +{ + + GLWindow::GLWindow(int X, int Y, int W, int H, const char* L) : + Fl_Gl_Window(X, Y, W, H, L) + { + } + + GLWindow::GLWindow(int W, int H, const char* L) : + Fl_Gl_Window(W, H, L) + { + } + +#ifndef __APPLE__ + void GLWindow::make_current() + { + GLContext ctx = this->context(); + if (!ctx) + return Fl_Gl_Window::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 + } +#endif + +} // namespace mrv diff --git a/mrv2/lib/mrvGL/mrvGLWindow.h b/mrv2/lib/mrvGL/mrvGLWindow.h new file mode 100644 index 000000000..3801241e9 --- /dev/null +++ b/mrv2/lib/mrvGL/mrvGLWindow.h @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: BSD-3-Clause +// mrv2 +// Copyright Contributors to the mrv2 Project. All rights reserved. + +#pragma once + +#include + +namespace mrv +{ + + // + // This class implements coomon OpenGL functionality + // + class GLWindow : public Fl_Gl_Window + { + + public: + GLWindow(int X, int Y, int W, int H, const char* L = 0); + GLWindow(int W, int H, const char* L = 0); + + void make_current(); + }; +} // namespace mrv diff --git a/mrv2/lib/mrvGL/mrvGLWindow.mm b/mrv2/lib/mrvGL/mrvGLWindow.mm new file mode 100644 index 000000000..ca58cd3ad --- /dev/null +++ b/mrv2/lib/mrvGL/mrvGLWindow.mm @@ -0,0 +1,13 @@ + +#import +#import + +#include "mrvGL/mrvGLWindow.h" + +namespace mrv +{ + void GLWindow::make_current() + { + [(NSOpenGLContext*)this->context() makeCurrentContext]; + } +} diff --git a/mrv2/lib/mrvGL/mrvTimelineViewport.h b/mrv2/lib/mrvGL/mrvTimelineViewport.h index 370329e98..743f3097f 100644 --- a/mrv2/lib/mrvGL/mrvTimelineViewport.h +++ b/mrv2/lib/mrvGL/mrvTimelineViewport.h @@ -15,8 +15,10 @@ #include "mrvFl/mrvLaserFadeData.h" // FLTK includes -#include -#define Fl_SuperClass Fl_Gl_Window +#ifdef TLRENDER_GL +# include "mrvGL/mrvGLWindow.h" +# define Fl_SuperClass GLWindow +#endif class ViewerUI; diff --git a/mrv2/lib/mrvGL/mrvTimelineWidget.cpp b/mrv2/lib/mrvGL/mrvTimelineWidget.cpp index 101352ccb..69357f682 100644 --- a/mrv2/lib/mrvGL/mrvTimelineWidget.cpp +++ b/mrv2/lib/mrvGL/mrvTimelineWidget.cpp @@ -144,7 +144,7 @@ namespace mrv }; TimelineWidget::TimelineWidget(int X, int Y, int W, int H, const char* L) : - Fl_Gl_Window(X, Y, W, H, L), + Fl_SuperClass(X, Y, W, H, L), _p(new Private) { int fl_double = FL_DOUBLE; @@ -520,6 +520,9 @@ namespace mrv { TLRENDER_P(); const math::Size2i renderSize(pixel_w(), pixel_h()); + + make_current(); + if (!valid()) { _initializeGL(); diff --git a/mrv2/lib/mrvGL/mrvTimelineWidget.h b/mrv2/lib/mrvGL/mrvTimelineWidget.h index 7b824a8cd..ff1328aeb 100644 --- a/mrv2/lib/mrvGL/mrvTimelineWidget.h +++ b/mrv2/lib/mrvGL/mrvTimelineWidget.h @@ -12,10 +12,13 @@ #include -#include - #include "mrvFl/mrvTimelinePlayer.h" +#ifdef TLRENDER_GL +# include "mrvGL/mrvGLWindow.h" +# define Fl_SuperClass GLWindow +#endif + namespace tl { namespace timeline @@ -33,7 +36,7 @@ namespace mrv class ThumbnailCreator; //! Timeline widget. - class TimelineWidget : public Fl_Gl_Window + class TimelineWidget : public Fl_SuperClass { public: TimelineWidget(int X, int Y, int W, int H, const char* L = 0);