无法使用单独的着色器程序"<program> object is not successfully linked."
Unable to use separate shader programs "<program> object is not successfully linked."
const char *vs_source =
"#version 440n
layout(location = 0) in vec2 position;n
layout(location = 1) in float offset;n
void main() {n
vec2 new_pos = vec2(position.x + offset,position.y);n
gl_Position = vec4(new_pos,0,1);n
}";
const char *fs_source =
"#version 440n
out vec4 out_color;n
void main() {n
out_color = vec4(1,0,0,1);n
}";
auto vsp = createShaderProgram(GL_VERTEX_SHADER,1,&vs_source);
auto fsp = createShaderProgram(GL_FRAGMENT_SHADER,1,&fs_source);
GLuint pipeline;
glGenProgramPipelines(1,&pipeline);
glUseProgramStages(pipeline, GL_VERTEX_SHADER_BIT , vsp.handle);
glUseProgramStages(pipeline, GL_FRAGMENT_SHADER_BIT, fsp.handle);
glBindProgramPipeline(pipeline);
跟
struct Program{
GLuint handle;
};
Program createShaderProgram(GLenum type,
GLsizei count,
const char **strings){
const GLuint shader = glCreateShader(type);
if (shader) {
glShaderSource(shader, count, strings, NULL);
glCompileShader(shader);
const GLuint program = glCreateProgram();
if (program) {
GLint compiled = GL_FALSE;
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
glProgramParameteri(program, GL_PROGRAM_SEPARABLE, GL_TRUE);
if (compiled) {
glAttachShader(program, shader);
glLinkProgram(program);
glDetachShader(program, shader);
}
else{
/* append-shader-info-log-to-program-info-log */
GLint infoLogLength;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
GLchar* infoLog = new GLchar[infoLogLength + 1];
glGetShaderInfoLog(shader, infoLogLength, NULL, infoLog);
std::cout << "ERROR: Unable to compile shader" << std::endl << infoLog << std::endl;
delete[] infoLog;
}
}
glDeleteShader(shader);
return Program{program};
} else {
return Program{0};
}
}
OpenGL告诉我
message: GL_INVALID_OPERATION error generated. <program> object is not successfully linked.
type: ERROR
HIGH
我也不知道为什么。如果我以旧方式链接它并且只创建一个程序,它可以完美运行。
我猜我滥用了新的管道系统?
我还应该提到,该错误仅在我开始调用时才出现
glUseProgramStages(pipeline, GL_VERTEX_SHADER_BIT , vsp.handle);
glUseProgramStages(pipeline, GL_FRAGMENT_SHADER_BIT, fsp.handle);
这可能是驱动程序错误吗?
解决了。顶点着色器未链接。我不得不重新宣布gl_Position。
const char *vs_source =
"#version 440n
layout(location = 0) in vec2 position;n
layout(location = 1) in float offset;n
out gl_PerVertexn
{n
vec4 gl_Position;n
float gl_PointSize;n
float gl_ClipDistance[];n
};n
void main() {n
vec2 new_pos = vec2(position.x + offset,position.y);n
gl_Position = vec4(new_pos,0,1);n
}";
相关文章:
- EASTL矢量<向量<int>>连续的
- Monty Hall program c++
- "Program ended with exit code: 0"出现在我的输出的开头?
- LCM program in C++
- 为什么 C++ 编译器在"c:program filesgnu emacsinclude"中查找包含文件?
- 在 EAX 模式下加密数据时"program has stopped working"
- 为什么删除执行组件指针会导致"Program.exe has triggered a breakpoint"
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- for(;;) vs do..while() for main program loop
- C 字符串比较“祝您好运”&gt;“再见”
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- C++ "Program has stopped working" - ROT-107(凯撒密码)
- C 操作员&gt;&gt;与突变器过载
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 是否需要使用 - &gt;运算符在C 中调用成员函数时
- 什么是模板&lt;&gt;inline bla bla
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- 错误,包括&lt; ctype&gt;在原子上使用C 11