Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2021-04-04 20:18:53 +0300
committerClément Foucault <foucault.clem@gmail.com>2021-04-04 22:56:55 +0300
commita766ee6d5d47324819d1af33e677744e611f409d (patch)
treed6d03138960db47e2c268541c15f4eef7de39a53 /source/blender/draw/engines/eevee/eevee_shader.hh
parentebf455daba7cdc98cfde6f3d48dc38721ee7808b (diff)
EEVEE: Shader: Add preprocessor to have better shared enum definition
This removes the use of very ugly macros. Now we preprocess the .hh string at startup to change enum definitions to a more GLSL friendly variant.
Diffstat (limited to 'source/blender/draw/engines/eevee/eevee_shader.hh')
-rw-r--r--source/blender/draw/engines/eevee/eevee_shader.hh45
1 files changed, 43 insertions, 2 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_shader.hh b/source/blender/draw/engines/eevee/eevee_shader.hh
index fed54314c5b..e5717d4819f 100644
--- a/source/blender/draw/engines/eevee/eevee_shader.hh
+++ b/source/blender/draw/engines/eevee/eevee_shader.hh
@@ -26,7 +26,9 @@
#pragma once
#include <array>
+#include <string>
+#include "BLI_string_ref.hh"
#include "DRW_render.h"
#include "GPU_shader.h"
@@ -69,6 +71,7 @@ class ShaderModule {
DRWShaderLibrary *shader_lib_ = nullptr;
std::array<GPUShader *, MAX_SHADER_TYPE> shaders_;
std::array<ShaderDescription, MAX_SHADER_TYPE> shader_descriptions_;
+ std::string shared_lib_;
public:
ShaderModule()
@@ -77,10 +80,11 @@ class ShaderModule {
shader = nullptr;
}
+ shared_lib_ = enum_preprocess(datatoc_eevee_shader_shared_hh);
+
shader_lib_ = DRW_shader_library_create();
/* NOTE: These need to be ordered by dependencies. */
- DRW_shader_library_add_file(
- shader_lib_, datatoc_eevee_shader_shared_hh, "eevee_shader_shared.hh");
+ DRW_shader_library_add_file(shader_lib_, shared_lib_.c_str(), "eevee_shader_shared.hh");
DRW_SHADER_LIB_ADD(shader_lib_, common_math_lib);
DRW_SHADER_LIB_ADD(shader_lib_, common_math_geom_lib);
DRW_SHADER_LIB_ADD(shader_lib_, common_hair_lib);
@@ -142,6 +146,43 @@ class ShaderModule {
}
return shaders_[shader_type];
}
+
+ private:
+ /* Run some custom preprocessor shader rewrite and returns a new string. */
+ std::string enum_preprocess(const char *input)
+ {
+ std::string output = "";
+ /* Not failure safe but this is only ran on static data. */
+ const char *cursor = input;
+ while ((cursor = strstr(cursor, "enum "))) {
+ output += StringRef(input, cursor - input);
+
+ /* Skip "enum" keyword. */
+ cursor = strstr(cursor, " ");
+
+ const char *enum_name = cursor;
+ cursor = strstr(cursor, " :");
+
+ output += "#define " + StringRef(enum_name, cursor - enum_name) + " uint\n";
+ output += "const uint ";
+
+ const char *enum_values = strstr(cursor, "{") + 1;
+ cursor = strstr(cursor, "}");
+ output += StringRef(enum_values, cursor - enum_values);
+
+ if (cursor != nullptr) {
+ /* Skip the curly bracket but not the semicolon. */
+ input = cursor + 1;
+ }
+ else {
+ input = nullptr;
+ }
+ }
+ if (input != nullptr) {
+ output += input;
+ }
+ return output;
+ }
};
} // namespace blender::eevee