I am following the OpenGL SuperBible 6th Edition and I have come upon a peculiar problem.
I have the following code rendering:
const GLfloat color[] = { 0.0f, 0.2f, 0.0f, 1.0f };
//crtime += 0.01;
glClearBufferfv(GL_COLOR, 0, color);
checkError();
glUseProgram(program);
checkError();
GLfloat attrib[] = { (float)sin(crtime) * 0.5f, (float)cos(crtime) * 0.6f, 0.0f, 0.0f };
glVertexAttrib4fv(0, attrib);
checkError();
glDrawArrays(GL_TRIANGLES, 0, 3);
checkError();
checkError()
is a simple function that checks if there's any OpenGL error and prints the gluErrorString
for it if there is.
My OpenGL program consists of the following shaders:
vertex.glsl
#version 430 core
layout (location = 0) in vec4 offset;
void main(void) {
const vec4 vertices[3] = vec4[3](vec4(0.25, -0.25, 0.5, 1.0), vec4(-0.25, -0.25, 0.5, 1.0), vec4(0.25, 0.25, 0.5, 1.0));
gl_Position = vertices[gl_VertexID] + offset;
}
tessctrlshader.glsl
#version 430 core
layout (vertices = 3) out;
void main(void) {
if(gl_InvocationID == 0) {
gl_TessLevelInner[0] = 5.0;
gl_TessLevelOuter[0] = 5.0;
gl_TessLevelOuter[1] = 5.0;
gl_TessLevelOuter[2] = 5.0;
}
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
tessevalshader.glsl
#version 430 core
layout (triangles) in;
void main(void) {
gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position) + (gl_TessCoord.y * gl_in[1].gl_Position) + (gl_TessCoord.z * gl_in[2].gl_Position);
}
fragment.glsl
#version 430 core
out vec4 color;
void main(void) {
color = vec4(0.0, 0.8, 1.0, 1.0);
}
Here's the initialization code (LCAShader()
loads from a file and prints compilation errors if any)
program = glCreateProgram();
LCAShader("vertex.glsl", program, GL_VERTEX_SHADER);
LCAShader("tessctrlshader.glsl", program, GL_TESS_CONTROL_SHADER);
LCAShader("tessevalshader.glsl", program, GL_TESS_EVALUATION_SHADER);
LCAShader("fragment.glsl", program, GL_FRAGMENT_SHADER);
glLinkProgram(program);
glGenVertexArrays(1, &vertex_array_object);
glBindVertexArray(vertex_array_object);
Every time glDrawArrays
is hit, OpenGL throws an GL_INVALID_OPERATION
error. However, if I remove both of the tesselation shaders, this does not happen.