#version 120
#extension GL_ARB_geometry_shader4 : enable

layout (lines_adjacency) in;
layout (line_strip, max_vertices=2) out;

void main(void) {
  vec4 p1=gl_PositionIn[1];
  vec4 p2=gl_PositionIn[2];
  vec4 c1=gl_PositionIn[0];
  vec4 c2=gl_PositionIn[3];

  p1/=p1.w;
  p2/=p2.w;
  c1/=c1.w;
  c2/=c2.w;

  c1-=p1;
  c2-=p1;
  p2-=p1;

  if (sign(p2.x*c1.y - p2.y*c1.x) == sign(p2.x*c2.y - p2.y*c2.x))
  {
    gl_FrontColor=gl_FrontColorIn[0];

    gl_Position=gl_PositionIn[1];
    EmitVertex();

    gl_Position=gl_PositionIn[2];
    EmitVertex();

    EndPrimitive();
  }
}
