From 3e8f53e98c73efbb42f998e1792b142b6ac4922e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 20:26:58 +0200 Subject: [PATCH] - fixed shader building. We really need a version directive for user shaders, this is getting too messy. :( --- src/common/rendering/gl/gl_shader.cpp | 8 +++++--- src/common/rendering/vulkan/shaders/vk_shader.cpp | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/common/rendering/gl/gl_shader.cpp b/src/common/rendering/gl/gl_shader.cpp index c00ab0911..51f3fb3eb 100644 --- a/src/common/rendering/gl/gl_shader.cpp +++ b/src/common/rendering/gl/gl_shader.cpp @@ -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 << defines << i_data.GetChars(); FString fp_comb = vp_comb; + vp_comb << defines << i_data.GetChars(); + fp_comb << "$placeholder$\n" << defines << i_data.GetChars(); vp_comb << "#line 1\n"; fp_comb << "#line 1\n"; vp_comb << RemoveLayoutLocationDecl(vp_data.GetString(), "out").GetChars() << "\n"; fp_comb << RemoveLayoutLocationDecl(fp_data.GetString(), "in").GetChars() << "\n"; + FString placeholder = "\n"; 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) { // 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 { @@ -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.Substitute("$placeholder$", placeholder); if (light_fragprog) { diff --git a/src/common/rendering/vulkan/shaders/vk_shader.cpp b/src/common/rendering/vulkan/shaders/vk_shader.cpp index 8162cf7b3..092a20e69 100644 --- a/src/common/rendering/vulkan/shaders/vk_shader.cpp +++ b/src/common/rendering/vulkan/shaders/vk_shader.cpp @@ -284,8 +284,10 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername { FString code = GetTargetGlslVersion(); 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 << shaderBindings; + FString placeholder = "\n"; if (!device->UsedDeviceFeatures.shaderClipDistance) code << "#define NO_CLIPDISTANCE_SUPPORT\n"; if (!alphatest) code << "#define NO_ALPHATEST\n"; @@ -342,7 +344,7 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername 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. - code.Insert(0, "#define LEGACY_USER_SHADER\n"); + placeholder << "#define LEGACY_USER_SHADER\n"; } } else @@ -351,6 +353,7 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername code << (material_lump + 1) << "\n"; } } + code.Substitute("$placeholder$", placeholder); if (light_lump) {