From 4e0188fd3a0d280c89820b45fa43ff158d7ed618 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 28 Mar 2019 18:21:35 +1100 Subject: [PATCH] enforce trilinear and mipmap generation --- effects/effect.cpp | 4 +++- rendering/exportthread.cpp | 2 +- rendering/framebufferobject.cpp | 22 ++++++++++++---------- rendering/renderfunctions.cpp | 14 +++++++++++--- timeline/clip.cpp | 2 +- ui/viewerwidget.cpp | 4 +++- ui/viewerwindow.cpp | 2 +- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/effects/effect.cpp b/effects/effect.cpp index 5fbff641f..7aca89711 100644 --- a/effects/effect.cpp +++ b/effects/effect.cpp @@ -805,7 +805,9 @@ void Effect::startEffect() { } void Effect::endEffect() { - if (bound) glslProgram->release(); + if (bound) { + glslProgram->release(); + } bound = false; } diff --git a/rendering/exportthread.cpp b/rendering/exportthread.cpp index fcbb77067..239f22b2b 100644 --- a/rendering/exportthread.cpp +++ b/rendering/exportthread.cpp @@ -574,7 +574,7 @@ void ExportThread::Export() return; } - // Flush remaining packets out of video and audio encoders + // Flush remaining packets out of video and audio encoders by sending a null frame if (params_.video_enabled) { Encode(fmt_ctx, vcodec_ctx, nullptr, &video_pkt, video_stream); } diff --git a/rendering/framebufferobject.cpp b/rendering/framebufferobject.cpp index 10a2cbb96..b9585400b 100644 --- a/rendering/framebufferobject.cpp +++ b/rendering/framebufferobject.cpp @@ -26,37 +26,39 @@ void FramebufferObject::Create(QOpenGLContext *ctx, int width, int height) // set context to new context provided ctx_ = ctx; + QOpenGLFunctions* f = ctx->functions(); + // create framebuffer object - ctx->functions()->glGenFramebuffers(1, &buffer_); + f->glGenFramebuffers(1, &buffer_); // create texture - ctx->functions()->glGenTextures(1, &texture_); + f->glGenTextures(1, &texture_); // bind framebuffer for attaching - ctx->functions()->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, buffer_); + f->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, buffer_); // bind texture - ctx->functions()->glBindTexture(GL_TEXTURE_2D, texture_); + f->glBindTexture(GL_TEXTURE_2D, texture_); // allocate storage for texture - ctx->functions()->glTexImage2D( + f->glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr ); // set texture filtering to bilinear - ctx->functions()->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - ctx->functions()->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // attach texture to framebuffer - ctx->functions()->glFramebufferTexture2D( + f->glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_, 0 ); // release texture - ctx->functions()->glBindTexture(GL_TEXTURE_2D, 0); + f->glBindTexture(GL_TEXTURE_2D, 0); // release framebuffer - ctx->functions()->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + f->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); } void FramebufferObject::Destroy() diff --git a/rendering/renderfunctions.cpp b/rendering/renderfunctions.cpp index 48cfc1a84..25db7e8f9 100644 --- a/rendering/renderfunctions.cpp +++ b/rendering/renderfunctions.cpp @@ -51,7 +51,17 @@ namespace OCIO = OCIO_NAMESPACE; #include "panels/timeline.h" #include "panels/viewer.h" +void PrepareToDraw(QOpenGLFunctions* f) { + f->glGenerateMipmap(GL_TEXTURE_2D); + f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); +} + void full_blit() { + PrepareToDraw(QOpenGLContext::currentContext()->functions()); + glPushMatrix(); glLoadIdentity(); glOrtho(0, 1, 0, 1, -1, 1); @@ -484,9 +494,7 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams ¶ms) { glBindTexture(GL_TEXTURE_2D, textureID); // set texture filter to bilinear - params.ctx->functions()->glGenerateMipmap(GL_TEXTURE_2D); - params.ctx->functions()->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - params.ctx->functions()->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + PrepareToDraw(params.ctx->functions()); // draw clip on screen according to gl coordinates glBegin(GL_QUADS); diff --git a/timeline/clip.cpp b/timeline/clip.cpp index 743587f79..1caaf70d1 100644 --- a/timeline/clip.cpp +++ b/timeline/clip.cpp @@ -574,7 +574,7 @@ bool Clip::Retrieve() texture->setFormat(QOpenGLTexture::RGBA8_UNorm); texture->setMipLevels(texture->maximumMipLevels()); - texture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); + texture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear); texture->allocateStorage(QOpenGLTexture::RGBA, QOpenGLTexture::UInt8); } diff --git a/ui/viewerwidget.cpp b/ui/viewerwidget.cpp index 5847eaa32..b00081370 100644 --- a/ui/viewerwidget.cpp +++ b/ui/viewerwidget.cpp @@ -548,7 +548,7 @@ void ViewerWidget::paintGL() { makeCurrent(); // clear to solid black - glClearColor(0.0, 0.0, 0.0, 1.0); + glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); // set color multipler to straight white @@ -564,6 +564,8 @@ void ViewerWidget::paintGL() { glBindTexture(GL_TEXTURE_2D, tex); + context()->functions()->glGenerateMipmap(GL_TEXTURE_2D); + glBegin(GL_QUADS); double zoom_factor = container->zoom/(double(width())/double(viewer->seq->width)); diff --git a/ui/viewerwindow.cpp b/ui/viewerwindow.cpp index 646db81f9..a73b4cb76 100644 --- a/ui/viewerwindow.cpp +++ b/ui/viewerwindow.cpp @@ -111,7 +111,7 @@ void ViewerWindow::paintGL() { if (texture > 0) { if (mutex != nullptr) mutex->lock(); - glClearColor(0.0, 0.0, 0.0, 1.0); + glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_TEXTURE_2D);