diff --git a/app/core.cpp b/app/core.cpp index 37ee31929..757bbc99e 100644 --- a/app/core.cpp +++ b/app/core.cpp @@ -33,6 +33,7 @@ #include "panel/project/project.h" #include "project/item/footage/footage.h" #include "project/item/sequence/sequence.h" +#include "render/colorservice.h" #include "task/import/import.h" #include "task/taskmanager.h" #include "ui/style/style.h" @@ -359,7 +360,8 @@ void Core::StartGUI(bool full_screen) // When a new project is opened, update the mainwindow connect(this, SIGNAL(ProjectOpened(Project*)), main_window_, SLOT(ProjectOpen(Project*))); - + // Initialize color service + ColorService::Init(); } Project *Core::GetActiveProject() diff --git a/app/render/colorservice.cpp b/app/render/colorservice.cpp index 7c57fafd7..0df81d32c 100644 --- a/app/render/colorservice.cpp +++ b/app/render/colorservice.cpp @@ -4,13 +4,25 @@ ColorService::ColorService(const char* source_space, const char* dest_space) { - // FIXME: Hardcoded values for testing purposes - OCIO::ConstConfigRcPtr config = OCIO::Config::CreateFromFile("/run/media/matt/Home/OpenColorIO/ocio.configs.0.7v4/nuke-default/config.ocio"); + OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig(); processor = config->getProcessor(source_space, dest_space); } +void ColorService::Init() +{ + // FIXME: Hardcoded values for testing purposes + OCIO::ConstConfigRcPtr config = OCIO::Config::CreateFromFile("/run/media/matt/Home/OpenColorIO/ocio.configs.0.7v4/nuke-default/config.ocio"); + + OCIO::SetCurrentConfig(config); +} + +ColorServicePtr ColorService::Create(const char *source_space, const char *dest_space) +{ + return std::make_shared(source_space, dest_space); +} + void ColorService::ConvertFrame(FramePtr f) { OCIO::PackedImageDesc img(reinterpret_cast(f->data()), f->width(), f->height(), kRGBAChannels); diff --git a/app/render/colorservice.h b/app/render/colorservice.h index 5d2de01b1..1f46e38c1 100644 --- a/app/render/colorservice.h +++ b/app/render/colorservice.h @@ -8,11 +8,18 @@ namespace OCIO = OCIO_NAMESPACE::v1; #include "decoder/frame.h" #include "render/gl/shadergenerators.h" +class ColorService; +using ColorServicePtr = std::shared_ptr; + class ColorService { public: ColorService(const char *source_space, const char *dest_space); + static void Init(); + + static ColorServicePtr Create(const char *source_space, const char *dest_space); + void ConvertFrame(FramePtr f); OCIO::ConstProcessorRcPtr GetProcessor(); @@ -21,6 +28,4 @@ private: OCIO::ConstProcessorRcPtr processor; }; -using ColorServicePtr = std::shared_ptr; - #endif // COLORSERVICE_H diff --git a/app/widget/viewer/viewerglwidget.cpp b/app/widget/viewer/viewerglwidget.cpp index 2a499edde..751fb62cd 100644 --- a/app/widget/viewer/viewerglwidget.cpp +++ b/app/widget/viewer/viewerglwidget.cpp @@ -29,8 +29,11 @@ ViewerGLWidget::ViewerGLWidget(QWidget *parent) : QOpenGLWidget(parent), - texture_(0) + texture_(0), + ocio_lut_(0) { + // FIXME: Hardcoded values for testing + color_service_ = ColorService::Create(OCIO::ROLE_SCENE_LINEAR, "srgb"); } void ViewerGLWidget::SetTexture(GLuint tex) @@ -45,7 +48,12 @@ void ViewerGLWidget::SetTexture(GLuint tex) void ViewerGLWidget::initializeGL() { // Re-retrieve pipeline pertaining to this context - pipeline_ = olive::ShaderGenerator::DefaultPipeline(); + pipeline_ = olive::ShaderGenerator::OCIOPipeline(context(), + ocio_lut_, + color_service_->GetProcessor(), + true); + + connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(ContextCleanup()), Qt::DirectConnection); } void ViewerGLWidget::paintGL() @@ -63,9 +71,23 @@ void ViewerGLWidget::paintGL() f->glBindTexture(GL_TEXTURE_2D, texture_); // Blit using the pipeline retrieved in initializeGL() - olive::gl::Blit(pipeline_, true); + olive::gl::OCIOBlit(pipeline_, ocio_lut_, true); // Release retrieved texture f->glBindTexture(GL_TEXTURE_2D, 0); } } + +void ViewerGLWidget::ContextCleanup() +{ + makeCurrent(); + + if (ocio_lut_ != 0) { + context()->functions()->glDeleteTextures(1, &ocio_lut_); + ocio_lut_ = 0; + } + + pipeline_ = nullptr; + + doneCurrent(); +} diff --git a/app/widget/viewer/viewerglwidget.h b/app/widget/viewer/viewerglwidget.h index 61e589f98..8dee3c379 100644 --- a/app/widget/viewer/viewerglwidget.h +++ b/app/widget/viewer/viewerglwidget.h @@ -23,6 +23,7 @@ #include +#include "render/colorservice.h" #include "render/gl/shaderptr.h" /** @@ -42,6 +43,7 @@ */ class ViewerGLWidget : public QOpenGLWidget { + Q_OBJECT public: /** * @brief ViewerGLWidget Constructor @@ -88,6 +90,19 @@ private: * Retrieved every initializeGL() in order to stay up to date when new contexts are generated. */ ShaderPtr pipeline_; + + /** + * @brief OCIO LUT texture used for conversions + */ + GLuint ocio_lut_; + + /** + * @brief Color management service + */ + ColorServicePtr color_service_; + +private slots: + void ContextCleanup(); }; #endif // VIEWERGLWIDGET_H