diff --git a/src/rendering/gl/shaders/gl_shader.cpp b/src/rendering/gl/shaders/gl_shader.cpp index 967a0abda7..d7ee04cce3 100644 --- a/src/rendering/gl/shaders/gl_shader.cpp +++ b/src/rendering/gl/shaders/gl_shader.cpp @@ -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) { diff --git a/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp b/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp index f109f720a8..923e9da306 100644 --- a/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp +++ b/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp @@ -185,6 +185,54 @@ FString RemoveSamplerBindings(FString code, TArray> &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. diff --git a/src/rendering/hwrenderer/utility/hw_shaderpatcher.h b/src/rendering/hwrenderer/utility/hw_shaderpatcher.h index 6a91f4a6b0..7133441a29 100644 --- a/src/rendering/hwrenderer/utility/hw_shaderpatcher.h +++ b/src/rendering/hwrenderer/utility/hw_shaderpatcher.h @@ -6,6 +6,7 @@ FString RemoveLegacyUserUniforms(FString code); FString RemoveSamplerBindings(FString code, TArray> &samplerstobind); // For GL 3.3 compatibility which cannot declare sampler bindings in the sampler source. +FString RemoveLayoutLocationDecl(FString code, const char *inoutkeyword); struct FDefaultShader {