0
\$\begingroup\$

I am starting to work with tessellation and have some problems right in the beginning. I try to render a quad made of two triangles with tessellation, but nothing appears on the screen. But as soon as I remove the tessellation shaders and change GL_PATCHES to GL_TRIANGLESagain, it starts working again, without tessellation obviously.

So here is my code to setup the tessellation shaders:

glPatchParameteri(GL_PATCH_VERTICES, 3);
shaderID = glCreateProgram();
{
    vertex = GraphicsUtilities::loadShader("D:\\vert.glsl", GL_VERTEX_SHADER);
    glAttachShader(shaderID, vertex);


    fragment = GraphicsUtilities::loadShader("D:\\frag.glsl", GL_FRAGMENT_SHADER);          
    glAttachShader(shaderID, fragment);

    tcs = GraphicsUtilities::loadShader("D:\\tcs.glsl", GL_TESS_CONTROL_SHADER);
    glAttachShader(shaderID, tcs);

    tes = GraphicsUtilities::loadShader("D:\\tes.glsl", GL_TESS_EVALUATION_SHADER);
    glAttachShader(shaderID, tes);
}
glLinkProgram(shaderID);

This is the vertex shader:

   #version 400

layout(location=0) in vec4 vertPosition;
layout(location=1) in vec2 vertUV;
layout(location=2) in vec3 vertNormal;

void main(void){            
    gl_Position = vertPosition; 
}

The TCS:

#version 400
layout (vertices = 3) out;

void main()
{
    gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;

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

And the TES:

#version 400
layout(triangles, equal_spacing, cw) in;

void main()
{
    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);
}

And this is how I draw the quad:

glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glUseProgram(shaderID); 
glBindVertexArray(quad->getVboID());

glDrawElements(GL_PATCHES, 6, GL_UNSIGNED_INT, (GLvoid*)0);

glBindVertexArray(0);

glUseProgram(0);
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

I tried using in and out variables instead of gl_in/out, but that doesn't work either. I also tried it without the TCS. I was also using Apitrace to look up any errors, but nothing. The function loadShader() looks for compile errors. So what could cause this problem? I really have no idea how to debug this thing any further.

\$\endgroup\$
  • \$\begingroup\$ you need to add glPatchParameteri(GL_PATCH_VERTICES, 3) \$\endgroup\$ – alariq Jul 15 '15 at 20:40
  • \$\begingroup\$ I have, at the top of the first code example. \$\endgroup\$ – Liess Jemai Jul 15 '15 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.