c++openglglslshadertesselation

glsl error: "v_color" not declared as an output from the previous stage while trying to render wtih tesselation shaders


I want my renderer to be able to use tesselation shaders, but when it comes to run, the debugger says

%s
Link info
---------
error: "v_color" not declared as an output from the previous stage

and I do not know what does it exactly mean.

v_color is the fragment shader in vec4 which comes from the vertex shader and vertex shader gets this value from the vbo like this:

#version 420 core                                                 

layout (location = 1) in vec4 a_color                             
out vec4 v_color;                                                 
void main(void)                                                   
{                                                                    
    gl_Position = //something;                          
    v_color = a_color;                                            
}  

#version 420 core                                                  

out vec4 color;                                                    
in vec4 v_color;                                                   

void main(void)                                                    
{                                                                  
    color = v_color;                                               
}         

and vertex shader gets a_color from vertex attrib pointer.

Why it returns error?


Solution

  • Each shader stage pass the output to the input of the next stage. The vertex shader is followed by the tessellation control shader, which is followed by the tessellation evaluation shader and finally the fragment shader (if there is no geometry shader).

    If you have a tessellation shader and you want to pass an attribute from the vertex sahder to the fragment shader, then you have to pass the attribute through all shader stages:

    e.g.:

    Vertex shader:

    #version 420 core                                                 
    
    layout (location = 1) in vec4 a_color                             
    out vec4 v_color;                                                 
    
    void main(void)                                                   
    {                                                                    
       v_color = a_color;
    
       // .....                                            
    }
    

    Tessellation control shader:

    #version 420 core    
    
    layout(vertices=3) out; 
    
    in  vec4 v_color[];
    out vec4 tc_color[];
    
    void main()
    {
        tc_color[gl_InvocationID] = v_color[gl_InvocationID];
    
        // .....
    }
    

    Tessellation evaluation shader:

    #version 420 core 
    
    layout(triangles) in;
    
    in  vec4 tc_color[];
    out vec4 te_color;
    
    void main()
    {
        te_color = tc_color[0] * gl_TessCoord.x +
                   tc_color[1] * gl_TessCoord.y +
                   tc_color[2] * gl_TessCoord.z;
    
        // .....
    }
    

    Fragment shader:

    #version 420 core                                                  
    
    in  vec4 te_color;  
    out vec4 color;                                                    
    
    void main(void)                                                    
    {                                                                  
        color = te_color;                                               
    }