Skip to content

Commit

Permalink
Only use gl_TexCoord for index values < 4
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Jul 9, 2019
1 parent f90b01f commit fce588b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions profiles/mojoshader_profile_glsl.c
Expand Up @@ -623,15 +623,19 @@ void emit_GLSL_global(Context *ctx, RegisterType regtype, int regnum)
// ps_1_1 TEX opcode expects to overwrite it.
if (!shader_version_atleast(ctx, 1, 4))
{
// GLSL ES does not have gl_TexCoord!
// Also, gl_TexCoord[4+] is unreliable!
#if SUPPORT_PROFILE_GLSLES
// GLSL ES does not have gl_TexCoord
if (support_glsles(ctx))
const int skipGLTexCoord = support_glsles(ctx) || (regnum >= 4);
#else
const int skipGLTexCoord = (regnum >= 4);
#endif
if (skipGLTexCoord)
output_line(ctx, "vec4 %s = io_%i_%i;",
varname, MOJOSHADER_USAGE_TEXCOORD, regnum);
else
#endif
output_line(ctx, "vec4 %s = gl_TexCoord[%d];",
varname, regnum);
output_line(ctx, "vec4 %s = gl_TexCoord[%d];",
varname, regnum);
} // if
} // else if
break;
Expand Down Expand Up @@ -915,6 +919,8 @@ void emit_GLSL_attribute(Context *ctx, RegisterType regtype, int regnum,
if (support_glsles(ctx))
break; // GLSL ES does not have gl_TexCoord
#endif
if (index >= 4)
break; // gl_TexCoord[4+] is unreliable!
snprintf(index_str, sizeof (index_str), "%u", (uint) index);
usage_str = "gl_TexCoord";
arrayleft = "[";
Expand Down Expand Up @@ -990,7 +996,7 @@ void emit_GLSL_attribute(Context *ctx, RegisterType regtype, int regnum,
{
// ps_1_1 does a different hack for this attribute.
// Refer to emit_GLSL_global()'s REG_TYPE_ADDRESS code.
if (shader_version_atleast(ctx, 1, 4))
if (shader_version_atleast(ctx, 1, 4) && (index < 4)) // gl_TexCoord[4+] is unreliable!
{
snprintf(index_str, sizeof (index_str), "%u", (uint) index);
usage_str = "gl_TexCoord";
Expand Down

0 comments on commit fce588b

Please sign in to comment.