/[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 72 by william, Thu Jul 15 14:22:00 2010 UTC revision 102 by william, Sat Jul 17 13:54:18 2010 UTC
# Line 3  using System.Collections.Generic; Line 3  using System.Collections.Generic;
3  using System.Text;  using System.Text;
4  using gr2lib.core.helpers;  using gr2lib.core.helpers;
5    
6    using gr2lib.core.interfaces;
7    using System.Diagnostics;
8    
9  namespace gr2lib.core.coretypes.implementation  namespace gr2lib.core.coretypes.implementation
10  {  {
   
     public interface ITexture  
     {  
         string FromFileName { get; set; }  
         int TextureType { get; set; }  
         int Width { get; set; }  
         int Height { get; set; }  
         int Encoding { get; set; }  
         int SubFormat { get; set; }  
         Layout Layout { get; set; }  
         List<Image> Images { get; set; }  
         IntPtr ExtendedData { get; set; }  
     }  
   
11      public class Texture : ITexture      public class Texture : ITexture
12      {      {
13          private string _FromFileName;          private FilePath _FromFileName;
14          private int _TextureType;          private int _TextureType;
15          private int _Width;          private int _Width;
16          private int _Height;          private int _Height;
# Line 29  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;
         private IntPtr _ExtendedData;  
21    
22          public IntPtr NativePointer;  
23            
24    
25          public Texture()          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)          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
98          public string FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }          public FilePath FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }
99          public int TextureType { get { return _TextureType; } set { _TextureType = value; } }          public int TextureType { get { return _TextureType; } set { _TextureType = value; } }
100          public int Width { get { return _Width; } set { _Width = value; } }          public int Width { get { return _Width; } set { _Width = value; } }
101          public int Height { get { return _Height; } set { _Height = value; } }          public int Height { get { return _Height; } set { _Height = value; } }
# Line 80  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; } }
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; } }          public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
116          #endregion          #endregion
117      }      }

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

  ViewVC Help
Powered by ViewVC 1.1.22