From 009b84bb1ab7bb3b7dcb314fe5701a6c4de06073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Wed, 16 Apr 2025 13:09:56 -0300 Subject: [PATCH] print warning for deprecated uniform declarations --- .../hwrenderer/data/hw_shaderpatcher.cpp | 11 +++++++++-- src/common/utility/zstring.cpp | 15 +++++++++------ src/common/utility/zstring.h | 10 +++++----- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp b/src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp index d32b09e23..24ffa23f3 100644 --- a/src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp +++ b/src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp @@ -39,6 +39,7 @@ #include "textures.h" #include "hw_renderstate.h" #include "v_video.h" +#include "printf.h" static bool IsGlslWhitespace(char c) @@ -81,8 +82,8 @@ FString RemoveLegacyUserUniforms(FString code) { // User shaders must declare their uniforms via the GLDEFS file. - code.Substitute("uniform sampler2D tex;", " "); - code.Substitute("uniform float timer;", " "); + bool found = code.Substitute("uniform sampler2D tex;", " "); + found = code.Substitute("uniform float timer;", " ") || found; // The following code searches for legacy uniform declarations in the shader itself and replaces them with whitespace. @@ -120,6 +121,7 @@ FString RemoveLegacyUserUniforms(FString code) chars[i] = ' '; } startIndex = statementEndIndex; + found = true; } else { @@ -127,6 +129,11 @@ FString RemoveLegacyUserUniforms(FString code) } } + if(found) + { + DPrintf(DMSG_WARNING, TEXTCOLOR_ORANGE "timer and tex uniforms should not be explicitly declared.\n"); + } + // 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) diff --git a/src/common/utility/zstring.cpp b/src/common/utility/zstring.cpp index 488c09eb6..0a5405e43 100644 --- a/src/common/utility/zstring.cpp +++ b/src/common/utility/zstring.cpp @@ -1031,29 +1031,30 @@ void FString::MergeChars (const char *charset, char newchar) UnlockBuffer(); } -void FString::Substitute (const FString &oldstr, const FString &newstr) +bool FString::Substitute (const FString &oldstr, const FString &newstr) { return Substitute (oldstr.Chars, newstr.Chars, oldstr.Len(), newstr.Len()); } -void FString::Substitute (const char *oldstr, const FString &newstr) +bool FString::Substitute (const char *oldstr, const FString &newstr) { return Substitute (oldstr, newstr.Chars, strlen(oldstr), newstr.Len()); } -void FString::Substitute (const FString &oldstr, const char *newstr) +bool FString::Substitute (const FString &oldstr, const char *newstr) { return Substitute (oldstr.Chars, newstr, oldstr.Len(), strlen(newstr)); } -void FString::Substitute (const char *oldstr, const char *newstr) +bool FString::Substitute (const char *oldstr, const char *newstr) { return Substitute (oldstr, newstr, strlen(oldstr), strlen(newstr)); } -void FString::Substitute (const char *oldstr, const char *newstr, size_t oldstrlen, size_t newstrlen) +bool FString::Substitute (const char *oldstr, const char *newstr, size_t oldstrlen, size_t newstrlen) { - if (oldstr == nullptr || newstr == nullptr || *oldstr == 0) return; + if (oldstr == nullptr || newstr == nullptr || *oldstr == 0) return false; + bool found = false; LockBuffer(); for (size_t checkpt = 0; checkpt < Len(); ) { @@ -1061,6 +1062,7 @@ void FString::Substitute (const char *oldstr, const char *newstr, size_t oldstrl size_t len = Len(); if (match != NULL) { + found = true; size_t matchpt = match - Chars; if (oldstrlen != newstrlen) { @@ -1076,6 +1078,7 @@ void FString::Substitute (const char *oldstr, const char *newstr, size_t oldstrl } } UnlockBuffer(); + return found; } bool FString::IsInt () const diff --git a/src/common/utility/zstring.h b/src/common/utility/zstring.h index 284027712..2bc27d7b3 100644 --- a/src/common/utility/zstring.h +++ b/src/common/utility/zstring.h @@ -297,11 +297,11 @@ public: void MergeChars (char merger, char newchar); void MergeChars (const char *charset, char newchar); - void Substitute (const FString &oldstr, const FString &newstr); - void Substitute (const char *oldstr, const FString &newstr); - void Substitute (const FString &oldstr, const char *newstr); - void Substitute (const char *oldstr, const char *newstr); - void Substitute (const char *oldstr, const char *newstr, size_t oldstrlen, size_t newstrlen); + bool Substitute (const FString &oldstr, const FString &newstr); + bool Substitute (const char *oldstr, const FString &newstr); + bool Substitute (const FString &oldstr, const char *newstr); + bool Substitute (const char *oldstr, const char *newstr); + bool Substitute (const char *oldstr, const char *newstr, size_t oldstrlen, size_t newstrlen); void Format (const char *fmt, ...) PRINTFISH(3); void AppendFormat (const char *fmt, ...) PRINTFISH(3);