#version 330 core
#extension GL_EXT_geometry_shader4 : enable

precision lowp float;

layout(points) in;

layout(triangle_strip, max_vertices=4) out;

in struct
{
	vec2 scale;
	vec4 texCoord;
	vec4 texCoord2;
	vec4 color;
	float angle;
	float blend;
}gInfo[];

out struct
{
	vec2 texCoord;
	vec2 texCoord2;
	float blend;
	vec4 color;
}fInfo;

uniform mat4 projectionMatrix;

void main()
{
	const vec2 offset[4] = vec2[4](vec2(-0.5, 0.5), vec2(0.5, 0.5), vec2(-0.5, -0.5), vec2(0.5, -0.5));
	const vec2 texOffset[4] = vec2[4](vec2(0, 0), vec2(1, 0), vec2(0, 1), vec2(1, 1));
	
	float msin = sin(gInfo[0].angle);
	float mcos = cos(gInfo[0].angle);
	mat2 rm = mat2(vec2(mcos, msin), vec2(-msin, mcos));
	fInfo.color = gInfo[0].color;
    fInfo.blend = gInfo[0].blend;
    
	for(int i = 0; i < 4; i++)
	{
		vec2 s = rm*offset[i]*gInfo[0].scale;
		s = mat2(projectionMatrix)*s;
		gl_Position = gl_in[0].gl_Position;
		gl_Position.x += s.x;
		gl_Position.y += s.y;
		fInfo.texCoord = gInfo[0].texCoord.xy+texOffset[i]*gInfo[0].texCoord.zw;
		fInfo.texCoord2 = gInfo[0].texCoord2.xy+texOffset[i]*gInfo[0].texCoord2.zw;
		EmitVertex();
	}
	EndPrimitive();
}