问题描述
有人在报告客户端软件中着色器中的错误.报告看起来像这样:
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
我们尝试将所有这些ifs更改为以下格式:
We tried changing all these ifs to the following format:
#if (ATLAS_MAG_MIN_FILTER == 7) // Comment
但是错误仍在发生.我找不到有关在GLSL中编写#if的方式的任何文档.有人可以告诉我如何正确使用它们吗?
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?
已添加:ATLAS_MAG_MIN_FILTER定义为:
Added:ATLAS_MAG_MIN_FILTER is defined as:
#define ATLAS_MAG_MIN_FILTER (ATLAS_FILTER_MODE & 0x7)
ATLAS_FILTER_MODE定义为:
ATLAS_FILTER_MODE is defined as:
#define ATLAS_FILTER_MODE 5
所有换行符到位.
行上也有错误,也没有注释.
There are errors on lines without comments too.
我在此处上传了着色器的完整代码,错误发生在第63、67、71、75、79行,83、87、91、111、114、115、122、125、126.
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.
推荐答案
我发现了问题:在某些实现中不允许使用十六进制常量.在驱动程序版本为8.17.10.1129的ATI Radeon HD 4800系列上进行了测试.
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
仅在行#if (TESTVAR_1 == 0)
上发生错误,表示TESTVAR_1
为空.
Error occurred only on line #if (TESTVAR_1 == 0)
means TESTVAR_1
is empty.
我真的很惊讶,首先定义自己没有错误...
这篇关于GLSL #if指令,带==的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!