00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 using System;
00011 using System.Diagnostics;
00012 using System.Runtime.InteropServices;
00013
00014 namespace OpenTK.Platform.MacOS
00015 {
00016 #pragma warning disable 0169
00017
00018
00019
00020
00021 using AGLDevice = IntPtr;
00022
00023
00024
00025
00026 using AGLDrawable = IntPtr;
00027
00028
00029
00030
00031 using AGLRendererInfo = IntPtr;
00032 using AGLPixelFormat = IntPtr;
00033 using AGLContext = IntPtr;
00034 using AGLPbuffer = IntPtr;
00035
00036 using GLenum = UInt32;
00037
00038 unsafe static partial class Agl
00039 {
00040
00041 const string agl = "/System/Library/Frameworks/AGL.framework/Versions/Current/AGL";
00042
00043
00044
00045
00046 const int AGL_VERSION_2_0 = 1;
00047
00048
00049
00050
00051
00052
00053 internal enum PixelFormatAttribute
00054 {
00055 AGL_NONE = 0,
00056 AGL_ALL_RENDERERS = 1,
00057 AGL_BUFFER_SIZE = 2,
00058 AGL_LEVEL = 3,
00059 AGL_RGBA = 4,
00060 AGL_DOUBLEBUFFER = 5,
00061 AGL_STEREO = 6,
00062 AGL_AUX_BUFFERS = 7,
00063 AGL_RED_SIZE = 8,
00064 AGL_GREEN_SIZE = 9,
00065 AGL_BLUE_SIZE = 10,
00066 AGL_ALPHA_SIZE = 11,
00067 AGL_DEPTH_SIZE = 12,
00068 AGL_STENCIL_SIZE = 13,
00069 AGL_ACCUM_RED_SIZE = 14,
00070 AGL_ACCUM_GREEN_SIZE = 15,
00071 AGL_ACCUM_BLUE_SIZE = 16,
00072 AGL_ACCUM_ALPHA_SIZE = 17,
00073 AGL_PIXEL_SIZE = 50,
00074 AGL_MINIMUM_POLICY = 51,
00075 AGL_MAXIMUM_POLICY = 52,
00076 AGL_OFFSCREEN = 53,
00077 AGL_FULLSCREEN = 54,
00078 AGL_SAMPLE_BUFFERS_ARB = 55,
00079 AGL_SAMPLES_ARB = 56,
00080 AGL_AUX_DEPTH_STENCIL = 57,
00081 AGL_COLOR_FLOAT = 58,
00082 AGL_MULTISAMPLE = 59,
00083 AGL_SUPERSAMPLE = 60,
00084 AGL_SAMPLE_ALPHA = 61,
00085 }
00086
00087
00088
00089 internal enum ExtendedAttribute
00090 {
00091 AGL_PIXEL_SIZE = 50,
00092 AGL_MINIMUM_POLICY = 51,
00093 AGL_MAXIMUM_POLICY = 52,
00094 AGL_OFFSCREEN = 53,
00095 AGL_FULLSCREEN = 54,
00096 AGL_SAMPLE_BUFFERS_ARB = 55,
00097 AGL_SAMPLES_ARB = 56,
00098 AGL_AUX_DEPTH_STENCIL = 57,
00099 AGL_COLOR_FLOAT = 58,
00100 AGL_MULTISAMPLE = 59,
00101 AGL_SUPERSAMPLE = 60,
00102 AGL_SAMPLE_ALPHA = 61,
00103 }
00104
00105
00106
00107 internal enum RendererManagement
00108 {
00109 AGL_RENDERER_ID = 70,
00110 AGL_SINGLE_RENDERER = 71,
00111 AGL_NO_RECOVERY = 72,
00112 AGL_ACCELERATED = 73,
00113 AGL_CLOSEST_POLICY = 74,
00114 AGL_ROBUST = 75,
00115 AGL_BACKING_STORE = 76,
00116 AGL_MP_SAFE = 78,
00117
00118 AGL_WINDOW = 80,
00119 AGL_MULTISCREEN = 81,
00120 AGL_VIRTUAL_SCREEN = 82,
00121 AGL_COMPLIANT = 83,
00122
00123 AGL_PBUFFER = 90,
00124 AGL_REMOTE_PBUFFER = 91,
00125 }
00126
00127
00128
00129 internal enum RendererProperties
00130 {
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 AGL_BUFFER_MODES = 100,
00143 AGL_MIN_LEVEL = 101,
00144 AGL_MAX_LEVEL = 102,
00145 AGL_COLOR_MODES = 103,
00146 AGL_ACCUM_MODES = 104,
00147 AGL_DEPTH_MODES = 105,
00148 AGL_STENCIL_MODES = 106,
00149 AGL_MAX_AUX_BUFFERS = 107,
00150 AGL_VIDEO_MEMORY = 120,
00151 AGL_TEXTURE_MEMORY = 121,
00152 AGL_RENDERER_COUNT = 128,
00153 }
00154
00155
00156
00157 internal enum ParameterNames
00158 {
00159 AGL_SWAP_RECT = 200,
00160 AGL_BUFFER_RECT = 202,
00161 AGL_SWAP_LIMIT = 203,
00162 AGL_COLORMAP_TRACKING = 210,
00163 AGL_COLORMAP_ENTRY = 212,
00164 AGL_RASTERIZATION = 220,
00165 AGL_SWAP_INTERVAL = 222,
00166 AGL_STATE_VALIDATION = 230,
00167 AGL_BUFFER_NAME = 231,
00168 AGL_ORDER_CONTEXT_TO_FRONT = 232,
00169 AGL_CONTEXT_SURFACE_ID = 233,
00170 AGL_CONTEXT_DISPLAY_ID = 234,
00171 AGL_SURFACE_ORDER = 235,
00172 AGL_SURFACE_OPACITY = 236,
00173 AGL_CLIP_REGION = 254,
00174 AGL_FS_CAPTURE_SINGLE = 255,
00175 AGL_SURFACE_BACKING_SIZE = 304,
00176 AGL_ENABLE_SURFACE_BACKING_SIZE = 305,
00177 AGL_SURFACE_VOLATILE = 306,
00178 }
00179
00180
00181
00182 internal enum OptionName
00183 {
00184 AGL_FORMAT_CACHE_SIZE = 501,
00185 AGL_CLEAR_FORMAT_CACHE = 502,
00186 AGL_RETAIN_RENDERERS = 503,
00187 }
00188
00189 internal enum BufferModes
00190 {
00191 AGL_MONOSCOPIC_BIT = 0x00000001,
00192 AGL_STEREOSCOPIC_BIT = 0x00000002,
00193 AGL_SINGLEBUFFER_BIT = 0x00000004,
00194 AGL_DOUBLEBUFFER_BIT = 0x00000008,
00195 }
00196
00197 internal enum BitDepths
00198 {
00199
00200 AGL_0_BIT = 0x00000001,
00201 AGL_1_BIT = 0x00000002,
00202 AGL_2_BIT = 0x00000004,
00203 AGL_3_BIT = 0x00000008,
00204 AGL_4_BIT = 0x00000010,
00205 AGL_5_BIT = 0x00000020,
00206 AGL_6_BIT = 0x00000040,
00207 AGL_8_BIT = 0x00000080,
00208 AGL_10_BIT = 0x00000100,
00209 AGL_12_BIT = 0x00000200,
00210 AGL_16_BIT = 0x00000400,
00211 AGL_24_BIT = 0x00000800,
00212 AGL_32_BIT = 0x00001000,
00213 AGL_48_BIT = 0x00002000,
00214 AGL_64_BIT = 0x00004000,
00215 AGL_96_BIT = 0x00008000,
00216 AGL_128_BIT = 0x00010000,
00217 }
00218
00219 internal enum ColorModes
00220 {
00221 AGL_RGB8_BIT = 0x00000001,
00222 AGL_RGB8_A8_BIT = 0x00000002,
00223 AGL_BGR233_BIT = 0x00000004,
00224 AGL_BGR233_A8_BIT = 0x00000008,
00225 AGL_RGB332_BIT = 0x00000010,
00226 AGL_RGB332_A8_BIT = 0x00000020,
00227 AGL_RGB444_BIT = 0x00000040,
00228 AGL_ARGB4444_BIT = 0x00000080,
00229 AGL_RGB444_A8_BIT = 0x00000100,
00230 AGL_RGB555_BIT = 0x00000200,
00231 AGL_ARGB1555_BIT = 0x00000400,
00232 AGL_RGB555_A8_BIT = 0x00000800,
00233 AGL_RGB565_BIT = 0x00001000,
00234 AGL_RGB565_A8_BIT = 0x00002000,
00235 AGL_RGB888_BIT = 0x00004000,
00236 AGL_ARGB8888_BIT = 0x00008000,
00237 AGL_RGB888_A8_BIT = 0x00010000,
00238 AGL_RGB101010_BIT = 0x00020000,
00239 AGL_ARGB2101010_BIT = 0x00040000,
00240 AGL_RGB101010_A8_BIT = 0x00080000,
00241 AGL_RGB121212_BIT = 0x00100000,
00242 AGL_ARGB12121212_BIT = 0x00200000,
00243 AGL_RGB161616_BIT = 0x00400000,
00244 AGL_ARGB16161616_BIT = 0x00800000,
00245 AGL_INDEX8_BIT = 0x20000000,
00246 AGL_INDEX16_BIT = 0x40000000,
00247 AGL_RGBFLOAT64_BIT = 0x01000000,
00248 AGL_RGBAFLOAT64_BIT = 0x02000000,
00249 AGL_RGBFLOAT128_BIT = 0x04000000,
00250 AGL_RGBAFLOAT128_BIT = 0x08000000,
00251 AGL_RGBFLOAT256_BIT = 0x10000000,
00252 AGL_RGBAFLOAT256_BIT = 0x20000000,
00253 }
00254
00255
00256
00257 internal enum AglError
00258 {
00259 NoError = 0,
00260
00261 BadAttribute = 10000,
00262 BadProperty = 10001,
00263 BadPixelFormat = 10002,
00264 BadRendererInfo = 10003,
00265 BadContext = 10004,
00266 BadDrawable = 10005,
00267 BadGraphicsDevice = 10006,
00268 BadState = 10007,
00269 BadValue = 10008,
00270 BadMatch = 10009,
00271 BadEnum = 10010,
00272 BadOffscreen = 10011,
00273 BadFullscreen = 10012,
00274 BadWindow = 10013,
00275 BadPointer = 10014,
00276 BadModule = 10015,
00277 BadAlloc = 10016,
00278 BadConnection = 10017,
00279 }
00280
00281
00282
00283
00284
00285 [DllImport(agl)] internal static extern AGLPixelFormat aglChoosePixelFormat(ref AGLDevice gdevs, int ndev, int []attribs);
00297 [DllImport(agl)] internal static extern AGLPixelFormat aglChoosePixelFormat(IntPtr gdevs, int ndev, int []attribs);
00298 [DllImport(agl)] internal static extern void aglDestroyPixelFormat(AGLPixelFormat pix);
00299 [DllImport(agl)] internal static extern AGLPixelFormat aglNextPixelFormat(AGLPixelFormat pix);
00300 [DllImport(agl)] static extern byte aglDescribePixelFormat(AGLPixelFormat pix, int attrib, out int value);
00301 [Obsolete("Use aglDisplaysOfPixelFormat instead.")]
00302 [DllImport(agl)] static extern AGLDevice *aglDevicesOfPixelFormat(AGLPixelFormat pix, int *ndevs);
00303
00304
00305
00306
00307 [DllImport(agl)] static extern AGLRendererInfo aglQueryRendererInfo(AGLDevice[] gdevs, int ndev);
00308 [DllImport(agl)] static extern void aglDestroyRendererInfo(AGLRendererInfo rend);
00309 [DllImport(agl)] static extern AGLRendererInfo aglNextRendererInfo(AGLRendererInfo rend);
00310 [DllImport(agl)] static extern byte aglDescribeRenderer(AGLRendererInfo rend, int prop, out int value);
00311
00312
00313
00314
00315 [DllImport(agl)] internal static extern AGLContext aglCreateContext(AGLPixelFormat pix, AGLContext share);
00316 [DllImport(agl,EntryPoint="aglDestroyContext")] static extern byte _aglDestroyContext(AGLContext ctx);
00317 internal static bool aglDestroyContext(AGLContext context)
00318 {
00319 return (_aglDestroyContext(context) != 0) ? true : false;
00320 }
00321
00322 [DllImport(agl)] static extern byte aglCopyContext(AGLContext src, AGLContext dst, uint mask);
00323 [DllImport(agl)] internal static extern byte aglUpdateContext(AGLContext ctx);
00324
00325
00326
00327
00328 #region --- aglSetCurrentContext ---
00329
00330 [DllImport(agl,EntryPoint="aglSetCurrentContext")] static extern byte _aglSetCurrentContext(AGLContext ctx);
00331 internal static bool aglSetCurrentContext(IntPtr context)
00332 {
00333 byte retval = _aglSetCurrentContext(context);
00334
00335 if (retval != 0)
00336 return true;
00337 else
00338 return false;
00339 }
00340
00341 #endregion
00342
00343 [DllImport(agl)] internal static extern AGLContext aglGetCurrentContext();
00344
00345
00346
00347
00348
00349 [DllImport(agl,EntryPoint="aglSetDrawable")]
00350 static extern byte _aglSetDrawable(AGLContext ctx, AGLDrawable draw);
00351
00352 internal static void aglSetDrawable(AGLContext ctx, AGLDrawable draw)
00353 {
00354 byte retval = _aglSetDrawable(ctx, draw);
00355
00356 if (retval == 0)
00357 {
00358 AglError err = GetError();
00359
00360 throw new MacOSException(err, ErrorString(err));
00361 }
00362 }
00363 [DllImport(agl)] static extern byte aglSetOffScreen(AGLContext ctx, int width, int height, int rowbytes, IntPtr baseaddr);
00364 [DllImport(agl)] static extern AGLDrawable aglGetDrawable(AGLContext ctx);
00365
00366 [DllImport(agl, EntryPoint = "aglSetFullScreen")]
00367 static extern byte _aglSetFullScreen(AGLContext ctx, int width, int height, int freq, int device);
00368 internal static void aglSetFullScreen(AGLContext ctx, int width, int height, int freq, int device)
00369 {
00370 byte retval = _aglSetFullScreen(ctx, width, height, freq, device);
00371
00372 if (retval == 0)
00373 {
00374 AglError err = GetError();
00375 Debug.Print("AGL Error: {0}", err);
00376 Debug.Indent();
00377 Debug.Print(ErrorString(err));
00378 Debug.Unindent();
00379
00380 throw new MacOSException(err, ErrorString(err));
00381 }
00382 }
00383
00384
00385
00386 [DllImport(agl)] static extern byte aglSetVirtualScreen(AGLContext ctx, int screen);
00387 [DllImport(agl)] static extern int aglGetVirtualScreen(AGLContext ctx);
00388
00389
00390
00391
00392 [DllImport(agl)] static extern void aglGetVersion(int *major, int *minor);
00393
00394
00395
00396
00397 [DllImport(agl)] static extern byte aglConfigure(GLenum pname, uint param);
00398
00399
00400
00401
00402 [DllImport(agl)] internal static extern void aglSwapBuffers(AGLContext ctx);
00403
00404
00405
00406
00407 [DllImport(agl)] internal static extern byte aglEnable(AGLContext ctx, ParameterNames pname);
00408 [DllImport(agl)] internal static extern byte aglDisable(AGLContext ctx, ParameterNames pname);
00409 [DllImport(agl)] static extern byte aglIsEnabled(AGLContext ctx, GLenum pname);
00410 [DllImport(agl)]
00411 internal static extern byte aglSetInteger(AGLContext ctx, ParameterNames pname, ref int @params);
00412 [DllImport(agl)]
00413 internal static extern byte aglSetInteger(AGLContext ctx, ParameterNames pname, int []@params);
00414 [DllImport(agl)]
00415 static extern byte aglGetInteger(AGLContext ctx, GLenum pname, int* @params);
00416
00417
00418
00419
00420
00421 [DllImport(agl)] static extern byte aglUseFont(AGLContext ctx, int fontID, int face, int size, int first, int count, int @base);
00422
00423
00424
00425
00426 [DllImport(agl,EntryPoint="aglGetError")] internal static extern AglError GetError();
00427 [DllImport(agl,EntryPoint="aglErrorString")] static extern IntPtr _aglErrorString(AglError code);
00428 internal static string ErrorString(AglError code)
00429 {
00430 return Marshal.PtrToStringAnsi(_aglErrorString(code));
00431 }
00432
00433
00434
00435
00436 [DllImport(agl)] static extern void aglResetLibrary();
00437
00438
00439
00440
00441 [DllImport(agl)] static extern void aglSurfaceTexture (AGLContext context, GLenum target, GLenum internalformat, AGLContext surfacecontext) ;
00442
00443
00444
00445
00446 [DllImport(agl)] static extern byte aglCreatePBuffer (int width, int height, GLenum target, GLenum internalFormat, long max_level, AGLPbuffer *pbuffer);
00447 [DllImport(agl)] static extern byte aglDestroyPBuffer (AGLPbuffer pbuffer);
00448 [DllImport(agl)] static extern byte aglDescribePBuffer (AGLPbuffer pbuffer, int *width, int *height, GLenum *target, GLenum *internalFormat, int *max_level);
00449 [DllImport(agl)] static extern byte aglTexImagePBuffer (AGLContext ctx, AGLPbuffer pbuffer, int source);
00450
00451
00452
00453
00454 [DllImport(agl)] static extern byte aglSetPBuffer (AGLContext ctx, AGLPbuffer pbuffer, int face, int level, int screen) ;
00455 [DllImport(agl)] static extern byte aglGetPBuffer (AGLContext ctx, AGLPbuffer *pbuffer, int *face, int *level, int *screen) ;
00456
00457
00458
00459
00460 [DllImport(agl)] static extern byte aglGetCGLContext(AGLContext ctx, void **cgl_ctx) ;
00461 [DllImport(agl)] static extern byte aglGetCGLPixelFormat(AGLPixelFormat pix, void **cgl_pix);
00462
00463 #pragma warning restore 0169
00464 }
00465 }