Skip to content

Commit

Permalink
Generalise MythRenderOpenGL::SetProgramParams when using GLSL.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Kendall committed Jan 29, 2011
1 parent 1ead6b7 commit 0e8c1b2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
35 changes: 20 additions & 15 deletions mythtv/libs/libmythtv/openglvideo.cpp
Expand Up @@ -22,6 +22,8 @@ extern "C" {
#define LOC QString("GLVid: ")
#define LOC_ERR QString("GLVid, Error: ")

#define COLOUR_UNIFORM "m_colourMatrix"

class OpenGLFilter
{
public:
Expand Down Expand Up @@ -1040,7 +1042,8 @@ void OpenGLVideo::PrepareFrame(bool topfieldfirst, FrameScanType scan,
}

if (type == kGLFilterYUV2RGB)
gl_context->SetProgramParams(program, colourSpace->GetMatrix());
gl_context->SetProgramParams(program, colourSpace->GetMatrix(),
COLOUR_UNIFORM);

gl_context->DrawBitmap(textures, texture_count, target, &trect, &vrect,
program);
Expand Down Expand Up @@ -1569,6 +1572,8 @@ void OpenGLVideo::CustomiseProgramString(QString &string)
string.replace("%5", QString::number(colWidth, 'f', 8));
string.replace("%6", QString::number((float)fb_size.width(), 'f', 1));
string.replace("%7", QString::number((float)fb_size.height(), 'f', 1));

string.replace("COLOUR_UNIFORM", COLOUR_UNIFORM);
}

static const QString YUV2RGBVertexShader =
Expand All @@ -1583,45 +1588,45 @@ static const QString YUV2RGBVertexShader =
static const QString YUV2RGBFragmentShader =
"GLSL_DEFINES"
"uniform GLSL_SAMPLER s_texture0;\n"
"uniform mat4 m_colourMatrix;\n"
"uniform mat4 COLOUR_UNIFORM;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
" vec4 yuva = GLSL_TEXTURE(s_texture0, v_texcoord0);\n"
" vec4 res = vec4(yuva.arb, 1.0) * m_colourMatrix;\n"
" vec4 res = vec4(yuva.arb, 1.0) * COLOUR_UNIFORM;\n"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n";

static const QString OneFieldShader[2] = {
"GLSL_DEFINES"
"uniform GLSL_SAMPLER s_texture0;\n"
"uniform mat4 m_colourMatrix;\n"
"uniform mat4 COLOUR_UNIFORM;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
" vec2 field = vec2(0.0, step(0.5, fract(v_texcoord0.y * %2)) * %3);\n"
" vec4 yuva = GLSL_TEXTURE(s_texture0, v_texcoord0 + field);\n"
" vec4 res = vec4(yuva.arb, 1.0) * m_colourMatrix;\n"
" vec4 res = vec4(yuva.arb, 1.0) * COLOUR_UNIFORM;\n"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n",

"GLSL_DEFINES"
"uniform GLSL_SAMPLER s_texture0;\n"
"uniform mat4 m_colourMatrix;\n"
"uniform mat4 COLOUR_UNIFORM;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
" vec2 field = vec2(0.0, step(0.5, 1 - fract(v_texcoord0.y * %2)) * %3);\n"
" vec4 yuva = GLSL_TEXTURE(s_texture0, v_texcoord0 + field);\n"
" vec4 res = vec4(yuva.arb, 1.0) * m_colourMatrix;\n"
" vec4 res = vec4(yuva.arb, 1.0) * COLOUR_UNIFORM;\n"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n"
};

static const QString LinearBlendShader[2] = {
"GLSL_DEFINES"
"uniform GLSL_SAMPLER s_texture0;\n"
"uniform mat4 m_colourMatrix;\n"
"uniform mat4 COLOUR_UNIFORM;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
Expand All @@ -1631,13 +1636,13 @@ static const QString LinearBlendShader[2] = {
" vec4 below = GLSL_TEXTURE(s_texture0, v_texcoord0 - line);\n"
" if (fract(v_texcoord0.y * %2) >= 0.5)\n"
" yuva = mix(above, below, 0.5);\n"
" vec4 res = vec4(yuva.arb, 1.0) * m_colourMatrix;\n"
" vec4 res = vec4(yuva.arb, 1.0) * COLOUR_UNIFORM;\n"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n",

"GLSL_DEFINES"
"uniform GLSL_SAMPLER s_texture0;\n"
"uniform mat4 m_colourMatrix;\n"
"uniform mat4 COLOUR_UNIFORM;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
Expand All @@ -1647,7 +1652,7 @@ static const QString LinearBlendShader[2] = {
" vec4 below = GLSL_TEXTURE(s_texture0, v_texcoord0 - line);\n"
" if (fract(v_texcoord0.y * %2) < 0.5)\n"
" yuva = mix(above, below, 0.5);\n"
" vec4 res = vec4(yuva.arb, 1.0) * m_colourMatrix;\n"
" vec4 res = vec4(yuva.arb, 1.0) * COLOUR_UNIFORM;\n"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n"
};
Expand All @@ -1656,7 +1661,7 @@ static const QString KernelShader[2] = {
"GLSL_DEFINES"
"uniform GLSL_SAMPLER s_texture1;\n"
"uniform GLSL_SAMPLER s_texture2;\n"
"uniform mat4 m_colourMatrix;\n"
"uniform mat4 COLOUR_UNIFORM;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
Expand All @@ -1681,14 +1686,14 @@ static const QString KernelShader[2] = {
" yuva = (line00 * -0.0625) + yuva;\n"
" yuva = (line40 * -0.0625) + yuva;\n"
" }\n"
" vec4 res = vec4(yuva.arb, 1.0) * m_colourMatrix;\n"
" vec4 res = vec4(yuva.arb, 1.0) * COLOUR_UNIFORM;\n"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n",

"GLSL_DEFINES"
"uniform GLSL_SAMPLER s_texture0;\n"
"uniform GLSL_SAMPLER s_texture1;\n"
"uniform mat4 m_colourMatrix;\n"
"uniform mat4 COLOUR_UNIFORM;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
Expand All @@ -1713,7 +1718,7 @@ static const QString KernelShader[2] = {
" yuva = (line00 * -0.0625) + yuva;\n"
" yuva = (line40 * -0.0625) + yuva;\n"
" }\n"
" vec4 res = vec4(yuva.arb, 1.0) * m_colourMatrix;\n"
" vec4 res = vec4(yuva.arb, 1.0) * COLOUR_UNIFORM;\n"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n"
};
Expand Down
11 changes: 6 additions & 5 deletions mythtv/libs/libmythui/mythrender_opengl.cpp
Expand Up @@ -189,9 +189,9 @@ void MythRenderOpenGL::SetFeatures(uint features)
{
m_exts_used = features;

m_profile = kGLLegacyProfile;
VERBOSE(VB_GENERAL, LOC + "Forcing legacy profile.");
return;
//m_profile = kGLLegacyProfile;
//VERBOSE(VB_GENERAL, LOC + "Forcing legacy profile.");
//return;

if ((m_exts_used & kGLExtVBO) && (m_exts_used & kGLSL) &&
(m_exts_used & kGLExtFBufObj))
Expand Down Expand Up @@ -2186,7 +2186,8 @@ uint MythRenderOpenGL::GetBufferSize(QSize size, uint fmt, uint type)
return size.width() * size.height() * bpp * bytes;
}

void MythRenderOpenGL::SetProgramParams(uint prog, void* vals)
void MythRenderOpenGL::SetProgramParams(uint prog, void* vals,
const char* uniform)
{
makeCurrent();
const float *v = (float*)vals;
Expand All @@ -2204,7 +2205,7 @@ void MythRenderOpenGL::SetProgramParams(uint prog, void* vals)
else if (kGLHighProfile == m_profile)
{
EnableShaderObject(prog);
GLint loc = m_glGetUniformLocation(prog, "m_colourMatrix");
GLint loc = m_glGetUniformLocation(prog, uniform);
m_glUniformMatrix4fv(loc, 1, GL_FALSE, v);
}

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythrender_opengl.h
Expand Up @@ -117,7 +117,7 @@ class MPUBLIC MythRenderOpenGL : public QGLContext, public MythRender
bool CreateFragmentProgram(const QString &program, uint &prog);
void DeleteFragmentProgram(uint prog);
void EnableFragmentProgram(int fp);
void SetProgramParams(uint prog, void* vals);
void SetProgramParams(uint prog, void* vals, const char* uniform);

uint CreateShaderObject(const QString &vert, const QString &frag);
void DeleteShaderObject(uint obj);
Expand Down

0 comments on commit 0e8c1b2

Please sign in to comment.