Skip to content

Commit

Permalink
OpenGLVideo: Move more conditional code into the shader
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-kendall committed Jun 28, 2019
1 parent c56cd2a commit 9052314
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
43 changes: 13 additions & 30 deletions mythtv/libs/libmythtv/openglvideo.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 14 additions & 3 deletions mythtv/libs/libmythtv/openglvideoshaders.h
Expand Up @@ -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"
Expand All @@ -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"

Expand Down

0 comments on commit 9052314

Please sign in to comment.