/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/Material.cs
ViewVC logotype

Contents of /trunk/gr2lib/core/coretypes/implementation/Material.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95 - (show annotations) (download)
Sat Jul 17 05:10:22 2010 UTC (9 years, 7 months ago) by william
File size: 3297 byte(s)
add StackTrace support for error handling (to see the stack calls)

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using gr2lib.core.helpers;
6 using gr2lib.core.interfaces;
7 using System.Diagnostics;
8 namespace gr2lib.core.coretypes.implementation
9 {
10
11
12 public class Material : IMaterial
13 {
14 public Material()
15 {
16 //this.NativePointer = IntPtr.Zero;
17 //this.ExtendedData = IntPtr.Zero;
18 this.Name = "";
19 this.Maps = new List<Map>();
20 this.Texture = new Texture();
21
22 }
23
24 internal static Material ReadFromMemory(IntPtr pointer)
25 {
26 try
27 {
28 if (pointer == IntPtr.Zero) return null;
29 native.Material native = Helpers.ReadFromMemory<native.Material>(pointer);
30 Material managed = ReadFromNative(native);
31 managed.NativePointer = pointer;
32 return managed;
33 }
34 catch (Exception ex)
35 {
36 StackTrace st = new StackTrace(true);
37 Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
38 return default(Material);
39 }
40 }
41
42 internal static Material ReadFromNative(native.Material native)
43 {
44 try
45 {
46 Material managed = new Material();
47 managed.Name = native.Name;
48 IntPtr[] maps = Helpers.ReadPtrArrayFromMemory<native.Map>(native.Maps);
49 int length = maps.Length;
50 managed.Maps = new List<Map>(length);
51 foreach (IntPtr ptr in maps)
52 {
53 managed.Maps.Add(new Map());
54 }
55 for (int i = 0; i < length; i++)
56 {
57 managed.Maps[i] = Map.ReadFromMemory(maps[i]);
58 }
59 managed.Texture = Texture.ReadFromMemory(native.Texture);
60 managed.ExtendedData = native.ExtendedData;
61 return managed;
62 }
63 catch (Exception ex)
64 {
65 StackTrace st = new StackTrace(true);
66 Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
67 return default(Material);
68 }
69 }
70
71 #region INativePointer Members
72 private IntPtr _NativePointer;
73 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
74 #endregion
75
76 #region IMaterial Members
77 private string _Name;
78 private List<Map> _Maps;
79 private Texture _Texture;
80 public string Name { get { return _Name; } set { _Name = value; } }
81 public List<Map> Maps { get { return _Maps; } set { _Maps = value; } }
82 public Texture Texture { get { return _Texture; } set { _Texture = value; } }
83 public bool IsTexture { get { if (Texture == null) { return false; } else { return true; } } }
84 #endregion
85
86 #region IExtendedData Members
87 private IntPtr _ExtendedData;
88 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
89 #endregion
90 }
91 }

  ViewVC Help
Powered by ViewVC 1.1.22