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:
@@ -7,7 +7,6 @@
|
||||
|
||||
OpenGLBackend::OpenGLBackend(QObject *parent) :
|
||||
VideoRenderBackend(parent),
|
||||
master_texture_(nullptr),
|
||||
proxy_(nullptr)
|
||||
{
|
||||
}
|
||||
@@ -49,17 +48,6 @@ bool OpenGLBackend::InitInternal()
|
||||
connect(processor, &OpenGLWorker::RequestRunNodeAccelerated, proxy_, &OpenGLProxy::RunNodeAccelerated, Qt::BlockingQueuedConnection);
|
||||
}
|
||||
|
||||
// Create master texture (the one sent to the viewer)
|
||||
master_texture_ = std::make_shared<OpenGLTexture>();
|
||||
master_texture_->Create(QOpenGLContext::currentContext(),
|
||||
params().effective_width(),
|
||||
params().effective_height(),
|
||||
params().format());
|
||||
|
||||
// Create copy buffer/pipeline
|
||||
copy_buffer_.Create(QOpenGLContext::currentContext());
|
||||
copy_pipeline_ = OpenGLShader::CreateDefault();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -70,25 +58,9 @@ void OpenGLBackend::CloseInternal()
|
||||
proxy_ = nullptr;
|
||||
}
|
||||
|
||||
copy_buffer_.Destroy();
|
||||
copy_pipeline_ = nullptr;
|
||||
master_texture_ = nullptr;
|
||||
|
||||
VideoRenderBackend::CloseInternal();
|
||||
}
|
||||
|
||||
OpenGLTexturePtr OpenGLBackend::GetCachedFrameAsTexture(const rational &time)
|
||||
{
|
||||
const char* cached_frame = GetCachedFrame(time);
|
||||
|
||||
if (cached_frame) {
|
||||
master_texture_->Upload(cached_frame);
|
||||
return master_texture_;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool OpenGLBackend::CompileInternal()
|
||||
{
|
||||
return true;
|
||||
@@ -98,52 +70,10 @@ void OpenGLBackend::DecompileInternal()
|
||||
{
|
||||
}
|
||||
|
||||
void OpenGLBackend::EmitCachedFrameReady(const rational &time, const QVariant &value, qint64 job_time)
|
||||
{
|
||||
OpenGLTextureCache::ReferencePtr ref = value.value<OpenGLTextureCache::ReferencePtr>();
|
||||
OpenGLTexturePtr tex;
|
||||
|
||||
if (ref && ref->texture()) {
|
||||
tex = CopyTexture(ref->texture());
|
||||
} else {
|
||||
tex = nullptr;
|
||||
}
|
||||
|
||||
emit CachedFrameReady(time, QVariant::fromValue(tex), job_time);
|
||||
}
|
||||
|
||||
void OpenGLBackend::ParamsChangedEvent()
|
||||
{
|
||||
// If we're initiated, we need to recreate the texture. Otherwise this backend isn't active so it doesn't matter.
|
||||
if (IsInitiated()) {
|
||||
master_texture_->Destroy();
|
||||
master_texture_->Create(QOpenGLContext::currentContext(),
|
||||
params().effective_width(),
|
||||
params().effective_height(),
|
||||
params().format());
|
||||
|
||||
proxy_->SetParameters(params());
|
||||
}
|
||||
}
|
||||
|
||||
OpenGLTexturePtr OpenGLBackend::CopyTexture(OpenGLTexturePtr input)
|
||||
{
|
||||
QOpenGLContext* ctx = QOpenGLContext::currentContext();
|
||||
|
||||
OpenGLTexturePtr copy = std::make_shared<OpenGLTexture>();
|
||||
copy->Create(ctx, input->width(), input->height(), input->format());
|
||||
|
||||
ctx->functions()->glViewport(0, 0, input->width(), input->height());
|
||||
|
||||
copy_buffer_.Attach(copy);
|
||||
copy_buffer_.Bind();
|
||||
input->Bind();
|
||||
|
||||
OpenGLRenderFunctions::Blit(copy_pipeline_);
|
||||
|
||||
input->Release();
|
||||
copy_buffer_.Release();
|
||||
copy_buffer_.Detach();
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@ public:
|
||||
|
||||
virtual ~OpenGLBackend() override;
|
||||
|
||||
OpenGLTexturePtr GetCachedFrameAsTexture(const rational& time);
|
||||
|
||||
protected:
|
||||
virtual bool InitInternal() override;
|
||||
|
||||
@@ -27,18 +25,9 @@ protected:
|
||||
|
||||
virtual void DecompileInternal() override;
|
||||
|
||||
virtual void EmitCachedFrameReady(const rational &time, const QVariant& value, qint64 job_time) override;
|
||||
|
||||
virtual void ParamsChangedEvent() override;
|
||||
|
||||
private:
|
||||
OpenGLTexturePtr CopyTexture(OpenGLTexturePtr input);
|
||||
|
||||
OpenGLTexturePtr master_texture_;
|
||||
|
||||
OpenGLFramebuffer copy_buffer_;
|
||||
OpenGLShaderPtr copy_pipeline_;
|
||||
|
||||
OpenGLProxy* proxy_;
|
||||
|
||||
};
|
||||
|
||||
@@ -58,7 +58,7 @@ void OpenGLTexture::Create(QOpenGLContext *ctx, int width, int height, const Pix
|
||||
height_ = height;
|
||||
format_ = format;
|
||||
|
||||
connect(created_ctx_, SIGNAL(aboutToBeDestroyed()), this, SLOT(Destroy()));
|
||||
connect(created_ctx_, SIGNAL(aboutToBeDestroyed()), this, SLOT(Destroy()), Qt::DirectConnection);
|
||||
|
||||
// Create main texture
|
||||
CreateInternal(created_ctx_, &texture_, data);
|
||||
@@ -83,26 +83,12 @@ void OpenGLTexture::Destroy()
|
||||
|
||||
void OpenGLTexture::Bind()
|
||||
{
|
||||
QOpenGLContext* context = QOpenGLContext::currentContext();
|
||||
|
||||
if (!context) {
|
||||
qWarning() << "OpenGLTexture::Bind() called with an invalid context";
|
||||
return;
|
||||
}
|
||||
|
||||
context->functions()->glBindTexture(GL_TEXTURE_2D, texture_);
|
||||
created_ctx_->functions()->glBindTexture(GL_TEXTURE_2D, texture_);
|
||||
}
|
||||
|
||||
void OpenGLTexture::Release()
|
||||
{
|
||||
QOpenGLContext* context = QOpenGLContext::currentContext();
|
||||
|
||||
if (!context) {
|
||||
qWarning() << "OpenGLTexture::Release() called with an invalid context";
|
||||
return;
|
||||
}
|
||||
|
||||
context->functions()->glBindTexture(GL_TEXTURE_2D, 0);
|
||||
created_ctx_->functions()->glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
const int &OpenGLTexture::width() const
|
||||
@@ -132,26 +118,19 @@ void OpenGLTexture::Upload(const void *data)
|
||||
return;
|
||||
}
|
||||
|
||||
QOpenGLContext* context = QOpenGLContext::currentContext();
|
||||
|
||||
if (!context) {
|
||||
qWarning() << "OpenGLTexture::Release() called with an invalid context";
|
||||
return;
|
||||
}
|
||||
|
||||
Bind();
|
||||
|
||||
PixelFormat::Info info = PixelService::GetPixelFormatInfo(format_);
|
||||
|
||||
context->functions()->glTexSubImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
width_,
|
||||
height_,
|
||||
info.pixel_format,
|
||||
info.gl_pixel_type,
|
||||
data);
|
||||
created_ctx_->functions()->glTexSubImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
width_,
|
||||
height_,
|
||||
info.pixel_format,
|
||||
info.gl_pixel_type,
|
||||
data);
|
||||
|
||||
Release();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user