Skip to content

Commit

Permalink
Refactor GLSL shader customisations to allow hardcoded texture types.
Browse files Browse the repository at this point in the history
This just allows us to use straight 2D or 1D textures in shaders without
overriding them if rectangular textures are available.
  • Loading branch information
Mark Kendall committed Jan 11, 2011
1 parent b137919 commit 3742c06
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 39 deletions.
68 changes: 34 additions & 34 deletions mythtv/libs/libmythtv/openglvideo.cpp
Expand Up @@ -1573,69 +1573,69 @@ static const QString YUV2RGBVertexShader =

static const QString YUV2RGBFragmentShader =
"GLSL_DEFINES"
"uniform sampler2D s_texture0;\n"
"uniform GLSL_SAMPLER s_texture0;\n"
"uniform mat4 m_colourMatrix;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
" vec4 yuva = texture2D(s_texture0, v_texcoord0);\n"
" vec4 yuva = GLSL_TEXTURE(s_texture0, v_texcoord0);\n"
" vec4 res = vec4(yuva.arb, 1.0) * m_colourMatrix;\n"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n";

static const QString OneFieldShader[2] = {
"GLSL_DEFINES"
"uniform sampler2D s_texture0;\n"
"uniform GLSL_SAMPLER s_texture0;\n"
"uniform mat4 m_colourMatrix;\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 = texture2D(s_texture0, v_texcoord0 + field);\n"
" vec4 yuva = GLSL_TEXTURE(s_texture0, v_texcoord0 + field);\n"
" vec4 res = vec4(yuva.arb, 1.0) * m_colourMatrix;\n"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n",

"GLSL_DEFINES"
"uniform sampler2D s_texture0;\n"
"uniform GLSL_SAMPLER s_texture0;\n"
"uniform mat4 m_colourMatrix;\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 = texture2D(s_texture0, v_texcoord0 + field);\n"
" vec4 yuva = GLSL_TEXTURE(s_texture0, v_texcoord0 + field);\n"
" vec4 res = vec4(yuva.arb, 1.0) * m_colourMatrix;\n"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n"
};

static const QString LinearBlendShader[2] = {
"GLSL_DEFINES"
"uniform sampler2D s_texture0;\n"
"uniform GLSL_SAMPLER s_texture0;\n"
"uniform mat4 m_colourMatrix;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
" vec2 line = vec2(0.0, %3);\n"
" vec4 yuva = texture2D(s_texture0, v_texcoord0);\n"
" vec4 above = texture2D(s_texture0, v_texcoord0 + line);\n"
" vec4 below = texture2D(s_texture0, v_texcoord0 - line);\n"
" vec4 yuva = GLSL_TEXTURE(s_texture0, v_texcoord0);\n"
" vec4 above = GLSL_TEXTURE(s_texture0, v_texcoord0 + line);\n"
" 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"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n",

"GLSL_DEFINES"
"uniform sampler2D s_texture0;\n"
"uniform GLSL_SAMPLER s_texture0;\n"
"uniform mat4 m_colourMatrix;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
" vec2 line = vec2(0.0, %3);\n"
" vec4 yuva = texture2D(s_texture0, v_texcoord0);\n"
" vec4 above = texture2D(s_texture0, v_texcoord0 + line);\n"
" vec4 below = texture2D(s_texture0, v_texcoord0 - line);\n"
" vec4 yuva = GLSL_TEXTURE(s_texture0, v_texcoord0);\n"
" vec4 above = GLSL_TEXTURE(s_texture0, v_texcoord0 + line);\n"
" 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"
Expand All @@ -1645,22 +1645,22 @@ static const QString LinearBlendShader[2] = {

static const QString KernelShader[2] = {
"GLSL_DEFINES"
"uniform sampler2D s_texture1;\n"
"uniform sampler2D s_texture2;\n"
"uniform GLSL_SAMPLER s_texture1;\n"
"uniform GLSL_SAMPLER s_texture2;\n"
"uniform mat4 m_colourMatrix;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
" vec2 twoup = v_texcoord0 - vec2(0.0, %4);\n"
" vec2 twodown = v_texcoord0 + vec2(0.0, %4);\n"
" vec4 yuva = texture2D(s_texture1, v_texcoord0);\n"
" vec4 line0 = texture2D(s_texture1, twoup);\n"
" vec4 line1 = texture2D(s_texture1, v_texcoord0 - vec2(0.0, %3));\n"
" vec4 line3 = texture2D(s_texture1, v_texcoord0 + vec2(0.0, %3));\n"
" vec4 line4 = texture2D(s_texture1, twodown);\n"
" vec4 line00 = texture2D(s_texture2, twoup);\n"
" vec4 line20 = texture2D(s_texture2, v_texcoord0);\n"
" vec4 line40 = texture2D(s_texture2, twodown);\n"
" vec4 yuva = GLSL_TEXTURE(s_texture1, v_texcoord0);\n"
" vec4 line0 = GLSL_TEXTURE(s_texture1, twoup);\n"
" vec4 line1 = GLSL_TEXTURE(s_texture1, v_texcoord0 - vec2(0.0, %3));\n"
" vec4 line3 = GLSL_TEXTURE(s_texture1, v_texcoord0 + vec2(0.0, %3));\n"
" vec4 line4 = GLSL_TEXTURE(s_texture1, twodown);\n"
" vec4 line00 = GLSL_TEXTURE(s_texture2, twoup);\n"
" vec4 line20 = GLSL_TEXTURE(s_texture2, v_texcoord0);\n"
" vec4 line40 = GLSL_TEXTURE(s_texture2, twodown);\n"
" if (fract(v_texcoord0.y * %2) >= 0.5)\n"
" {\n"
" yuva = (yuva * 0.125);\n"
Expand All @@ -1677,22 +1677,22 @@ static const QString KernelShader[2] = {
"}\n",

"GLSL_DEFINES"
"uniform sampler2D s_texture0;\n"
"uniform sampler2D s_texture1;\n"
"uniform GLSL_SAMPLER s_texture0;\n"
"uniform GLSL_SAMPLER s_texture1;\n"
"uniform mat4 m_colourMatrix;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
" vec2 twoup = v_texcoord0 - vec2(0.0, %4);\n"
" vec2 twodown = v_texcoord0 + vec2(0.0, %4);\n"
" vec4 yuva = texture2D(s_texture1, v_texcoord0);\n"
" vec4 line0 = texture2D(s_texture1, twoup);\n"
" vec4 line1 = texture2D(s_texture1, v_texcoord0 - vec2(0.0, %3));\n"
" vec4 line3 = texture2D(s_texture1, v_texcoord0 + vec2(0.0, %3));\n"
" vec4 line4 = texture2D(s_texture1, twodown);\n"
" vec4 line00 = texture2D(s_texture0, twoup);\n"
" vec4 line20 = texture2D(s_texture0, v_texcoord0);\n"
" vec4 line40 = texture2D(s_texture0, twodown);\n"
" vec4 yuva = GLSL_TEXTURE(s_texture1, v_texcoord0);\n"
" vec4 line0 = GLSL_TEXTURE(s_texture1, twoup);\n"
" vec4 line1 = GLSL_TEXTURE(s_texture1, v_texcoord0 - vec2(0.0, %3));\n"
" vec4 line3 = GLSL_TEXTURE(s_texture1, v_texcoord0 + vec2(0.0, %3));\n"
" vec4 line4 = GLSL_TEXTURE(s_texture1, twodown);\n"
" vec4 line00 = GLSL_TEXTURE(s_texture0, twoup);\n"
" vec4 line20 = GLSL_TEXTURE(s_texture0, v_texcoord0);\n"
" vec4 line40 = GLSL_TEXTURE(s_texture0, twodown);\n"
" if (fract(v_texcoord0.y * %2) < 0.5)\n"
" {\n"
" yuva = (yuva * 0.125);\n"
Expand Down
14 changes: 9 additions & 5 deletions mythtv/libs/libmythui/mythrender_opengl.cpp
Expand Up @@ -37,12 +37,12 @@ static const QString kDefaultVertexShader =

static const QString kDefaultFragmentShader =
"GLSL_DEFINES"
"uniform sampler2D s_texture0;\n"
"uniform GLSL_SAMPLER s_texture0;\n"
"varying vec4 v_color;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = texture2D(s_texture0, v_texcoord0) * v_color;\n"
" gl_FragColor = GLSL_TEXTURE(s_texture0, v_texcoord0) * v_color;\n"
"}\n";

static const QString kSimpleVertexShader =
Expand Down Expand Up @@ -1860,14 +1860,18 @@ void MythRenderOpenGL::OptimiseShaderSource(QString &source)
{
QString version = "#version 120\n";
QString extensions = "";
QString sampler = "sampler2D";
QString texture = "texture2D";

if (m_exts_used & kGLExtRect)
if ((m_exts_used & kGLExtRect) && source.contains("GLSL_SAMPLER"))
{
extensions += "#extension GL_ARB_texture_rectangle : enable\n";
source.replace("sampler2D", "sampler2DRect");
source.replace("texture2D", "texture2DRect");
sampler += "Rect";
texture += "Rect";
}

source.replace("GLSL_SAMPLER", sampler);
source.replace("GLSL_TEXTURE", texture);
source.replace("GLSL_DEFINES", version + extensions);

VERBOSE(VB_EXTRA, "\n" + source);
Expand Down

0 comments on commit 3742c06

Please sign in to comment.