/[gr2lib]/trunk/gr2lib/core/coreapi/coreapi.cs
ViewVC logotype

Contents of /trunk/gr2lib/core/coreapi/coreapi.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 191 - (show annotations) (download)
Sat Jul 24 06:31:50 2010 UTC (9 years, 1 month ago) by william
File size: 21983 byte(s)
In coreapi:
*Add more texture methods
*Move everthing into related classes, to group related methods,etc
*Update all classes to use these grouped classes

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(&amp;major,&amp;minor,&amp;customization,&amp;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 /// <summary>
140 /// GrannySwapRGBAToBGRA(granny_pixel_layout SourceLayoutFromEnum, out Layout SourcePixelLayout)
141 /// </summary>
142 /// <param name="SourceLayoutFromEnum">the source layout to swap: <see cref="granny_pixel_layout"/></param>
143 /// <param name="SwappedPixelLayout">returns the swapped pixel layout</param>
144 public static void GrannySwapRGBAToBGRA(granny_pixel_layout SourceLayoutFromEnum, out Layout SwappedPixelLayout)
145 {
146 SwappedPixelLayout = granny_pixel_layouts.GrannyDefaultPixelLayout;
147 switch (SourceLayoutFromEnum)
148 {
149 case granny_pixel_layout.GrannyBGR555PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGB555PixelFormat; break;
150 case granny_pixel_layout.GrannyBGR565PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGB565PixelFormat; break;
151 case granny_pixel_layout.GrannyBGR888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGB888PixelFormat; break;
152 case granny_pixel_layout.GrannyBGRA4444PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGBA4444PixelFormat; break;
153 case granny_pixel_layout.GrannyBGRA5551PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGBA5551PixelFormat; break;
154 case granny_pixel_layout.GrannyBGRA8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGBA8888PixelFormat; break;
155 case granny_pixel_layout.GrannyRGB555PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGR555PixelFormat; break;
156 case granny_pixel_layout.GrannyRGB565PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGR565PixelFormat; break;
157 case granny_pixel_layout.GrannyRGB888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGR888PixelFormat; break;
158 case granny_pixel_layout.GrannyRGBA4444PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGRA4444PixelFormat; break;
159 case granny_pixel_layout.GrannyRGBA5551PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGRA5551PixelFormat; break;
160 case granny_pixel_layout.GrannyRGBA8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGRA8888PixelFormat; break;
161 case granny_pixel_layout.GrannyARGB8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyABGR8888PixelFormat; break;
162 case granny_pixel_layout.GrannyABGR8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyARGB8888PixelFormat; break;
163 default: SwappedPixelLayout = granny_pixel_layouts.GrannyDefaultPixelLayout; break;
164 }
165 }
166 /// <summary>
167 ///
168 /// </summary>
169 /// <param name="Width"></param>
170 /// <param name="Height"></param>
171 /// <param name="ResultingLayout"></param>
172 /// <param name="StrideAlignment"></param>
173 /// <returns></returns>
174 [DllImport("granny2.dll", EntryPoint = "_GrannyBeginRawTexture@16", CallingConvention = CallingConvention.StdCall)]
175 public static extern IntPtr GrannyBeginRawTexture(granny_int32x Width, granny_int32x Height, IntPtr ResultingLayout, granny_int32x StrideAlignment);
176 /// <summary>
177 ///
178 /// </summary>
179 /// <param name="Width"></param>
180 /// <param name="Height"></param>
181 /// <param name="Format"></param>
182 /// <returns></returns>
183 [DllImport("granny2.dll", EntryPoint = "_GrannyBeginS3TCTexture@12", CallingConvention = CallingConvention.StdCall)]
184 public static extern IntPtr GrannyBeginS3TCTexture(granny_int32x Width, granny_int32x Height, granny_s3tc_texture_format Format);
185 /// <summary>
186 ///
187 /// </summary>
188 /// <param name="Width"></param>
189 /// <param name="Height"></param>
190 /// <returns></returns>
191 [DllImport("granny2.dll", EntryPoint = "_GrannyBeginBestMatchS3TCTexture@8", CallingConvention = CallingConvention.StdCall)]
192 public static extern IntPtr GrannyBeginBestMatchS3TCTexture(granny_int32x Width, granny_int32x Height);
193 /// <summary>
194 ///
195 /// </summary>
196 /// <param name="Width"></param>
197 /// <param name="Height"></param>
198 /// <param name="Compression"></param>
199 /// <param name="Flags"></param>
200 /// <returns></returns>
201 [DllImport("granny2.dll", EntryPoint = "_GrannyBeginBinkTexture@16", CallingConvention = CallingConvention.StdCall)]
202 public static extern IntPtr GrannyBeginBinkTexture(granny_int32x Width, granny_int32x Height, granny_int32x Compression, granny_uint32x Flags);
203 /// <summary>
204 ///
205 /// </summary>
206 /// <param name="Builder"></param>
207 /// <returns></returns>
208 [DllImport("granny2.dll", EntryPoint = "_GrannyEndTexture@4", CallingConvention = CallingConvention.StdCall)]
209 public static extern IntPtr GrannyEndTexture(IntPtr Builder);
210 /// <summary>
211 ///
212 /// </summary>
213 /// <param name="Builder"></param>
214 /// <returns></returns>
215 [DllImport("granny2.dll", EntryPoint = "_GrannyGetResultingTextureSize@4", CallingConvention = CallingConvention.StdCall)]
216 public static extern granny_int32x GrannyGetResultingTextureSize(gr2lib.core.coretypes.native.granny_texture_builder Builder);
217 /// <summary>
218 ///
219 /// </summary>
220 /// <param name="Builder"></param>
221 /// <param name="Memory"></param>
222 /// <returns></returns>
223 [DllImport("granny2.dll", EntryPoint = "_GrannyEndTextureInPlace@8", CallingConvention = CallingConvention.StdCall)]
224 public static extern IntPtr GrannyEndTextureInPlace(IntPtr Builder, IntPtr Memory);
225 /// <summary>
226 ///
227 /// </summary>
228 /// <param name="Builder"></param>
229 /// <param name="UpsamplingFilter"></param>
230 /// <param name="DownsamplingFilter"></param>
231 [DllImport("granny2.dll", EntryPoint = "_GrannySetImageScalingFilter@12", CallingConvention = CallingConvention.StdCall)]
232 public static extern void GrannySetImageScalingFilter(IntPtr Builder, granny_pixel_filter_type UpsamplingFilter, granny_pixel_filter_type DownsamplingFilter);
233 /// <summary>
234 ///
235 /// </summary>
236 /// <param name="Builder"></param>
237 /// <param name="Width"></param>
238 /// <param name="Height"></param>
239 /// <param name="Stride"></param>
240 /// <param name="MIPLevelCount"></param>
241 /// <param name="RGBAData"></param>
242 [DllImport("granny2.dll", EntryPoint = "_GrannyEncodeImage@24", CallingConvention = CallingConvention.StdCall)]
243 public static extern void GrannyEncodeImage(IntPtr Builder, granny_int32x Width, granny_int32x Height, granny_int32x Stride, granny_int32x MIPLevelCount, IntPtr RGBAData);
244 }
245
246
247
248 #endregion
249
250 #region Granny2 API Logging Support
251 /// <summary>
252 /// LoggingSupport class
253 /// </summary>
254 public class LoggingSupport
255 {
256 /// <summary>
257 /// Delegate for the LogCallBack
258 /// </summary>
259 /// <param name="Type">The Log Type <see cref="granny_log_message_type"/></param>
260 /// <param name="Origin">The Log Origin <see cref="granny_log_message_origin"/></param>
261 /// <param name="Message">the message</param>
262 /// <param name="UserData">pointer to userdata [will always be IntPtr.Zero, in gr2lib]</param>
263 [DllImport("granny2.dll", EntryPoint = "granny_log_function", CallingConvention = CallingConvention.StdCall)]
264 public static extern void granny_log_function(granny_log_message_type Type, granny_log_message_origin Origin, string Message, IntPtr UserData);
265 /// <summary>
266 /// Set the Log Callback
267 /// </summary>
268 /// <param name="LogCallback">the callback <see cref="gr2lib.core.coretypes.implementation.granny_log_callback_builder.granny_log_callback"/></param>
269 [DllImport("granny2.dll", EntryPoint = "_GrannySetLogCallback@4", CallingConvention = CallingConvention.StdCall)]
270 public static extern void GrannySetLogCallback(ref gr2lib.core.coretypes.implementation.granny_log_callback_builder.granny_log_callback LogCallback);
271 /// <summary>
272 /// Get the Log Callback
273 /// </summary>
274 /// <param name="LogCallback">returns the callback <see cref="gr2lib.core.coretypes.implementation.granny_log_callback_builder.granny_log_callback"/></param>
275 [DllImport("granny2.dll", EntryPoint = "_GrannyGetLogCallback@4", CallingConvention = CallingConvention.StdCall)]
276 public static extern void GrannyGetLogCallback(out gr2lib.core.coretypes.implementation.granny_log_callback_builder.granny_log_callback LogCallback);
277 /// <summary>
278 /// Explicitly allow or disallow all logging
279 /// </summary>
280 /// <param name="Enabled">True = allow, False = disallow</param>
281 [DllImport("granny2.dll", EntryPoint = "_GrannyFilterAllMessages@4", CallingConvention = CallingConvention.StdCall)]
282 public static extern void GrannyFilterAllMessages(bool Enabled);
283 /// <summary>
284 /// Explicitly allow or disallow logging from specific Origin
285 /// </summary>
286 /// <param name="Origin">The Log Origin <see cref="granny_log_message_origin"/></param>
287 /// <param name="Enabled">>True = allow, False = disallow</param>
288 [DllImport("granny2.dll", EntryPoint = "_GrannyFilterMessage@8", CallingConvention = CallingConvention.StdCall)]
289 public static extern void GrannyFilterMessage(granny_log_message_origin Origin, bool Enabled);
290 /// <summary>
291 /// Check to see if anything is listening to log events
292 /// </summary>
293 /// <returns>a boolean value indicating if anything is listening to log events</returns>
294 [DllImport("granny2.dll", EntryPoint = "_GrannyLogging@0", CallingConvention = CallingConvention.StdCall)]
295 public static extern bool GrannyLogging();
296 /// <summary>
297 /// Returns the last Message Log Type, that was the most serious
298 /// </summary>
299 /// <returns></returns>
300 [DllImport("granny2.dll", EntryPoint = "_GrannyGetMostSeriousMessageType@0", CallingConvention = CallingConvention.StdCall)]
301 public static extern granny_log_message_type GrannyGetMostSeriousMessageType();
302 /// <summary>
303 /// Get the message from the last most serious message
304 /// </summary>
305 /// <returns></returns>
306 [DllImport("granny2.dll", EntryPoint = "_GrannyGetMostSeriousMessage@0", CallingConvention = CallingConvention.StdCall)]
307 public static extern string GrannyGetMostSeriousMessage();
308 /// <summary>
309 /// Clear the last most serious message, so that new messages can be tracked
310 /// </summary>
311 [DllImport("granny2.dll", EntryPoint = "_GrannyClearMostSeriousMessage@0", CallingConvention = CallingConvention.StdCall)]
312 public static extern void GrannyClearMostSeriousMessage();
313 /// <summary>
314 /// Enable logging of all Granny reports to a file:
315 /// </summary>
316 /// <param name="FileName">Filenanme to log to</param>
317 /// <param name="Clear">True = overwrite file, False = append to file</param>
318 /// <returns></returns>
319 [DllImport("granny2.dll", EntryPoint = "_GrannySetLogFileName@8", CallingConvention = CallingConvention.StdCall)]
320 public static extern bool GrannySetLogFileName([MarshalAs(UnmanagedType.LPStr)] string FileName, bool Clear);
321 }
322 #endregion
323
324 #region Granny2 API Enum Value to String Support
325 /// <summary>
326 /// EnumToStringSupport class
327 /// </summary>
328 public class EnumToStringSupport
329 {
330 /// <summary>
331 /// GetGrannyEnumTypeString&lt;T&gt;(T _type)
332 /// </summary>
333 /// <typeparam name="T">The Type of the enum</typeparam>
334 /// <param name="_type">The Enum value</param>
335 /// <returns>The name of the enum member associated with the _type value</returns>
336 public static string GetGrannyEnumTypeString<T>(T _type) { return Enum.GetName(typeof(T), _type); }
337 /// <summary>
338 /// GrannyGetLogMessageTypeString(granny_log_message_type Type)
339 /// </summary>
340 /// <param name="Type">The Log Type <see cref="granny_log_message_type"/></param>
341 /// <returns>The name of the enum member associated with the Type value</returns>
342 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); } }
343 /// <summary>
344 /// rannyGetLogMessageOriginString(granny_log_message_origin Origin)
345 /// </summary>
346 /// <param name="Origin">The Log Origin <see cref="granny_log_message_origin"/></param>
347 /// <returns>The name of the enum member associated with the Origin value</returns>
348 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); } }
349 #endregion
350 }
351 }
352 }

  ViewVC Help
Powered by ViewVC 1.1.22