#version 450 core

#pragma include ./shared.glsl
#pragma include ../misc/camera.glsl

layout (location = 0) in vec2 inPosMin;
layout (location = 1) in vec2 inPosMax;
layout (location = 2) in vec2 inTexMin;
layout (location = 3) in vec2 inTexMax;
layout (location = 4) in vec4 inColor;

out FragmentData fragmentData;

void main() {
    vec2 position = vec2(0.0);
    vec2 texCoords = vec2(0.0);

    switch (gl_VertexID) {
        case 0:
            position = vec2(inPosMin.x, inPosMax.y);
            texCoords = vec2(inTexMin.x, inTexMax.y);
            break;

        case 1:
            position = vec2(inPosMin.x, inPosMin.y);
            texCoords = vec2(inTexMin.x, inTexMin.y);
            break;

        case 2:
            position = vec2(inPosMax.x, inPosMax.y);
            texCoords = vec2(inTexMax.x, inTexMax.y);
            break;

        case 3:
            position = vec2(inPosMax.x, inPosMin.y);
            texCoords = vec2(inTexMax.x, inTexMin.y);
            break;
    }

    mat4 ortho = mat4(
        vec4(2.0 / uCamera.size.x, 0.0, 0.0, 0.0),
        vec4(0.0, -2.0 / uCamera.size.y, 0.0, 0.0),
        vec4(0.0, 0.0, 1.0, 0.0),
        vec4(-1.0, 1.0, 1.0, 1.0)
    );

    gl_Position = ortho * vec4(position, 0.0, 1.0);

    fragmentData.texCoords = texCoords;
    fragmentData.color = inColor;
}
