Falco Engine 3.9.0.1 (beta)
Material.cs
Go to the documentation of this file.
1using System;
2using System.Runtime.CompilerServices;
3using System.Runtime.InteropServices;
4
5namespace FalcoEngine
6{
7 public class Material : Asset
8 {
9 internal Material() { }
10
15 [MethodImpl(MethodImplOptions.InternalCall)]
16 public extern Material(string name);
17
23 public static Material Load(string name)
24 {
25 return INTERNAL_load(name);
26 }
27
31 public Shader shader { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }
32
33 //Get parameters
34
40 public void GetParameter(string name, out Matrix3 matrix)
41 {
42 INTERNAL_getParameterMat3(name, out matrix);
43 }
44
50 public void GetParameter(string name, out Matrix4 matrix)
51 {
52 INTERNAL_getParameterMat4(name, out matrix);
53 }
54
60 public void GetParameter(string name, out Vector2 vector2)
61 {
62 INTERNAL_getParameterVec2(name, out vector2);
63 }
64
70 public void GetParameter(string name, out Vector3 vector3)
71 {
72 INTERNAL_getParameterVec3(name, out vector3);
73 }
74
80 public void GetParameter(string name, out Vector4 vector4)
81 {
82 INTERNAL_getParameterVec4(name, out vector4);
83 }
84
90 public void GetParameter(string name, out float flt)
91 {
92 flt = INTERNAL_getParameterFloat(name);
93 }
94
100 public void GetParameter(string name, out int val)
101 {
102 val = INTERNAL_getParameterInt(name);
103 }
104
110 public void GetParameter(string name, out bool val)
111 {
112 val = INTERNAL_getParameterBool(name);
113 }
114
120 public void GetParameter(string name, out Color color)
121 {
122 INTERNAL_getParameterColor(name, out color);
123 }
124
130 public void GetParameter(string name, out Texture texture)
131 {
132 Texture tex = INTERNAL_getParameterTexture(name);
133 texture = tex;
134
135 }
136
143 public T GetParameter<T>(string name)
144 {
145 if (typeof(T) == typeof(Texture))
146 {
147 Texture value = INTERNAL_getParameterTexture(name);
148 return (T)Convert.ChangeType(value, typeof(T));
149 }
150
151 if (typeof(T) == typeof(Matrix3))
152 {
153 INTERNAL_getParameterMat3(name, out Matrix3 value);
154 return (T)Convert.ChangeType(value, typeof(T));
155 }
156
157 if (typeof(T) == typeof(Matrix4))
158 {
159 INTERNAL_getParameterMat4(name, out Matrix4 value);
160 return (T)Convert.ChangeType(value, typeof(T));
161 }
162
163 if (typeof(T) == typeof(Vector2))
164 {
165 INTERNAL_getParameterVec2(name, out Vector2 value);
166 return (T)Convert.ChangeType(value, typeof(T));
167 }
168
169 if (typeof(T) == typeof(Vector3))
170 {
171 INTERNAL_getParameterVec3(name, out Vector3 value);
172 return (T)Convert.ChangeType(value, typeof(T));
173 }
174
175 if (typeof(T) == typeof(Vector4))
176 {
177 INTERNAL_getParameterVec4(name, out Vector4 value);
178 return (T)Convert.ChangeType(value, typeof(T));
179 }
180
181 if (typeof(T) == typeof(float))
182 {
183 float value = INTERNAL_getParameterFloat(name);
184 return (T)Convert.ChangeType(value, typeof(T));
185 }
186
187 if (typeof(T) == typeof(int))
188 {
189 int value = INTERNAL_getParameterInt(name);
190 return (T)Convert.ChangeType(value, typeof(T));
191 }
192
193 if (typeof(T) == typeof(bool))
194 {
195 bool value = INTERNAL_getParameterBool(name);
196 return (T)Convert.ChangeType(value, typeof(T));
197 }
198
199 if (typeof(T) == typeof(Color))
200 {
201 INTERNAL_getParameterColor(name, out Color value);
202 return (T)Convert.ChangeType(value, typeof(T));
203 }
204
205 return default(T);
206 }
207
208 //Set parameters
209
215 public void SetParameter(string name, Matrix3 matrix)
216 {
217 INTERNAL_setParameterMat3(name, ref matrix);
218 }
219
225 public void SetParameter(string name, Matrix4 matrix)
226 {
227 INTERNAL_setParameterMat4(name, ref matrix);
228 }
229
235 public void SetParameter(string name, Vector2 vector2)
236 {
237 INTERNAL_setParameterVec2(name, ref vector2);
238 }
239
245 public void SetParameter(string name, Vector3 vector3)
246 {
247 INTERNAL_setParameterVec3(name, ref vector3);
248 }
249
255 public void SetParameter(string name, Vector4 vector4)
256 {
257 INTERNAL_setParameterVec4(name, ref vector4);
258 }
259
265 public void SetParameter(string name, float flt)
266 {
267 INTERNAL_setParameterFloat(name, flt);
268 }
269
275 public void SetParameter(string name, int val)
276 {
277 INTERNAL_setParameterInt(name, val);
278 }
279
285 public void SetParameter(string name, bool val)
286 {
287 INTERNAL_setParameterBool(name, val);
288 }
289
295 public void SetParameter(string name, Color color)
296 {
297 INTERNAL_setParameterColor(name, ref color);
298 }
299
305 public void SetParameter(string name, Texture texture)
306 {
307 INTERNAL_setParameterTexture(name, texture);
308 }
309
310 /*----------- INTERNAL CALLS ------------*/
311
312 [MethodImpl(MethodImplOptions.InternalCall)]
313 private static extern Material INTERNAL_load(string name);
314
315 //Get
316 [MethodImpl(MethodImplOptions.InternalCall)]
317 private extern void INTERNAL_getParameterMat3(string name, out Matrix3 matrix);
318
319 [MethodImpl(MethodImplOptions.InternalCall)]
320 private extern void INTERNAL_getParameterMat4(string name, out Matrix4 matrix);
321
322 [MethodImpl(MethodImplOptions.InternalCall)]
323 private extern void INTERNAL_getParameterVec2(string name, out Vector2 vector2);
324
325 [MethodImpl(MethodImplOptions.InternalCall)]
326 private extern void INTERNAL_getParameterVec3(string name, out Vector3 vector3);
327
328 [MethodImpl(MethodImplOptions.InternalCall)]
329 private extern void INTERNAL_getParameterVec4(string name, out Vector4 vector4);
330
331 [MethodImpl(MethodImplOptions.InternalCall)]
332 private extern float INTERNAL_getParameterFloat(string name);
333
334 [MethodImpl(MethodImplOptions.InternalCall)]
335 private extern int INTERNAL_getParameterInt(string name);
336
337 [MethodImpl(MethodImplOptions.InternalCall)]
338 private extern bool INTERNAL_getParameterBool(string name);
339
340 [MethodImpl(MethodImplOptions.InternalCall)]
341 private extern void INTERNAL_getParameterColor(string name, out Color color);
342
343 [MethodImpl(MethodImplOptions.InternalCall)]
344 private extern Texture INTERNAL_getParameterTexture(string name);
345
346 //Set
347 [MethodImpl(MethodImplOptions.InternalCall)]
348 private extern void INTERNAL_setParameterMat3(string name, ref Matrix3 matrix);
349
350 [MethodImpl(MethodImplOptions.InternalCall)]
351 private extern void INTERNAL_setParameterMat4(string name, ref Matrix4 matrix);
352
353 [MethodImpl(MethodImplOptions.InternalCall)]
354 private extern void INTERNAL_setParameterVec2(string name, ref Vector2 vector2);
355
356 [MethodImpl(MethodImplOptions.InternalCall)]
357 private extern void INTERNAL_setParameterVec3(string name, ref Vector3 vector3);
358
359 [MethodImpl(MethodImplOptions.InternalCall)]
360 private extern void INTERNAL_setParameterVec4(string name, ref Vector4 vector4);
361
362 [MethodImpl(MethodImplOptions.InternalCall)]
363 private extern void INTERNAL_setParameterFloat(string name, float flt);
364
365 [MethodImpl(MethodImplOptions.InternalCall)]
366 private extern void INTERNAL_setParameterInt(string name, int val);
367
368 [MethodImpl(MethodImplOptions.InternalCall)]
369 private extern void INTERNAL_setParameterBool(string name, bool val);
370
371 [MethodImpl(MethodImplOptions.InternalCall)]
372 private extern void INTERNAL_setParameterColor(string name, ref Color color);
373
374 [MethodImpl(MethodImplOptions.InternalCall)]
375 private extern void INTERNAL_setParameterTexture(string name, Texture texture);
376 }
377}
string name
Get asset name
Definition: Asset.cs:16
void SetParameter(string name, float flt)
Set value of the parameter
Definition: Material.cs:265
static Material Load(string name)
Load existing material
Definition: Material.cs:23
void GetParameter(string name, out Vector2 vector2)
Get value of the parameter
Definition: Material.cs:60
void SetParameter(string name, Vector4 vector4)
Set value of the parameter
Definition: Material.cs:255
void GetParameter(string name, out Matrix4 matrix)
Get value of the parameter
Definition: Material.cs:50
Material(string name)
Create a new material and set its name
void SetParameter(string name, Color color)
Set value of the parameter
Definition: Material.cs:295
void GetParameter(string name, out Color color)
Get value of the parameter
Definition: Material.cs:120
void SetParameter(string name, bool val)
Set value of the parameter
Definition: Material.cs:285
void SetParameter(string name, Texture texture)
Set value of the parameter
Definition: Material.cs:305
void GetParameter(string name, out Vector3 vector3)
Get value of the parameter
Definition: Material.cs:70
void SetParameter(string name, Matrix4 matrix)
Set value of the parameter
Definition: Material.cs:225
void GetParameter(string name, out Vector4 vector4)
Get value of the parameter
Definition: Material.cs:80
void SetParameter(string name, int val)
Set value of the parameter
Definition: Material.cs:275
void GetParameter(string name, out Matrix3 matrix)
Get value of the parameter
Definition: Material.cs:40
void SetParameter(string name, Matrix3 matrix)
Set value of the parameter
Definition: Material.cs:215
void SetParameter(string name, Vector2 vector2)
Set value of the parameter
Definition: Material.cs:235
void SetParameter(string name, Vector3 vector3)
Set value of the parameter
Definition: Material.cs:245
void GetParameter(string name, out bool val)
Get value of the parameter
Definition: Material.cs:110
T GetParameter< T >(string name)
Get value of the parameter
Definition: Material.cs:143
Shader shader
Get or set a shader for this material
Definition: Material.cs:31
void GetParameter(string name, out int val)
Get value of the parameter
Definition: Material.cs:100
void GetParameter(string name, out float flt)
Get value of the parameter
Definition: Material.cs:90
void GetParameter(string name, out Texture texture)
Get value of the parameter
Definition: Material.cs:130