/[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 106 by william, Sat Jul 17 14:52:37 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    using gr2lib.core.exceptions;
9    
10  namespace gr2lib.core.coretypes.implementation  namespace gr2lib.core.coretypes.implementation
11  {  {
   
     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; }  
     }  
   
12      public class Texture : ITexture      public class Texture : ITexture
13      {      {
14          private string _FromFileName;          private FilePath _FromFileName;
15          private int _TextureType;          private int _TextureType;
16          private int _Width;          private int _Width;
17          private int _Height;          private int _Height;
# Line 29  namespace gr2lib.core.coretypes.implemen Line 19  namespace gr2lib.core.coretypes.implemen
19          private int _SubFormat;          private int _SubFormat;
20          private Layout _Layout;          private Layout _Layout;
21          private List<Image> _Images;          private List<Image> _Images;
         private IntPtr _ExtendedData;  
22    
23          public IntPtr NativePointer;  
24            
25    
26          public Texture()          public Texture()
27          {          {
# Line 43  namespace gr2lib.core.coretypes.implemen Line 33  namespace gr2lib.core.coretypes.implemen
33              this.SubFormat = 0;              this.SubFormat = 0;
34              this.Layout = new Layout();              this.Layout = new Layout();
35              this.Images = new List<Image>();              this.Images = new List<Image>();
36              this.ExtendedData = IntPtr.Zero;              //this.ExtendedData = new IntPtr();
37              this.NativePointer = IntPtr.Zero;              //this.NativePointer = IntPtr.Zero;
38          }          }
39    
40          internal static Texture ReadFromMemory(IntPtr pointer)          internal static Texture ReadFromMemory(IntPtr pointer)
41          {          {
42                try
43                {
44              if (pointer == IntPtr.Zero) return null;              if (pointer == IntPtr.Zero) return null;
45              native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer);              native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer);
46              Texture managed = ReadFromNative(native);              Texture managed = ReadFromNative(native);
47              managed.NativePointer = pointer;              managed.NativePointer = pointer;
48              return managed;              return managed;
49                }
50                catch (Exception ex)
51                {
52                    StackTrace st = new StackTrace(true);
53                    #if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
54                    Granny2ExceptionWriter.WriteToConsole(ex,st);
55    #endif
56                    return default(Texture);
57                }
58          }          }
59    
60          internal static Texture ReadFromNative(native.Texture native)          internal static Texture ReadFromNative(native.Texture native)
61          {          {
62              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)  
63              {              {
64                  managed.Images.Add(new Image());                  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              }              }
88              for (int i = 0; i < length; i++)              catch (Exception ex)
89              {              {
90                  managed.Images[i] = Image.ReadFromMemory(images[i]);                  StackTrace st = new StackTrace(true);
91    #if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
92                    Granny2ExceptionWriter.WriteToConsole(ex,st);
93    #endif
94                    return default(Texture);
95              }              }
             managed.ExtendedData = native.ExtendedData;  
             return managed;  
96          }          }
97    
98          #region ITexture Members          #region ITexture Members
99          public string FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }          public FilePath FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }
100          public int TextureType { get { return _TextureType; } set { _TextureType = value; } }          public int TextureType { get { return _TextureType; } set { _TextureType = value; } }
101          public int Width { get { return _Width; } set { _Width = value; } }          public int Width { get { return _Width; } set { _Width = value; } }
102          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 104  namespace gr2lib.core.coretypes.implemen
104          public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }          public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }
105          public Layout Layout { get { return _Layout; } set { _Layout = value; } }          public Layout Layout { get { return _Layout; } set { _Layout = value; } }
106          public List<Image> Images { get { return _Images; } set { _Images = value; } }          public List<Image> Images { get { return _Images; } set { _Images = value; } }
107            #endregion
108    
109            #region INativePointer Members
110            private IntPtr _NativePointer;
111            public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
112            #endregion
113    
114            #region IExtendedData Members
115            private IntPtr _ExtendedData;
116          public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }          public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
117          #endregion          #endregion
118      }      }

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

  ViewVC Help
Powered by ViewVC 1.1.22