mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-13 21:50:06 +00:00
Add the GL_ES macro for ES personalities, along with a general mechanism for adding preambles in front of shaders without effecting line numbers, etc.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@21122 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
63eed3867a
commit
b51f62c573
@ -8,3 +8,8 @@ out vec4 o;
|
||||
void main()
|
||||
{
|
||||
}
|
||||
#ifdef GL_ES
|
||||
#error GL_ES is set
|
||||
#else
|
||||
#error GL_ES is not set
|
||||
#endif
|
||||
|
@ -7,7 +7,7 @@ uniform mat4x4 m44;
|
||||
in vec3 v3;
|
||||
in vec2 v2;
|
||||
|
||||
in vec4 bad[10];
|
||||
in vec4 bad[10]; // ERROR
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -30,4 +30,10 @@ void main()
|
||||
mat3x3 im = inverse(m33);
|
||||
|
||||
mat3x2 op = outerProduct(v2, v3);
|
||||
|
||||
#ifdef GL_ES
|
||||
#error GL_ES is set
|
||||
#else
|
||||
#error GL_ES is not set
|
||||
#endif
|
||||
}
|
||||
|
@ -77,6 +77,16 @@ TParseContext::TParseContext(TSymbolTable& symt, TIntermediate& interm, int v, E
|
||||
defaultGlobalQualification.layoutSlotLocation = 0;
|
||||
}
|
||||
|
||||
// Get code that is not part of a shared symbol table, specific to this shader
|
||||
// or needed by CPP (which does not have a shared symbol table).
|
||||
const char* TParseContext::getPreamble()
|
||||
{
|
||||
if (profile == EEsProfile)
|
||||
return "#define GL_ES 1\n";
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Sub- vector and matrix fields
|
||||
|
@ -96,6 +96,7 @@ struct TParseContext {
|
||||
bool AfterEOF;
|
||||
|
||||
void initializeExtensionBehavior();
|
||||
const char* getPreamble();
|
||||
|
||||
void C_DECL error(TSourceLoc, const char *szReason, const char *szToken,
|
||||
const char *szExtraInfoFormat, ...);
|
||||
@ -159,7 +160,7 @@ struct TParseContext {
|
||||
void doubleCheck(int line, const char* op);
|
||||
};
|
||||
|
||||
int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext&);
|
||||
int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext&, const char* preamble);
|
||||
int PaParseComment(int &lineno, TParseContext&);
|
||||
void ResetFlex();
|
||||
|
||||
|
@ -132,7 +132,7 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil
|
||||
builtInShaders[0] = (*i).c_str();
|
||||
builtInLengths[0] = (int) (*i).size();
|
||||
|
||||
if (PaParseStrings(const_cast<char**>(builtInShaders), builtInLengths, 1, parseContext) != 0) {
|
||||
if (PaParseStrings(const_cast<char**>(builtInShaders), builtInLengths, 1, parseContext, 0) != 0) {
|
||||
infoSink.info.message(EPrefixInternalError, "Unable to parse built-ins");
|
||||
|
||||
return false;
|
||||
@ -548,7 +548,7 @@ int ShCompile(
|
||||
if (parseContext.insertBuiltInArrayAtGlobalLevel())
|
||||
success = false;
|
||||
|
||||
int ret = PaParseStrings(const_cast<char**>(shaderStrings), 0, numStrings, parseContext);
|
||||
int ret = PaParseStrings(const_cast<char**>(shaderStrings), 0, numStrings, parseContext, parseContext.getPreamble());
|
||||
if (ret)
|
||||
success = false;
|
||||
|
||||
|
@ -470,15 +470,8 @@ int yy_input(char* buf, int max_size)
|
||||
//
|
||||
// Returns 0 for success, as per yyparse().
|
||||
//
|
||||
int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseContextLocal)
|
||||
int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseContextLocal, const char* preamble)
|
||||
{
|
||||
int argv0len;
|
||||
|
||||
ScanFromString(argv[0]);
|
||||
|
||||
//Storing the Current Compiler Parse context into the cpp structure.
|
||||
cpp->pC = (void*)&parseContextLocal;
|
||||
|
||||
if (!argv || argc == 0)
|
||||
return 1;
|
||||
|
||||
@ -490,13 +483,27 @@ int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseCon
|
||||
}
|
||||
}
|
||||
|
||||
// set up all the cpp fields...
|
||||
cpp->pC = (void*)&parseContextLocal;
|
||||
char *writeablePreamble = 0;
|
||||
if (preamble) {
|
||||
// preAmble could be a hard-coded string; make writable copy
|
||||
// TODO: CPP: make it not need writable strings
|
||||
int size = strlen(preamble) + 1;
|
||||
writeablePreamble = new char[size];
|
||||
memcpy(writeablePreamble, preamble, size);
|
||||
ScanFromString(writeablePreamble);
|
||||
cpp->PaWhichStr = -1;
|
||||
} else {
|
||||
ScanFromString(argv[0]);
|
||||
cpp->PaWhichStr = 0;
|
||||
}
|
||||
if (! strLen) {
|
||||
argv0len = (int) strlen(argv[0]);
|
||||
int argv0len = (int) strlen(argv[0]);
|
||||
strLen = &argv0len;
|
||||
}
|
||||
yyrestart(0);
|
||||
(&parseContextLocal)->AfterEOF = false;
|
||||
cpp->PaWhichStr = 0;
|
||||
cpp->PaArgv = argv;
|
||||
cpp->PaArgc = argc;
|
||||
cpp->PaStrLen = strLen;
|
||||
@ -508,9 +515,10 @@ int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseCon
|
||||
while (argv[0][len] == ' ' ||
|
||||
argv[0][len] == '\t' ||
|
||||
argv[0][len] == '\n' ||
|
||||
argv[0][len] == '\r')
|
||||
argv[0][len] == '\r') {
|
||||
if (++len >= strLen[0])
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*cpp->PaStrLen > 0) {
|
||||
int ret;
|
||||
@ -519,11 +527,15 @@ int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseCon
|
||||
#else
|
||||
ret = yyparse((void*)(&parseContextLocal));
|
||||
#endif
|
||||
delete writeablePreamble;
|
||||
if (cpp->CompileError == 1 || parseContextLocal.recoveredFromError || parseContextLocal.numErrors > 0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
} else
|
||||
}
|
||||
|
||||
delete writeablePreamble;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -176,6 +176,10 @@ static int str_getch(StringInputSrc *in)
|
||||
}
|
||||
return *in->p++;
|
||||
}
|
||||
if (cpp->PaWhichStr < 0) {
|
||||
// we only parsed the built-in pre-amble; start with clean slate for user code
|
||||
cpp->notAVersionToken = 0;
|
||||
}
|
||||
if (++(cpp->PaWhichStr) < cpp->PaArgc) {
|
||||
free(in);
|
||||
SetStringNumber(cpp->PaWhichStr);
|
||||
@ -183,8 +187,7 @@ static int str_getch(StringInputSrc *in)
|
||||
ScanFromString(cpp->PaArgv[cpp->PaWhichStr]);
|
||||
in=(StringInputSrc*)cpp->currentInput;
|
||||
continue;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
cpp->currentInput = in->base.prev;
|
||||
cpp->PaWhichStr=0;
|
||||
free(in);
|
||||
|
Loading…
Reference in New Issue
Block a user