Fix codestyle; add ability to name the textures

This commit is contained in:
usernameak 2018-07-05 17:01:45 +03:00 committed by Christoph Oelckers
parent fa51a54042
commit e306d4ee04
2 changed files with 29 additions and 6 deletions

View file

@ -497,6 +497,7 @@ static const FDefaultShader defaultshaders[]=
TArray<FString> usershaders; TArray<FString> usershaders;
TArray<FString> usermaterials; TArray<FString> usermaterials;
TArray<FString> usershaderdefs;
struct FEffectShader struct FEffectShader
{ {
@ -648,7 +649,7 @@ void FShaderCollection::CompileShaders(EPassType passType)
FString name = ExtractFileBase(usershaders[i]); FString name = ExtractFileBase(usershaders[i]);
FName sfn = name; FName sfn = name;
FShader *shc = Compile(sfn, usershaders[i], usermaterials[i], "", true, passType); FShader *shc = Compile(sfn, usershaders[i], usermaterials[i], usershaderdefs[i], true, passType);
mMaterialShaders.Push(shc); mMaterialShaders.Push(shc);
} }

View file

@ -52,6 +52,7 @@ void InitializeActorLights(TArray<FLightAssociation> &LightAssociations);
extern TArray<FString> usershaders; extern TArray<FString> usershaders;
extern TArray<FString> usermaterials; extern TArray<FString> usermaterials;
extern TArray<FString> usershaderdefs;
extern TDeletingArray<FLightDefaults *> LightDefaults; extern TDeletingArray<FLightDefaults *> LightDefaults;
@ -1380,6 +1381,8 @@ class GLDefsParser
int maplump = -1; int maplump = -1;
FString maplumpname; FString maplumpname;
FString materiallumpname = "shaders/glsl/material_normal.fp"; FString materiallumpname = "shaders/glsl/material_normal.fp";
FString texnameDefs = "";
TArray<FString> texNameList;
float speed = 1.f; float speed = 1.f;
sc.MustGetString(); sc.MustGetString();
@ -1407,19 +1410,35 @@ class GLDefsParser
} }
else if (sc.Compare("texture")) else if (sc.Compare("texture"))
{ {
sc.MustGetString();
FString textureName = sc.String;
for(FString &texName : texNameList)
{
if(!texName.Compare(textureName))
{
sc.ScriptError("Trying to redefine custom hardware shader texture '%s' in texture '%s'\n", textureName.GetChars(), tex? tex->Name.GetChars() : "(null)");
}
}
texNameList.Push(textureName);
sc.MustGetString(); sc.MustGetString();
bool okay = false; bool okay = false;
for(int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++) { for (int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++)
if(!tex->CustomShaderTextures[i]) { {
if (!tex->CustomShaderTextures[i])
{
tex->CustomShaderTextures[i] = TexMan.FindTexture(sc.String, ETextureType::Any, FTextureManager::TEXMAN_TryAny); tex->CustomShaderTextures[i] = TexMan.FindTexture(sc.String, ETextureType::Any, FTextureManager::TEXMAN_TryAny);
if (!tex->CustomShaderTextures[i]) { if (!tex->CustomShaderTextures[i])
{
sc.ScriptError("Custom hardware shader texture '%s' not found in texture '%s'\n", sc.String, tex? tex->Name.GetChars() : "(null)"); sc.ScriptError("Custom hardware shader texture '%s' not found in texture '%s'\n", sc.String, tex? tex->Name.GetChars() : "(null)");
} }
texnameDefs.AppendFormat("#define %s texture%d\n", textureName.GetChars(), i + 2);
okay = true; okay = true;
break; break;
} }
} }
if(!okay) { if(!okay)
{
sc.ScriptError("Error: out of texture units in texture '%s'", tex? tex->Name.GetChars() : "(null)"); sc.ScriptError("Error: out of texture units in texture '%s'", tex? tex->Name.GetChars() : "(null)");
} }
} }
@ -1439,7 +1458,9 @@ class GLDefsParser
tex->shaderspeed = speed; tex->shaderspeed = speed;
for (unsigned i = 0; i < usershaders.Size(); i++) for (unsigned i = 0; i < usershaders.Size(); i++)
{ {
if (!usershaders[i].CompareNoCase(maplumpname) && !usermaterials[i].CompareNoCase(materiallumpname)) if (!usershaders[i].CompareNoCase(maplumpname) &&
!usermaterials[i].CompareNoCase(materiallumpname) &&
!usershaderdefs[i].Compare(texnameDefs))
{ {
tex->shaderindex = i + FIRST_USER_SHADER; tex->shaderindex = i + FIRST_USER_SHADER;
return; return;
@ -1447,6 +1468,7 @@ class GLDefsParser
} }
tex->shaderindex = usershaders.Push(maplumpname) + FIRST_USER_SHADER; tex->shaderindex = usershaders.Push(maplumpname) + FIRST_USER_SHADER;
usermaterials.Push(materiallumpname); usermaterials.Push(materiallumpname);
usershaderdefs.Push(texnameDefs);
} }
} }
} }