viewer: fixed deinterlacing and pan regression, reworked gizmos
This commit is contained in:
@@ -39,6 +39,7 @@ namespace olive {
|
||||
|
||||
ViewerDisplayWidget::ViewerDisplayWidget(QWidget *parent) :
|
||||
ManagedDisplayWidget(parent),
|
||||
deinterlace_texture_(nullptr),
|
||||
signal_cursor_color_(false),
|
||||
gizmos_(nullptr),
|
||||
gizmo_click_(false),
|
||||
@@ -80,15 +81,6 @@ void ViewerDisplayWidget::UpdateCursor()
|
||||
}
|
||||
}
|
||||
|
||||
QMatrix4x4 ViewerDisplayWidget::GetCompleteMatrixFlippedYTranslation()
|
||||
{
|
||||
QMatrix4x4 mat = combined_matrix_;
|
||||
|
||||
mat.scale(1, -1, 1);
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
void ViewerDisplayWidget::SetSignalCursorColorEnabled(bool e)
|
||||
{
|
||||
signal_cursor_color_ = e;
|
||||
@@ -121,6 +113,14 @@ void ViewerDisplayWidget::SetImage(FramePtr in_buffer)
|
||||
void ViewerDisplayWidget::SetDeinterlacing(bool e)
|
||||
{
|
||||
deinterlace_ = e;
|
||||
|
||||
if (deinterlace_) {
|
||||
deinterlace_shader_ = renderer()->CreateNativeShader(ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/deinterlace.frag"))));
|
||||
} else {
|
||||
renderer()->DestroyNativeShader(deinterlace_shader_);
|
||||
deinterlace_texture_ = nullptr;
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -176,18 +176,18 @@ QPoint ViewerDisplayWidget::TransformViewerSpaceToBufferSpace(QPoint pos)
|
||||
* Inversion will only fail if the viewer has been scaled by 0 in any direction
|
||||
* which I think should never happen.
|
||||
*/
|
||||
return pos * GenerateWorldTransform().inverted();
|
||||
return pos * GenerateGizmoTransform().inverted();
|
||||
}
|
||||
|
||||
void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton && gizmos_
|
||||
&& gizmos_->GizmoPress(gizmo_db_, TransformViewerSpaceToBufferSpace(event->pos()),
|
||||
QVector2D(GetTexturePosition(size())), size())) {
|
||||
&& gizmos_->GizmoPress(gizmo_db_, TransformViewerSpaceToBufferSpace(event->pos()))) {
|
||||
|
||||
// Handle gizmo click
|
||||
gizmo_click_ = true;
|
||||
gizmo_drag_time_ = GetGizmoTime();
|
||||
gizmo_start_drag_ = event->pos();
|
||||
|
||||
} else if (IsHandDrag(event)) {
|
||||
|
||||
@@ -245,7 +245,8 @@ void ViewerDisplayWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
// Signal movement
|
||||
gizmos_->GizmoMove(TransformViewerSpaceToBufferSpace(event->pos()),
|
||||
QVector2D(GetTexturePosition(size())), gizmo_drag_time_);
|
||||
gizmo_drag_time_);
|
||||
gizmo_start_drag_ = event->pos();
|
||||
update();
|
||||
|
||||
} else {
|
||||
@@ -292,10 +293,22 @@ void ViewerDisplayWidget::OnPaint()
|
||||
// We only draw if we have a pipeline
|
||||
if (last_loaded_buffer_ && color_service()) {
|
||||
|
||||
TexturePtr texture_to_draw = texture_;
|
||||
|
||||
if (deinterlace_) {
|
||||
qDebug() << "FIXME: Deinterlacing is currently broken, we're working on this...";
|
||||
//color_service()->pipeline()->setUniformValue("ove_resolution", texture_.width(), texture_.height());
|
||||
//color_service()->pipeline()->setUniformValue("ove_deinterlace", deinterlace_);
|
||||
if (!deinterlace_texture_
|
||||
|| deinterlace_texture_->params() != texture_to_draw->params()) {
|
||||
// (Re)create texture
|
||||
deinterlace_texture_ = renderer()->CreateTexture(texture_to_draw->params());
|
||||
}
|
||||
|
||||
ShaderJob job;
|
||||
job.InsertValue(QStringLiteral("resolution_in"), ShaderValue(QVector2D(texture_to_draw->width(), texture_to_draw->height()), NodeParam::kVec2));
|
||||
job.InsertValue(QStringLiteral("ove_maintex"), ShaderValue(QVariant::fromValue(texture_to_draw), NodeParam::kTexture));
|
||||
|
||||
renderer()->BlitToTexture(deinterlace_shader_, job, deinterlace_texture_.get());
|
||||
|
||||
texture_to_draw = deinterlace_texture_;
|
||||
}
|
||||
|
||||
// Draw texture through color transform
|
||||
@@ -303,24 +316,26 @@ void ViewerDisplayWidget::OnPaint()
|
||||
int device_height = height() * devicePixelRatioF();
|
||||
VideoParams::Format device_format = static_cast<VideoParams::Format>(Config::Current()["OfflinePixelFormat"].toInt());
|
||||
|
||||
renderer()->BlitColorManaged(color_service(), texture_, true,
|
||||
renderer()->BlitColorManaged(color_service(), texture_to_draw, true,
|
||||
VideoParams(device_width, device_height, device_format, VideoParams::kInternalChannelCount),
|
||||
GetCompleteMatrixFlippedYTranslation());
|
||||
combined_matrix_flipped_);
|
||||
}
|
||||
|
||||
QTransform world_transform = GenerateWorldTransform();
|
||||
|
||||
// Draw gizmos if we have any
|
||||
if (gizmos_) {
|
||||
GizmoTraverser gt(QSize(gizmo_params_.width(), gizmo_params_.height()));
|
||||
GizmoTraverser gt(QVector2D(gizmo_params_.width() * gizmo_params_.pixel_aspect_ratio().toDouble(),
|
||||
gizmo_params_.height()));
|
||||
|
||||
rational node_time = GetGizmoTime();
|
||||
|
||||
gizmo_db_ = gt.GenerateDatabase(gizmos_, TimeRange(node_time, node_time));
|
||||
gizmo_db_ = gt.GenerateDatabase(gizmos_, TimeRange(node_time,
|
||||
node_time + gizmo_params_.time_base()));
|
||||
|
||||
QPainter p(inner_widget());
|
||||
p.setWorldTransform(world_transform);
|
||||
gizmos_->DrawGizmos(gizmo_db_, &p, QVector2D(GetTexturePosition(size())), size());
|
||||
p.setWorldTransform(GenerateGizmoTransform());
|
||||
gizmos_->DrawGizmos(gizmo_db_, &p);
|
||||
}
|
||||
|
||||
// Draw action/title safe areas
|
||||
@@ -365,11 +380,6 @@ void ViewerDisplayWidget::OnDestroy()
|
||||
texture_ = nullptr;
|
||||
}
|
||||
|
||||
QMatrix4x4 ViewerDisplayWidget::GetMatrixTranslate()
|
||||
{
|
||||
return translate_matrix_;
|
||||
}
|
||||
|
||||
QPointF ViewerDisplayWidget::GetTexturePosition(const QPoint &screen_pos)
|
||||
{
|
||||
return GetTexturePosition(screen_pos.x(), screen_pos.y());
|
||||
@@ -400,6 +410,10 @@ void ViewerDisplayWidget::UpdateMatrix()
|
||||
{
|
||||
combined_matrix_ = scale_matrix_ * translate_matrix_;
|
||||
|
||||
combined_matrix_flipped_.setToIdentity();
|
||||
combined_matrix_flipped_.scale(1.0, -1.0, 1.0);
|
||||
combined_matrix_flipped_ *= combined_matrix_;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -425,4 +439,12 @@ QTransform ViewerDisplayWidget::GenerateWorldTransform()
|
||||
return world;
|
||||
}
|
||||
|
||||
QTransform ViewerDisplayWidget::GenerateGizmoTransform()
|
||||
{
|
||||
QVector2D viewer_scale(GetTexturePosition(size()));
|
||||
QTransform gizmo_transform = GenerateWorldTransform();
|
||||
gizmo_transform.scale(viewer_scale.x(), viewer_scale.y());
|
||||
return gizmo_transform;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -64,17 +64,6 @@ public:
|
||||
|
||||
virtual ~ViewerDisplayWidget() override;
|
||||
|
||||
/**
|
||||
* @brief Return the translation only matrix.
|
||||
*/
|
||||
QMatrix4x4 GetMatrixTranslate();
|
||||
|
||||
/**
|
||||
* @brief Return the complete translation and scale matrix but with the Y translation flipped
|
||||
* as OpenGL stores textures "upside down".
|
||||
*/
|
||||
QMatrix4x4 GetCompleteMatrixFlippedYTranslation();
|
||||
|
||||
const ViewerSafeMarginInfo& GetSafeMargin() const;
|
||||
void SetSafeMargins(const ViewerSafeMarginInfo& safe_margin);
|
||||
|
||||
@@ -208,11 +197,23 @@ private:
|
||||
|
||||
QTransform GenerateWorldTransform();
|
||||
|
||||
QTransform GenerateGizmoTransform();
|
||||
|
||||
/**
|
||||
* @brief Internal reference to the OpenGL texture to draw. Set in SetTexture() and used in paintGL().
|
||||
*/
|
||||
TexturePtr texture_;
|
||||
|
||||
/**
|
||||
* @brief Internal texture to deinterlace to
|
||||
*/
|
||||
TexturePtr deinterlace_texture_;
|
||||
|
||||
/**
|
||||
* @brief Deinterlace shader
|
||||
*/
|
||||
QVariant deinterlace_shader_;
|
||||
|
||||
/**
|
||||
* @brief Translation only matrix (defaults to identity).
|
||||
*/
|
||||
@@ -227,6 +228,7 @@ private:
|
||||
* @brief Cached result of translate_matrix_ and scale_matrix_ multiplied
|
||||
*/
|
||||
QMatrix4x4 combined_matrix_;
|
||||
QMatrix4x4 combined_matrix_flipped_;
|
||||
|
||||
bool signal_cursor_color_;
|
||||
|
||||
@@ -236,6 +238,7 @@ private:
|
||||
NodeValueDatabase gizmo_db_;
|
||||
rational gizmo_drag_time_;
|
||||
VideoParams gizmo_params_;
|
||||
QPoint gizmo_start_drag_;
|
||||
bool gizmo_click_;
|
||||
|
||||
rational time_;
|
||||
|
||||
Reference in New Issue
Block a user