From fb67e0d20264e615545e3af2b9fa8e18eb50526e Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 31 Oct 2021 20:19:31 +0800 Subject: * shader compiler --- Runtime/Graphics/ShaderCompiler.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'Runtime/Graphics/ShaderCompiler.cpp') 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); -- cgit v1.1-26-g67d0