OpenToonz - An open-source full-featured 2D animation creation software
C
Fix OpenGL widgets in floating panels disapper on room switch (#2684)
shun-iwasawae40777885d90
diff --git a/toonz/sources/include/toonzqt/lutcalibrator.h b/toonz/sources/include/toonzqt/lutcalibrator.hindex 986fcdf90..951a57da7 100644--- a/toonz/sources/include/toonzqt/lutcalibrator.h+++ b/toonz/sources/include/toonzqt/lutcalibrator.h@@ -29,7 +29,8 @@ class QOpenGLContext;class QColor;class DVAPI LutCalibrator : public QOpenGLFunctions {- bool m_isValid = false;+ bool m_isValid = false;+ bool m_isInitialized = false;struct LutTextureShader {QOpenGLShader* vert = nullptr;@@ -58,6 +59,7 @@ public:void initialize();bool isValid() { return m_isValid; }+ bool isInitialized() { return m_isInitialized; }~LutCalibrator() {}diff --git a/toonz/sources/include/toonzqt/styleeditor.h b/toonz/sources/include/toonzqt/styleeditor.hindex 484bdadcd..1f53f5891 100644--- a/toonz/sources/include/toonzqt/styleeditor.h+++ b/toonz/sources/include/toonzqt/styleeditor.h@@ -152,6 +152,8 @@ class DVAPI HexagonalColorWheel final : public GLWidgetForHighDpi {QOpenGLFramebufferObject *m_fbo = NULL;LutCalibrator *m_lutCalibrator = NULL;+ bool m_firstInitialized = true;+private:void drawCurrentColorMark();void clickLeftWheel(const QPoint &pos);diff --git a/toonz/sources/toonz/imageviewer.cpp b/toonz/sources/toonz/imageviewer.cppindex 9a924e5ea..96d4f51f1 100644--- a/toonz/sources/toonz/imageviewer.cpp+++ b/toonz/sources/toonz/imageviewer.cpp@@ -442,7 +442,7 @@ void ImageViewer::initializeGL() {initializeOpenGLFunctions();// to be computed once through the software- if (m_lutCalibrator) {+ if (m_lutCalibrator && !m_lutCalibrator->isInitialized()) {m_lutCalibrator->initialize();connect(context(), SIGNAL(aboutToBeDestroyed()), this,SLOT(onContextAboutToBeDestroyed()));@@ -450,6 +450,13 @@ void ImageViewer::initializeGL() {// glClearColor(1.0,1.0,1.0,1);glClear(GL_COLOR_BUFFER_BIT);++ if (m_firstInitialized)+ m_firstInitialized = false;+ else {+ resizeGL(width(), height());+ update();+ }}//-----------------------------------------------------------------------------diff --git a/toonz/sources/toonz/imageviewer.h b/toonz/sources/toonz/imageviewer.hindex ecdb09524..757b741fb 100644--- a/toonz/sources/toonz/imageviewer.h+++ b/toonz/sources/toonz/imageviewer.h@@ -71,7 +71,8 @@ class ImageViewer final : public GLWidgetForHighDpi {bool m_panning = false;double m_scaleFactor; // used for zoom gesture- bool m_stylusUsed = false;+ bool m_stylusUsed = false;+ bool m_firstInitialized = true;int getDragType(const TPoint &pos, const TRect &loadBox);void updateLoadbox(const TPoint &curPos);diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cppindex e451ad204..523277fa8 100644--- a/toonz/sources/toonz/mainwindow.cpp+++ b/toonz/sources/toonz/mainwindow.cpp@@ -1056,7 +1056,6 @@ void MainWindow::onCurrentRoomChanged(int newRoomIndex) {TPanel *pane = paneList.at(i);if (pane->isFloating() && !pane->isHidden()) {QRect oldGeometry = pane->geometry();-// Just setting the new parent is not enough for the new layout manager.// Must be removed from the old and added to the new.oldRoom->removeDockWidget(pane);diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cppindex 3e50de491..2d2743738 100644--- a/toonz/sources/toonz/sceneviewer.cpp+++ b/toonz/sources/toonz/sceneviewer.cpp@@ -929,7 +929,7 @@ void SceneViewer::initializeGL() {registerContext();// to be computed once through the software- if (m_lutCalibrator) {+ if (m_lutCalibrator && !m_lutCalibrator->isInitialized()) {m_lutCalibrator->initialize();connect(context(), SIGNAL(aboutToBeDestroyed()), this,SLOT(onContextAboutToBeDestroyed()));@@ -937,6 +937,13 @@ void SceneViewer::initializeGL() {// glClearColor(1.0,1.0,1.0,1);glClear(GL_COLOR_BUFFER_BIT);++ if (m_firstInitialized)+ m_firstInitialized = false;+ else {+ resizeGL(width(), height());+ update();+ }}//-----------------------------------------------------------------------------diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.hindex ec2ccb389..72f488ddd 100644--- a/toonz/sources/toonz/sceneviewer.h+++ b/toonz/sources/toonz/sceneviewer.h@@ -181,6 +181,8 @@ class SceneViewer final : public GLWidgetForHighDpi,double m_rotationAngle[2];+ bool m_firstInitialized = true;+public:enum ReferenceMode {NORMAL_REFERENCE = 1,diff --git a/toonz/sources/toonzqt/lutcalibrator.cpp b/toonz/sources/toonzqt/lutcalibrator.cppindex fec60f88f..acbc17368 100644--- a/toonz/sources/toonzqt/lutcalibrator.cpp+++ b/toonz/sources/toonzqt/lutcalibrator.cpp@@ -20,7 +20,7 @@ inline bool execWarning(const QString& s) {DVGui::MsgBox(DVGui::WARNING, s);return false;}-};+}; // namespace#ifdef WIN32@@ -161,13 +161,14 @@ QStringList getMonitorNames() {return nameList;}-};+}; // namespace#endif//-----------------------------------------------------------------------------void LutCalibrator::initialize() {initializeOpenGLFunctions();+ m_isInitialized = true;if (!LutManager::instance()->isValid()) return;@@ -191,6 +192,7 @@ void LutCalibrator::initialize() {//-----------------------------------------------------------------------------void LutCalibrator::cleanup() {+ m_isInitialized = false;if (!isValid()) return;// release shaderif (m_shader.program) {@@ -213,6 +215,7 @@ void LutCalibrator::cleanup() {delete m_lutTex;m_lutTex = NULL;}+ m_isValid = false;}//-----------------------------------------------------------------------------@@ -560,7 +563,7 @@ void LutManager::convert(float& r, float& g, float& b) {for (int bb = 0; bb < 2; bb++) {float* val = &m_lut.data[locals::getCoord(index[0][rr], index[1][gg], index[2][bb], m_lut.meshSize)];- for (int chan = 0; chan < 3; chan++, val++)+ for (int chan = 0; chan < 3; chan++, val++)vertex_color[rr][gg][bb][chan] = *val;}float result[3];diff --git a/toonz/sources/toonzqt/styleeditor.cpp b/toonz/sources/toonzqt/styleeditor.cppindex 00c094445..2791965bf 100644--- a/toonz/sources/toonzqt/styleeditor.cpp+++ b/toonz/sources/toonzqt/styleeditor.cpp@@ -577,7 +577,7 @@ void HexagonalColorWheel::initializeGL() {initializeOpenGLFunctions();// to be computed once through the software- if (m_lutCalibrator) {+ if (m_lutCalibrator && !m_lutCalibrator->isInitialized()) {m_lutCalibrator->initialize();connect(context(), SIGNAL(aboutToBeDestroyed()), this,SLOT(onContextAboutToBeDestroyed()));@@ -585,6 +585,15 @@ void HexagonalColorWheel::initializeGL() {QColor const color = getBGColor();glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());++ // Without the following lines, the wheel in a floating style editor+ // dissapears on switching the room due to context switching.+ if (m_firstInitialized)+ m_firstInitialized = false;+ else {+ resizeGL(width(), height());+ update();+ }}//-----------------------------------------------------------------------------@@ -813,7 +822,7 @@ void HexagonalColorWheel::mouseReleaseEvent(QMouseEvent *event) {//-----------------------------------------------------------------------------/*! compute hue and saturation position. saturation value must be clamped-*/+ */void HexagonalColorWheel::clickLeftWheel(const QPoint &pos) {QLineF p(m_wp[0] + m_wheelPosition, QPointF(pos));QLineF horizontal(0, 0, 1, 0);@@ -824,7 +833,7 @@ void HexagonalColorWheel::clickLeftWheel(const QPoint &pos) {// d is a length from center to edge of the wheel when saturation = 100float d = m_triHeight / cosf(phi / 180.0f * 3.1415f);- int h = (int)theta;+ int h = (int)theta;if (h > 359) h = 359;// clampingint s = (int)(std::min(p.length() / d, 1.0) * 100.0f);@@ -2326,7 +2335,7 @@ void SpecialStyleChooserPage::loadItems() {tagId == 2002 || // ??tagId == 3000 || // vector brushtagId == 4001 // mypaint brush- )+ )continue;TColorStyle *style = TColorStyle::create(tagId);@@ -3128,7 +3137,7 @@ QFrame *StyleEditor::createBottomWidget() {bool ret = true;ret = ret && connect(m_applyButton, SIGNAL(clicked()), this,SLOT(applyButtonClicked()));- ret = ret && connect(m_autoButton, SIGNAL(toggled(bool)), this,+ ret = ret && connect(m_autoButton, SIGNAL(toggled(bool)), this,SLOT(autoCheckChanged(bool)));ret = ret && connect(m_oldColor, SIGNAL(clicked(const TColorStyle &)), this,SLOT(onOldStyleClicked(const TColorStyle &)));@@ -3191,9 +3200,9 @@ QFrame *StyleEditor::createVectorPage() {bool ret = true;ret = ret && connect(specialButton, SIGNAL(toggled(bool)), this,SLOT(onSpecialButtonToggled(bool)));- ret = ret && connect(customButton, SIGNAL(toggled(bool)), this,+ ret = ret && connect(customButton, SIGNAL(toggled(bool)), this,SLOT(onCustomButtonToggled(bool)));- ret = ret && connect(vectorBrushButton, SIGNAL(toggled(bool)), this,+ ret = ret && connect(vectorBrushButton, SIGNAL(toggled(bool)), this,SLOT(onVectorBrushButtonToggled(bool)));assert(ret);return vectorOutsideFrame;@@ -3230,9 +3239,9 @@ void StyleEditor::showEvent(QShowEvent *) {bool ret = true;ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleSwitched()),SLOT(onStyleSwitched()));- ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleChanged(bool)),+ ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleChanged(bool)),SLOT(onStyleChanged(bool)));- ret = ret && connect(m_paletteHandle, SIGNAL(paletteSwitched()), this,+ ret = ret && connect(m_paletteHandle, SIGNAL(paletteSwitched()), this,SLOT(onStyleSwitched()));if (m_cleanupPaletteHandle)ret =@@ -3381,10 +3390,9 @@ void StyleEditor::copyEditedStyleToPalette(bool isDragging) {m_editedStyle->setIsEditedFlag(true);}- palette->setStyle(- styleIndex,- m_editedStyle->clone()); // Must be done *before* setting the eventual- // palette keyframe+ palette->setStyle(styleIndex,+ m_editedStyle->clone()); // Must be done *before* setting+ // the eventual palette keyframeif (!isDragging) {if (!(*m_oldStyle == *m_editedStyle)) {// do not register undo if the edited color is special one (e.g. changing