Merge branch 'nicebyte-glsl-ext'

This commit is contained in:
John Kessenich 2018-04-17 17:24:03 -06:00
commit fccbb8b40a

View File

@ -1196,38 +1196,46 @@ int C_DECL main(int argc, char* argv[])
// .frag = fragment // .frag = fragment
// .comp = compute // .comp = compute
// //
EShLanguage FindLanguage(const std::string& name, bool parseSuffix) // Additionally, the file names may end in .<stage>.glsl and .<stage>.hlsl
// where <stage> is one of the stages listed above.
//
EShLanguage FindLanguage(const std::string& name, bool parseStageName)
{ {
size_t ext = 0; std::string stageName;
std::string suffix;
if (shaderStageName) if (shaderStageName)
suffix = shaderStageName; stageName = shaderStageName;
else { else if (parseStageName) {
// Search for a suffix on a filename: e.g, "myfile.frag". If given // Note: "first" extension means "first from the end", i.e.
// the suffix directly, we skip looking for the '.' // if the file is named foo.vert.glsl, then "glsl" is first,
if (parseSuffix) { // "vert" is second.
ext = name.rfind('.'); size_t firstExtStart = name.find_last_of(".");
if (ext == std::string::npos) { bool hasFirstExt = firstExtStart != std::string::npos;
usage(); size_t secondExtStart = hasFirstExt ? name.find_last_of(".", firstExtStart - 1) : std::string::npos;
return EShLangVertex; bool hasSecondExt = secondExtStart != std::string::npos;
} std::string firstExt = name.substr(firstExtStart + 1, std::string::npos);
++ext; bool usesUnifiedExt = hasFirstExt && (firstExt == "glsl" || firstExt == "hlsl");
if (hasFirstExt && !usesUnifiedExt) {
stageName = firstExt;
} else if (usesUnifiedExt && hasSecondExt) {
stageName = name.substr(secondExtStart + 1, firstExtStart - secondExtStart - 1);
} else {
usage();
return EShLangVertex;
} }
suffix = name.substr(ext, std::string::npos); } else
} stageName = name;
if (suffix == "vert") if (stageName == "vert")
return EShLangVertex; return EShLangVertex;
else if (suffix == "tesc") else if (stageName == "tesc")
return EShLangTessControl; return EShLangTessControl;
else if (suffix == "tese") else if (stageName == "tese")
return EShLangTessEvaluation; return EShLangTessEvaluation;
else if (suffix == "geom") else if (stageName == "geom")
return EShLangGeometry; return EShLangGeometry;
else if (suffix == "frag") else if (stageName == "frag")
return EShLangFragment; return EShLangFragment;
else if (suffix == "comp") else if (stageName == "comp")
return EShLangCompute; return EShLangCompute;
usage(); usage();