#include "transform/polar.glsl"

layout(points) in;
layout(triangle_strip, max_vertices = 4) out;

// conf: Range, Elevation,  Resolution, 0.0
uniform vec4 conf;
in float in_value[];

out float x;
out float y;
out float value;

flat out vec4 vrange;


void main() {
    vec4 reso = vec4(conf.x/2.0, conf.y/2.0 * radian, 0.0, 0.0);
    vec4 loc;
    float c = cos(reso.y);

    vec4 po = gl_in[0].gl_Position;
    po.y = po.y * radian;

    vrange = vec4(po.x - reso.x, po.y - reso.y, po.x + reso.x, po.y + reso.y);
    value = in_value[0];

    gl_Position = po - reso;
    loc = forward(gl_Position);
    x = loc.x;
    y = loc.y;
    gl_Position = <transform(loc)>;
    EmitVertex();

    gl_Position = po + vec4(reso.x, -reso.y, 0.0, 0.0);   
    gl_Position.x = gl_Position.x / c;
    loc = forward(gl_Position);
    x = loc.x;
    y = loc.y;
    gl_Position = <transform(loc)>;
    EmitVertex();

    gl_Position = po + vec4(-reso.x, reso.y, 0.0, 0.0);
    loc = forward(gl_Position);
    x = loc.x;
    y = loc.y;
    gl_Position = <transform(loc)>;
    EmitVertex();

    gl_Position = po + reso;
    gl_Position.x = gl_Position.x / c;
    loc = forward(gl_Position);
    x = loc.x;
    y = loc.y;
    gl_Position = <transform(loc)>;
    EmitVertex();

    EndPrimitive();

}

