1 module evael.graphics.Drawable;
2 
3 import evael.graphics.GraphicsDevice;
4 import evael.graphics.Texture;
5 import evael.graphics.shaders.Shader;
6 
7 import evael.utils.Math;
8 import evael.utils.Size;
9 import evael.utils.Rectangle;
10 
11 abstract class Drawable
12 {	
13 	protected GraphicsDevice m_graphicsDevice;
14 	protected Shader 	     m_shader;
15 	protected vec3 			 m_position;
16 	protected vec3 			 m_scale;
17 	protected Quaternionf 	 m_rotation;
18 	protected Size!int	     m_size;
19 	protected Texture 	     m_texture;
20 	protected bool 			 m_isVisible;
21 	
22 	protected uint m_vao, m_vertexBuffer, m_indexBuffer;
23 
24 	/**
25 	 * Drawable constructor.
26 	 */
27 	@nogc @safe
28 	public this(GraphicsDevice graphicsDevice) pure nothrow
29 	{
30 		this.m_graphicsDevice = graphicsDevice;
31 
32 		this.m_position = vec3(0, 0, 0);
33 		this.m_scale = vec3(1, 1, 1);
34 		this.m_rotation = Quaternionf.identity;
35 		this.m_isVisible = true;
36 	}
37 
38 	@nogc @safe
39 	public this(in float x = 0.0f, in float y = 0.0f, in float z = 0.0f) pure nothrow
40 	{
41 		auto position = vec3(x, y, z);
42 		auto size = Size!int();
43 
44 		this(position, size);
45 	}
46 
47 	@nogc @safe
48 	public this(in float x, in float y, in float z, in Size!int size) pure nothrow
49 	{
50 		vec3 position = vec3(x, y, z);
51 		this(position, size);
52 	}
53 
54 	@nogc @safe
55 	public this()(in ref vec3 position, in Size!int size) pure nothrow
56 	{
57 		this.m_position = position;
58 		this.m_size = size;
59 		this.m_isVisible = true;
60 		this.m_scale = vec3(1, 1, 1);
61 		this.m_rotation = Quaternionf.identity;
62 	}
63 
64 	public abstract void draw(in float deltaTime, mat4 view, mat4 projection);
65 
66 	@nogc 
67 	@property nothrow
68 	{
69 		public GraphicsDevice graphics()
70 		{	
71 			return this.m_graphicsDevice;
72 		}
73 
74 		public void graphics(GraphicsDevice value)
75 		{	
76 			this.m_graphicsDevice = value;
77 		}
78 
79 		public ref const(vec3) position() const
80 		{	
81 			return this.m_position;
82 		}
83 	
84 		public void position(in vec3 value)
85 		{	
86 			this.m_position = value;
87 		}
88 	
89 		public void scale(in float value)
90 		{	
91 			this.m_scale = vec3(value, value, value);
92 		}
93 
94 		public ref vec3 scale()
95 		{	
96 			return this.m_scale;
97 		}
98 
99 		public void rotation(in Quaternionf value)
100 		{	
101 			this.m_rotation = value;
102 		}
103 
104 		public ref const(Size!int) size() const
105 		{	
106 			return this.m_size;
107 		}
108 
109 		public void size(in Size!int value)
110 		{	
111 			this.m_size = value;
112 		}
113 	
114 		public Texture texture()
115 		{	
116 			return this.m_texture;
117 		}
118 	
119 		public void texture(Texture value)
120 		{	
121 			this.m_texture = value;
122 		}
123 		
124 		public bool isVisible() const
125 		{	
126 			return this.m_isVisible;
127 		}
128 
129 		public void isVisible(in bool value)
130 		{
131 			this.m_isVisible = value;
132 		}	
133 
134 		public uint vertexBuffer() const
135 		{	
136 			return this.m_vertexBuffer;
137 		}
138 
139 		public Shader shader()
140 		{	
141 			return this.m_shader;
142 		}
143 	
144 		public void shader(Shader value)
145 		{
146 			this.m_shader = value;
147 		}
148 	}
149 }
150