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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 79 - (hide annotations) (download)
Thu Jul 15 21:50:56 2010 UTC (9 years, 5 months ago) by william
File size: 3464 byte(s)
create and implement interfaces for all core classes (for type casting)

1 william 72 using System;
2     using System.Collections.Generic;
3     using System.Text;
4     using gr2lib.core.helpers;
5    
6 william 79 using gr2lib.core.interfaces;
7    
8 william 72 namespace gr2lib.core.coretypes.implementation
9     {
10     public class Texture : ITexture
11     {
12 william 75 private FilePath _FromFileName;
13 william 72 private int _TextureType;
14     private int _Width;
15     private int _Height;
16     private int _Encoding;
17     private int _SubFormat;
18     private Layout _Layout;
19     private List<Image> _Images;
20     private IntPtr _ExtendedData;
21    
22 william 79
23 william 72
24     public Texture()
25     {
26 william 73 this.FromFileName = "";
27     this.TextureType = 0;
28     this.Width = 0;
29     this.Height = 0;
30     this.Encoding = 0;
31     this.SubFormat = 0;
32     this.Layout = new Layout();
33     this.Images = new List<Image>();
34     this.ExtendedData = IntPtr.Zero;
35     this.NativePointer = IntPtr.Zero;
36 william 72 }
37    
38     internal static Texture ReadFromMemory(IntPtr pointer)
39     {
40     if (pointer == IntPtr.Zero) return null;
41     native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer);
42     Texture managed = ReadFromNative(native);
43     managed.NativePointer = pointer;
44     return managed;
45     }
46    
47     internal static Texture ReadFromNative(native.Texture native)
48     {
49     Texture managed = new Texture();
50     managed.FromFileName = native.FromFileName;
51     managed.TextureType = native.TextureType;
52     managed.Width = native.Width;
53     managed.Height = native.Height;
54     managed.Encoding = native.Encoding;
55     managed.SubFormat = native.SubFormat;
56     managed.Layout = Layout.ReadFromNative(native.Layout);
57     IntPtr[] images = Helpers.ReadPtrArrayFromMemory<native.Image>(native.Images);
58     int length = images.Length;
59     managed.Images = new List<Image>(length);
60     foreach (IntPtr ptr in images)
61     {
62     managed.Images.Add(new Image());
63     }
64     for (int i = 0; i < length; i++)
65     {
66     managed.Images[i] = Image.ReadFromMemory(images[i]);
67     }
68     managed.ExtendedData = native.ExtendedData;
69     return managed;
70     }
71    
72     #region ITexture Members
73 william 75 public FilePath FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }
74 william 72 public int TextureType { get { return _TextureType; } set { _TextureType = value; } }
75     public int Width { get { return _Width; } set { _Width = value; } }
76     public int Height { get { return _Height; } set { _Height = value; } }
77     public int Encoding { get { return _Encoding; } set { _Encoding = value; } }
78     public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }
79     public Layout Layout { get { return _Layout; } set { _Layout = value; } }
80     public List<Image> Images { get { return _Images; } set { _Images = value; } }
81     public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
82     #endregion
83 william 79
84     #region INativePointer Members
85     private IntPtr _NativePointer;
86     public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
87     #endregion
88 william 72 }
89     }

  ViewVC Help
Powered by ViewVC 1.1.22