#version 430 core
layout (triangles) in;
layout (triangle_strip, max_vertices = 4) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
in vec4 vCol[];
out vec4 gColC; // center color
out vec4 gColE; // edge color
out vec2 gBoundingBox;
out vec3 gPos;

void main()
{
  vec4 pat = gl_in[0].gl_Position;
  vec4 pbt = gl_in[1].gl_Position;
  vec4 pct = gl_in[2].gl_Position;
  vec4 pa = theMat * pat;
  vec4 pb = theMat * pbt;
  vec4 pc = theMat * pct;
  gColC = vCol[0];
  gColE = vCol[1];

  gBoundingBox = vec2 (-1,1);
  gl_Position = pb;
  gPos = pbt.xyz;
  EmitVertex();
  gBoundingBox = vec2 (1,1);
  gl_Position = pa;
  gPos = pat.xyz;
  EmitVertex();
  gBoundingBox = vec2 (-1,-1);
  gl_Position = pc;
  gPos = pct.xyz;
  EmitVertex();
  gBoundingBox = vec2 (1,-1);
  gl_Position = pa + pc - pb;
  gPos = pat.xyz + pct.xyz - pbt.xyz;
  EmitVertex();

  EndPrimitive();
}
