Files
oak-editor/app/widget/scope/scopebase/scopebase.cpp
T
itsmattkc 1d61f89920 large scale renderer rework
- Abstracts all OpenGL functionality including UI objects
- Cleans up several rendering codepaths
- Improves threading functionality
- Removes old code and problematic functions
2020-11-10 11:24:51 +11:00

118 lines
2.6 KiB
C++

/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "scopebase.h"
OLIVE_NAMESPACE_ENTER
ScopeBase::ScopeBase(QWidget* parent) :
ManagedDisplayWidget(parent),
buffer_(nullptr)
{
EnableDefaultContextMenu();
}
ScopeBase::~ScopeBase()
{
OnDestroy();
}
void ScopeBase::SetBuffer(Frame *frame)
{
buffer_ = frame;
UploadTextureFromBuffer();
}
void ScopeBase::showEvent(QShowEvent* e)
{
ManagedDisplayWidget::showEvent(e);
UploadTextureFromBuffer();
}
void ScopeBase::DrawScope(Renderer::TexturePtr managed_tex, QVariant pipeline)
{
renderer()->Blit(managed_tex.get(), pipeline, Renderer::ShaderUniformMap());
}
void ScopeBase::UploadTextureFromBuffer()
{
if (!isVisible()) {
return;
}
if (buffer_) {
makeCurrent();
if (!texture_
|| texture_->width() != buffer_->width()
|| texture_->height() != buffer_->height()
|| texture_->format() != buffer_->format()) {
texture_ = nullptr;
managed_tex_ = nullptr;
texture_ = renderer()->CreateTexture(buffer_->video_params(),
buffer_->data(), buffer_->linesize_pixels());
managed_tex_ = renderer()->CreateTexture(buffer_->video_params());
} else {
texture_->Upload(buffer_->data(), buffer_->linesize_pixels());
}
doneCurrent();
}
update();
}
void ScopeBase::OnInit()
{
ManagedDisplayWidget::OnInit();
UploadTextureFromBuffer();
pipeline_ = renderer()->CreateNativeShader(GenerateShaderCode());
}
void ScopeBase::OnPaint()
{
// Clear display surface
renderer()->ClearDestination();
if (buffer_) {
// Convert reference frame to display space
renderer()->BlitColorManaged(color_service(), texture_.get(), managed_tex_.get());
renderer()->SetViewport(width(), height());
DrawScope(managed_tex_, pipeline_);
}
}
void ScopeBase::OnDestroy()
{
ManagedDisplayWidget::OnDestroy();
managed_tex_ = nullptr;
texture_ = nullptr;
pipeline_.clear();
}
OLIVE_NAMESPACE_EXIT