diff --git a/app/node/traverser.cpp b/app/node/traverser.cpp index 9cb2c89b0..0364bb7dc 100644 --- a/app/node/traverser.cpp +++ b/app/node/traverser.cpp @@ -146,24 +146,25 @@ NodeGlobals NodeTraverser::GenerateGlobals(const VideoParams ¶ms, const Time int NodeTraverser::GetChannelCountFromJob(const GenerateJob &job) { + int max_channel_count = 0; + + // Find maximum channel count + for (auto it=job.GetValues().cbegin(); it!=job.GetValues().cend(); it++) { + if (it.value().type() == NodeValue::kTexture) { + TexturePtr tex = it.value().data().value(); + if (tex) { + max_channel_count = qMax(max_channel_count, tex->channel_count()); + } + } + } + switch (job.GetAlphaChannelRequired()) { case GenerateJob::kAlphaForceOn: return VideoParams::kRGBAChannelCount; case GenerateJob::kAlphaForceOff: return VideoParams::kRGBChannelCount; case GenerateJob::kAlphaAuto: - for (auto it=job.GetValues().cbegin(); it!=job.GetValues().cend(); it++) { - if (it.value().type() == NodeValue::kTexture) { - TexturePtr tex = it.value().data().value(); - if (tex && tex->channel_count() == VideoParams::kRGBAChannelCount) { - // An input texture has an alpha channel so assume we need one too - return VideoParams::kRGBAChannelCount; - } - } - } - - // No textures had alpha so assume we don't need one - return VideoParams::kRGBChannelCount; + return max_channel_count; } // Default fallback, should never get here diff --git a/app/render/opengl/openglrenderer.cpp b/app/render/opengl/openglrenderer.cpp index 2b9a498b8..a339bb23e 100644 --- a/app/render/opengl/openglrenderer.cpp +++ b/app/render/opengl/openglrenderer.cpp @@ -539,6 +539,13 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Texture *destination, Video functions_->glBindTexture(target, tex_id); PrepareInputTexture(target, t.interpolation); + + if (texture && texture->channel_count() == 1 && destination_params.channel_count() != 1) { + // Interpret this texture as a grayscale texture + functions_->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); + functions_->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_RED); + functions_->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED); + } } // Ensure matrix is set, at least to identity