glsl: rewrite tfx function to ease future update

No need to put lots of ifdef, compiler will optimize everything
It increases a bit the readability
This commit is contained in:
Gregory Hainaut 2015-07-17 20:05:31 +02:00
parent ea9e608288
commit 5f247a6e16
2 changed files with 34 additions and 34 deletions

View File

@ -277,30 +277,30 @@ vec4 sample_color(vec2 st, float q)
return t;
}
// FIXME Precompute the factor 255/128 in VS
vec4 tfx(vec4 t, vec4 c)
{
vec4 c_out = c;
vec4 c_out;
// Note: It will be possible to precompute the factor 255/128 in the VS/GS
// However, I didn't see real speedup and it might make the code more difficult
// to support proper rounding
vec4 FxT = c * t * 255.0f / 128.0f;
#if (PS_TFX == 0)
if(PS_TCC != 0)
c_out = c * t * 255.0f / 128.0f;
else
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f;
c_out = FxT;
#elif (PS_TFX == 1)
if(PS_TCC != 0)
c_out = t;
else
c_out.rgb = t.rgb;
#elif (PS_TFX == 2)
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;
if(PS_TCC != 0)
c_out.a += t.a;
c_out.rgb = FxT.rgb + c.a;
c_out.a = t.a + c.a;
#elif (PS_TFX == 3)
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;
if(PS_TCC != 0)
c_out.rgb = FxT.rgb + c.a;
c_out.a = t.a;
#else
c_out = c;
#endif
#if (PS_TCC == 0)
c_out.a = c.a;
#endif
return c_out;

View File

@ -1138,30 +1138,30 @@ static const char* tfx_fs_all_glsl =
" return t;\n"
"}\n"
"\n"
"// FIXME Precompute the factor 255/128 in VS\n"
"vec4 tfx(vec4 t, vec4 c)\n"
"{\n"
" vec4 c_out = c;\n"
" vec4 c_out;\n"
" // Note: It will be possible to precompute the factor 255/128 in the VS/GS\n"
" // However, I didn't see real speedup and it might make the code more difficult\n"
" // to support proper rounding\n"
" vec4 FxT = c * t * 255.0f / 128.0f;\n"
"\n"
"#if (PS_TFX == 0)\n"
" if(PS_TCC != 0)\n"
" c_out = c * t * 255.0f / 128.0f;\n"
" else\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f;\n"
" c_out = FxT;\n"
"#elif (PS_TFX == 1)\n"
" if(PS_TCC != 0)\n"
" c_out = t;\n"
" else\n"
" c_out.rgb = t.rgb;\n"
"#elif (PS_TFX == 2)\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;\n"
"\n"
" if(PS_TCC != 0)\n"
" c_out.a += t.a;\n"
" c_out.rgb = FxT.rgb + c.a;\n"
" c_out.a = t.a + c.a;\n"
"#elif (PS_TFX == 3)\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;\n"
"\n"
" if(PS_TCC != 0)\n"
" c_out.rgb = FxT.rgb + c.a;\n"
" c_out.a = t.a;\n"
"#else\n"
" c_out = c;\n"
"#endif\n"
"\n"
"#if (PS_TCC == 0)\n"
" c_out.a = c.a;\n"
"#endif\n"
"\n"
" return c_out;\n"