/[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 86 - (hide annotations) (download)
Fri Jul 16 23:35:21 2010 UTC (9 years, 11 months ago) by william
File size: 3070 byte(s)
Add Try/Catch blocks in to all API 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     namespace gr2lib.core.coretypes.implementation
8     {
9    
10 william 86
11 william 79 public class Material : IMaterial
12     {
13 william 80 public Material()
14     {
15 william 83 //this.NativePointer = IntPtr.Zero;
16     //this.ExtendedData = IntPtr.Zero;
17 william 80 this.Name = "";
18     this.Maps = new List<Map>();
19     this.Texture = new Texture();
20 william 86
21 william 80 }
22    
23 william 86 internal static Material ReadFromMemory(IntPtr pointer)
24 william 79 {
25 william 86 try
26     {
27     if (pointer == IntPtr.Zero) return null;
28     native.Material native = Helpers.ReadFromMemory<native.Material>(pointer);
29     Material managed = ReadFromNative(native);
30     managed.NativePointer = pointer;
31     return managed;
32     }
33     catch (Exception ex)
34     {
35     Console.WriteLine(ex.ToString());
36     return default(Material);
37     }
38 william 79 }
39    
40     internal static Material ReadFromNative(native.Material native)
41     {
42 william 86 try
43 william 80 {
44 william 86 Material managed = new Material();
45     managed.Name = native.Name;
46     IntPtr[] maps = Helpers.ReadPtrArrayFromMemory<native.Map>(native.Maps);
47     int length = maps.Length;
48     managed.Maps = new List<Map>(length);
49     foreach (IntPtr ptr in maps)
50     {
51     managed.Maps.Add(new Map());
52     }
53     for (int i = 0; i < length; i++)
54     {
55     managed.Maps[i] = Map.ReadFromMemory(maps[i]);
56     }
57     managed.Texture = Texture.ReadFromMemory(native.Texture);
58     managed.ExtendedData = native.ExtendedData;
59     return managed;
60 william 80 }
61 william 86 catch (Exception ex)
62 william 79 {
63 william 86 Console.WriteLine(ex.ToString());
64     return default(Material);
65 william 79 }
66     }
67    
68     #region INativePointer Members
69     private IntPtr _NativePointer;
70     public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
71     #endregion
72    
73     #region IMaterial Members
74     private string _Name;
75     private List<Map> _Maps;
76     private Texture _Texture;
77     public string Name { get { return _Name; } set { _Name = value; } }
78     public List<Map> Maps { get { return _Maps; } set { _Maps = value; } }
79 william 86 public Texture Texture { get { return _Texture; } set { _Texture = value; } }
80 william 80 public bool IsTexture { get { if (Texture == null) { return false; } else { return true; } } }
81 william 79 #endregion
82 william 82
83     #region IExtendedData Members
84     private IntPtr _ExtendedData;
85     public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
86     #endregion
87 william 79 }
88     }

  ViewVC Help
Powered by ViewVC 1.1.22