1 module evael.graphics.shapes.Polygon;
2 
3 import evael.graphics.GraphicsDevice;
4 import evael.graphics.Drawable;
5 import evael.graphics.shaders.Shader;
6 import evael.graphics.Vertex;
7 import evael.graphics.Texture;
8 
9 import evael.utils.Math;
10 import evael.utils.Color;
11 import evael.utils.Size;
12 
13 /**
14  * Polygon.
15  */
16 class Polygon : Drawable
17 {
18 	private VertexPositionColor!3[] m_vertices;
19 
20 	/**
21 	 * Polygon constructor.
22 	 * Params:
23 	 *		graphicsDevice : graphics device
24 	 */
25 	@nogc @safe
26 	public this()(GraphicsDevice graphicsDevice) pure nothrow
27 	{
28 		super(0, 0, 0, Size!int(0, 0));
29 
30 		this.m_graphicsDevice = graphicsDevice;
31 	}
32 
33 	/**
34 	 * Initializes polygon.
35 	 */
36 	public void initialize()
37 	{
38 		this.m_vertexBuffer = this.m_graphicsDevice.createVertexBuffer(VertexPositionColor!3.sizeof * this.m_vertices.length, this.m_vertices.ptr);
39 	}
40 
41 	public override void draw(in float deltaTime, mat4 view, mat4 projection)					
42 	{
43 		if (!this.m_isVisible)
44 			return;
45 
46 		this.m_graphicsDevice.enableShader(this.m_shader);
47 
48 		this.m_graphicsDevice.setMatrix(this.m_shader.modelMatrix, mat4.identity.arrayof.ptr);
49 		this.m_graphicsDevice.setMatrix(this.m_shader.viewMatrix, view.arrayof.ptr);
50 		this.m_graphicsDevice.setMatrix(this.m_shader.projectionMatrix, projection.arrayof.ptr);
51 
52 		this.m_graphicsDevice.setVertexBuffer!(VertexPositionColor!3)(this.m_vertexBuffer);
53 
54 		this.m_graphicsDevice.drawPrimitives!(PrimitiveType.TriangleFan)(this.m_vertices.length);
55 
56 		this.m_graphicsDevice.disableShader();
57 	}
58 
59 	public void draw(in float deltaTime)
60 	{
61 		this.draw(deltaTime, this.m_graphicsDevice.viewMatrix, this.m_graphicsDevice.projectionMatrix);
62 	}
63 
64 	@nogc @safe
65 	@property pure nothrow
66 	{
67 		public void vertices(VertexPositionColor!3[] value) 
68 		{
69 			this.m_vertices = value;
70 		}
71 
72 		public ref VertexPositionColor!3[] vertices() 
73 		{
74 			return vertices;
75 		}
76 	}
77 }