mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-01-31 13:00:59 +00:00
- Make uniform removal a little bit more robust by only searching for known legacy uniforms
This commit is contained in:
parent
f01ef3d7a7
commit
5528d4157b
1 changed files with 31 additions and 4 deletions
|
@ -67,10 +67,26 @@ static bool IsGlslWhitespace(char c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FString NextGlslToken(const char *chars, long len, long &pos)
|
||||||
|
{
|
||||||
|
// Eat whitespace
|
||||||
|
long tokenStart = pos;
|
||||||
|
while (tokenStart != len && IsGlslWhitespace(chars[tokenStart]))
|
||||||
|
tokenStart++;
|
||||||
|
|
||||||
|
// Find token end
|
||||||
|
long tokenEnd = tokenStart;
|
||||||
|
while (tokenEnd != len && !IsGlslWhitespace(chars[tokenEnd]) && chars[tokenEnd] != ';')
|
||||||
|
tokenEnd++;
|
||||||
|
|
||||||
|
pos = tokenEnd;
|
||||||
|
return FString(chars + tokenStart, tokenEnd - tokenStart);
|
||||||
|
}
|
||||||
|
|
||||||
static FString RemoveLegacyUserUniforms(FString code)
|
static FString RemoveLegacyUserUniforms(FString code)
|
||||||
{
|
{
|
||||||
// User shaders must declare their uniforms via the GLDEFS file.
|
// User shaders must declare their uniforms via the GLDEFS file.
|
||||||
// The following code searches for uniform declarations in the shader itself and replaces them with whitespace.
|
// The following code searches for legacy uniform declarations in the shader itself and replaces them with whitespace.
|
||||||
|
|
||||||
long len = (long)code.Len();
|
long len = (long)code.Len();
|
||||||
char *chars = code.LockBuffer();
|
char *chars = code.LockBuffer();
|
||||||
|
@ -82,14 +98,25 @@ static FString RemoveLegacyUserUniforms(FString code)
|
||||||
if (matchIndex == -1)
|
if (matchIndex == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
bool isLegacyUniformName = false;
|
||||||
|
|
||||||
bool isKeywordStart = matchIndex == 0 || IsGlslWhitespace(chars[matchIndex - 1]);
|
bool isKeywordStart = matchIndex == 0 || IsGlslWhitespace(chars[matchIndex - 1]);
|
||||||
bool isKeywordEnd = matchIndex + 7 == len || IsGlslWhitespace(chars[matchIndex + 7]);
|
bool isKeywordEnd = matchIndex + 7 == len || IsGlslWhitespace(chars[matchIndex + 7]);
|
||||||
if (isKeywordStart && isKeywordEnd)
|
if (isKeywordStart && isKeywordEnd)
|
||||||
|
{
|
||||||
|
long pos = matchIndex + 7;
|
||||||
|
FString type = NextGlslToken(chars, len, pos);
|
||||||
|
FString identifier = NextGlslToken(chars, len, pos);
|
||||||
|
|
||||||
|
isLegacyUniformName = type.Compare("float") == 0 && identifier.Compare("timer") == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLegacyUniformName)
|
||||||
{
|
{
|
||||||
long statementEndIndex = code.IndexOf(';', matchIndex + 7);
|
long statementEndIndex = code.IndexOf(';', matchIndex + 7);
|
||||||
if (statementEndIndex == -1)
|
if (statementEndIndex == -1)
|
||||||
statementEndIndex = len;
|
statementEndIndex = len;
|
||||||
for (long i = matchIndex; i < statementEndIndex; i++)
|
for (long i = matchIndex; i <= statementEndIndex; i++)
|
||||||
{
|
{
|
||||||
if (!IsGlslWhitespace(chars[i]))
|
if (!IsGlslWhitespace(chars[i]))
|
||||||
chars[i] = ' ';
|
chars[i] = ' ';
|
||||||
|
@ -281,7 +308,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
||||||
FString fp_comb = vp_comb;
|
FString fp_comb = vp_comb;
|
||||||
|
|
||||||
vp_comb << vp_data.GetString().GetChars() << "\n";
|
vp_comb << vp_data.GetString().GetChars() << "\n";
|
||||||
fp_comb << RemoveLegacyUserUniforms(fp_data.GetString()).GetChars() << "\n";
|
fp_comb << fp_data.GetString().GetChars() << "\n";
|
||||||
|
|
||||||
if (proc_prog_lump != NULL)
|
if (proc_prog_lump != NULL)
|
||||||
{
|
{
|
||||||
|
@ -298,7 +325,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
||||||
|
|
||||||
fp_comb.Substitute("vec4 frag = ProcessTexel();", "vec4 frag = Process(vec4(1.0));");
|
fp_comb.Substitute("vec4 frag = ProcessTexel();", "vec4 frag = Process(vec4(1.0));");
|
||||||
}
|
}
|
||||||
fp_comb << pp_data.GetString().GetChars();
|
fp_comb << RemoveLegacyUserUniforms(pp_data.GetString()).GetChars();
|
||||||
fp_comb.Substitute("gl_TexCoord[0]", "vTexCoord"); // fix old custom shaders.
|
fp_comb.Substitute("gl_TexCoord[0]", "vTexCoord"); // fix old custom shaders.
|
||||||
|
|
||||||
if (pp_data.GetString().IndexOf("ProcessLight") < 0)
|
if (pp_data.GetString().IndexOf("ProcessLight") < 0)
|
||||||
|
|
Loading…
Reference in a new issue