#version 460

#extension GL_EXT_buffer_reference : require
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_nonuniform_qualifier : require

#include "structures.glsl"

layout (location = 0) in vec2 in_gui_pos_0;
layout (location = 1) in vec2 in_gui_pos_1;
layout (location = 2) in vec4 in_col;
layout (location = 3) in uint in_image;

layout (location = 0) out vec4 out_color;
layout (location = 1) out vec2 out_uv;
layout (location = 2) out uint out_image;

vec2 uvs[] = {
	vec2(0.0, 1.0),
	vec2(0.0, 0.0),
	vec2(1.0, 1.0),
	vec2(1.0, 0.0)
};

vec2 rotate(vec2 coords, float theta)
{
	return mat2(cos(theta), sin(theta), -sin(theta), cos(theta)) * coords;
}

void main()
{
	// Draw with 6 indices, gl_VertexIndex will use the appropriate index, iterates through 0-3 and not 0-5
	vec2 dst_pos = gl_VertexIndex == 0 ? vec2(in_gui_pos_0.x, in_gui_pos_1.y) :
								 gl_VertexIndex == 1 ? vec2(in_gui_pos_0.x, in_gui_pos_0.y) :
								 gl_VertexIndex == 2 ? vec2(in_gui_pos_1.x, in_gui_pos_1.y) :
								 gl_VertexIndex == 3 ? vec2(in_gui_pos_1.x, in_gui_pos_0.y) : vec2(0.0, 0.0);

	out_uv = uvs[gl_VertexIndex];
	out_color = in_col;
	out_image = in_image;

	gl_Position = vec4(2 * dst_pos.x / PC.res.x - 1,
										 2 * dst_pos.y / PC.res.y - 1,
										 0,
										 1);
}
