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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 72 - (show annotations) (download)
Thu Jul 15 14:22:00 2010 UTC (9 years, 5 months ago) by william
File size: 3266 byte(s)
add: reading of textures

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

  ViewVC Help
Powered by ViewVC 1.1.22