1 module Engine.Material;
2 
3 import Engine.Shader;
4 import Engine.Texture;
5 import Engine.Batch;
6 import Engine.Renderer;
7 import Engine.Core;
8 
9 class Material {
10 	@property Shader shader() {
11 		return _shader;	
12 	};
13 	@property ITexture texture() {
14 		return _texture;	
15 	};
16 	@property Renderer renderer() {
17 		return _renderer;	
18 	};
19 
20 	bool changed;
21 	
22 	Shader _shader;
23 	ITexture _texture;
24 	Renderer _renderer;
25 
26 	this(ITexture texture) {
27 		_shader = Core.shader;
28 		_texture = texture;
29 		_renderer = defaultRenderer;
30 	}
31 
32 	final void render(Batch batch) {
33 		if (renderer !is null) {
34 			renderer()(batch);
35 		}
36 	}
37 		
38 	override bool opEquals(Object mato) {
39 		Material mat = cast(Material)mato;
40 		if (this is mat)
41 			return false;	
42 		if (shader !is mat.shader)
43 			return false;
44 		if (texture !is null && mat.texture !is null) {
45 			if (texture.id != mat.texture.id)
46 				return false;
47 		} else {
48 			if (texture !is mat.texture)
49 				return false;
50 		}
51 		if (renderer != mat.renderer)
52 			return false;
53 		return true;
54 	}	
55 }
56 
57