diff --git a/app/widget/viewer/viewerglwidget.cpp b/app/widget/viewer/viewerglwidget.cpp index 6b614cacc..68efab4af 100644 --- a/app/widget/viewer/viewerglwidget.cpp +++ b/app/widget/viewer/viewerglwidget.cpp @@ -33,9 +33,7 @@ ViewerGLWidget::ViewerGLWidget(QWidget *parent) : texture_(0), ocio_lut_(0) { - connect(ColorManager::instance(), SIGNAL(ConfigChanged()), this, SLOT(ColorConfigChangedSlot())); - - RefreshColorSettings(); + connect(ColorManager::instance(), SIGNAL(ConfigChanged()), this, SLOT(RefreshColorPipeline())); setContextMenuPolicy(Qt::CustomContextMenu); connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShowContextMenu(const QPoint&))); @@ -46,6 +44,27 @@ ViewerGLWidget::~ViewerGLWidget() ContextCleanup(); } +void ViewerGLWidget::SetOCIODisplay(const QString &display) +{ + ocio_display_ = display; + SetupColorProcessor(); + update(); +} + +void ViewerGLWidget::SetOCIOView(const QString &view) +{ + ocio_view_ = view; + SetupColorProcessor(); + update(); +} + +void ViewerGLWidget::SetOCIOLook(const QString &look) +{ + ocio_look_ = look; + SetupColorProcessor(); + update(); +} + void ViewerGLWidget::SetTexture(GLuint tex) { // Update the texture @@ -57,7 +76,7 @@ void ViewerGLWidget::SetTexture(GLuint tex) void ViewerGLWidget::initializeGL() { - SetupPipeline(); + SetupColorProcessor(); connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(ContextCleanup()), Qt::DirectConnection); } @@ -84,39 +103,54 @@ void ViewerGLWidget::paintGL() } } -void ViewerGLWidget::SetupPipeline() +void ViewerGLWidget::RefreshColorPipeline() { - // Re-retrieve pipeline pertaining to this context + QStringList displays = ColorManager::ListAvailableDisplays(); + if (!displays.contains(ocio_display_)) { + ocio_display_ = ColorManager::GetDefaultDisplay(); + } + + QStringList views = ColorManager::ListAvailableViews(ocio_display_); + if (!views.contains(ocio_view_)) { + ocio_view_ = ColorManager::GetDefaultView(ocio_display_); + } + + QStringList looks = ColorManager::ListAvailableLooks(); + if (!looks.contains(ocio_look_)) { + ocio_look_.clear(); + } + + SetupColorProcessor(); + update(); +} + +void ViewerGLWidget::SetupColorProcessor() +{ + ClearOCIOLutTexture(); + + // (Re)create color processor + color_service_ = ColorProcessor::Create(OCIO::ROLE_SCENE_LINEAR, ocio_display_, ocio_view_, ocio_look_); + + // (Re)create pipeline from color processor pipeline_ = OpenGLShader::CreateOCIO(context(), ocio_lut_, color_service_->GetProcessor(), true); } -void ViewerGLWidget::RefreshColorSettings() +void ViewerGLWidget::ClearOCIOLutTexture() { - // FIXME: Should probably check first whether the new config has the existing settings - - ocio_display_ = ColorManager::GetDefaultDisplay(); - ocio_view_ = ColorManager::GetDefaultView(ocio_display_); - ocio_look_.clear(); - - SetupColorProcessor(); -} - -void ViewerGLWidget::SetupColorProcessor() -{ - color_service_ = ColorProcessor::Create(OCIO::ROLE_SCENE_LINEAR, ocio_display_, ocio_view_, ocio_look_); + if (ocio_lut_ > 0) { + context()->functions()->glDeleteTextures(1, &ocio_lut_); + ocio_lut_ = 0; + } } void ViewerGLWidget::ContextCleanup() { makeCurrent(); - if (ocio_lut_ != 0) { - context()->functions()->glDeleteTextures(1, &ocio_lut_); - ocio_lut_ = 0; - } + ClearOCIOLutTexture(); pipeline_ = nullptr; @@ -128,34 +162,52 @@ void ViewerGLWidget::ShowContextMenu(const QPoint &pos) QMenu menu; QStringList displays = ColorManager::ListAvailableDisplays(); - QMenu* ocio_display_menu = menu.addMenu(tr("OCIO Display")); - foreach (QString d, displays) { + QMenu* ocio_display_menu = menu.addMenu(tr("Display")); + connect(ocio_display_menu, SIGNAL(triggered(QAction*)), this, SLOT(ColorDisplayChanged(QAction*))); + foreach (const QString& d, displays) { QAction* action = ocio_display_menu->addAction(d); + action->setCheckable(true); action->setChecked(ocio_display_ == d); + action->setData(d); } QStringList views = ColorManager::ListAvailableViews(ocio_display_); - QMenu* ocio_view_menu = menu.addMenu(tr("OCIO View")); - foreach (QString v, views) { + QMenu* ocio_view_menu = menu.addMenu(tr("View")); + connect(ocio_view_menu, SIGNAL(triggered(QAction*)), this, SLOT(ColorViewChanged(QAction*))); + foreach (const QString& v, views) { QAction* action = ocio_view_menu->addAction(v); + action->setCheckable(true); action->setChecked(ocio_view_ == v); + action->setData(v); } QStringList looks = ColorManager::ListAvailableLooks(); - QMenu* ocio_look_menu = menu.addMenu(tr("OCIO Look")); - foreach (QString l, looks) { + QMenu* ocio_look_menu = menu.addMenu(tr("Look")); + connect(ocio_look_menu, SIGNAL(triggered(QAction*)), this, SLOT(ColorLookChanged(QAction*))); + QAction* no_look_action = ocio_look_menu->addAction(tr("(None)")); + no_look_action->setCheckable(true); + no_look_action->setChecked(ocio_look_.isEmpty()); + foreach (const QString& l, looks) { QAction* action = ocio_look_menu->addAction(l); + action->setCheckable(true); action->setChecked(ocio_look_ == l); + action->setData(l); } menu.exec(mapToGlobal(pos)); } -void ViewerGLWidget::ColorConfigChangedSlot() +void ViewerGLWidget::ColorDisplayChanged(QAction* action) { - RefreshColorSettings(); + SetOCIODisplay(action->data().toString()); +} - if (pipeline_ != nullptr) { - SetupPipeline(); - } +void ViewerGLWidget::ColorViewChanged(QAction *action) +{ + SetOCIOView(action->data().toString()); +} + +void ViewerGLWidget::ColorLookChanged(QAction *action) +{ + SetOCIOLook(action->data().toString()); } diff --git a/app/widget/viewer/viewerglwidget.h b/app/widget/viewer/viewerglwidget.h index 1544db1e2..66084dc25 100644 --- a/app/widget/viewer/viewerglwidget.h +++ b/app/widget/viewer/viewerglwidget.h @@ -76,6 +76,27 @@ public: */ ViewerGLWidget& operator=(ViewerGLWidget&& other) = delete; + /** + * @brief Externally set the OCIO display to use + * + * This value must be a valid display in the current OCIO configuration. + */ + void SetOCIODisplay(const QString& display); + + /** + * @brief Externally set the OCIO view to use + * + * This value must be a valid display in the current OCIO configuration. + */ + void SetOCIOView(const QString& view); + + /** + * @brief Externally set the OCIO look to use (use empty string if none) + * + * This value must be a valid display in the current OCIO configuration. + */ + void SetOCIOLook(const QString& look); + public slots: /** * @brief Set the texture to draw and draw it @@ -102,23 +123,16 @@ protected: virtual void paintGL() override; private: - /** - * @brief Creates the render pipeline shader - * - * If it already exists, it will be deleted. - */ - void SetupPipeline(); - - /** - * @brief Sets all color settings to the defaults pertaining to this configuration - */ - void RefreshColorSettings(); - /** * @brief Call this if this user has selected a different display/view/look to recreate the processor */ void SetupColorProcessor(); + /** + * @brief Cleanup function + */ + void ClearOCIOLutTexture(); + /** * @brief Internal variable to set color space to */ @@ -168,9 +182,25 @@ private slots: void ShowContextMenu(const QPoint& pos); /** - * @brief Slot called whenever the color configuration changes + * @brief Sets all color settings to the defaults pertaining to this configuration */ - void ColorConfigChangedSlot(); + void RefreshColorPipeline(); + + /** + * @brief Slot called whenever this viewer's OCIO display setting has changed + */ + void ColorDisplayChanged(QAction* action); + + /** + * @brief Slot called whenever this viewer's OCIO view setting has changed + */ + void ColorViewChanged(QAction* action); + + /** + * @brief Slot called whenever this viewer's OCIO look setting has changed + */ + void ColorLookChanged(QAction* action); + }; #endif // VIEWERGLWIDGET_H