print warning for deprecated uniform declarations

This commit is contained in:
Ricardo Luís Vaz Silva 2025-04-16 13:09:56 -03:00
commit 009b84bb1a
3 changed files with 23 additions and 13 deletions

View file

@ -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)

View file

@ -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

View file

@ -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);