viewer: use internal texture to allow viewer to control texture as part of its

context

More intuitive code flow and allows the user to undock the viewer (which
forcibly destroys and recreates the context) and the viewer will handle
creation of the new texture in said new context.
This commit is contained in:
itsmattkc
2020-02-16 18:24:49 +11:00
parent 21755c7f20
commit ceb70a1870
14 changed files with 116 additions and 227 deletions
+7 -18
View File
@@ -83,7 +83,6 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
// Start background renderers
video_renderer_ = new OpenGLBackend(this);
connect(video_renderer_, &VideoRenderBackend::CachedFrameReady, this, &ViewerWidget::RendererCachedFrame);
connect(video_renderer_, &VideoRenderBackend::CachedTimeReady, this, &ViewerWidget::RendererCachedTime);
connect(video_renderer_, &VideoRenderBackend::CachedTimeReady, ruler(), &TimeRuler::CacheTimeReady);
connect(video_renderer_, &VideoRenderBackend::RangeInvalidated, ruler(), &TimeRuler::CacheInvalidatedRange);
@@ -215,17 +214,16 @@ VideoRenderBackend *ViewerWidget::video_renderer() const
return video_renderer_;
}
void ViewerWidget::SetTexture(OpenGLTexturePtr tex)
{
gl_widget_->SetTexture(tex);
}
void ViewerWidget::UpdateTextureFromNode(const rational& time)
{
if (!GetConnectedNode()) {
SetTexture(nullptr);
if (!GetConnectedNode() || time >= GetConnectedNode()->Length()) {
gl_widget_->SetImage(QString());
} else {
SetTexture(video_renderer_->GetCachedFrameAsTexture(time));
QString frame_fn = video_renderer_->GetCachedFrame(time);
if (!frame_fn.isEmpty()) {
gl_widget_->SetImage(frame_fn);
}
}
}
@@ -466,15 +464,6 @@ void ViewerWidget::PlaybackTimerUpdate()
}
}
void ViewerWidget::RendererCachedFrame(const rational &time, QVariant value, qint64 job_time)
{
if (GetTime() == time && job_time > frame_cache_job_time_) {
frame_cache_job_time_ = job_time;
SetTexture(value.value<OpenGLTexturePtr>());
}
}
void ViewerWidget::RendererCachedTime(const rational &time, qint64 job_time)
{
if (GetTime() == time && job_time > frame_cache_job_time_) {
-10
View File
@@ -72,15 +72,6 @@ public:
VideoRenderBackend* video_renderer() const;
public slots:
/**
* @brief Set the texture to draw and draw it
*
* Wrapper function for ViewerGLWidget::SetTexture().
*
* @param tex
*/
void SetTexture(OpenGLTexturePtr tex);
void Play();
void Pause();
@@ -166,7 +157,6 @@ private:
private slots:
void PlaybackTimerUpdate();
void RendererCachedFrame(const rational& time, QVariant value, qint64 job_time);
void RendererCachedTime(const rational& time, qint64 job_time);
void SizeChangedSlot(int width, int height);
+53 -14
View File
@@ -20,6 +20,8 @@
#include "viewerglwidget.h"
#include <OpenImageIO/imagebuf.h>
#include <QFileInfo>
#include <QMessageBox>
#include <QOpenGLContext>
#include <QOpenGLFunctions>
@@ -27,10 +29,10 @@
#include "render/backend/opengl/openglrenderfunctions.h"
#include "render/backend/opengl/openglshader.h"
#include "render/pixelservice.h"
ViewerGLWidget::ViewerGLWidget(QWidget *parent) :
QOpenGLWidget(parent),
texture_(0),
ocio_lut_(0),
color_manager_(nullptr)
{
@@ -68,6 +70,51 @@ void ViewerGLWidget::SetMatrix(const QMatrix4x4 &mat)
update();
}
void ViewerGLWidget::SetImage(const QString &fn)
{
OIIO::ImageBuf* in;
if (fn.isEmpty()) {
// Backend had no filename
goto end;
}
if (!QFileInfo::exists(fn)) {
goto end;
}
in = new OIIO::ImageBuf(fn.toStdString());
if (in->read(0, 0, true)) {
PixelFormat::Format image_format = PixelService::OIIOFormatToOliveFormat(in->spec().format);
// Ensure the following texture operations are done in our context (in case we're in a separate window for instance)
makeCurrent();
if (!texture_.IsCreated()
|| texture_.width() != in->spec().width
|| texture_.height() != in->spec().height
|| texture_.format() != image_format) {
texture_.Destroy();
texture_.Create(context(), in->spec().width, in->spec().height, image_format);
}
texture_.Upload(in->localpixels());
doneCurrent();
} else {
qWarning() << "OIIO Error:" << OIIO::geterror().c_str();
}
delete in;
end:
update();
}
void ViewerGLWidget::SetOCIODisplay(const QString &display)
{
ocio_display_ = display;
@@ -109,15 +156,6 @@ const QString &ViewerGLWidget::ocio_look() const
return ocio_look_;
}
void ViewerGLWidget::SetTexture(OpenGLTexturePtr tex)
{
// Update the texture
texture_ = tex;
// Paint the texture
update();
}
void ViewerGLWidget::SetOCIOParameters(const QString &display, const QString &view, const QString &look)
{
ocio_display_ = display;
@@ -144,15 +182,16 @@ void ViewerGLWidget::paintGL()
f->glClear(GL_COLOR_BUFFER_BIT);
// We only draw if we have a pipeline
if (!pipeline_ || !texture_) {
if (!pipeline_ || !texture_.IsCreated()) {
return;
}
// Bind retrieved texture
f->glBindTexture(GL_TEXTURE_2D, texture_->texture());
f->glBindTexture(GL_TEXTURE_2D, texture_.texture());
// Blit using the pipeline retrieved in initializeGL()
OpenGLRenderFunctions::OCIOBlit(pipeline_, ocio_lut_, true, matrix_);
//OpenGLRenderFunctions::OCIOBlit(pipeline_, ocio_lut_, true, matrix_);
OpenGLRenderFunctions::Blit(pipeline_, true, matrix_);
// Release retrieved texture
f->glBindTexture(GL_TEXTURE_2D, 0);
@@ -240,7 +279,7 @@ void ViewerGLWidget::ContextCleanup()
makeCurrent();
ClearOCIOLutTexture();
texture_.Destroy();
pipeline_ = nullptr;
doneCurrent();
+7 -2
View File
@@ -74,6 +74,11 @@ public:
*/
void SetMatrix(const QMatrix4x4& mat);
/**
* @brief Set an image to load and display on screen
*/
void SetImage(const QString& fn);
public slots:
/**
* @brief Set the texture to draw and draw it
@@ -82,7 +87,7 @@ public slots:
*
* @param tex
*/
void SetTexture(OpenGLTexturePtr tex);
//void SetTexture(OpenGLTexturePtr tex);
void SetOCIOParameters(const QString& display, const QString& view, const QString& look);
@@ -157,7 +162,7 @@ private:
/**
* @brief Internal reference to the OpenGL texture to draw. Set in SetTexture() and used in paintGL().
*/
OpenGLTexturePtr texture_;
OpenGLTexture texture_;
/**
* @brief Internal shader object to use as the pipeline shader