1 |
william |
72 |
using System; |
2 |
|
|
using System.Collections.Generic; |
3 |
|
|
using System.Text; |
4 |
|
|
using gr2lib.core.helpers; |
5 |
|
|
|
6 |
|
|
namespace gr2lib.core.coretypes.implementation |
7 |
|
|
{ |
8 |
|
|
|
9 |
|
|
public interface ITexture |
10 |
|
|
{ |
11 |
|
|
string FromFileName { get; set; } |
12 |
|
|
int TextureType { get; set; } |
13 |
|
|
int Width { get; set; } |
14 |
|
|
int Height { get; set; } |
15 |
|
|
int Encoding { get; set; } |
16 |
|
|
int SubFormat { get; set; } |
17 |
|
|
Layout Layout { get; set; } |
18 |
|
|
List<Image> Images { get; set; } |
19 |
|
|
IntPtr ExtendedData { get; set; } |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
public class Texture : ITexture |
23 |
|
|
{ |
24 |
|
|
private string _FromFileName; |
25 |
|
|
private int _TextureType; |
26 |
|
|
private int _Width; |
27 |
|
|
private int _Height; |
28 |
|
|
private int _Encoding; |
29 |
|
|
private int _SubFormat; |
30 |
|
|
private Layout _Layout; |
31 |
|
|
private List<Image> _Images; |
32 |
|
|
private IntPtr _ExtendedData; |
33 |
|
|
|
34 |
|
|
public IntPtr NativePointer; |
35 |
|
|
|
36 |
|
|
public Texture() |
37 |
|
|
{ |
38 |
william |
73 |
this.FromFileName = ""; |
39 |
|
|
this.TextureType = 0; |
40 |
|
|
this.Width = 0; |
41 |
|
|
this.Height = 0; |
42 |
|
|
this.Encoding = 0; |
43 |
|
|
this.SubFormat = 0; |
44 |
|
|
this.Layout = new Layout(); |
45 |
|
|
this.Images = new List<Image>(); |
46 |
|
|
this.ExtendedData = IntPtr.Zero; |
47 |
|
|
this.NativePointer = IntPtr.Zero; |
48 |
william |
72 |
} |
49 |
|
|
|
50 |
|
|
internal static Texture ReadFromMemory(IntPtr pointer) |
51 |
|
|
{ |
52 |
|
|
if (pointer == IntPtr.Zero) return null; |
53 |
|
|
native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer); |
54 |
|
|
Texture managed = ReadFromNative(native); |
55 |
|
|
managed.NativePointer = pointer; |
56 |
|
|
return managed; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
internal static Texture ReadFromNative(native.Texture native) |
60 |
|
|
{ |
61 |
|
|
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 |
|
|
managed.Images.Add(new Image()); |
75 |
|
|
} |
76 |
|
|
for (int i = 0; i < length; i++) |
77 |
|
|
{ |
78 |
|
|
managed.Images[i] = Image.ReadFromMemory(images[i]); |
79 |
|
|
} |
80 |
|
|
managed.ExtendedData = native.ExtendedData; |
81 |
|
|
return managed; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
#region ITexture Members |
85 |
|
|
public string FromFileName { get { return _FromFileName; } set { _FromFileName = value; } } |
86 |
|
|
public int TextureType { get { return _TextureType; } set { _TextureType = value; } } |
87 |
|
|
public int Width { get { return _Width; } set { _Width = value; } } |
88 |
|
|
public int Height { get { return _Height; } set { _Height = value; } } |
89 |
|
|
public int Encoding { get { return _Encoding; } set { _Encoding = value; } } |
90 |
|
|
public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } } |
91 |
|
|
public Layout Layout { get { return _Layout; } set { _Layout = value; } } |
92 |
|
|
public List<Image> Images { get { return _Images; } set { _Images = value; } } |
93 |
|
|
public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } } |
94 |
|
|
#endregion |
95 |
|
|
} |
96 |
|
|
} |