- fixed shader building.

We really need a version directive for user shaders, this is getting too messy. :(
This commit is contained in:
Christoph Oelckers 2020-05-25 20:26:58 +02:00
parent 667b2d6bf4
commit 3e8f53e98c
2 changed files with 9 additions and 4 deletions

View File

@ -379,14 +379,16 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
vp_comb << "#define SUPPORTS_SHADOWMAPS\n"; vp_comb << "#define SUPPORTS_SHADOWMAPS\n";
} }
vp_comb << defines << i_data.GetChars();
FString fp_comb = vp_comb; FString fp_comb = vp_comb;
vp_comb << defines << i_data.GetChars();
fp_comb << "$placeholder$\n" << defines << i_data.GetChars();
vp_comb << "#line 1\n"; vp_comb << "#line 1\n";
fp_comb << "#line 1\n"; fp_comb << "#line 1\n";
vp_comb << RemoveLayoutLocationDecl(vp_data.GetString(), "out").GetChars() << "\n"; vp_comb << RemoveLayoutLocationDecl(vp_data.GetString(), "out").GetChars() << "\n";
fp_comb << RemoveLayoutLocationDecl(fp_data.GetString(), "in").GetChars() << "\n"; fp_comb << RemoveLayoutLocationDecl(fp_data.GetString(), "in").GetChars() << "\n";
FString placeholder = "\n";
if (proc_prog_lump != NULL) if (proc_prog_lump != NULL)
{ {
@ -448,9 +450,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
if (pp_data.GetString().IndexOf("ProcessMaterial") >= 0 && pp_data.GetString().IndexOf("SetupMaterial") < 0) if (pp_data.GetString().IndexOf("ProcessMaterial") >= 0 && pp_data.GetString().IndexOf("SetupMaterial") < 0)
{ {
// This reactivates the old logic and disables all features that cannot be supported with that method. // This reactivates the old logic and disables all features that cannot be supported with that method.
fp_comb.Insert(0, "#define LEGACY_USER_SHADER\n"); placeholder << "#define LEGACY_USER_SHADER\n";
} }
} }
else else
{ {
@ -458,6 +459,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
fp_comb << proc_prog_lump + 1; fp_comb << proc_prog_lump + 1;
} }
} }
fp_comb.Substitute("$placeholder$", placeholder);
if (light_fragprog) if (light_fragprog)
{ {

View File

@ -284,8 +284,10 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
{ {
FString code = GetTargetGlslVersion(); FString code = GetTargetGlslVersion();
code << defines; code << defines;
code << "\n$placeholder$"; // here the code can later add more needed #defines.
code << "\n#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n"; code << "\n#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n";
code << shaderBindings; code << shaderBindings;
FString placeholder = "\n";
if (!device->UsedDeviceFeatures.shaderClipDistance) code << "#define NO_CLIPDISTANCE_SUPPORT\n"; if (!device->UsedDeviceFeatures.shaderClipDistance) code << "#define NO_CLIPDISTANCE_SUPPORT\n";
if (!alphatest) code << "#define NO_ALPHATEST\n"; if (!alphatest) code << "#define NO_ALPHATEST\n";
@ -342,7 +344,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
if (pp_code.IndexOf("ProcessMaterial") >= 0 && pp_code.IndexOf("SetupMaterial") < 0) if (pp_code.IndexOf("ProcessMaterial") >= 0 && pp_code.IndexOf("SetupMaterial") < 0)
{ {
// This reactivates the old logic and disables all features that cannot be supported with that method. // This reactivates the old logic and disables all features that cannot be supported with that method.
code.Insert(0, "#define LEGACY_USER_SHADER\n"); placeholder << "#define LEGACY_USER_SHADER\n";
} }
} }
else else
@ -351,6 +353,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
code << (material_lump + 1) << "\n"; code << (material_lump + 1) << "\n";
} }
} }
code.Substitute("$placeholder$", placeholder);
if (light_lump) if (light_lump)
{ {