/[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 73 by william, Thu Jul 15 14:31:59 2010 UTC revision 86 by william, Fri Jul 16 23:35:21 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    
8  namespace gr2lib.core.coretypes.implementation  namespace gr2lib.core.coretypes.implementation
9  {  {
   
     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; }  
     }  
   
10      public class Texture : ITexture      public class Texture : ITexture
11      {      {
12          private string _FromFileName;          private FilePath _FromFileName;
13          private int _TextureType;          private int _TextureType;
14          private int _Width;          private int _Width;
15          private int _Height;          private int _Height;
# Line 29  namespace gr2lib.core.coretypes.implemen Line 17  namespace gr2lib.core.coretypes.implemen
17          private int _SubFormat;          private int _SubFormat;
18          private Layout _Layout;          private Layout _Layout;
19          private List<Image> _Images;          private List<Image> _Images;
         private IntPtr _ExtendedData;  
20    
21          public IntPtr NativePointer;  
22            
23    
24          public Texture()          public Texture()
25          {          {
# Line 43  namespace gr2lib.core.coretypes.implemen Line 31  namespace gr2lib.core.coretypes.implemen
31              this.SubFormat = 0;              this.SubFormat = 0;
32              this.Layout = new Layout();              this.Layout = new Layout();
33              this.Images = new List<Image>();              this.Images = new List<Image>();
34              this.ExtendedData = IntPtr.Zero;              //this.ExtendedData = new IntPtr();
35              this.NativePointer = IntPtr.Zero;              //this.NativePointer = IntPtr.Zero;
36          }          }
37    
38          internal static Texture ReadFromMemory(IntPtr pointer)          internal static Texture ReadFromMemory(IntPtr pointer)
39          {          {
40                try
41                {
42              if (pointer == IntPtr.Zero) return null;              if (pointer == IntPtr.Zero) return null;
43              native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer);              native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer);
44              Texture managed = ReadFromNative(native);              Texture managed = ReadFromNative(native);
45              managed.NativePointer = pointer;              managed.NativePointer = pointer;
46              return managed;              return managed;
47                }
48                catch (Exception ex)
49                {
50                    Console.WriteLine(ex.ToString());
51                    return default(Texture);
52                }
53          }          }
54    
55          internal static Texture ReadFromNative(native.Texture native)          internal static Texture ReadFromNative(native.Texture native)
56          {          {
57              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)  
58              {              {
59                  managed.Images.Add(new Image());                  Texture managed = new Texture();
60                    managed.FromFileName = native.FromFileName;
61                    managed.TextureType = native.TextureType;
62                    managed.Width = native.Width;
63                    managed.Height = native.Height;
64                    managed.Encoding = native.Encoding;
65                    managed.SubFormat = native.SubFormat;
66                    managed.Layout = Layout.ReadFromNative(native.Layout);
67                    IntPtr[] images = Helpers.ReadPtrArrayFromMemory<native.Image>(native.Images);
68                    int length = images.Length;
69                    managed.Images = new List<Image>(length);
70                    foreach (IntPtr ptr in images)
71                    {
72                        Image _tmp = new Image();
73                        _tmp.NativePointer = ptr;
74                        managed.Images.Add(_tmp);
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              for (int i = 0; i < length; i++)              catch (Exception ex)
84              {              {
85                  managed.Images[i] = Image.ReadFromMemory(images[i]);                  Console.WriteLine(ex.ToString());
86                    return default(Texture);
87              }              }
             managed.ExtendedData = native.ExtendedData;  
             return managed;  
88          }          }
89    
90          #region ITexture Members          #region ITexture Members
91          public string FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }          public FilePath FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }
92          public int TextureType { get { return _TextureType; } set { _TextureType = value; } }          public int TextureType { get { return _TextureType; } set { _TextureType = value; } }
93          public int Width { get { return _Width; } set { _Width = value; } }          public int Width { get { return _Width; } set { _Width = value; } }
94          public int Height { get { return _Height; } set { _Height = value; } }          public int Height { get { return _Height; } set { _Height = value; } }
# Line 90  namespace gr2lib.core.coretypes.implemen Line 96  namespace gr2lib.core.coretypes.implemen
96          public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }          public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }
97          public Layout Layout { get { return _Layout; } set { _Layout = value; } }          public Layout Layout { get { return _Layout; } set { _Layout = value; } }
98          public List<Image> Images { get { return _Images; } set { _Images = value; } }          public List<Image> Images { get { return _Images; } set { _Images = value; } }
99            #endregion
100    
101            #region INativePointer Members
102            private IntPtr _NativePointer;
103            public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
104            #endregion
105    
106            #region IExtendedData Members
107            private IntPtr _ExtendedData;
108          public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }          public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
109          #endregion          #endregion
110      }      }

Legend:
Removed from v.73  
changed lines
  Added in v.86

  ViewVC Help
Powered by ViewVC 1.1.22