From 9052314db9dcb935d8d6a4f91def2d729e3a0ab0 Mon Sep 17 00:00:00 2001 From: Mark Kendall Date: Fri, 28 Jun 2019 12:12:52 +0100 Subject: [PATCH] OpenGLVideo: Move more conditional code into the shader --- mythtv/libs/libmythtv/openglvideo.cpp | 43 +++++++--------------- mythtv/libs/libmythtv/openglvideoshaders.h | 17 +++++++-- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/mythtv/libs/libmythtv/openglvideo.cpp b/mythtv/libs/libmythtv/openglvideo.cpp index b40bc4ef6e3..4e04dd770cb 100644 --- a/mythtv/libs/libmythtv/openglvideo.cpp +++ b/mythtv/libs/libmythtv/openglvideo.cpp @@ -310,12 +310,24 @@ bool OpenGLVideo::CreateVideoShader(VideoShaderType Type, MythDeintType Deint) else if (FMT_YUYVHQ == m_outputType) defines << "YUYV"; - // if primaries are disabled, the primaries conversion matrxi will be identity + // if primaries are disabled, the primaries conversion matrix will be identity // and we can optimise out the conversion. QMatrix4x4 primaries = m_videoColourSpace->GetPrimaryMatrix(); if (!primaries.isIdentity()) defines << "PRIMARIES"; +#ifdef USING_VTB + // N.B. Rectangular texture support is only currently used for VideoToolBox + // video frames which are NV12. Do not use rectangular textures for the 'default' + // shaders as it breaks video resizing and would require changes to our + // FramebufferObject code. + if ((m_textureTarget == QOpenGLTexture::TargetRectangle) && (Default != Type)) + defines << "RECTS"; +#endif +#ifdef USING_MEDIACODEC + if (m_textureTarget == GL_TEXTURE_EXTERNAL_OES) + defines << "EXTOES"; +#endif if (!progressive) { if (topfield) @@ -384,35 +396,6 @@ bool OpenGLVideo::CreateVideoShader(VideoShaderType Type, MythDeintType Deint) } -#ifdef USING_VTB - // N.B. Rectangular texture support is only currently used for VideoToolBox - // video frames which are NV12. Do not use rectangular textures for the 'default' - // shaders as it breaks video resizing and would require changes to our - // FramebufferObject code. - if ((m_textureTarget == QOpenGLTexture::TargetRectangle) && (Default != Type)) - { - // N.B. Currently only NV12 shaders are supported and deinterlacing parameters - // need fixing as well (when interop deinterlacing is fixed) - fragment.replace("%NV12_UV_RECT%", " * vec2(0.5, 0.5)"); - fragment.replace("sampler2D", "sampler2DRect"); - fragment.replace("texture2D", "texture2DRect"); - fragment.prepend("#extension GL_ARB_texture_rectangle : enable\n"); - } - else -#endif -#ifdef USING_MEDIACODEC - if (m_textureTarget == GL_TEXTURE_EXTERNAL_OES) - { - fragment.replace("%NV12_UV_RECT%", ""); - fragment.replace("sampler2D", "samplerExternalOES"); - fragment.prepend("#extension GL_OES_EGL_image_external : require\n"); - } - else -#endif - { - fragment.replace("%NV12_UV_RECT%", ""); - } - m_shaderCost[Type] = cost; QOpenGLShaderProgram *program = m_render->CreateShaderProgram(vertex, fragment); if (!program) diff --git a/mythtv/libs/libmythtv/openglvideoshaders.h b/mythtv/libs/libmythtv/openglvideoshaders.h index 8c876d9309a..bbbb21318ee 100644 --- a/mythtv/libs/libmythtv/openglvideoshaders.h +++ b/mythtv/libs/libmythtv/openglvideoshaders.h @@ -39,6 +39,15 @@ static const QString MediaCodecVertexShader = static const QString YUVFragmentShader = { +"#ifdef MYTHTV_RECTS\n" +"#extension GL_ARB_texture_rectangle : enable\n" +"#define texture2D texture2DRect\n" +"#define sampler2D sampler2DRect\n" +"#endif\n" +"#ifdef MYTHTV_EXTOES\n" +"#extension GL_OES_EGL_image_external : require\n" +"#define sampler2D samplerExternalOES\n" +"#endif\n" "uniform highp mat4 m_colourMatrix;\n" "uniform highp vec4 m_frameData;\n" "varying highp vec2 v_texcoord0;\n" @@ -51,9 +60,11 @@ static const QString YUVFragmentShader = "#ifdef MYTHTV_NV12\n" "highp vec4 sampleYUV(in sampler2D texture1, in sampler2D texture2, highp vec2 texcoord)\n" "{\n" -" return vec4(texture2D(texture1, texcoord).r,\n" -" texture2D(texture2, texcoord%NV12_UV_RECT%).rg,\n" -" 1.0);\n" +"#ifdef MYTHTV_RECTS\n" +" return vec4(texture2D(texture1, texcoord).r, texture2D(texture2, texcoord * vec2(0.5, 0.5)).rg, 1.0);\n" +"#else\n" +" return vec4(texture2D(texture1, texcoord).r, texture2D(texture2, texcoord).rg, 1.0);\n" +"#endif" "}\n" "#endif\n"