From e306d4ee04a55a4ab8641a627edab7ec7801a765 Mon Sep 17 00:00:00 2001 From: usernameak Date: Thu, 5 Jul 2018 17:01:45 +0300 Subject: [PATCH] Fix codestyle; add ability to name the textures --- src/gl/shaders/gl_shader.cpp | 3 ++- src/r_data/gldefs.cpp | 32 +++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 31e9bbc5d..d14d80758 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -497,6 +497,7 @@ static const FDefaultShader defaultshaders[]= TArray usershaders; TArray usermaterials; +TArray usershaderdefs; struct FEffectShader { @@ -648,7 +649,7 @@ void FShaderCollection::CompileShaders(EPassType passType) FString name = ExtractFileBase(usershaders[i]); 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); } diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index 97619cd0f..d46dc450e 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -52,6 +52,7 @@ void InitializeActorLights(TArray &LightAssociations); extern TArray usershaders; extern TArray usermaterials; +extern TArray usershaderdefs; extern TDeletingArray LightDefaults; @@ -1380,6 +1381,8 @@ class GLDefsParser int maplump = -1; FString maplumpname; FString materiallumpname = "shaders/glsl/material_normal.fp"; + FString texnameDefs = ""; + TArray texNameList; float speed = 1.f; sc.MustGetString(); @@ -1407,19 +1410,35 @@ class GLDefsParser } 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(); bool okay = false; - for(int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++) { - if(!tex->CustomShaderTextures[i]) { + for (int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++) + { + if (!tex->CustomShaderTextures[i]) + { 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)"); } + + texnameDefs.AppendFormat("#define %s texture%d\n", textureName.GetChars(), i + 2); okay = true; break; } } - if(!okay) { + if(!okay) + { sc.ScriptError("Error: out of texture units in texture '%s'", tex? tex->Name.GetChars() : "(null)"); } } @@ -1439,7 +1458,9 @@ class GLDefsParser tex->shaderspeed = speed; 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; return; @@ -1447,6 +1468,7 @@ class GLDefsParser } tex->shaderindex = usershaders.Push(maplumpname) + FIRST_USER_SHADER; usermaterials.Push(materiallumpname); + usershaderdefs.Push(texnameDefs); } } }