From 9210811b74289b92de5c879117f268bb39bde8cd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Aug 2019 14:50:37 +0200 Subject: [PATCH] - patch the token 'texture2d' in GLSL sources. 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. --- .../hwrenderer/utility/hw_shaderpatcher.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp b/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp index c0bf52782..bdbaa50b4 100644 --- a/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp +++ b/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp @@ -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;