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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 79 by william, Thu Jul 15 21:50:56 2010 UTC revision 102 by william, Sat Jul 17 13:54:18 2010 UTC
# Line 4  using System.Text; Line 4  using System.Text;
4  using gr2lib.core.helpers;  using gr2lib.core.helpers;
5    
6  using gr2lib.core.interfaces;  using gr2lib.core.interfaces;
7    using System.Diagnostics;
8    
9  namespace gr2lib.core.coretypes.implementation  namespace gr2lib.core.coretypes.implementation
10  {  {
# Line 17  namespace gr2lib.core.coretypes.implemen Line 18  namespace gr2lib.core.coretypes.implemen
18          private int _SubFormat;          private int _SubFormat;
19          private Layout _Layout;          private Layout _Layout;
20          private List<Image> _Images;          private List<Image> _Images;
21          private IntPtr _ExtendedData;  
22    
23                    
24    
# Line 31  namespace gr2lib.core.coretypes.implemen Line 32  namespace gr2lib.core.coretypes.implemen
32              this.SubFormat = 0;              this.SubFormat = 0;
33              this.Layout = new Layout();              this.Layout = new Layout();
34              this.Images = new List<Image>();              this.Images = new List<Image>();
35              this.ExtendedData = IntPtr.Zero;              //this.ExtendedData = new IntPtr();
36              this.NativePointer = IntPtr.Zero;              //this.NativePointer = IntPtr.Zero;
37          }          }
38    
39          internal static Texture ReadFromMemory(IntPtr pointer)          internal static Texture ReadFromMemory(IntPtr pointer)
40          {          {
41                try
42                {
43              if (pointer == IntPtr.Zero) return null;              if (pointer == IntPtr.Zero) return null;
44              native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer);              native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer);
45              Texture managed = ReadFromNative(native);              Texture managed = ReadFromNative(native);
46              managed.NativePointer = pointer;              managed.NativePointer = pointer;
47              return managed;              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)          internal static Texture ReadFromNative(native.Texture native)
60          {          {
61              Texture managed = new Texture();              try
             managed.FromFileName = native.FromFileName;  
             managed.TextureType = native.TextureType;  
             managed.Width = native.Width;  
             managed.Height = native.Height;  
             managed.Encoding = native.Encoding;  
             managed.SubFormat = native.SubFormat;  
             managed.Layout = Layout.ReadFromNative(native.Layout);  
             IntPtr[] images = Helpers.ReadPtrArrayFromMemory<native.Image>(native.Images);  
             int length = images.Length;  
             managed.Images = new List<Image>(length);  
             foreach (IntPtr ptr in images)  
62              {              {
63                  managed.Images.Add(new Image());                  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              for (int i = 0; i < length; i++)              catch
88              {              {
89                  managed.Images[i] = Image.ReadFromMemory(images[i]);                  StackTrace st = new StackTrace(true);
90    #if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
91                    Console.WriteLine(st.ToString());
92    #endif
93                    return default(Texture);
94              }              }
             managed.ExtendedData = native.ExtendedData;  
             return managed;  
95          }          }
96    
97          #region ITexture Members          #region ITexture Members
# Line 78  namespace gr2lib.core.coretypes.implemen Line 103  namespace gr2lib.core.coretypes.implemen
103          public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }          public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }
104          public Layout Layout { get { return _Layout; } set { _Layout = value; } }          public Layout Layout { get { return _Layout; } set { _Layout = value; } }
105          public List<Image> Images { get { return _Images; } set { _Images = value; } }          public List<Image> Images { get { return _Images; } set { _Images = value; } }
         public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }  
106          #endregion          #endregion
107    
108          #region INativePointer Members          #region INativePointer Members
109          private IntPtr _NativePointer;          private IntPtr _NativePointer;
110          public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }          public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
111          #endregion          #endregion
112    
113            #region IExtendedData Members
114            private IntPtr _ExtendedData;
115            public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
116            #endregion
117      }      }
118  }  }

Legend:
Removed from v.79  
changed lines
  Added in v.102

  ViewVC Help
Powered by ViewVC 1.1.22