1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-06 18:15:32 +00:00

Rename argument shaderTemplate to templateName

This commit is contained in:
elsid 2020-05-01 19:11:04 +02:00
parent b9cd8d23a4
commit edf002aa97
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
2 changed files with 26 additions and 26 deletions

View file

@ -58,7 +58,7 @@ namespace Shader
return true; return true;
} }
bool parseIncludes(boost::filesystem::path shaderPath, std::string& source, const std::string& shaderTemplate) bool parseIncludes(boost::filesystem::path shaderPath, std::string& source, const std::string& templateName)
{ {
Misc::StringUtils::replaceAll(source, "\r\n", "\n"); Misc::StringUtils::replaceAll(source, "\r\n", "\n");
@ -70,13 +70,13 @@ namespace Shader
size_t start = source.find('"', foundPos); size_t start = source.find('"', foundPos);
if (start == std::string::npos || start == source.size()-1) if (start == std::string::npos || start == source.size()-1)
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: Invalid #include"; Log(Debug::Error) << "Shader " << templateName << " error: Invalid #include";
return false; return false;
} }
size_t end = source.find('"', start+1); size_t end = source.find('"', start+1);
if (end == std::string::npos) if (end == std::string::npos)
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: Invalid #include"; Log(Debug::Error) << "Shader " << templateName << " error: Invalid #include";
return false; return false;
} }
std::string includeFilename = source.substr(start+1, end-(start+1)); std::string includeFilename = source.substr(start+1, end-(start+1));
@ -85,7 +85,7 @@ namespace Shader
includeFstream.open(includePath); includeFstream.open(includePath);
if (includeFstream.fail()) if (includeFstream.fail())
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: Failed to open include " << includePath.string(); Log(Debug::Error) << "Shader " << templateName << " error: Failed to open include " << includePath.string();
return false; return false;
} }
@ -120,14 +120,14 @@ namespace Shader
if (includedFiles.insert(includePath).second == false) if (includedFiles.insert(includePath).second == false)
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: Detected cyclic #includes"; Log(Debug::Error) << "Shader " << templateName << " error: Detected cyclic #includes";
return false; return false;
} }
} }
return true; return true;
} }
bool parseFors(std::string& source, const std::string& shaderTemplate) bool parseFors(std::string& source, const std::string& templateName)
{ {
const char escapeCharacter = '$'; const char escapeCharacter = '$';
size_t foundPos = 0; size_t foundPos = 0;
@ -136,13 +136,13 @@ namespace Shader
size_t endPos = source.find_first_of(" \n\r()[].;,", foundPos); size_t endPos = source.find_first_of(" \n\r()[].;,", foundPos);
if (endPos == std::string::npos) if (endPos == std::string::npos)
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: Unexpected EOF"; Log(Debug::Error) << "Shader " << templateName << " error: Unexpected EOF";
return false; return false;
} }
std::string command = source.substr(foundPos + 1, endPos - (foundPos + 1)); std::string command = source.substr(foundPos + 1, endPos - (foundPos + 1));
if (command != "foreach") if (command != "foreach")
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: Unknown shader directive: $" << command; Log(Debug::Error) << "Shader " << templateName << " error: Unknown shader directive: $" << command;
return false; return false;
} }
@ -150,7 +150,7 @@ namespace Shader
size_t iterNameEnd = source.find_first_of(" \n\r()[].;,", iterNameStart); size_t iterNameEnd = source.find_first_of(" \n\r()[].;,", iterNameStart);
if (iterNameEnd == std::string::npos) if (iterNameEnd == std::string::npos)
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: Unexpected EOF"; Log(Debug::Error) << "Shader " << templateName << " error: Unexpected EOF";
return false; return false;
} }
std::string iteratorName = "$" + source.substr(iterNameStart, iterNameEnd - iterNameStart); std::string iteratorName = "$" + source.substr(iterNameStart, iterNameEnd - iterNameStart);
@ -159,7 +159,7 @@ namespace Shader
size_t listEnd = source.find_first_of("\n\r", listStart); size_t listEnd = source.find_first_of("\n\r", listStart);
if (listEnd == std::string::npos) if (listEnd == std::string::npos)
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: Unexpected EOF"; Log(Debug::Error) << "Shader " << templateName << " error: Unexpected EOF";
return false; return false;
} }
std::string list = source.substr(listStart, listEnd - listStart); std::string list = source.substr(listStart, listEnd - listStart);
@ -171,7 +171,7 @@ namespace Shader
size_t contentEnd = source.find("$endforeach", contentStart); size_t contentEnd = source.find("$endforeach", contentStart);
if (contentEnd == std::string::npos) if (contentEnd == std::string::npos)
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: Unexpected EOF"; Log(Debug::Error) << "Shader " << templateName << " error: Unexpected EOF";
return false; return false;
} }
std::string content = source.substr(contentStart, contentEnd - contentStart); std::string content = source.substr(contentStart, contentEnd - contentStart);
@ -211,7 +211,7 @@ namespace Shader
} }
bool parseDefines(std::string& source, const ShaderManager::DefineMap& defines, bool parseDefines(std::string& source, const ShaderManager::DefineMap& defines,
const ShaderManager::DefineMap& globalDefines, const std::string& shaderTemplate) const ShaderManager::DefineMap& globalDefines, const std::string& templateName)
{ {
const char escapeCharacter = '@'; const char escapeCharacter = '@';
size_t foundPos = 0; size_t foundPos = 0;
@ -221,7 +221,7 @@ namespace Shader
size_t endPos = source.find_first_of(" \n\r()[].;,", foundPos); size_t endPos = source.find_first_of(" \n\r()[].;,", foundPos);
if (endPos == std::string::npos) if (endPos == std::string::npos)
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: Unexpected EOF"; Log(Debug::Error) << "Shader " << templateName << " error: Unexpected EOF";
return false; return false;
} }
std::string define = source.substr(foundPos+1, endPos - (foundPos+1)); std::string define = source.substr(foundPos+1, endPos - (foundPos+1));
@ -234,7 +234,7 @@ namespace Shader
size_t iterNameEnd = source.find_first_of(" \n\r()[].;,", iterNameStart); size_t iterNameEnd = source.find_first_of(" \n\r()[].;,", iterNameStart);
if (iterNameEnd == std::string::npos) if (iterNameEnd == std::string::npos)
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: Unexpected EOF"; Log(Debug::Error) << "Shader " << templateName << " error: Unexpected EOF";
return false; return false;
} }
forIterators.push_back(source.substr(iterNameStart, iterNameEnd - iterNameStart)); forIterators.push_back(source.substr(iterNameStart, iterNameEnd - iterNameStart));
@ -244,7 +244,7 @@ namespace Shader
source.replace(foundPos, 1, "$"); source.replace(foundPos, 1, "$");
if (forIterators.empty()) if (forIterators.empty())
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: endforeach without foreach"; Log(Debug::Error) << "Shader " << templateName << " error: endforeach without foreach";
return false; return false;
} }
else else
@ -264,22 +264,22 @@ namespace Shader
} }
else else
{ {
Log(Debug::Error) << "Shader " << shaderTemplate << " error: Undefined " << define; Log(Debug::Error) << "Shader " << templateName << " error: Undefined " << define;
return false; return false;
} }
} }
return true; return true;
} }
osg::ref_ptr<osg::Shader> ShaderManager::getShader(const std::string &shaderTemplate, const ShaderManager::DefineMap &defines, osg::Shader::Type shaderType) osg::ref_ptr<osg::Shader> ShaderManager::getShader(const std::string &templateName, const ShaderManager::DefineMap &defines, osg::Shader::Type shaderType)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
// read the template if we haven't already // read the template if we haven't already
TemplateMap::iterator templateIt = mShaderTemplates.find(shaderTemplate); TemplateMap::iterator templateIt = mShaderTemplates.find(templateName);
if (templateIt == mShaderTemplates.end()) if (templateIt == mShaderTemplates.end())
{ {
boost::filesystem::path p = (boost::filesystem::path(mPath) / shaderTemplate); boost::filesystem::path p = (boost::filesystem::path(mPath) / templateName);
boost::filesystem::ifstream stream; boost::filesystem::ifstream stream;
stream.open(p); stream.open(p);
if (stream.fail()) if (stream.fail())
@ -293,20 +293,20 @@ namespace Shader
// parse includes // parse includes
std::string source = buffer.str(); std::string source = buffer.str();
if (!addLineDirectivesAfterConditionalBlocks(source) if (!addLineDirectivesAfterConditionalBlocks(source)
|| !parseIncludes(boost::filesystem::path(mPath), source, shaderTemplate)) || !parseIncludes(boost::filesystem::path(mPath), source, templateName))
return nullptr; return nullptr;
templateIt = mShaderTemplates.insert(std::make_pair(shaderTemplate, source)).first; templateIt = mShaderTemplates.insert(std::make_pair(templateName, source)).first;
} }
ShaderMap::iterator shaderIt = mShaders.find(std::make_pair(shaderTemplate, defines)); ShaderMap::iterator shaderIt = mShaders.find(std::make_pair(templateName, defines));
if (shaderIt == mShaders.end()) if (shaderIt == mShaders.end())
{ {
std::string shaderSource = templateIt->second; std::string shaderSource = templateIt->second;
if (!parseDefines(shaderSource, defines, mGlobalDefines, shaderTemplate) || !parseFors(shaderSource, shaderTemplate)) if (!parseDefines(shaderSource, defines, mGlobalDefines, templateName) || !parseFors(shaderSource, templateName))
{ {
// Add to the cache anyway to avoid logging the same error over and over. // Add to the cache anyway to avoid logging the same error over and over.
mShaders.insert(std::make_pair(std::make_pair(shaderTemplate, defines), nullptr)); mShaders.insert(std::make_pair(std::make_pair(templateName, defines), nullptr));
return nullptr; return nullptr;
} }
@ -316,7 +316,7 @@ namespace Shader
static unsigned int counter = 0; static unsigned int counter = 0;
shader->setName(std::to_string(counter++)); shader->setName(std::to_string(counter++));
shaderIt = mShaders.insert(std::make_pair(std::make_pair(shaderTemplate, defines), shader)).first; shaderIt = mShaders.insert(std::make_pair(std::make_pair(templateName, defines), shader)).first;
} }
return shaderIt->second; return shaderIt->second;
} }

View file

@ -30,7 +30,7 @@ namespace Shader
/// @param shaderType The type of shader (usually vertex or fragment shader). /// @param shaderType The type of shader (usually vertex or fragment shader).
/// @note May return nullptr on failure. /// @note May return nullptr on failure.
/// @note Thread safe. /// @note Thread safe.
osg::ref_ptr<osg::Shader> getShader(const std::string& shaderTemplate, const DefineMap& defines, osg::Shader::Type shaderType); osg::ref_ptr<osg::Shader> getShader(const std::string& templateName, const DefineMap& defines, osg::Shader::Type shaderType);
osg::ref_ptr<osg::Program> getProgram(osg::ref_ptr<osg::Shader> vertexShader, osg::ref_ptr<osg::Shader> fragmentShader); osg::ref_ptr<osg::Program> getProgram(osg::ref_ptr<osg::Shader> vertexShader, osg::ref_ptr<osg::Shader> fragmentShader);