From 17b9a7e3ada402e895d9bbeff06405291d97e5f4 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Mon, 16 Nov 2020 02:02:12 +1100 Subject: [PATCH] renderer: moved alpha channel detection to where texture is actually made --- app/render/opengl/openglrenderer.cpp | 12 ------------ app/render/renderprocessor.cpp | 23 +++++++++++++++++++---- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/render/opengl/openglrenderer.cpp b/app/render/opengl/openglrenderer.cpp index 66233d6f1..a5578a569 100644 --- a/app/render/opengl/openglrenderer.cpp +++ b/app/render/opengl/openglrenderer.cpp @@ -286,7 +286,6 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Texture *destination, Video QString iterative_name; GLuint iterative_input = 0; QVector textures_to_bind; - bool input_textures_have_alpha = false; QOpenGLShaderProgram* shader = Node::ValueToPtr(s); @@ -360,10 +359,6 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Texture *destination, Video GLuint tex_id = texture ? texture->id().value() : 0; textures_to_bind.append({texture, job.GetInterpolation(it.key())}); - if (texture && texture->channel_count() == VideoParams::kRGBAChannelCount) { - input_textures_have_alpha = true; - } - // Set enable flag if shader wants it int enable_param_location = shader->uniformLocation(QStringLiteral("%1_enabled").arg(it.key())); if (enable_param_location > -1) { @@ -440,13 +435,6 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Texture *destination, Video destination_params.effective_width(), destination_params.effective_height()); - // Set whether our destination texture needs an alpha channel - if (input_textures_have_alpha || job.GetAlphaChannelRequired()) { - destination_params.set_channel_count(VideoParams::kRGBAChannelCount); - } else { - destination_params.set_channel_count(VideoParams::kRGBChannelCount); - } - // Bind vertex array object QOpenGLVertexArrayObject vao_; vao_.create(); diff --git a/app/render/renderprocessor.cpp b/app/render/renderprocessor.cpp index 98935967b..74a6ee56b 100644 --- a/app/render/renderprocessor.cpp +++ b/app/render/renderprocessor.cpp @@ -391,9 +391,26 @@ QVariant RenderProcessor::ProcessShader(const Node *node, const TimeRange &range } } - const VideoParams& video_params = ticket_->property("vparam").value(); + VideoParams tex_params = ticket_->property("vparam").value(); - TexturePtr destination = render_ctx_->CreateTexture(video_params); + bool input_textures_have_alpha = false; + for (auto it=job.GetValues().cbegin(); it!=job.GetValues().cend(); it++) { + if (it.value().type == NodeParam::kTexture) { + TexturePtr tex = it.value().data.value(); + if (tex && tex->channel_count() == VideoParams::kRGBAChannelCount) { + input_textures_have_alpha = true; + break; + } + } + } + + if (input_textures_have_alpha || job.GetAlphaChannelRequired()) { + tex_params.set_channel_count(VideoParams::kRGBAChannelCount); + } else { + tex_params.set_channel_count(VideoParams::kRGBChannelCount); + } + + TexturePtr destination = render_ctx_->CreateTexture(tex_params); // Run shader render_ctx_->BlitToTexture(shader, job, destination.get()); @@ -487,8 +504,6 @@ QVariant RenderProcessor::GetCachedFrame(const Node *node, const rational &time) f->set_video_params(p); - qDebug() << "Using cached frame!"; - TexturePtr texture = render_ctx_->CreateTexture(f->video_params(), f->data(), f->linesize_pixels()); return QVariant::fromValue(texture); }