Support multiple default versions, to enable ES vs. desktop contexts, for shaders missing a #version statement.

This also moved some parseContext code from the flex file to the proper C++ file.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@20501 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-02-06 23:06:52 +00:00
parent c435c71d87
commit 46eaf4939e
5 changed files with 79 additions and 64 deletions

View file

@ -45,17 +45,82 @@
////////////////////////////////////////////////////////////////////////
TParseContext::TParseContext(TSymbolTable& symt, TIntermediate& interm, EShLanguage L, TInfoSink& is) :
TParseContext::TParseContext(TSymbolTable& symt, TIntermediate& interm, EShLanguage L, TInfoSink& is, int defaultVersion) :
intermediate(interm), symbolTable(symt), infoSink(is), language(L), treeRoot(0),
recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0),
switchNestingLevel(0), inTypeParen(false),
version(110), profile(ENoProfile), futureCompatibility(false),
futureCompatibility(false),
contextPragma(true, false)
{
// Default precisions for version 110, to be overridden for
// other versions/profiles/stage combinations
for (int type = 0; type < EbtNumTypes; ++type)
defaultPrecision[type] = EpqNone;
setVersion(defaultVersion);
setProfile(ENoProfile);
}
void TParseContext::setVersion(int newVersion)
{
version = newVersion;
if (version == 100 || version == 300) {
if (language == EShLangVertex) {
defaultPrecision[EbtInt] = EpqHigh;
defaultPrecision[EbtFloat] = EpqHigh;
defaultPrecision[EbtSampler2D] = EpqLow;
defaultPrecision[EbtSamplerCube] = EpqLow;
}
if (language == EShLangFragment) {
defaultPrecision[EbtInt] = EpqMedium;
defaultPrecision[EbtSampler2D] = EpqLow;
defaultPrecision[EbtSamplerCube] = EpqLow;
}
}
}
// Important assumption: SetVersion() is called before SetProfile(), and is always called
// if there is a version, sending in a ENoProfile if there is no profile given.
void TParseContext::setProfile(EProfile newProfile)
{
const int FirstProfileVersion = 150;
if (newProfile == ENoProfile) {
if (version == 300) {
error(1, "version 300 requires specifying the 'es' profile", "#version", "");
profile = EEsProfile;
} else if (version == 100)
profile = EEsProfile;
else if (version >= FirstProfileVersion)
profile = ECoreProfile;
else
profile = ENoProfile;
} else {
// a profile was provided...
if (version < 150) {
error(1, "versions before 150 do not allow a profile token", "#version", "");
if (version == 100)
profile = EEsProfile;
else
profile = ENoProfile;
} else if (version == 300) {
if (newProfile != EEsProfile)
error(1, "only version 300 supports the es profile", "#version", "");
profile = EEsProfile;
} else {
if (newProfile == EEsProfile) {
error(1, "only version 300 supports the es profile", "#version", "");
if (version >= FirstProfileVersion)
profile = ECoreProfile;
else
profile = ENoProfile;
} else {
// typical desktop case... e.g., "#version 410 core"
profile = newProfile;
}
}
}
}
//