Fragment shader compilation problem

For several days I am trying to reach the problem with my shader. I have several varying floats and problem comes in question when I call my function join. Adding this line causes error which states: “Could not pack varying _v_linejoin”. I am using Qt platform and OpenGL 3.2.

This is my code for fragment shader:


precision highp float;

const float PI = 3.14159265358979323846264;
const float THETA = 15.0 * 3.14159265358979323846264/180.0;

float cap( int type, float dx, float dy, float t ){
		float d = 0.0;
		dx = abs(dx);
		dy = abs(dy);
     
		// None
		if      (type == 0)  discard;
		// Round
		else if (type == 1)  d = sqrt(dx*dx+dy*dy);
		// Triangle in
		else if (type == 3)  d = (dx+abs(dy));
		// Triangle out
		else if (type == 2)  d = max(abs(dy),(t+dx-abs(dy)));
		// Square
		else if (type == 4)  d = max(dx,dy);
		// Butt
		else if (type == 5)  d = max(dx+t,dy);
    
		return d;
}


float join( in float type, in float d, in vec2 segment, in vec2 texcoord, in vec2 miter, in float miter_limit, in float linewidth )
{
		float dx = texcoord.x;
    
		// Round join
		// --------------------------------
		if( type == 1.0 )
		{
			if (dx < segment.x) {
				d = max(d,length( texcoord - vec2(segment.x,0.0)));
				//d = length( texcoord - vec2(segment.x,0.0));
			} else if (dx > segment.y) {
				d = max(d,length( texcoord - vec2(segment.y,0.0)));
				//d = length( texcoord - vec2(segment.y,0.0));
			}
		}
    
		else if ( type == 2.0 )
		{
			if( (dx < segment.x) ||  (dx > segment.y) )
				d = max(d, min(abs(miter.x),abs(miter.y)));
		}
    
		// Miter limit
		// --------------------------------
		if( (dx < segment.x) ||  (dx > segment.y) )
		{
			d = max(d, min(abs(miter.x),abs(miter.y)) - miter_limit*linewidth/2.0 );
		}
    
		return d;
}


uniform sampler2D u_dash_atlas;


varying vec4  v_color;
varying vec2  v_segment;
varying vec2  v_angles;
varying vec2  v_linecaps;
varying vec2  v_texcoord;
varying vec2  v_miter;
varying float v_miter_limit;
varying float v_length;
varying float v_linejoin;
varying float v_linewidth;
varying float v_antialias;
varying float v_dash_phase;
varying float v_dash_period;
varying float v_dash_index;
varying vec2  v_dash_caps;
varying float v_closed;



	void main() 
	{
		//gl_FragColor = vec4(0.,0.,0.,1.);

		// If color is fully transparent we just discard the fragment
		if( v_color.a <= 0.0 )
		{
			discard;
		
		}

		// Test if dash pattern is the solid one (0)
		bool solid =  (v_dash_index == 0.0);

		// Test if path is closed
		bool closed = (v_closed > 0.0);

		vec4 color = v_color;
		float dx = v_texcoord.x;
		float dy = v_texcoord.y;
		float t = v_linewidth/2.0-v_antialias;
		float width = v_linewidth;
		float d = 0.0;
   
		vec2 linecaps = v_linecaps;
		vec2 dash_caps = v_dash_caps;
		float line_start = 0.0;
		float line_stop  = v_length;
	
		if( solid ) 
		{
			d = abs(dy);
			if( (!closed) && (dx < line_start) )
			{
				d = cap( int(v_linecaps.x), abs(dx), abs(dy), t );
			}
			else if( (!closed) &&  (dx > line_stop) )
			{
				d = cap( int(v_linecaps.y), abs(dx)-line_stop, abs(dy), t );
			}
			else
			{
                                d = join( v_linejoin, abs(dy), v_segment, v_texcoord,
                                                  v_miter, v_miter_limit, v_linewidth );
			}
       
		}
        	
			gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
		

	}


I have no idea why it fails to compile.

I think you may be exceeding the maximum number of varying components. You can check with glGet to see how many you can use.


GL_MAX_VARYING_COMPONENTS
data returns one value, the number components for varying variables, which must be at least 60.

GL_MAX_VARYING_VECTORS
data returns one value, the number 4-vectors for varying variables, which is equal to the value of GL_MAX_VARYING_COMPONENTS and must be at least 15.

GL_MAX_VARYING_FLOATS
data returns one value, the maximum number of interpolators available for processing varying variables used by vertex and fragment shaders. This value represents the number of individual floating-point values that can be interpolated; varying variables declared as vectors, matrices, and arrays will all consume multiple interpolators. The value must be at least 32.

Other people have had the same problem too:
http://www.khronos.org/message_boards/showthread.php/7074-Link-error-quot-Could-not-pack-varying-quot

http://www.opengl.org/discussion_boards/showthread.php/164526-GLSL-instruction-or-operation-limitation?p=1162398#post1162398