diff options
author | chai <chaifix@163.com> | 2021-10-31 20:19:31 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-31 20:19:31 +0800 |
commit | fb67e0d20264e615545e3af2b9fa8e18eb50526e (patch) | |
tree | 236f3cdad56ccfa41f04f4b7443cbbd037ed6b48 /Runtime/Graphics/ShaderCompiler.cpp | |
parent | 9e0ad4279c8ccf2f419694e4ca15a1372e8b20d6 (diff) |
* shader compiler
Diffstat (limited to 'Runtime/Graphics/ShaderCompiler.cpp')
-rw-r--r-- | Runtime/Graphics/ShaderCompiler.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/Runtime/Graphics/ShaderCompiler.cpp b/Runtime/Graphics/ShaderCompiler.cpp index 637fd59..a3dcf50 100644 --- a/Runtime/Graphics/ShaderCompiler.cpp +++ b/Runtime/Graphics/ShaderCompiler.cpp @@ -32,14 +32,23 @@ if(pos == string::npos || !IsLabelActive(src, label)) {\ CheckLabel(FSH_BEGIN);
CheckLabel(FSH_END);
- bool hasCmd = IsLabelActive(src, CMD_BEGIN) && IsLabelActive(src, CMD_END);
vsh = GetContent(src, VSH_BEGIN, VSH_END);
fsh = GetContent(src, FSH_BEGIN, FSH_END);
- string cmd = GetContent(src, CMD_BEGIN, CMD_END);
- if (cmd.size() > 0)
- ParseCmd(cmd, group);
+ bool hasCmd = IsLabelActive(src, CMD_BEGIN) && IsLabelActive(src, CMD_END);
+ if (hasCmd)
+ {
+ string cmd = GetContent(src, CMD_BEGIN, CMD_END);
+ if (cmd.size() > 0)
+ {
+ ParseCmd(cmd, group);
+ }
+ else
+ {
+ hasCmd = false;
+ }
+ }
string common;
common = TrimContent(src, VSH_BEGIN, VSH_END);
@@ -55,6 +64,10 @@ std::string GLSLCompiler::GetContent(std::string& src, const char* from, const c {
int begin = src.find(from);
int end = src.find(to);
+ if (begin == string::npos || end == string::npos)
+ {
+ return "";
+ }
std::string content = src.substr(begin + strlen(from), end - begin - strlen(from));
return content;
}
@@ -132,7 +145,7 @@ void GLSLCompiler::ParseCmd(std::string& cmds, RenderCommandGroup& group) }
}
-#define IsSeperator(c) (c == ' ' || c == '\r' || c == '\n' || c == '\9')
+#define IsSeperator(c) (c == ' ' || c == '\r' || c == '\n' || c == /*tab*/9)
// 找到行内的第一个单词,作为命令名
bool GLSLCompiler::FindCmdPos(std::string& line, int* start, int* end)
@@ -291,7 +304,7 @@ void GLSLCompiler::CommandDepthWrite(std::string& p, RenderCommandGroup& group) else
{
delete pwrite;
- s_CompileError = string("Compile Shader Error: Invalid parameter of Cmd_DepthWrite: " + params[0]);
+ s_CompileError = string("Compile Shader Error: Invalid parameter of DepthWrite: " + params[0]);
throw GLSLCompileException(s_CompileError.c_str());
}
group.push_back(pwrite);
|