1 |
using System; |
2 |
using System.Runtime.InteropServices; |
3 |
|
4 |
using gr2lib.core.typedefs; |
5 |
using gr2lib.core.coretypes; |
6 |
using gr2lib.core.coretypes.implementation; |
7 |
//using gr2lib.core.coretypes; |
8 |
|
9 |
namespace gr2lib.core |
10 |
{ |
11 |
/// <summary> |
12 |
/// coreapi class (this is the heart of gr2lib, this is where all of the Granny2 API calls will live |
13 |
/// </summary> |
14 |
public class coreapi |
15 |
{ |
16 |
#region INTEROP SUPPORT |
17 |
/// <summary> |
18 |
/// ExternalSupport class |
19 |
/// </summary> |
20 |
public class ExternalSupport |
21 |
{ |
22 |
/// <summary> |
23 |
/// GetProcAddress(IntPtr hModule, string procName); |
24 |
/// </summary> |
25 |
/// <param name="hModule">pointer to module</param> |
26 |
/// <param name="procName">procedure name</param> |
27 |
/// <returns></returns> |
28 |
[DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)] |
29 |
public static extern IntPtr GetProcAddress(IntPtr hModule, string procName); |
30 |
/// <summary> |
31 |
/// LoadLibrary(string lpFileName); |
32 |
/// </summary> |
33 |
/// <param name="lpFileName">filename</param> |
34 |
/// <returns></returns> |
35 |
[DllImport("kernel32", SetLastError = true)] |
36 |
public static extern IntPtr LoadLibrary(string lpFileName); |
37 |
} |
38 |
#endregion |
39 |
|
40 |
#region Granny2 API Version Support |
41 |
/// <summary> |
42 |
/// VersionSupport class |
43 |
/// </summary> |
44 |
public class VersionSupport |
45 |
{ |
46 |
/// <summary> |
47 |
/// GrannyVersionsMatch(major,minor,customization,build) |
48 |
/// </summary> |
49 |
/// <param name="MajorVersion">an integer, representing the major</param> |
50 |
/// <param name="MinorVersion">an integer, representing the minor</param> |
51 |
/// <param name="Customization">an integer, representing the customization</param> |
52 |
/// <param name="BuildNumber">an integer, representing the build</param> |
53 |
/// <returns>boolean indicating if the supplied version matches what the granny2.dll's intenal version</returns> |
54 |
[DllImport("granny2.dll", EntryPoint = "GrannyVersionsMatch_", CallingConvention = CallingConvention.StdCall)] |
55 |
internal static extern bool GrannyVersionsMatch(granny_int32x MajorVersion, granny_int32x MinorVersion, granny_int32x Customization, granny_int32x BuildNumber); |
56 |
/// <summary> |
57 |
/// GrannyGetVersion(&major,&minor,&customization,&build) |
58 |
/// </summary> |
59 |
/// <param name="MajorVersion">an integer, to store the major</param> |
60 |
/// <param name="MinorVersion">an integer, to store the minor</param> |
61 |
/// <param name="Customization">an integer, to store the customization</param> |
62 |
/// <param name="BuildNumber">an integer, to store the build</param> |
63 |
[DllImport("granny2.dll", EntryPoint = "GrannyGetVersion", CallingConvention = CallingConvention.StdCall)] |
64 |
internal static extern void GrannyGetVersion(ref granny_int32x MajorVersion, ref granny_int32x MinorVersion, ref granny_int32x Customization, ref granny_int32x BuildNumber); |
65 |
/// <summary> |
66 |
/// GrannyGetVersionString() |
67 |
/// </summary> |
68 |
/// <returns>a string representing the granny2.dll's internal library version</returns> |
69 |
[DllImport("granny2.dll", EntryPoint = "GrannyGetVersionString", CallingConvention = CallingConvention.StdCall)] |
70 |
internal static extern string GrannyGetVersionString(); |
71 |
} |
72 |
#endregion |
73 |
|
74 |
#region Granny2 API File Loading Support |
75 |
/// <summary> |
76 |
/// FileLoadingSupport class |
77 |
/// </summary> |
78 |
public class FileLoadingSupport |
79 |
{ |
80 |
/// <summary> |
81 |
/// GrannyReadEntireFile(string fileName) |
82 |
/// </summary> |
83 |
/// <param name="fileName">the filename to load</param> |
84 |
/// <returns>a pointer to the file</returns> |
85 |
[DllImport("granny2.dll", EntryPoint = "GrannyReadEntireFile", CallingConvention = CallingConvention.StdCall)] |
86 |
public static extern IntPtr GrannyReadEntireFile(string fileName); |
87 |
/// <summary> |
88 |
/// GetFileInfo(IntPtr file) |
89 |
/// </summary> |
90 |
/// <param name="file">pointer to the file: <see cref="GrannyReadEntireFile"/></param> |
91 |
/// <returns>a pointer to the file info</returns> |
92 |
[DllImport("granny2.dll", EntryPoint = "GrannyGetFileInfo", CallingConvention = CallingConvention.StdCall)] |
93 |
public static extern IntPtr GetFileInfo(IntPtr file); |
94 |
/// <summary> |
95 |
/// FreeFile(IntPtr pointer) |
96 |
/// </summary> |
97 |
/// <param name="file">pointer to the file: <see cref="GrannyReadEntireFile"/></param> |
98 |
[DllImport("granny2.dll", EntryPoint = "GrannyFreeFile", CallingConvention = CallingConvention.StdCall)] |
99 |
public static extern void FreeFile(IntPtr file); |
100 |
} |
101 |
#endregion |
102 |
|
103 |
#region Granny2 API Header Support |
104 |
/// <summary> |
105 |
/// HeaderSupport class |
106 |
/// </summary> |
107 |
public class HeaderSupport |
108 |
{ |
109 |
/// <summary> |
110 |
/// GrannyGetFileTypeTag(IntPtr File) |
111 |
/// </summary> |
112 |
/// <param name="File">pointer to the file: <see cref="coreapi.FileLoadingSupport.GrannyReadEntireFile"/></param> |
113 |
/// <returns>an integer representing the TypeTag</returns> |
114 |
[DllImport("granny2.dll", EntryPoint = "GrannyGetFileTypeTag", CallingConvention = CallingConvention.StdCall)] |
115 |
public static extern int GrannyGetFileTypeTag(IntPtr File); |
116 |
} |
117 |
#endregion |
118 |
|
119 |
#region Granny2 API Granny Texture Format Support |
120 |
/// <summary> |
121 |
/// TextureSupport class |
122 |
/// </summary> |
123 |
public class TextureSupport |
124 |
{ |
125 |
/// <summary> |
126 |
/// GrannyCopyTextureImage(IntPtr Texture, int ImageIndex, int MIPIndex, IntPtr Layout, int DestWidth, int DestHeight, int DestStride, IntPtr Pixels); |
127 |
/// </summary> |
128 |
/// <param name="Texture">pointer to the texture to copy (use the nativepointer, of the texture class)</param> |
129 |
/// <param name="ImageIndex">index in the images list</param> |
130 |
/// <param name="MIPIndex">index of the miplevel in the images list at ImageIndex</param> |
131 |
/// <param name="Layout">pointer to the pixel layout (use the nativepointer, of the layout class)</param> |
132 |
/// <param name="DestWidth">the target width</param> |
133 |
/// <param name="DestHeight">the target height</param> |
134 |
/// <param name="DestStride">width*bytesperpixel</param> |
135 |
/// <param name="Pixels">pointer to the pixels (this will hold the copied pixels)</param> |
136 |
/// <returns>a boolean value indicating that the copy operation succeeded</returns> |
137 |
[DllImport("granny2.dll", EntryPoint = "_GrannyCopyTextureImage@32", CallingConvention = CallingConvention.StdCall)] |
138 |
public static extern bool GrannyCopyTextureImage(IntPtr Texture, int ImageIndex, int MIPIndex, IntPtr Layout, int DestWidth, int DestHeight, int DestStride, IntPtr Pixels); |
139 |
[DllImport("granny2.dll", EntryPoint = "_GrannyGetRecommendedPixelLayout@8", CallingConvention = CallingConvention.StdCall)] |
140 |
public static extern bool GrannyGetRecommendedPixelLayout(IntPtr Texture, IntPtr Layout); |
141 |
/// <summary> |
142 |
/// GrannySwapRGBAToBGRA(granny_pixel_layout SourceLayoutFromEnum, out Layout SourcePixelLayout) |
143 |
/// </summary> |
144 |
/// <param name="SourceLayoutFromEnum">the source layout to swap: <see cref="granny_pixel_layout"/></param> |
145 |
/// <param name="SwappedPixelLayout">returns the swapped pixel layout</param> |
146 |
/// <param name="SwappedLayout">returns the swapped layout as a granny_pixel_layout value</param> |
147 |
public static void GrannySwapRGBAToBGRA(granny_pixel_layout SourceLayoutFromEnum, out Layout SwappedPixelLayout, out granny_pixel_layout SwappedLayout) |
148 |
{ |
149 |
SwappedPixelLayout = granny_pixel_layouts.GrannyDefaultPixelLayout; |
150 |
SwappedLayout = granny_pixel_layout.GrannyRGBA8888PixelFormat; |
151 |
switch (SourceLayoutFromEnum) |
152 |
{ |
153 |
case granny_pixel_layout.GrannyBGR555PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGB555PixelFormat; SwappedLayout = granny_pixel_layout.GrannyRGB555PixelFormat; break; |
154 |
case granny_pixel_layout.GrannyBGR565PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGB565PixelFormat; SwappedLayout = granny_pixel_layout.GrannyRGB565PixelFormat; break; |
155 |
case granny_pixel_layout.GrannyBGR888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGB888PixelFormat; SwappedLayout = granny_pixel_layout.GrannyRGB888PixelFormat; break; |
156 |
case granny_pixel_layout.GrannyBGRA4444PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGBA4444PixelFormat; SwappedLayout = granny_pixel_layout.GrannyRGBA4444PixelFormat; break; |
157 |
case granny_pixel_layout.GrannyBGRA5551PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGBA5551PixelFormat; SwappedLayout = granny_pixel_layout.GrannyRGBA5551PixelFormat; break; |
158 |
case granny_pixel_layout.GrannyBGRA8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGBA8888PixelFormat; SwappedLayout = granny_pixel_layout.GrannyRGBA8888PixelFormat; break; |
159 |
case granny_pixel_layout.GrannyRGB555PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGR555PixelFormat; SwappedLayout = granny_pixel_layout.GrannyBGR555PixelFormat; break; |
160 |
case granny_pixel_layout.GrannyRGB565PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGR565PixelFormat; SwappedLayout = granny_pixel_layout.GrannyBGR565PixelFormat; break; |
161 |
case granny_pixel_layout.GrannyRGB888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGR888PixelFormat; SwappedLayout = granny_pixel_layout.GrannyBGR888PixelFormat; break; |
162 |
case granny_pixel_layout.GrannyRGBA4444PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGRA4444PixelFormat; SwappedLayout = granny_pixel_layout.GrannyBGRA4444PixelFormat; break; |
163 |
case granny_pixel_layout.GrannyRGBA5551PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGRA5551PixelFormat; SwappedLayout = granny_pixel_layout.GrannyBGRA5551PixelFormat; break; |
164 |
case granny_pixel_layout.GrannyRGBA8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGRA8888PixelFormat; SwappedLayout = granny_pixel_layout.GrannyBGRA8888PixelFormat; break; |
165 |
case granny_pixel_layout.GrannyARGB8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyABGR8888PixelFormat; SwappedLayout = granny_pixel_layout.GrannyABGR8888PixelFormat; break; |
166 |
case granny_pixel_layout.GrannyABGR8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyARGB8888PixelFormat; SwappedLayout = granny_pixel_layout.GrannyARGB8888PixelFormat; break; |
167 |
default: SwappedPixelLayout = granny_pixel_layouts.GrannyDefaultPixelLayout; break; |
168 |
} |
169 |
} |
170 |
/// <summary> |
171 |
/// GrannySwapRGBAToBGRA(granny_pixel_layout SourceLayoutFromEnum) |
172 |
/// </summary> |
173 |
/// <param name="SourceLayoutFromEnum">the source layout to swap: <see cref="granny_pixel_layout"/></param> |
174 |
/// <returns>layout</returns> |
175 |
public static Layout GrannySwapRGBAToBGRA(granny_pixel_layout SourceLayoutFromEnum) |
176 |
{ |
177 |
Layout SwappedPixelLayout = new Layout(); |
178 |
SwappedPixelLayout = granny_pixel_layouts.GrannyDefaultPixelLayout; |
179 |
switch (SourceLayoutFromEnum) |
180 |
{ |
181 |
case granny_pixel_layout.GrannyBGR555PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGB555PixelFormat; break; |
182 |
case granny_pixel_layout.GrannyBGR565PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGB565PixelFormat; break; |
183 |
case granny_pixel_layout.GrannyBGR888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGB888PixelFormat; break; |
184 |
case granny_pixel_layout.GrannyBGRA4444PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGBA4444PixelFormat; break; |
185 |
case granny_pixel_layout.GrannyBGRA5551PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGBA5551PixelFormat; break; |
186 |
case granny_pixel_layout.GrannyBGRA8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGBA8888PixelFormat; break; |
187 |
case granny_pixel_layout.GrannyRGB555PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGR555PixelFormat; break; |
188 |
case granny_pixel_layout.GrannyRGB565PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGR565PixelFormat; break; |
189 |
case granny_pixel_layout.GrannyRGB888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGR888PixelFormat; break; |
190 |
case granny_pixel_layout.GrannyRGBA4444PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGRA4444PixelFormat; break; |
191 |
case granny_pixel_layout.GrannyRGBA5551PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGRA5551PixelFormat; break; |
192 |
case granny_pixel_layout.GrannyRGBA8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGRA8888PixelFormat; break; |
193 |
case granny_pixel_layout.GrannyARGB8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyABGR8888PixelFormat; break; |
194 |
case granny_pixel_layout.GrannyABGR8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyARGB8888PixelFormat; break; |
195 |
default: SwappedPixelLayout = granny_pixel_layouts.GrannyDefaultPixelLayout; break; |
196 |
} |
197 |
return SwappedPixelLayout; |
198 |
} |
199 |
/// <summary> |
200 |
/// Begin's a Raw Texture |
201 |
/// </summary> |
202 |
/// <param name="Width">image width</param> |
203 |
/// <param name="Height">image height</param> |
204 |
/// <param name="ResultingLayout">pointer to pixel layout</param> |
205 |
/// <param name="StrideAlignment">StrideAlignment</param> |
206 |
/// <returns>pointer to texture_builder</returns> |
207 |
[DllImport("granny2.dll", EntryPoint = "_GrannyBeginRawTexture@16", CallingConvention = CallingConvention.StdCall)] |
208 |
public static extern IntPtr GrannyBeginRawTexture(granny_int32x Width, granny_int32x Height, IntPtr ResultingLayout, granny_int32x StrideAlignment); |
209 |
/// <summary> |
210 |
/// Begin's a S3TC Texture |
211 |
/// </summary> |
212 |
/// <param name="Width">image width</param> |
213 |
/// <param name="Height">image height</param> |
214 |
/// <param name="Format">granny_s3tc_texture_format Format</param> |
215 |
/// <returns>pointer to texture_builder</returns> |
216 |
[DllImport("granny2.dll", EntryPoint = "_GrannyBeginS3TCTexture@12", CallingConvention = CallingConvention.StdCall)] |
217 |
public static extern IntPtr GrannyBeginS3TCTexture(granny_int32x Width, granny_int32x Height, granny_s3tc_texture_format Format); |
218 |
/// <summary> |
219 |
/// Begin's a Best S3TC Texture match |
220 |
/// </summary> |
221 |
/// <param name="Width">image width</param> |
222 |
/// <param name="Height">image height</param> |
223 |
/// <returns>pointer to texture_builder</returns> |
224 |
[DllImport("granny2.dll", EntryPoint = "_GrannyBeginBestMatchS3TCTexture@8", CallingConvention = CallingConvention.StdCall)] |
225 |
public static extern IntPtr GrannyBeginBestMatchS3TCTexture(granny_int32x Width, granny_int32x Height); |
226 |
/// <summary> |
227 |
/// Begin's a Bink Texture |
228 |
/// </summary> |
229 |
/// <param name="Width">image width</param> |
230 |
/// <param name="Height">image height</param> |
231 |
/// <param name="Compression">granny_compression_type ??? Compression</param> |
232 |
/// <param name="Flags">granny_bink_texture_flags ??? Flags</param> |
233 |
/// <returns>pointer to texture_builder</returns> |
234 |
[DllImport("granny2.dll", EntryPoint = "_GrannyBeginBinkTexture@16", CallingConvention = CallingConvention.StdCall)] |
235 |
public static extern IntPtr GrannyBeginBinkTexture(granny_int32x Width, granny_int32x Height, granny_int32x Compression, granny_uint32x Flags); |
236 |
/// <summary> |
237 |
/// End's a Texture |
238 |
/// </summary> |
239 |
/// <param name="Builder">pointer texture_build</param> |
240 |
/// <returns>pointer to texture</returns> |
241 |
[DllImport("granny2.dll", EntryPoint = "_GrannyEndTexture@4", CallingConvention = CallingConvention.StdCall)] |
242 |
public static extern IntPtr GrannyEndTexture(IntPtr Builder); |
243 |
/// <summary> |
244 |
/// Gets the resulting Texture size |
245 |
/// </summary> |
246 |
/// <param name="Builder">pointer to texture_builder</param> |
247 |
/// <returns>granny_int32x</returns> |
248 |
[DllImport("granny2.dll", EntryPoint = "_GrannyGetResultingTextureSize@4", CallingConvention = CallingConvention.StdCall)] |
249 |
public static extern granny_int32x GrannyGetResultingTextureSize(IntPtr Builder); |
250 |
|
251 |
[DllImport("granny2.dll", EntryPoint = "_GrannyGetRawImageSize@16", CallingConvention = CallingConvention.StdCall)] |
252 |
public static extern granny_int32x GrannyGetRawImageSize(IntPtr Layout, granny_int32x Stride, granny_int32x Width, granny_int32x Height); |
253 |
[DllImport("granny2.dll", EntryPoint = "_GrannyGetS3TCImageSize@12", CallingConvention = CallingConvention.StdCall)] |
254 |
public static extern granny_int32x GrannyGetS3TCImageSize(granny_s3tc_texture_format Format, granny_int32x Width, granny_int32x Height); |
255 |
/// <summary> |
256 |
/// End's Texture in Place (basically the same as GrannyEndTexture |
257 |
/// </summary> |
258 |
/// <param name="Builder">pointer to texture_builder</param> |
259 |
/// <param name="Memory">pointer memory</param> |
260 |
/// <returns></returns> |
261 |
[DllImport("granny2.dll", EntryPoint = "_GrannyEndTextureInPlace@8", CallingConvention = CallingConvention.StdCall)] |
262 |
public static extern IntPtr GrannyEndTextureInPlace(IntPtr Builder, IntPtr Memory); |
263 |
/// <summary> |
264 |
/// Set Image Scaling Filter |
265 |
/// </summary> |
266 |
/// <param name="Builder">pointer to texture_builder</param> |
267 |
/// <param name="UpsamplingFilter">granny_pixel_filter_type UpsamplingFilter</param> |
268 |
/// <param name="DownsamplingFilter">granny_pixel_filter_type DownsamplingFilter</param> |
269 |
[DllImport("granny2.dll", EntryPoint = "_GrannySetImageScalingFilter@12", CallingConvention = CallingConvention.StdCall)] |
270 |
public static extern void GrannySetImageScalingFilter(IntPtr Builder, granny_pixel_filter_type UpsamplingFilter, granny_pixel_filter_type DownsamplingFilter); |
271 |
/// <summary> |
272 |
/// Encode Image |
273 |
/// </summary> |
274 |
/// <param name="Builder">pointer to texture_builder</param> |
275 |
/// <param name="Width">image width</param> |
276 |
/// <param name="Height">image height</param> |
277 |
/// <param name="Stride">Stride</param> |
278 |
/// <param name="MIPLevelCount">MIPLevelCount</param> |
279 |
/// <param name="RGBAData">pointer to RGBAData, in a byte[]</param> |
280 |
[DllImport("granny2.dll", EntryPoint = "_GrannyEncodeImage@24", CallingConvention = CallingConvention.StdCall)] |
281 |
public static extern void GrannyEncodeImage(IntPtr Builder, granny_int32x Width, granny_int32x Height, granny_int32x Stride, granny_int32x MIPLevelCount, IntPtr RGBAData); |
282 |
/// <summary> |
283 |
/// Free texture_builder |
284 |
/// </summary> |
285 |
/// <param name="Result">pointer to texture</param> |
286 |
[DllImport("granny2.dll", EntryPoint = "_GrannyFreeBuilderResult@4", CallingConvention = CallingConvention.StdCall)] |
287 |
public static extern void GrannyFreeBuilderResult(IntPtr Result); |
288 |
|
289 |
public static Layout GrannyGetS3TCPixelLayout(granny_s3tc_texture_format Format) |
290 |
{ |
291 |
switch (Format) |
292 |
{ |
293 |
case granny_s3tc_texture_format.GrannyS3TCBGR565: return granny_pixel_layouts.GrannyRGB565PixelFormat; |
294 |
case granny_s3tc_texture_format.GrannyS3TCBGRA5551: return granny_pixel_layouts.GrannyRGBA5551PixelFormat; |
295 |
case granny_s3tc_texture_format.GrannyS3TCBGRA8888InterpolatedAlpha: return granny_pixel_layouts.GrannyRGBA8888PixelFormat; |
296 |
case granny_s3tc_texture_format.GrannyS3TCBGRA8888MappedAlpha: return granny_pixel_layouts.GrannyRGBA8888PixelFormat; |
297 |
default: return granny_pixel_layouts.GrannyDefaultPixelLayout; |
298 |
} |
299 |
} |
300 |
//public static granny_s3tc_texture_format GrannyGetS3TCPixelSubFormat(int Format) |
301 |
//{ |
302 |
// foreach(int value in Enum.GetValues(typeof(granny_s3tc_texture_format))) |
303 |
// { |
304 |
// if (value == Format) return (granny_s3tc_texture_format)value; |
305 |
// } |
306 |
// throw new InvalidCastException("Cannot Convert Value: 0x" + Format.ToString("X2") + " to a granny_s3tc_texture_format."); |
307 |
//} |
308 |
public static granny_pixel_layout GrannyGetS3TCPixelSubFormat(granny_s3tc_texture_format Format) |
309 |
{ |
310 |
switch (Format) |
311 |
{ |
312 |
case granny_s3tc_texture_format.GrannyS3TCBGR565: return granny_pixel_layout.GrannyRGB565PixelFormat; |
313 |
case granny_s3tc_texture_format.GrannyS3TCBGRA5551: return granny_pixel_layout.GrannyRGBA5551PixelFormat; |
314 |
case granny_s3tc_texture_format.GrannyS3TCBGRA8888InterpolatedAlpha: return granny_pixel_layout.GrannyRGBA8888PixelFormat; |
315 |
case granny_s3tc_texture_format.GrannyS3TCBGRA8888MappedAlpha: return granny_pixel_layout.GrannyRGBA8888PixelFormat; |
316 |
default: return granny_pixel_layouts.GrannyDefaultPixelLayoutToEnum; |
317 |
} |
318 |
} |
319 |
|
320 |
} |
321 |
|
322 |
|
323 |
|
324 |
#endregion |
325 |
|
326 |
//#region Granny2 API Logging Support |
327 |
///// <summary> |
328 |
///// LoggingSupport class |
329 |
///// </summary> |
330 |
//public class LoggingSupport |
331 |
//{ |
332 |
// /// <summary> |
333 |
// /// Delegate for the LogCallBack |
334 |
// /// </summary> |
335 |
// /// <param name="Type">The Log Type <see cref="granny_log_message_type"/></param> |
336 |
// /// <param name="Origin">The Log Origin <see cref="granny_log_message_origin"/></param> |
337 |
// /// <param name="Message">the message</param> |
338 |
// /// <param name="UserData">pointer to userdata [will always be IntPtr.Zero, in gr2lib]</param> |
339 |
// [DllImport("granny2.dll", EntryPoint = "granny_log_function", CallingConvention = CallingConvention.StdCall)] |
340 |
// public static extern void granny_log_function(granny_log_message_type Type, granny_log_message_origin Origin, string Message, IntPtr UserData); |
341 |
// /// <summary> |
342 |
// /// Set the Log Callback |
343 |
// /// </summary> |
344 |
// /// <param name="LogCallback">the callback <see cref="gr2lib.core.coretypes.implementation.granny_log_callback_builder.granny_log_callback"/></param> |
345 |
// [DllImport("granny2.dll", EntryPoint = "_GrannySetLogCallback@4", CallingConvention = CallingConvention.StdCall)] |
346 |
// public static extern void GrannySetLogCallback(ref gr2lib.core.coretypes.implementation.granny_log_callback_builder.granny_log_callback LogCallback); |
347 |
// /// <summary> |
348 |
// /// Get the Log Callback |
349 |
// /// </summary> |
350 |
// /// <param name="LogCallback">returns the callback <see cref="gr2lib.core.coretypes.implementation.granny_log_callback_builder.granny_log_callback"/></param> |
351 |
// [DllImport("granny2.dll", EntryPoint = "_GrannyGetLogCallback@4", CallingConvention = CallingConvention.StdCall)] |
352 |
// public static extern void GrannyGetLogCallback(out gr2lib.core.coretypes.implementation.granny_log_callback_builder.granny_log_callback LogCallback); |
353 |
// /// <summary> |
354 |
// /// Explicitly allow or disallow all logging |
355 |
// /// </summary> |
356 |
// /// <param name="Enabled">True = allow, False = disallow</param> |
357 |
// [DllImport("granny2.dll", EntryPoint = "_GrannyFilterAllMessages@4", CallingConvention = CallingConvention.StdCall)] |
358 |
// public static extern void GrannyFilterAllMessages(bool Enabled); |
359 |
// /// <summary> |
360 |
// /// Explicitly allow or disallow logging from specific Origin |
361 |
// /// </summary> |
362 |
// /// <param name="Origin">The Log Origin <see cref="granny_log_message_origin"/></param> |
363 |
// /// <param name="Enabled">>True = allow, False = disallow</param> |
364 |
// [DllImport("granny2.dll", EntryPoint = "_GrannyFilterMessage@8", CallingConvention = CallingConvention.StdCall)] |
365 |
// public static extern void GrannyFilterMessage(granny_log_message_origin Origin, bool Enabled); |
366 |
// /// <summary> |
367 |
// /// Check to see if anything is listening to log events |
368 |
// /// </summary> |
369 |
// /// <returns>a boolean value indicating if anything is listening to log events</returns> |
370 |
// [DllImport("granny2.dll", EntryPoint = "_GrannyLogging@0", CallingConvention = CallingConvention.StdCall)] |
371 |
// public static extern bool GrannyLogging(); |
372 |
// /// <summary> |
373 |
// /// Returns the last Message Log Type, that was the most serious |
374 |
// /// </summary> |
375 |
// /// <returns></returns> |
376 |
// [DllImport("granny2.dll", EntryPoint = "_GrannyGetMostSeriousMessageType@0", CallingConvention = CallingConvention.StdCall)] |
377 |
// public static extern granny_log_message_type GrannyGetMostSeriousMessageType(); |
378 |
// /// <summary> |
379 |
// /// Get the message from the last most serious message |
380 |
// /// </summary> |
381 |
// /// <returns></returns> |
382 |
// [DllImport("granny2.dll", EntryPoint = "_GrannyGetMostSeriousMessage@0", CallingConvention = CallingConvention.StdCall)] |
383 |
// public static extern string GrannyGetMostSeriousMessage(); |
384 |
// /// <summary> |
385 |
// /// Clear the last most serious message, so that new messages can be tracked |
386 |
// /// </summary> |
387 |
// [DllImport("granny2.dll", EntryPoint = "_GrannyClearMostSeriousMessage@0", CallingConvention = CallingConvention.StdCall)] |
388 |
// public static extern void GrannyClearMostSeriousMessage(); |
389 |
// /// <summary> |
390 |
// /// Enable logging of all Granny reports to a file: |
391 |
// /// </summary> |
392 |
// /// <param name="FileName">Filenanme to log to</param> |
393 |
// /// <param name="Clear">True = overwrite file, False = append to file</param> |
394 |
// /// <returns></returns> |
395 |
// [DllImport("granny2.dll", EntryPoint = "_GrannySetLogFileName@8", CallingConvention = CallingConvention.StdCall)] |
396 |
// public static extern bool GrannySetLogFileName([MarshalAs(UnmanagedType.LPStr)] string FileName, bool Clear); |
397 |
//} |
398 |
//#endregion |
399 |
|
400 |
#region Granny2 API Enum Value to String Support |
401 |
/// <summary> |
402 |
/// EnumToStringSupport class |
403 |
/// </summary> |
404 |
public class EnumToStringSupport |
405 |
{ |
406 |
/// <summary> |
407 |
/// GetGrannyEnumTypeString<T>(T _type) |
408 |
/// </summary> |
409 |
/// <typeparam name="T">The Type of the enum</typeparam> |
410 |
/// <param name="_type">The Enum value</param> |
411 |
/// <returns>The name of the enum member associated with the _type value</returns> |
412 |
public static string GetGrannyEnumTypeString<T>(T _type) { return Enum.GetName(typeof(T), _type); } |
413 |
/// <summary> |
414 |
/// GrannyGetLogMessageTypeString(granny_log_message_type Type) |
415 |
/// </summary> |
416 |
/// <param name="Type">The Log Type <see cref="granny_log_message_type"/></param> |
417 |
/// <returns>The name of the enum member associated with the Type value</returns> |
418 |
public static string GrannyGetLogMessageTypeString(granny_log_message_type Type) { try { return GetGrannyEnumTypeString<granny_log_message_type>(Type); } catch { return GetGrannyEnumTypeString<granny_log_message_type>(granny_log_message_type.GrannyUnknownLogMessage); } } |
419 |
/// <summary> |
420 |
/// rannyGetLogMessageOriginString(granny_log_message_origin Origin) |
421 |
/// </summary> |
422 |
/// <param name="Origin">The Log Origin <see cref="granny_log_message_origin"/></param> |
423 |
/// <returns>The name of the enum member associated with the Origin value</returns> |
424 |
public static string GrannyGetLogMessageOriginString(granny_log_message_origin Origin) { try { return GetGrannyEnumTypeString<granny_log_message_origin>(Origin); } catch { return GetGrannyEnumTypeString<granny_log_message_origin>(granny_log_message_origin.GrannyUnknownLogMessage); } } |
425 |
} |
426 |
#endregion |
427 |
|
428 |
#region Granny2 API Mesh Support |
429 |
public class MeshSupport |
430 |
{ |
431 |
[DllImport("granny2.dll", EntryPoint = "_GrannyGetMeshVertexCount@4", CallingConvention = CallingConvention.StdCall)] |
432 |
public static extern granny_int32x GrannyGetMeshVertexCount(IntPtr Mesh); |
433 |
[DllImport("granny2.dll", EntryPoint = "_GrannyGetMeshVertices@4", CallingConvention = CallingConvention.StdCall)] |
434 |
public static extern IntPtr GrannyGetMeshVertices(IntPtr Mesh); |
435 |
[DllImport("granny2.dll", EntryPoint = "_GrannyGetMeshBytesPerIndex@4", CallingConvention = CallingConvention.StdCall)] |
436 |
public static extern granny_int32x GrannyGetMeshBytesPerIndex(IntPtr Mesh); |
437 |
[DllImport("granny2.dll", EntryPoint = "_GrannyGetMeshIndexCount@4", CallingConvention = CallingConvention.StdCall)] |
438 |
public static extern granny_int32x GrannyGetMeshIndexCount(IntPtr mesh); |
439 |
[DllImport("granny2.dll", EntryPoint = "_GrannyGetMeshIndices@4", CallingConvention = CallingConvention.StdCall)] |
440 |
public static extern IntPtr GrannyGetMeshIndices(IntPtr mesh); |
441 |
[DllImport("granny2.dll", EntryPoint = "_GrannyGetMeshTriangleGroupCount@4", CallingConvention = CallingConvention.StdCall)] |
442 |
public static extern int GrannyGetMeshTriangleGroupCount(IntPtr mesh); |
443 |
[DllImport("granny2.dll", EntryPoint = "_GrannyGetMeshTriangleGroups@4", CallingConvention = CallingConvention.StdCall)] |
444 |
public static extern IntPtr GrannyGetMeshTriangleGroups(IntPtr mesh); |
445 |
[DllImport("granny2.dll", EntryPoint = "_GrannyGetVertexComponentIndex@8", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] |
446 |
public static extern int GrannyGetVertexComponentIndex(string name, IntPtr vertexStringMember); |
447 |
} |
448 |
#endregion |
449 |
|
450 |
} |
451 |
} |