Skip to content

Commit

Permalink
- patch the token 'texture2d' in GLSL sources.
Browse files Browse the repository at this point in the history
This builtin function no longer exists outside of backwards compatible GLSL compilers so it needs to be remapped to 'texture' so that user shaders still using it can compile.
  • Loading branch information
coelckers committed Aug 18, 2019
1 parent ae57bc7 commit 9210811
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp
Expand Up @@ -116,6 +116,24 @@ FString RemoveLegacyUserUniforms(FString code)
}
}

// Also remove all occurences of the token 'texture2d'. Some shaders may still use this deprecated function to access a sampler.
// Modern GLSL only allows use of 'texture'.
while (true)
{
long matchIndex = code.IndexOf("texture2d", startIndex);
if (matchIndex == -1)
break;

// Check if this is a real token.
bool isKeywordStart = matchIndex == 0 || !isalnum(chars[matchIndex - 1] & 255);
bool isKeywordEnd = matchIndex + 9 == len || !isalnum(chars[matchIndex + 9] & 255);
if (isKeywordStart && isKeywordEnd)
{
chars[matchIndex + 7] = chars[matchIndex + 8] = ' ';
}
startIndex = matchIndex + 9;
}

code.UnlockBuffer();

return code;
Expand Down

0 comments on commit 9210811

Please sign in to comment.