# OpenGL Tessellation Shader Not Working

I've been trying to play around with tessellation shaders in OpenGL for a couple of hours now, but I'm having trouble to get it to work. I've been following The Little Grasshopper Triangle Tessellation with OpenGL 4.0, and I believed I had done the necessary OpenGL bureaucracy to get it to execute (but apparently not). My setup geometry is basically two triangles combined into a square, with just two attributes: position and texture coords. I have a vertex, tessellation control + evaluation, and also a fragment shader. You'll find all of the shaders below, as well as the setup code for the shaders (it's a wrapper, but there is nothing too surprising in there). Anyway, I've also added a screenshot of when I have the tessellation shaders on and off, and when they aren't enabled (just the vertex and the frag. shader), everything works OK. I've on purpose done so the TCS doesn't give new geometry, it just tries to mirror the input given (I'm aware it won't tesselate anything yet), but that doesn't work either.

I've also tried to move over the transformations done in the vertex shader (i.e. the MVP-transform) to the TES, but that didn't seem to help either. I thought it might have been the cause since I was doing tessellation work in camera-space (that is what is being done below, but I've tried the latter as well).

I'm honestly baffled, I can't for the life of me figure out what could be wrong. Maybe it's just some typo or some sort of name conflict in the interface blocks but I can't spot it. Any help is greatly appreciated!

Thanks for the help!

#version 410

in vec3 position;
in vec2 texture_coordinate;

uniform mat4 model;
uniform mat4 projection_view;

out PipelineData {
vec4 position;
vec2 texture_coordinate;
} vs_out;

void main() {
mat4 pvm = projection_view * model;
vs_out.texture_coordinate = texture_coordinate;
vec4 homogenous_position = vec4(position, 1.0);
vs_out.position = pvm * homogenous_position;

gl_Position = vs_out.position;
}


#version 410

layout(vertices = 3) out;

in PipelineData {
vec4 position;
vec2 texture_coordinate;
} tc_in[];

out PipelineData {
vec4 position;
vec2 texture_coordinate;
} tc_out[];

void main() {
tc_out[gl_InvocationID].texture_coordinate = tc_in[gl_InvocationID].texture_coordinate;
tc_out[gl_InvocationID].position = tc_in[gl_InvocationID].position;

gl_TessLevelInner[0] = 1;
gl_TessLevelOuter[0] = 1;
gl_TessLevelOuter[1] = 1;
gl_TessLevelOuter[2] = 1;
}


#version 410

layout(triangles) in;

in PipelineData {
vec4 position;
vec2 texture_coordinate;
} te_in[];

out PipelineData {
vec4 position;
vec2 texture_coordinate;
} te_out;

void main() {
te_out.texture_coordinate  = gl_TessCoord.x * te_in[0].texture_coordinate;
te_out.texture_coordinate += gl_TessCoord.y * te_in[1].texture_coordinate;
te_out.texture_coordinate += gl_TessCoord.z * te_in[2].texture_coordinate;

te_out.position  = gl_TessCoord.x * te_in[0].position;
te_out.position += gl_TessCoord.y * te_in[1].position;
te_out.position += gl_TessCoord.z * te_in[2].position;

gl_Position = te_out.position;
}


#version 410

in PipelineData {
vec4 position;
vec2 texture_coordinate;
} fs_in;

uniform sampler2D diffuse_texture;

out vec4 color;

void main() {
vec4 diffuse_texel = texture(diffuse_texture, fs_in.texture_coordinate);
color = vec4(1.0); // color = vec4(diffuse_texel);
}


// Excerpt of the setup code, with tessellation (see image below).
glPatchParameteri(GL_PATCH_VERTICES, 3);



// Excerpt of the setup code, tessellation disabled (see image below).
// glPatchParameteri(GL_PATCH_VERTICES, 3);



GLFW version: 3.2.1 X11 GLX EGL clock_gettime /dev/js Xf86vm shared
GLEW version: 2.1.0
OpenGL vendor: X.Org
OpenGL renderer: AMD CYPRESS (DRM 2.50.0 / 4.14.13-1-ARCH, LLVM 5.0.1)
OpenGL version: 4.1 (Core Profile) Mesa 17.3.1
OpenGL GLSL version: 4.10


After a couple of minutes after asking the question I was finally able to figure it out. It seems I missed to change the draw call to use patches instead of triangle primitives. For future reference to other ppl, when working with tessellation shaders, always use patches when drawing and set the amount too.

Below is the fix.

glPatchParameteri(GL_PATCH_VERTICES, 3);