#version 330 core


layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;

in VertexData {
    vec3 Position_modelspace;
    flat uint Texture;
    vec3 FaceNormal_modelspace;
#ifdef PBR
    vec3 FaceNormal_worldspace;
    vec3 EyeDirection_cameraspace;
    vec3 LightDirection_cameraspace;
#endif
#ifdef FOG
    float Depth;
#endif
} vs_in[];

out GeometryData {
    vec3 Position_modelspace;
    flat uint Textures[3];
    vec3 TextureRatio;
    vec3 FaceNormal_modelspace;
#ifdef PBR
    vec3 FaceNormal_worldspace;
    vec3 EyeDirection_cameraspace;
    vec3 LightDirection_cameraspace;
#endif
#ifdef FOG
    float Depth;
#endif
} gs;

void main() {
    for(int i = 0; i < gl_in.length(); i++) {

        gl_Position = gl_in[i].gl_Position;
        gs.Position_modelspace = vs_in[i].Position_modelspace;
        gs.FaceNormal_modelspace = vs_in[i].FaceNormal_modelspace;

        gs.Textures[i] = vs_in[i].Texture;
        switch(int(mod(i,3))) {
            case 0:
                gs.TextureRatio = vec3(1,0,0);
                break;
            case 1:
                gs.TextureRatio = vec3(0,1,0);
                break;
            case 2:
                gs.TextureRatio = vec3(0,0,1);
                break;
            default:
                gs.TextureRatio = vec3(0);
                break;
        };

#ifdef PBR
        gs.FaceNormal_worldspace = vs_in[i].FaceNormal_worldspace;
        gs.EyeDirection_cameraspace = vs_in[i].EyeDirection_cameraspace;
        gs.LightDirection_cameraspace = vs_in[i].LightDirection_cameraspace;
#endif
#ifdef SHADOW
        gs.ShadowCoord = vs_in[i].ShadowCoord;
#endif
#ifdef FOG
        gs.Depth = vs_in[i].Depth;
#endif
        EmitVertex();
    }
    EndPrimitive();
}