1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use std::collections::hash_map::HashMap;

use crate::core::format::*;
use crate::core::variant::*;
use crate::core::resource::*;

#[derive(Debug)]
pub enum BlendFactor
{
	Zero,
	One,
	DstCol,
	SrcColor,
	SrcAlpha,
	DstAlpha,
	OneMinusSrcCol,
	OneMinusDstCol,
	OneMinusSrcAlpha,
	OneMinusDstAlpha,
	ConstantColor,
	ConstantAlpha,
	OneMinusConstantColor,
	OneMinusConstantAlpha,
	SrcAlphaSaturate,
}

#[derive(Debug)]
pub enum BlendOp
{
	Add,
	Subtract,
	RevSubtract
}

#[derive(Debug)]
pub enum ComparisonFunc
{
	Never,
	Less,
	Equal,
	Lequal,
	Greater,
	Notequal,
	Gequal,
	Always
}

#[derive(Debug)]
pub enum CullMode
{
	None,
	Front,
	Back,
	FrontBack,
}

#[derive(Debug)]
pub enum FrontFace
{
	CW,
	CCW,
}

#[derive(Debug)]
pub enum PolygonMode
{
	Point,
	Wireframe,
	Solid,
}

#[derive(Debug)]
pub struct VertexAttrib
{
	pub index:u8,
	pub count:u8,
	pub size:u8,
	pub stride:u8,
	pub offset:u16,
	pub format:Format,
}

impl VertexAttrib
{
	pub fn new(format:Format, index:u8, count:u8, size:u8, stride:u8, offset:u16) -> Self
	{
		Self
		{
			index:index,
			count:count,
			size:size,
			stride:stride,
			offset:offset,
			format:format,
		}
	}
}

pub trait Material : Resource
{
	fn input_layout(&self) -> &[VertexAttrib];
	fn uniforms(&self) -> &HashMap<String, Variant>;

	fn set_uniform(&mut self, name:&str, value:Variant);

	fn vs(&self) -> &str;
	fn fs(&self) -> &str;

	fn blend_enable(&self) -> bool { false }
	fn blend_op(&self) -> BlendOp { BlendOp::Add }
	fn blend_src(&self) -> BlendFactor { BlendFactor::SrcAlpha }
	fn blend_dest(&self) -> BlendFactor { BlendFactor::OneMinusConstantAlpha }
	fn blend_alpha_op(&self) -> BlendOp { BlendOp::Add }
	fn blend_alpha_src(&self) -> BlendFactor { BlendFactor::SrcAlpha }
	fn blend_alpha_dest(&self) -> BlendFactor { BlendFactor::OneMinusConstantAlpha }

	fn color_write_mask(&self) -> u32 { 0xFFFFFFFF }

	fn polygon_mode(&self) -> PolygonMode { PolygonMode::Solid }

	fn depth_enable(&self) -> bool { true }
	fn depth_write_enable(&self) -> bool { true }
	fn depth_func(&self) -> ComparisonFunc { ComparisonFunc::Lequal }

	fn cull_mode(&self) -> CullMode { CullMode::Back }

	fn line_width(&self) -> f32 { 1.0 }

	fn front_face(&self) -> FrontFace { FrontFace::CCW }
}