From 77c0c9d95afde283b73d9b87eb1d87d88ac57b5a Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 22 Feb 2020 00:13:28 +1100 Subject: [PATCH] viewer: ported to openglcolorprocessor for simpler code and fixed bug that snuck in breaking color managed display --- .../backend/opengl/openglcolorprocessor.cpp | 4 +- .../backend/opengl/openglcolorprocessor.h | 2 +- .../backend/opengl/openglrenderfunctions.cpp | 6 +-- app/widget/viewer/viewerglwidget.cpp | 40 ++++++------------- app/widget/viewer/viewerglwidget.h | 15 +------ 5 files changed, 20 insertions(+), 47 deletions(-) diff --git a/app/render/backend/opengl/openglcolorprocessor.cpp b/app/render/backend/opengl/openglcolorprocessor.cpp index 60ea99c5c..5d137664e 100644 --- a/app/render/backend/opengl/openglcolorprocessor.cpp +++ b/app/render/backend/opengl/openglcolorprocessor.cpp @@ -31,9 +31,9 @@ OpenGLShaderPtr OpenGLColorProcessor::pipeline() const return pipeline_; } -void OpenGLColorProcessor::ProcessOpenGL() +void OpenGLColorProcessor::ProcessOpenGL(bool flipped, const QMatrix4x4& matrix) { - OpenGLRenderFunctions::OCIOBlit(pipeline_, ocio_lut_); + OpenGLRenderFunctions::OCIOBlit(pipeline_, ocio_lut_, flipped, matrix); } void OpenGLColorProcessor::ClearTexture() diff --git a/app/render/backend/opengl/openglcolorprocessor.h b/app/render/backend/opengl/openglcolorprocessor.h index d7c2b9910..894068e5a 100644 --- a/app/render/backend/opengl/openglcolorprocessor.h +++ b/app/render/backend/opengl/openglcolorprocessor.h @@ -34,7 +34,7 @@ public: OpenGLShaderPtr pipeline() const; - void ProcessOpenGL(); + void ProcessOpenGL(bool flipped = false, const QMatrix4x4& matrix = QMatrix4x4()); private: QOpenGLContext* context_; diff --git a/app/render/backend/opengl/openglrenderfunctions.cpp b/app/render/backend/opengl/openglrenderfunctions.cpp index eebdac0fe..00c8a32af 100644 --- a/app/render/backend/opengl/openglrenderfunctions.cpp +++ b/app/render/backend/opengl/openglrenderfunctions.cpp @@ -121,9 +121,9 @@ void OpenGLRenderFunctions::Blit(OpenGLShaderPtr pipeline, bool flipped, QMatrix } void OpenGLRenderFunctions::OCIOBlit(OpenGLShaderPtr pipeline, - GLuint lut, - bool flipped, - QMatrix4x4 matrix) + GLuint lut, + bool flipped, + QMatrix4x4 matrix) { QOpenGLContext* ctx = QOpenGLContext::currentContext(); QOpenGLExtraFunctions* xf = ctx->extraFunctions(); diff --git a/app/widget/viewer/viewerglwidget.cpp b/app/widget/viewer/viewerglwidget.cpp index 59ead4e5c..95854f13f 100644 --- a/app/widget/viewer/viewerglwidget.cpp +++ b/app/widget/viewer/viewerglwidget.cpp @@ -37,7 +37,6 @@ bool ViewerGLWidget::nouveau_check_done_ = false; ViewerGLWidget::ViewerGLWidget(QWidget *parent) : QOpenGLWidget(parent), - ocio_lut_(0), color_manager_(nullptr), has_image_(false) { @@ -207,16 +206,15 @@ void ViewerGLWidget::paintGL() f->glClear(GL_COLOR_BUFFER_BIT); // We only draw if we have a pipeline - if (!has_image_ || !pipeline_ || !texture_.IsCreated()) { + if (!has_image_ || !color_service_ || !texture_.IsCreated()) { return; } // Bind retrieved texture f->glBindTexture(GL_TEXTURE_2D, texture_.texture()); - // Blit using the pipeline retrieved in initializeGL() - //OpenGLRenderFunctions::OCIOBlit(pipeline_, ocio_lut_, true, matrix_); - OpenGLRenderFunctions::Blit(pipeline_, true, matrix_); + // Blit using the color service + color_service_->ProcessOpenGL(true, matrix_); // Release retrieved texture f->glBindTexture(GL_TEXTURE_2D, 0); @@ -226,7 +224,6 @@ void ViewerGLWidget::RefreshColorPipeline() { if (!color_manager_) { color_service_ = nullptr; - pipeline_ = nullptr; return; } @@ -267,7 +264,7 @@ void ViewerGLWidget::SetupColorProcessor() return; } - ClearOCIOLutTexture(); + color_service_ = nullptr; if (color_manager_) { // (Re)create color processor @@ -279,17 +276,14 @@ void ViewerGLWidget::SetupColorProcessor() ocio_view_, ocio_look_); - color_service_ = ColorProcessor::Create(color_manager_->GetConfig(), - OCIO::ROLE_SCENE_LINEAR, - ocio_display_, - ocio_view_, - ocio_look_); + color_service_ = OpenGLColorProcessor::CreateOpenGL(color_manager_->GetConfig(), + OCIO::ROLE_SCENE_LINEAR, + ocio_display_, + ocio_view_, + ocio_look_); + + color_service_->Enable(context(), true); - // (Re)create pipeline from color processor - pipeline_ = OpenGLShader::CreateOCIO(context(), - ocio_lut_, - color_service_->GetProcessor(), - true); } catch (OCIO::Exception& e) { QMessageBox::critical(this, tr("OpenColorIO Error"), @@ -299,15 +293,6 @@ void ViewerGLWidget::SetupColorProcessor() } else { color_service_ = nullptr; - pipeline_ = nullptr; - } -} - -void ViewerGLWidget::ClearOCIOLutTexture() -{ - if (ocio_lut_ > 0) { - context()->functions()->glDeleteTextures(1, &ocio_lut_); - ocio_lut_ = 0; } } @@ -315,9 +300,8 @@ void ViewerGLWidget::ContextCleanup() { makeCurrent(); - ClearOCIOLutTexture(); + color_service_ = nullptr; texture_.Destroy(); - pipeline_ = nullptr; doneCurrent(); } diff --git a/app/widget/viewer/viewerglwidget.h b/app/widget/viewer/viewerglwidget.h index c9b2fccd0..cb46d46de 100644 --- a/app/widget/viewer/viewerglwidget.h +++ b/app/widget/viewer/viewerglwidget.h @@ -23,6 +23,7 @@ #include +#include "render/backend/opengl/openglcolorprocessor.h" #include "render/backend/opengl/openglshader.h" #include "render/backend/opengl/opengltexture.h" #include "render/colormanager.h" @@ -164,18 +165,6 @@ private: */ OpenGLTexture texture_; - /** - * @brief Internal shader object to use as the pipeline shader - * - * Retrieved every initializeGL() in order to stay up to date when new contexts are generated. - */ - OpenGLShaderPtr pipeline_; - - /** - * @brief OCIO LUT texture used for conversions - */ - GLuint ocio_lut_; - /** * @brief Connected color manager */ @@ -184,7 +173,7 @@ private: /** * @brief Color management service */ - ColorProcessorPtr color_service_; + OpenGLColorProcessorPtr color_service_; /** * @brief Drawing matrix (defaults to identity)