问题
Some people are reporting bugs in shaders in our client software. Reports looks like this:
ERROR: 0:63: error#71) Syntax error incorrect preprocessor directive
WARNING: 0:63: warning#64) Unexpected tokens following the preprocessor directive - expected a newline(#if )
ERROR: 0:67: error#71) Syntax error incorrect preprocessor directive
WARNING: 0:67: warning#64) Unexpected tokens following the preprocessor directive - expected a newline(#if )
ERROR: 0:71: error#71) Syntax error incorrect preprocessor directive
WARNING: 0:71: warning#64) Unexpected tokens following the preprocessor directive - expected a newline(#if )
ERROR: 0:75: error#71) Syntax error incorrect preprocessor directive
WARNING: 0:75: warning#64) Unexpected tokens following the preprocessor directive - expected a newline(#if )
And more. Every error is on line like this:
#if ATLAS_MAG_MIN_FILTER == 7 // Here goes the comment
We tried changing all these ifs to the following format:
#if (ATLAS_MAG_MIN_FILTER == 7) // Comment
But the error is still occurring. I cant find any documentation on the way we should write #ifs in GLSL. Can anybody tell me how to use them correctly?
Added: ATLAS_MAG_MIN_FILTER is defined as:
#define ATLAS_MAG_MIN_FILTER (ATLAS_FILTER_MODE & 0x7)
ATLAS_FILTER_MODE is defined as:
#define ATLAS_FILTER_MODE 5
All newlines are in place.
There are errors on lines without comments too.
I uploaded full code of the shader here, errors occurred on lines 63, 67, 71, 75, 79, 83, 87, 91, 111, 114, 115, 122, 125, 126.
回答1:
I found the problem: hex constants are not allowed in some implementations. Tested on ATI Radeon HD 4800 Series with driver version 8.17.10.1129.
I used this code as test:
#define TESTVAR_1 (ATLAS_MAG_MIN_FILTER & 0x7)
#define TESTVAR_2 (ATLAS_MAG_MIN_FILTER & 7)
#if (TESTVAR_1 == 0)
void testFunc() {
}
#endif
#if (TESTVAR_2 == 0)
void testFunc2() {
}
#endif
Error occurred only on line #if (TESTVAR_1 == 0) means TESTVAR_1 is empty.
I'm really surprised there is no error in first define itself...
来源:https://stackoverflow.com/questions/26244930/glsl-if-directive-with