[英]GLSL Compiling error when more than one char pointer (glShaderSource)
What's wrong with this code for a 3.30 OpenGL and GLSL version? 对于3.30 OpenGL和GLSL版本,此代码有什么问题?
const char *vertSrcs[2] = { "#define A_MACRO\n", vShaderSrc };
const char *fragSrcs[2] = { "#define A_MACRO\n", fShaderSrc };
glShaderSource(vId, 2, vertSrcs, NULL);
glShaderSource(fId, 2, fragSrcs, NULL);
I gather the shader state with GL_COMPILE_STATUS after the its compiled, get this error: 编译后,我使用GL_COMPILE_STATUS收集了着色器状态,出现此错误:
Vertex shader failed to compile with the following errors:
The purpose for this macro is to change type qualifier on a color I passed from the vertex to the fragment, maybe there is another way to do that using a uniform and the layout but the question is why would the shader fail? 此宏的目的是更改我从顶点传递到片段的颜色上的类型限定符,也许还有另一种方法可以使用制服和布局来实现,但是问题是为什么着色器会失败? I wonder if there is another OpenGL command which must specify the 2 char pointers.
我想知道是否还有另一个OpenGL命令必须指定2个char指针。 By the way, this works:
顺便说一句,这有效:
...
glShaderSource(vId, 1, &vertSrcs[1], NULL);
...
EDIT : since I can't answer my own questions, found the solution 编辑 :由于我无法回答自己的问题,所以找到了解决方案
Very strange problem, the string loader happens to be the problem. 非常奇怪的问题,字符串加载器恰好是问题。 Without using ifstream along with std::ios::in |
不使用ifstream和std :: ios :: in | std::ios::binary flags, the string was loaded with some garbage information to the end even with null terminated, therefore concatenating the strings will produce the error.
std :: ios :: binary标志,即使字符串以null结尾,该字符串也会被加载一些垃圾信息,直到结尾,因此将字符串串联会产生错误。 For some reason the gl compiler didn't complain before with the single string version, besides calling
由于某种原因,gl编译器除了调用之前没有抱怨单字符串版本
inStream.flags(std::ios::in | std::ios::binary)
wasn't enough, it need to be specified when opening, didn't find any doc for this. 还不够,在打开时需要指定它,没有为此找到任何文档。
The very first nonempty line of a GLSL shader must be a #version
preprocessor statement. GLSL着色器的第一行非空行必须是
#version
预处理程序语句。 Anything else is an error. 其他都是错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.