From ce13252b6985a29a0b21f13d2683563e965c3385 Mon Sep 17 00:00:00 2001 From: touky Date: Sun, 16 Oct 2016 19:01:16 -0400 Subject: [PATCH] Shader version compatibility fix Shader replacement code for older shader version is now fixed --- .gitignore | 2 ++ src/gpu/shader.cpp | 43 +++++++++++++++++-------------------------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index e45b6e6d..91fe5638 100644 --- a/.gitignore +++ b/.gitignore @@ -123,3 +123,5 @@ tools/vslol/obj/*/* tools/vslol/obj/*/*/* tools/vslol/obj/*/*/* tools/vslol/*.suo +# Built stuff +binaries/ \ No newline at end of file diff --git a/src/gpu/shader.cpp b/src/gpu/shader.cpp index a2ced28f..94552cb4 100644 --- a/src/gpu/shader.cpp +++ b/src/gpu/shader.cpp @@ -658,9 +658,11 @@ String ShaderData::Patch(String const &code, ShaderType type) } /* Perform small replaces */ - char const * const fast_replaces[] = - { - "#version 130", "#version 120", + char const * const fast_replaces[] = + { + "#version 130", "#version 120", + "out vec4 out_color;", " ", + "out_color =", "gl_FragColor =", "in vec2", type == ShaderType::Vertex ? "attribute vec2" : "varying vec2", "in vec3", type == ShaderType::Vertex ? "attribute vec3" : "varying vec3", "in vec4", type == ShaderType::Vertex ? "attribute vec4" : "varying vec4", @@ -674,34 +676,23 @@ String ShaderData::Patch(String const &code, ShaderType type) for (char const * const *rep = fast_replaces; rep[0]; rep += 2) { - size_t l0 = strlen(rep[0]); - size_t l1 = strlen(rep[1]); - - if (l1 > l0) + while (true) { - int padding = patched_code.count_occurence(rep[0]) * (l1 - l0); - if (padding > 0) - { - patched_code.resize(patched_code.count() + padding); - end = patched_code.C() + patched_code.count() + 1 - padding; - } - } + int index = patched_code.index_of(rep[0]); + if (index == INDEX_NONE) + break; - char *match; - while ((match = strstr(patched_code.C(), rep[0]))) - { - if (l1 > l0) - memmove(match + l1, match + l0, (end - match) - l0); - memcpy(match, rep[1], l1); - if (l1 < l0) - memset(match + l0, ' ', l1 - l0); - end += l1 - l0; - } + size_t l0 = strlen(rep[0]); + size_t l1 = strlen(rep[1]); + + String left = patched_code.sub(0, index); + String right = patched_code.sub(index + l0, patched_code.count() - (index + l0)); + + patched_code = left + String(rep[1]) + right; + } } } - patched_code.resize((int)strlen(patched_code.C())); - return patched_code; }