waveformscope: convert buffers to DVL before drawing the waveform

This commit is contained in:
itsmattkc
2020-04-29 00:36:55 +10:00
parent bb61525d44
commit 3070aa7e40
2 changed files with 49 additions and 11 deletions
+44 -11
View File
@@ -61,11 +61,15 @@ void WaveformScope::initializeGL()
ManagedDisplayWidget::initializeGL();
makeCurrent();
pipeline_ = OpenGLShader::Create();
pipeline_->create();
pipeline_->addShaderFromSourceCode(QOpenGLShader::Vertex, OpenGLShader::CodeDefaultVertex());
pipeline_->addShaderFromSourceCode(QOpenGLShader::Fragment, Node::ReadFileAsString(":/shaders/rgbwaveform.frag"));
pipeline_->link();
framebuffer_.Create(context());
doneCurrent();
connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &WaveformScope::CleanUp, Qt::DirectConnection);
@@ -75,27 +79,51 @@ void WaveformScope::initializeGL()
void WaveformScope::paintGL()
{
context()->functions()->glClearColor(0, 0, 0, 0);
context()->functions()->glClear(GL_COLOR_BUFFER_BIT);
QOpenGLFunctions* f = context()->functions();
f->glClearColor(0, 0, 0, 0);
f->glClear(GL_COLOR_BUFFER_BIT);
if (!pipeline_ || !texture_.IsCreated()) {
return;
}
pipeline_->bind();
pipeline_->setUniformValue("ove_resolution", texture_.width(), texture_.height());
pipeline_->setUniformValue("ove_viewport", width(), height());
{
// Convert reference frame to display space
framebuffer_.Attach(&managed_tex_);
framebuffer_.Bind();
// The general size of a pixel
pipeline_->setUniformValue("threshold", 2.0f / static_cast<float>(height()));
texture_.Bind();
pipeline_->release();
f->glViewport(0, 0, texture_.width(), texture_.height());
texture_.Bind();
color_service()->ProcessOpenGL();
OpenGLRenderFunctions::Blit(pipeline_);
texture_.Release();
texture_.Release();
framebuffer_.Release();
framebuffer_.Detach();
}
{
// Draw waveform through shader
pipeline_->bind();
pipeline_->setUniformValue("ove_resolution", texture_.width(), texture_.height());
pipeline_->setUniformValue("ove_viewport", width(), height());
// The general size of a pixel
pipeline_->setUniformValue("threshold", 2.0f / static_cast<float>(height()));
pipeline_->release();
f->glViewport(0, 0, width(), height());
managed_tex_.Bind();
OpenGLRenderFunctions::Blit(pipeline_);
managed_tex_.Release();
}
}
void WaveformScope::UploadTextureFromBuffer()
@@ -111,7 +139,10 @@ void WaveformScope::UploadTextureFromBuffer()
|| texture_.height() != buffer_->height()
|| texture_.format() != buffer_->format()) {
texture_.Destroy();
managed_tex_.Destroy();
texture_.Create(context(), buffer_);
managed_tex_.Create(context(), buffer_->width(), buffer_->height(), buffer_->format());
} else {
texture_.Upload(buffer_);
}
@@ -127,6 +158,8 @@ void WaveformScope::CleanUp()
pipeline_ = nullptr;
texture_.Destroy();
managed_tex_.Destroy();
framebuffer_.Destroy();
doneCurrent();
}