summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/ShaderCompiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Graphics/ShaderCompiler.cpp')
-rw-r--r--Runtime/Graphics/ShaderCompiler.cpp25
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);