Skip to content

Commit

Permalink
Fixed OpenGL error.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Oct 25, 2023
1 parent 3c03b82 commit 1fe6118
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 69 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions mrv2/docs/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions mrv2/lib/mrvFl/mrvPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion mrv2/lib/mrvGL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(HEADERS
mrvGLUtil.h
mrvGLViewport.h
mrvGLViewportPrivate.h
mrvGLWindow.h
mrvThumbnailCreator.h
mrvThumbnailWindow.h
mrvTimelineViewport.h
Expand All @@ -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)
Expand Down
55 changes: 1 addition & 54 deletions mrv2/lib/mrvGL/mrvGLViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
3 changes: 0 additions & 3 deletions mrv2/lib/mrvGL/mrvGLViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
87 changes: 87 additions & 0 deletions mrv2/lib/mrvGL/mrvGLWindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// SPDX-License-Identifier: BSD-3-Clause
// mrv2
// Copyright Contributors to the mrv2 Project. All rights reserved.

#include <FL/platform.H>

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

#ifdef FLTK_USE_WAYLAND
# include <EGL/egl.h>
#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
24 changes: 24 additions & 0 deletions mrv2/lib/mrvGL/mrvGLWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: BSD-3-Clause
// mrv2
// Copyright Contributors to the mrv2 Project. All rights reserved.

#pragma once

#include <FL/Fl_Gl_Window.H>

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
13 changes: 13 additions & 0 deletions mrv2/lib/mrvGL/mrvGLWindow.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>

#include "mrvGL/mrvGLWindow.h"

namespace mrv
{
void GLWindow::make_current()
{
[(NSOpenGLContext*)this->context() makeCurrentContext];
}
}
6 changes: 4 additions & 2 deletions mrv2/lib/mrvGL/mrvTimelineViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#include "mrvFl/mrvLaserFadeData.h"

// FLTK includes
#include <FL/Fl_Gl_Window.H>
#define Fl_SuperClass Fl_Gl_Window
#ifdef TLRENDER_GL
# include "mrvGL/mrvGLWindow.h"
# define Fl_SuperClass GLWindow
#endif

class ViewerUI;

Expand Down
5 changes: 4 additions & 1 deletion mrv2/lib/mrvGL/mrvTimelineWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -520,6 +520,9 @@ namespace mrv
{
TLRENDER_P();
const math::Size2i renderSize(pixel_w(), pixel_h());

make_current();

if (!valid())
{
_initializeGL();
Expand Down
9 changes: 6 additions & 3 deletions mrv2/lib/mrvGL/mrvTimelineWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@

#include <tlTimelineUI/IItem.h>

#include <FL/Fl_Gl_Window.H>

#include "mrvFl/mrvTimelinePlayer.h"

#ifdef TLRENDER_GL
# include "mrvGL/mrvGLWindow.h"
# define Fl_SuperClass GLWindow
#endif

namespace tl
{
namespace timeline
Expand All @@ -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);
Expand Down

0 comments on commit 1fe6118

Please sign in to comment.