use global share context

This commit is contained in:
shun_iwasawa 2017-10-11 16:48:14 +09:00
parent 953c16267c
commit 5e0d4f6900
6 changed files with 14 additions and 82 deletions

View file

@ -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

View file

@ -412,6 +412,7 @@ void ImageViewer::hideHistogram() {
//-------------------------------------------------------------------
void ImageViewer::initializeGL() {
initializeOpenGLFunctions();
// glClearColor(1.0,1.0,1.0,1);
glClear(GL_COLOR_BUFFER_BIT);

View file

@ -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());

View file

@ -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() {

View file

@ -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);

View file

@ -585,6 +585,7 @@ HexagonalColorWheel::~HexagonalColorWheel() {
//-----------------------------------------------------------------------------
void HexagonalColorWheel::initializeGL() {
initializeOpenGLFunctions();
QColor const color = getBGColor();
glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());