I'm trying to learn how to use tesselation to render simple polygons, and for a starter I'm trying to write a simple program that essentially would just draw whatever vertices it's given, without any extra logic. My three shaders compile without error, but when I try to apply the program OpenGL returns error 1282. Based on the documentation for glUseProgram my best guess is that OpenGL is in a state where the program cannot be used, but I'm not able to tell why. If I don't include the TES in the program my code runs just fine, so I'm sure I'm not trying to apply the wrong program ID.
Since I know with fairly good confidence that my vertex and fragment shader are working correctly, the issue must be with the TES, which in my eyes will only put out the control points as vertices.
Is it not possible to simply pass control points through the shader as vertices?
My Tesselation Evaluation Shader:
#version 440 core
layout(triangles, equal_spacing, ccw) in;
in vec4 positionIn[];
void main()
{
gl_Position = positionIn[0];
}
Vertex Shader:
#version 440 core
layout(location = 0) in vec4 position;
uniform mat4 u_MVP;
void main()
{
gl_Position = u_MVP * position;
}
Fragment Shader:
#version 440 core
layout(location = 0) out vec4 colour;
uniform vec4 u_Colour;
void main()
{
colour = u_Colour;
}
Rest of the code that handles the compilation and setup:
int compileShader(unsigned int type, const std::string& source)
{
unsigned int id = glCreateShader(type);
const char* src = source.c_str();
glShaderSource(id, 1, &src, nullptr);
glCompileShader(id);
int result;
glGetShaderiv(id, GL_COMPILE_STATUS, &result);
if (result == GL_FALSE)
{
int length;
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length);
char* message = (char*)alloca(length * sizeof(char));
glGetShaderInfoLog(id, length, &length, message);
std::cout << message << std::endl;
glDeleteShader(id);
return 0;
}
return id;
}
void setUpProgram()
{
unsigned int program = glCreateProgram();
unsigned int vs = compileShader(GL_VERTEX_SHADER, vertexShader);
unsigned int fs = compileShader(GL_FRAGMENT_SHADER, fragmentShader);
unsigned int es = compileShader(GL_TESS_EVALUATION_SHADER, tesselationEvaluationShader);
glAttachShader(program, vs);
glAttachShader(program, fs);
glAttachShader(program, es);
glLinkProgram(program);
glValidateProgram(program);
GLenum error = glGetError();
while (error != GL_NO_ERROR)
{
std::cout << "Error: " << error << std::endl;
GLenum error = glGetError();
}
glUseProgram(program);
error = glGetError();
std::cout << "Error: " << error << std::endl;
}