Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

use global share context

shun_iwasawa5e0d4f6900c8
diff --git a/toonz/sources/include/toonzqt/glwidget_for_highdpi.h b/toonz/sources/include/toonzqt/glwidget_for_highdpi.h
index c64ba961e..2bee6b439 100644
--- a/toonz/sources/include/toonzqt/glwidget_for_highdpi.h
+++ b/toonz/sources/include/toonzqt/glwidget_for_highdpi.h
@@ -6,15 +6,13 @@
#include <QOpenGLWidget>
#include <QApplication>
#include <QDesktopWidget>
+#include <QOpenGLFunctions>
#include "toonzqt/gutil.h"
-// use obsolete QGLWidget instead of QOpenGLWidget for now...
-// TODO: replace with the "modern" OpenGL source and transfer to QOpenGLWidget
-class GLWidgetForHighDpi : public QOpenGLWidget {
+class GLWidgetForHighDpi : public QOpenGLWidget, protected QOpenGLFunctions {
public:
- GLWidgetForHighDpi(QWidget *parent = Q_NULLPTR,
- const QOpenGLWidget *shareWidget = Q_NULLPTR,
- Qt::WindowFlags f = Qt::WindowFlags())
+ GLWidgetForHighDpi(QWidget *parent = Q_NULLPTR,
+ Qt::WindowFlags f = Qt::WindowFlags())
: QOpenGLWidget(parent, f) {}
// modify sizes for high DPI monitors
diff --git a/toonz/sources/toonz/imageviewer.cpp b/toonz/sources/toonz/imageviewer.cpp
index 1cc0edc8c..d65d15ad3 100644
--- a/toonz/sources/toonz/imageviewer.cpp
+++ b/toonz/sources/toonz/imageviewer.cpp
@@ -412,6 +412,7 @@ void ImageViewer::hideHistogram() {
//-------------------------------------------------------------------
void ImageViewer::initializeGL() {
+ initializeOpenGLFunctions();
// glClearColor(1.0,1.0,1.0,1);
glClear(GL_COLOR_BUFFER_BIT);
diff --git a/toonz/sources/toonz/main.cpp b/toonz/sources/toonz/main.cpp
index a73a30b91..9c476588c 100644
--- a/toonz/sources/toonz/main.cpp
+++ b/toonz/sources/toonz/main.cpp
@@ -261,6 +261,9 @@ int main(int argc, char *argv[]) {
#if QT_VERSION >= 0x050600
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
+ // Enables resource sharing between the OpenGL contexts used by classes like
+ // QOpenGLWidget and QQuickWidget.
+ QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QApplication a(argc, argv);
@@ -522,8 +525,8 @@ int main(int argc, char *argv[]) {
loadShaderInterfaces(ToonzFolder::getLibraryFolder() + TFilePath("shaders"));
- splash.showMessage(offsetStr + "Initializing OpenToonz ...",
- Qt::AlignCenter, Qt::white);
+ splash.showMessage(offsetStr + "Initializing OpenToonz ...", Qt::AlignCenter,
+ Qt::white);
a.processEvents();
TTool::setApplication(TApp::instance());
diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp
index acd964180..996bab510 100644
--- a/toonz/sources/toonz/sceneviewer.cpp
+++ b/toonz/sources/toonz/sceneviewer.cpp
@@ -69,7 +69,6 @@
#include "timagecache.h"
#include "trasterimage.h"
#include "tstroke.h"
-#include "tgldisplaylistsmanager.h"
#include "ttoonzimage.h"
// Qt includes
@@ -90,36 +89,6 @@ void drawSpline(const TAffine &viewMatrix, const TRect &clipRect, bool camera3d,
//-------------------------------------------------------------------------------
namespace {
-//-------------------------------------------------------------------------------
-
-int l_displayListsSpaceId =
- -1; //!< Display lists space id associated with SceneViewers
-QOpenGLWidget *l_proxy = 0; //!< Proxy associated with the above
-std::set<TGlContext>
- l_contexts; //!< Stores every SceneViewer context (see ~SceneViewer)
-
-//-------------------------------------------------------------------------------
-
-QOpenGLWidget *touchProxy() {
- struct GLWidgetProxy final : public TGLDisplayListsProxy {
- ~GLWidgetProxy() {
- delete l_proxy;
- l_proxy = 0;
- }
-
- void makeCurrent() override { l_proxy->makeCurrent(); }
- void doneCurrent() override { l_proxy->doneCurrent(); }
- };
-
- // If it does not exist, create the viewer's display lists proxy
- if (!l_proxy) {
- l_proxy = new QOpenGLWidget;
- l_displayListsSpaceId =
- TGLDisplayListsManager::instance()->storeProxy(new GLWidgetProxy);
- }
-
- return l_proxy;
-}
//-------------------------------------------------------------------------------
@@ -469,7 +438,7 @@ public:
//-----------------------------------------------------------------------------
SceneViewer::SceneViewer(ImageUtils::FullScreenWidget *parent)
- : GLWidgetForHighDpi(parent, touchProxy())
+ : GLWidgetForHighDpi(parent)
, m_pressure(0)
, m_lastMousePos(0, 0)
, m_mouseButton(Qt::NoButton)
@@ -532,14 +501,6 @@ SceneViewer::SceneViewer(ImageUtils::FullScreenWidget *parent)
m_3DSideL = rasterFromQPixmap(svgToPixmap(":Resources/3Dside_l.svg"));
m_3DTop = rasterFromQPixmap(svgToPixmap(":Resources/3Dtop.svg"));
- makeCurrent();
- TGlContext context(tglGetCurrentContext());
- doneCurrent();
-
- TGLDisplayListsManager::instance()->attachContext(l_displayListsSpaceId,
- context);
- l_contexts.insert(context);
-
// iwsw commented out temporarily
// if (Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled() &&
// Ghibli3DLutUtil::m_isValid)
@@ -561,23 +522,6 @@ void SceneViewer::setVisual(const ImagePainter::VisualSettings &settings) {
//-----------------------------------------------------------------------------
SceneViewer::~SceneViewer() {
- // Due to a BUG on some old driver we've tested, it's necessary to remove the
- // proxy first,
- // before any QGLWidget which shares the context gets killed in turn. The bug
- // caused a crash
- // when the destruction order of the SceneViewer was inverted with respect to
- // the (shared) creation.
- if (l_proxy) {
- std::set<TGlContext>::iterator ct, cEnd(l_contexts.end());
- for (ct = l_contexts.begin(); ct != cEnd; ++ct)
- TGLDisplayListsManager::instance()->releaseContext(*ct);
- // assert(!l_proxy);
- }
-
- makeCurrent();
- if (m_tableDLId != -1) glDeleteLists(m_tableDLId, 1);
- doneCurrent();
-
// iwsw commented out temporarily
/*
if (m_ghibli3DLutUtil)
@@ -917,6 +861,7 @@ double SceneViewer::getHGuide(int index) { return m_hRuler->getGuide(index); }
//-----------------------------------------------------------------------------
void SceneViewer::initializeGL() {
+ initializeOpenGLFunctions();
// glClearColor(1.0,1.0,1.0,1);
glClear(GL_COLOR_BUFFER_BIT);
@@ -1443,22 +1388,6 @@ static void drawFpsGraph(int t0, int t1) {
//-----------------------------------------------------------------------------
-class Qt_GLContextManager final : public TGLContextManager {
- QGLContext *m_context;
-
-public:
- Qt_GLContextManager() : m_context(0) {}
- void store() override {
- // m_context = const_cast<QGLContext *>(QGLContext::currentContext());
- }
- void store(QGLContext *context) { m_context = context; }
- void restore() override {
- if (m_context) m_context->makeCurrent();
- }
-};
-
-//-----------------------------------------------------------------------------
-
//#define FPS_HISTOGRAM
void SceneViewer::paintGL() {
diff --git a/toonz/sources/toonzqt/planeviewer.cpp b/toonz/sources/toonzqt/planeviewer.cpp
index 74c1d6a6e..40b06443a 100644
--- a/toonz/sources/toonzqt/planeviewer.cpp
+++ b/toonz/sources/toonzqt/planeviewer.cpp
@@ -130,7 +130,7 @@ void PlaneViewer::drawBackground() {
//=========================================================================================
-void PlaneViewer::initializeGL() {}
+void PlaneViewer::initializeGL() { initializeOpenGLFunctions(); }
void PlaneViewer::resizeGL(int width, int height) {
glViewport(0, 0, width, height);
diff --git a/toonz/sources/toonzqt/styleeditor.cpp b/toonz/sources/toonzqt/styleeditor.cpp
index 588abb532..847d19deb 100644
--- a/toonz/sources/toonzqt/styleeditor.cpp
+++ b/toonz/sources/toonzqt/styleeditor.cpp
@@ -585,6 +585,7 @@ HexagonalColorWheel::~HexagonalColorWheel() {
//-----------------------------------------------------------------------------
void HexagonalColorWheel::initializeGL() {
+ initializeOpenGLFunctions();
QColor const color = getBGColor();
glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());