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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 102 - (show annotations) (download)
Sat Jul 17 13:54:18 2010 UTC (9 years, 2 months ago) by william
File size: 4333 byte(s)
add compiler directive to write exceptions to console or not

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

  ViewVC Help
Powered by ViewVC 1.1.22