1 |
william |
72 |
using System; |
2 |
|
|
using System.Collections.Generic; |
3 |
|
|
using System.Text; |
4 |
|
|
using gr2lib.core.helpers; |
5 |
|
|
|
6 |
william |
79 |
using gr2lib.core.interfaces; |
7 |
william |
95 |
using System.Diagnostics; |
8 |
william |
79 |
|
9 |
william |
72 |
namespace gr2lib.core.coretypes.implementation |
10 |
|
|
{ |
11 |
|
|
public class Texture : ITexture |
12 |
|
|
{ |
13 |
william |
75 |
private FilePath _FromFileName; |
14 |
william |
72 |
private int _TextureType; |
15 |
|
|
private int _Width; |
16 |
|
|
private int _Height; |
17 |
|
|
private int _Encoding; |
18 |
|
|
private int _SubFormat; |
19 |
|
|
private Layout _Layout; |
20 |
|
|
private List<Image> _Images; |
21 |
|
|
|
22 |
william |
82 |
|
23 |
william |
79 |
|
24 |
william |
72 |
|
25 |
|
|
public Texture() |
26 |
|
|
{ |
27 |
william |
73 |
this.FromFileName = ""; |
28 |
|
|
this.TextureType = 0; |
29 |
|
|
this.Width = 0; |
30 |
|
|
this.Height = 0; |
31 |
|
|
this.Encoding = 0; |
32 |
|
|
this.SubFormat = 0; |
33 |
|
|
this.Layout = new Layout(); |
34 |
|
|
this.Images = new List<Image>(); |
35 |
william |
83 |
//this.ExtendedData = new IntPtr(); |
36 |
|
|
//this.NativePointer = IntPtr.Zero; |
37 |
william |
72 |
} |
38 |
|
|
|
39 |
|
|
internal static Texture ReadFromMemory(IntPtr pointer) |
40 |
|
|
{ |
41 |
william |
86 |
try |
42 |
|
|
{ |
43 |
william |
72 |
if (pointer == IntPtr.Zero) return null; |
44 |
|
|
native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer); |
45 |
|
|
Texture managed = ReadFromNative(native); |
46 |
|
|
managed.NativePointer = pointer; |
47 |
|
|
return managed; |
48 |
william |
86 |
} |
49 |
|
|
catch (Exception ex) |
50 |
|
|
{ |
51 |
william |
95 |
StackTrace st = new StackTrace(true); |
52 |
|
|
Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString()); |
53 |
william |
86 |
return default(Texture); |
54 |
|
|
} |
55 |
william |
72 |
} |
56 |
|
|
|
57 |
|
|
internal static Texture ReadFromNative(native.Texture native) |
58 |
|
|
{ |
59 |
william |
86 |
try |
60 |
william |
72 |
{ |
61 |
william |
86 |
Texture managed = new Texture(); |
62 |
|
|
managed.FromFileName = native.FromFileName; |
63 |
|
|
managed.TextureType = native.TextureType; |
64 |
|
|
managed.Width = native.Width; |
65 |
|
|
managed.Height = native.Height; |
66 |
|
|
managed.Encoding = native.Encoding; |
67 |
|
|
managed.SubFormat = native.SubFormat; |
68 |
|
|
managed.Layout = Layout.ReadFromNative(native.Layout); |
69 |
|
|
IntPtr[] images = Helpers.ReadPtrArrayFromMemory<native.Image>(native.Images); |
70 |
|
|
int length = images.Length; |
71 |
|
|
managed.Images = new List<Image>(length); |
72 |
|
|
foreach (IntPtr ptr in images) |
73 |
|
|
{ |
74 |
|
|
Image _tmp = new Image(); |
75 |
|
|
_tmp.NativePointer = ptr; |
76 |
|
|
managed.Images.Add(_tmp); |
77 |
|
|
} |
78 |
|
|
for (int i = 0; i < length; i++) |
79 |
|
|
{ |
80 |
|
|
managed.Images[i] = Image.ReadFromMemory(images[i]); |
81 |
|
|
} |
82 |
|
|
managed.ExtendedData = native.ExtendedData; |
83 |
|
|
return managed; |
84 |
william |
72 |
} |
85 |
william |
86 |
catch (Exception ex) |
86 |
william |
72 |
{ |
87 |
william |
95 |
StackTrace st = new StackTrace(true); |
88 |
|
|
Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString()); |
89 |
william |
86 |
return default(Texture); |
90 |
william |
72 |
} |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
#region ITexture Members |
94 |
william |
75 |
public FilePath FromFileName { get { return _FromFileName; } set { _FromFileName = value; } } |
95 |
william |
72 |
public int TextureType { get { return _TextureType; } set { _TextureType = value; } } |
96 |
|
|
public int Width { get { return _Width; } set { _Width = value; } } |
97 |
|
|
public int Height { get { return _Height; } set { _Height = value; } } |
98 |
|
|
public int Encoding { get { return _Encoding; } set { _Encoding = value; } } |
99 |
|
|
public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } } |
100 |
|
|
public Layout Layout { get { return _Layout; } set { _Layout = value; } } |
101 |
|
|
public List<Image> Images { get { return _Images; } set { _Images = value; } } |
102 |
|
|
#endregion |
103 |
william |
79 |
|
104 |
|
|
#region INativePointer Members |
105 |
|
|
private IntPtr _NativePointer; |
106 |
|
|
public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } } |
107 |
|
|
#endregion |
108 |
william |
82 |
|
109 |
|
|
#region IExtendedData Members |
110 |
|
|
private IntPtr _ExtendedData; |
111 |
|
|
public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } } |
112 |
|
|
#endregion |
113 |
william |
72 |
} |
114 |
|
|
} |