- patch in/out layout declarations for OpenGL

This commit is contained in:
Magnus Norddahl 2019-03-05 01:17:23 +01:00
parent c70aff99e7
commit c137e868de
3 changed files with 51 additions and 2 deletions

View file

@ -360,8 +360,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
vp_comb << "#line 1\n";
fp_comb << "#line 1\n";
vp_comb << vp_data.GetString().GetChars() << "\n";
fp_comb << fp_data.GetString().GetChars() << "\n";
vp_comb << RemoveLayoutLocationDecl(vp_data.GetString(), "out").GetChars() << "\n";
fp_comb << RemoveLayoutLocationDecl(fp_data.GetString(), "in").GetChars() << "\n";
if (proc_prog_lump != NULL)
{

View file

@ -185,6 +185,54 @@ FString RemoveSamplerBindings(FString code, TArray<std::pair<FString, int>> &sam
return code;
}
FString RemoveLayoutLocationDecl(FString code, const char *inoutkeyword)
{
long len = (long)code.Len();
char *chars = code.LockBuffer();
long startIndex = 0;
while (true)
{
long matchIndex = code.IndexOf("layout(location", startIndex);
if (matchIndex == -1)
break;
long endIndex = startIndex;
// Find end of layout declaration
while (chars[endIndex] != ')' && chars[endIndex] != 0)
endIndex++;
// Skip whitespace
while (IsGlslWhitespace(chars[endIndex]))
endIndex++;
// keyword following the declaration?
bool keywordFound = true;
long i;
for (i = 0; inoutkeyword[i] != 0; i++)
{
if (chars[endIndex + i] != inoutkeyword[i])
{
keywordFound = false;
break;
}
}
if (keywordFound && IsGlslWhitespace(chars[endIndex + i]))
{
// yes - replace declaration with spaces
for (long i = startIndex; i < endIndex; i++)
chars[i] = ' ';
}
startIndex = endIndex;
}
code.UnlockBuffer();
return code;
}
/////////////////////////////////////////////////////////////////////////////
// Note: the MaterialShaderIndex enum in gl_shader.h needs to be updated whenever this array is modified.

View file

@ -6,6 +6,7 @@
FString RemoveLegacyUserUniforms(FString code);
FString RemoveSamplerBindings(FString code, TArray<std::pair<FString, int>> &samplerstobind); // For GL 3.3 compatibility which cannot declare sampler bindings in the sampler source.
FString RemoveLayoutLocationDecl(FString code, const char *inoutkeyword);
struct FDefaultShader
{