work on internal color management

This commit is contained in:
itsmattkc
2019-09-28 01:38:15 +10:00
parent 4c90405feb
commit d2dc0d2823
24 changed files with 983 additions and 175 deletions
+75 -7
View File
@@ -20,6 +20,7 @@
#include "viewerglwidget.h"
#include <QMenu>
#include <QOpenGLContext>
#include <QOpenGLFunctions>
#include <QOpenGLTexture>
@@ -32,8 +33,17 @@ ViewerGLWidget::ViewerGLWidget(QWidget *parent) :
texture_(0),
ocio_lut_(0)
{
// FIXME: Hardcoded values for testing
color_service_ = ColorService::Create(OCIO::ROLE_SCENE_LINEAR, "srgb");
connect(ColorManager::instance(), SIGNAL(ConfigChanged()), this, SLOT(ColorConfigChangedSlot()));
RefreshColorSettings();
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShowContextMenu(const QPoint&)));
}
ViewerGLWidget::~ViewerGLWidget()
{
ContextCleanup();
}
void ViewerGLWidget::SetTexture(GLuint tex)
@@ -47,11 +57,7 @@ void ViewerGLWidget::SetTexture(GLuint tex)
void ViewerGLWidget::initializeGL()
{
// Re-retrieve pipeline pertaining to this context
pipeline_ = olive::ShaderGenerator::OCIOPipeline(context(),
ocio_lut_,
color_service_->GetProcessor(),
true);
SetupPipeline();
connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(ContextCleanup()), Qt::DirectConnection);
}
@@ -78,6 +84,31 @@ void ViewerGLWidget::paintGL()
}
}
void ViewerGLWidget::SetupPipeline()
{
// Re-retrieve pipeline pertaining to this context
pipeline_ = olive::ShaderGenerator::OCIOPipeline(context(),
ocio_lut_,
color_service_->GetProcessor(),
true);
}
void ViewerGLWidget::RefreshColorSettings()
{
// 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_);
}
void ViewerGLWidget::ContextCleanup()
{
makeCurrent();
@@ -91,3 +122,40 @@ void ViewerGLWidget::ContextCleanup()
doneCurrent();
}
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) {
QAction* action = ocio_display_menu->addAction(d);
action->setChecked(ocio_display_ == d);
}
QStringList views = ColorManager::ListAvailableViews(ocio_display_);
QMenu* ocio_view_menu = menu.addMenu(tr("OCIO View"));
foreach (QString v, views) {
QAction* action = ocio_view_menu->addAction(v);
action->setChecked(ocio_view_ == v);
}
QStringList looks = ColorManager::ListAvailableLooks();
QMenu* ocio_look_menu = menu.addMenu(tr("OCIO Look"));
foreach (QString l, looks) {
QAction* action = ocio_look_menu->addAction(l);
action->setChecked(ocio_look_ == l);
}
menu.exec(mapToGlobal(pos));
}
void ViewerGLWidget::ColorConfigChangedSlot()
{
RefreshColorSettings();
if (pipeline_ != nullptr) {
SetupPipeline();
}
}
+69 -2
View File
@@ -23,7 +23,7 @@
#include <QOpenGLWidget>
#include "render/colorservice.h"
#include "render/colormanager.h"
#include "render/gl/shaderptr.h"
/**
@@ -54,6 +54,28 @@ public:
*/
ViewerGLWidget(QWidget* parent);
virtual ~ViewerGLWidget() override;
/**
* @brief Deleted copy constructor
*/
ViewerGLWidget(const ViewerGLWidget& other) = delete;
/**
* @brief Deleted move constructor
*/
ViewerGLWidget(ViewerGLWidget&& other) = delete;
/**
* @brief Deleted copy assignment
*/
ViewerGLWidget& operator=(const ViewerGLWidget& other) = delete;
/**
* @brief Deleted move assignment
*/
ViewerGLWidget& operator=(ViewerGLWidget&& other) = delete;
public slots:
/**
* @brief Set the texture to draw and draw it
@@ -79,6 +101,38 @@ 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 Internal variable to set color space to
*/
QString ocio_display_;
/**
* @brief Internal variable to set color space to
*/
QString ocio_view_;
/**
* @brief Internal variable to set color space to
*/
QString ocio_look_;
/**
* @brief Internal reference to the OpenGL texture to draw. Set in SetTexture() and used in paintGL().
*/
@@ -99,10 +153,23 @@ private:
/**
* @brief Color management service
*/
ColorServicePtr color_service_;
ColorProcessorPtr color_service_;
private slots:
/**
* @brief Slot to connect just before the OpenGL context is destroyed to clean up resources
*/
void ContextCleanup();
/**
* @brief Show context menu
*/
void ShowContextMenu(const QPoint& pos);
/**
* @brief Slot called whenever the color configuration changes
*/
void ColorConfigChangedSlot();
};
#endif // VIEWERGLWIDGET_H