Linking error at tessellation shaders in GLSL

2.9k views Asked by At

I'm testing the triangle tessellation from the link http://prideout.net/blog/?p=48#shaders. All the shader are compiled correctly, but when I try to link the program using the command:

glLinkProgram(programID);

I got the following error:

Tessellation control info
(0): error C6029: No input primitive type
----------------------------------------
Tessellation evaluation info
(0): error c7005: No tessellation primitive mode specified
-----------------------------------------------------------
Geometry info
(0): error C6022: No input primitive type
(0): error C6029: No ouput primitive type
----------------------------------------
Not valid

It's so strange I declare output for TC Shader using command:

layout(vertices = 3) out;

And input layout for TE shader using command:

layout(triangles, equal_spacing, cw) in;

Why I still got this error? I hope to see you answer about it.

I put my shaders in below:

Vertex shader:

#version 410 core

in vec4 Position;
out vec3 vPosition;

void main()
{
    vPosition = Position.xyz;
}

TC shader:

#version 410 core

layout(vertices = 3) out;
in vec3 vPosition[];
out vec3 tcPosition[];

#define ID gl_InvocationID

void main()
{
    float TessLevelInner = 3;
    float TessLevelOuter = 2; 
    tcPosition[ID] = vPosition[ID];
    if (ID == 0) {
        gl_TessLevelInner[0] = TessLevelInner;
        gl_TessLevelOuter[0] = TessLevelOuter;
        gl_TessLevelOuter[1] = TessLevelOuter;
        gl_TessLevelOuter[2] = TessLevelOuter;
    }
}

TE Shader:

#version 410 core
//TessEval

layout(triangles, equal_spacing, cw) in;
in vec3 tcPosition[];
out vec3 tePosition;
out vec3 tePatchDistance;
uniform mat4 Projection;
uniform mat4 Modelview; 

void main()
{
    vec3 p0 = gl_TessCoord.x * tcPosition[0];
    vec3 p1 = gl_TessCoord.y * tcPosition[1];
    vec3 p2 = gl_TessCoord.z * tcPosition[2];
    tePatchDistance = gl_TessCoord;
    tePosition = normalize(p0 + p1 + p2);
    gl_Position = Projection * Modelview * vec4(tePosition, 1);
}

Geometry shader:

#version 410 core
//geometry shader
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
in vec3 tePosition[3];
in vec3 tePatchDistance[3];
out vec3 gFacetNormal;
out vec3 gPatchDistance;
out vec3 gTriDistance;
uniform mat4 Modelview;
uniform mat3 NormalMatrix;

void main()
{
    vec3 A = tePosition[2] - tePosition[0];
    vec3 B = tePosition[1] - tePosition[0];
    gFacetNormal = NormalMatrix * normalize(cross(A, B));

    gPatchDistance = tePatchDistance[0];
    gTriDistance = vec3(1, 0, 0);
    gl_Position = gl_in[0].gl_Position; EmitVertex();

    gPatchDistance = tePatchDistance[1];
    gTriDistance = vec3(0, 1, 0);
    gl_Position = gl_in[1].gl_Position; EmitVertex();

    gPatchDistance = tePatchDistance[2];
    gTriDistance = vec3(0, 0, 1);
    gl_Position = gl_in[2].gl_Position; EmitVertex();

    EndPrimitive();
}

Fragment Shader:

#version 410 core
//fragment shader
out vec4 FragColor;
in vec3 gFacetNormal;
in vec3 gTriDistance;
in vec3 gPatchDistance;
in float gPrimitive;
uniform vec3 LightPosition;

float amplify(float d, float scale, float offset)
{
    d = scale * d + offset;
    d = clamp(d, 0, 1);
    d = 1 - exp2(-2*d*d);
    return d;
}

void main()
{
    vec3 AmbientMaterial = vec3(0.04f, 0.04f, 0.04f);
    vec3 DiffuseMaterial = vec3(0, 0.75, 0.75);
vec3 LightPosition = vec3(0.25, 0.25, 1);
    vec3 N = normalize(gFacetNormal);
    vec3 L = LightPosition;
    float df = abs(dot(N, L));
    vec3 color = AmbientMaterial + df * DiffuseMaterial;

    float d1 = min(min(gTriDistance.x, gTriDistance.y), gTriDistance.z);
    float d2 = min(min(gPatchDistance.x, gPatchDistance.y), gPatchDistance.z);
    color = amplify(d1, 40, -0.5) * amplify(d2, 60, -0.5) * color;

    FragColor = vec4(color, 1.0);
}

FINALLY, this is the code I set up shader sources:

 std::string filename = "shaders//terrain//terrain_TCShader.glsl"
 FILE* fp = fopen(fileName.c_str(), "rt");
if (!fp)
    return;
// Get all lines from a file
vector<string> sLines;
char sLine[255];
while (fgets(sLine, 255, fp))
    sLines.push_back(sLine);
fclose(fp);

const char** sProgram = new const char*[sLines.size()];
for (int i = 0; i < sLines.size(); i++){
    sProgram[i] = sLines[i].c_str();
}

    //Also for GL_TESS_EVALUATION_SHADER, ..VERTEX, ...FRAGMENT
pShader[st] = glCreateShader(GL_TESS_CONTROL_SHADER); 
glShaderSource(pShader[st], 1, (const GLchar**)sProgram, NULL);
glAttachShader(pProgram, pShader[st]);
glCompileShader(pShader[st]);
//==> I tried to check error here but it's ok, the compiler do not notify anything

After compile all the shader, I link the program

glLinkProgram(pProgram);

//And check error again:

glGetProgramiv(pProgram, GL_INFO_LOG_LENGTH,&infologLength);

    if (infologLength > 0)
    {
        infoLog = (char *)malloc(infologLength);
        glGetProgramInfoLog(pProgram, infologLength, &charsWritten, infoLog);
            }

//I got the error here, as I described above.

1

There are 1 answers

0
khanhhh89 On BEST ANSWER

I solved the problem. The error is in the code of loading shader.

glShaderSource(pShader[st], 1, (const GLchar**)sProgram, NULL);

I changed 1 to size of the char* array sProgram