diff options
author | chai <chaifix@163.com> | 2021-10-28 16:24:34 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-28 16:24:34 +0800 |
commit | 40d40edcdeef4978a0d9c7333b7007d1fa4c0bc6 (patch) | |
tree | 5b96c37f9bd85dd0be7a8b880a1de24914ae2880 /Runtime/Graphics/ShaderCompiler.cpp | |
parent | 92dd401d75e19281dc7a01492ab3c0996de330fc (diff) |
*misc
Diffstat (limited to 'Runtime/Graphics/ShaderCompiler.cpp')
-rw-r--r-- | Runtime/Graphics/ShaderCompiler.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/Runtime/Graphics/ShaderCompiler.cpp b/Runtime/Graphics/ShaderCompiler.cpp index 66413e9..b3db629 100644 --- a/Runtime/Graphics/ShaderCompiler.cpp +++ b/Runtime/Graphics/ShaderCompiler.cpp @@ -1,7 +1,40 @@ #include "ShaderCompiler.h"
-void GLSLCompiler::Compile(std::string& src, std::string& vsh, std::string& fsh)
+using namespace std;
+
+const char* VSH_BEGIN = "VSH_BEGIN";
+const char* VSH_END = "VSH_END";
+const char* FSH_BEGIN = "FSH_BEGIN";
+const char* FSH_END = "FSH_END";
+
+// GLSL分为三部分
+// VERTEX_SHADER_BEGIN 和 VERTEX_SHADER_END之间的顶点着色器
+// FRAGMENT_SHADER_BEGIN 和 FRAGMENT_SHADER_END之间的片段着色器
+// 两者之外的公共部分
+void GLSLCompiler::Compile(std::string& src, std::string& vsh, std::string& fsh)/*throw GLSLCompileException*/
{
+ int vsh_begin = src.find(VSH_BEGIN);
+ if (vsh_begin == string::npos)
+ throw GLSLCompileException("Compile Shader Error: No VSH_BEGIN label");
+ int vsh_end = src.find(VSH_END);
+ if (vsh_end == string::npos)
+ throw GLSLCompileException("Compile Shader Error: No VSH_END label");
+ int fsh_begin = src.find(FSH_BEGIN);
+ if (fsh_begin == string::npos)
+ throw GLSLCompileException("Compile Shader Error: No FSH_BEGIN label");
+ int fsh_end = src.find(FSH_END);
+ if (fsh_end == string::npos)
+ throw GLSLCompileException("Compile Shader Error: No FSH_END label");
+
+ vsh = src.substr(vsh_begin + strlen(VSH_BEGIN), vsh_end - vsh_begin - strlen(VSH_BEGIN));
+ fsh = src.substr(fsh_begin + strlen(FSH_BEGIN), fsh_end - fsh_begin - strlen(FSH_BEGIN));
+ string common;
+ common = src.erase(vsh_begin, vsh_end + strlen(VSH_END) - vsh_begin);
+ int fsh_begin2 = common.find(FSH_BEGIN);
+ int fsh_end2 = common.find(FSH_END);
+ common = common.erase(fsh_begin2, fsh_end2 + strlen(FSH_END) - fsh_begin2);
+ vsh = common + vsh;
+ fsh = common + fsh;
}
|