/[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

--- trunk/gr2lib/core/coretypes/implementation/Texture.cs	2010/07/15 14:31:59	73
+++ trunk/gr2lib/core/coretypes/implementation/Texture.cs	2010/07/17 13:54:18	102
@@ -3,25 +3,14 @@
 using System.Text;
 using gr2lib.core.helpers;
 
+using gr2lib.core.interfaces;
+using System.Diagnostics;
+
 namespace gr2lib.core.coretypes.implementation
 {
-
-    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; }
-    }
-
     public class Texture : ITexture
     {
-        private string _FromFileName;
+        private FilePath _FromFileName;
         private int _TextureType;
         private int _Width;
         private int _Height;
@@ -29,9 +18,9 @@
         private int _SubFormat;
         private Layout _Layout;
         private List<Image> _Images;
-        private IntPtr _ExtendedData;
 
-        public IntPtr NativePointer;
+
+        
 
         public Texture()
         {
@@ -43,46 +32,70 @@
             this.SubFormat = 0;
             this.Layout = new Layout();
             this.Images = new List<Image>();
-            this.ExtendedData = IntPtr.Zero;
-            this.NativePointer = IntPtr.Zero;
+            //this.ExtendedData = new IntPtr();
+            //this.NativePointer = IntPtr.Zero;
         }
 
         internal static Texture ReadFromMemory(IntPtr pointer)
         {
+            try 
+            {
             if (pointer == IntPtr.Zero) return null;
             native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer);
             Texture managed = ReadFromNative(native);
             managed.NativePointer = pointer;
             return managed;
+            }
+            catch
+            {
+                StackTrace st = new StackTrace(true);
+                #if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
+                Console.WriteLine(st.ToString());
+#endif
+                return default(Texture);
+            }
         }
 
         internal static Texture ReadFromNative(native.Texture native)
         {
-            Texture managed = new Texture();
-            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)
+            try
             {
-                managed.Images.Add(new Image());
+                Texture managed = new Texture();
+                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)
+                {
+                    Image _tmp = new Image();
+                    _tmp.NativePointer = ptr;
+                    managed.Images.Add(_tmp);
+                }
+                for (int i = 0; i < length; i++)
+                {
+                    managed.Images[i] = Image.ReadFromMemory(images[i]);
+                }
+                managed.ExtendedData = native.ExtendedData;
+                return managed;
             }
-            for (int i = 0; i < length; i++)
+            catch
             {
-                managed.Images[i] = Image.ReadFromMemory(images[i]);
+                StackTrace st = new StackTrace(true);
+#if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
+                Console.WriteLine(st.ToString());
+#endif
+                return default(Texture);
             }
-            managed.ExtendedData = native.ExtendedData;
-            return managed;
         }
 
         #region ITexture Members
-        public string FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }
+        public FilePath FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }
         public int TextureType { get { return _TextureType; } set { _TextureType = value; } }
         public int Width { get { return _Width; } set { _Width = value; } }
         public int Height { get { return _Height; } set { _Height = value; } }
@@ -90,6 +103,15 @@
         public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }
         public Layout Layout { get { return _Layout; } set { _Layout = value; } }
         public List<Image> Images { get { return _Images; } set { _Images = value; } }
+        #endregion
+
+        #region INativePointer Members
+        private IntPtr _NativePointer;
+        public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
+        #endregion
+
+        #region IExtendedData Members
+        private IntPtr _ExtendedData;
         public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
         #endregion
     }

 

  ViewVC Help
Powered by ViewVC 1.1.22