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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 william 79 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 william 95 using System.Diagnostics;
8 william 79 namespace gr2lib.core.coretypes.implementation
9     {
10    
11 william 86
12 william 79 public class Material : IMaterial
13     {
14 william 80 public Material()
15     {
16 william 83 //this.NativePointer = IntPtr.Zero;
17     //this.ExtendedData = IntPtr.Zero;
18 william 80 this.Name = "";
19     this.Maps = new List<Map>();
20     this.Texture = new Texture();
21 william 86
22 william 80 }
23    
24 william 86 internal static Material ReadFromMemory(IntPtr pointer)
25 william 79 {
26 william 86 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 william 95 StackTrace st = new StackTrace(true);
37     Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
38 william 86 return default(Material);
39     }
40 william 79 }
41    
42     internal static Material ReadFromNative(native.Material native)
43     {
44 william 86 try
45 william 80 {
46 william 86 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 william 80 }
63 william 86 catch (Exception ex)
64 william 79 {
65 william 95 StackTrace st = new StackTrace(true);
66     Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
67 william 86 return default(Material);
68 william 79 }
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 william 86 public Texture Texture { get { return _Texture; } set { _Texture = value; } }
83 william 80 public bool IsTexture { get { if (Texture == null) { return false; } else { return true; } } }
84 william 79 #endregion
85 william 82
86     #region IExtendedData Members
87     private IntPtr _ExtendedData;
88     public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
89     #endregion
90 william 79 }
91     }

  ViewVC Help
Powered by ViewVC 1.1.22