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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 106 - (hide annotations) (download)
Sat Jul 17 14:52:37 2010 UTC (9 years, 4 months ago) by william
File size: 4418 byte(s)
implement Granny2ExceptionWriter

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

  ViewVC Help
Powered by ViewVC 1.1.22