1 /* 2 3 Boost Software License - Version 1.0 - August 17th, 2003 4 5 Permission is hereby granted, free of charge, to any person or organization 6 obtaining a copy of the software and accompanying documentation covered by 7 this license (the "Software") to use, reproduce, display, distribute, 8 execute, and transmit the Software, and to prepare derivative works of the 9 Software, and to permit third-parties to whom the Software is furnished to 10 do so, all subject to the following: 11 12 The copyright notices in the Software and this entire statement, including 13 the above license grant, this restriction and the following disclaimer, 14 must be included in all copies of the Software, in whole or in part, and 15 all derivative works of the Software, unless such copies or derivative 16 works are solely in the form of machine-executable object code generated by 17 a source language processor. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 DEALINGS IN THE SOFTWARE. 26 27 */ 28 module derelict.opengl.cgl; 29 30 // Original version: 2008-04-03 by Hugues De Keyzer 31 32 // Original C headers: 33 // OpenGL.h 34 // CGLTypes.h 35 // CGLCurrent.h 36 // from /System/Library/Frameworks/OpenGL.framework/Headers from Mac OS X 10.4 37 38 version(darwin) 39 { 40 version = CGL; 41 } 42 else version(OSX) 43 { 44 version = CGL; 45 } 46 47 version (CGL) 48 { 49 50 private 51 { 52 import derelict.opengl.gltypes; 53 import derelict.util.compat; 54 import derelict.util.loader; 55 } 56 57 /* 58 ** CGLContext structure. 59 */ 60 struct _CGLContextObject {} 61 62 struct _CGLPixelFormatObject {} 63 struct _CGLRendererInfoObject {} 64 struct _CGLPBufferObject {} 65 66 /* 67 ** CGL opaque data. 68 */ 69 alias _CGLContextObject* CGLContextObj; 70 alias _CGLPixelFormatObject* CGLPixelFormatObj; 71 alias _CGLRendererInfoObject* CGLRendererInfoObj; 72 alias _CGLPBufferObject* CGLPBufferObj; 73 74 /* 75 ** Attribute names for CGLChoosePixelFormat and CGLDescribePixelFormat. 76 */ 77 enum CGLPixelFormatAttribute 78 { 79 kCGLPFAAllRenderers = 1, /* choose from all available renderers */ 80 kCGLPFADoubleBuffer = 5, /* choose a double buffered pixel format */ 81 kCGLPFAStereo = 6, /* stereo buffering supported */ 82 kCGLPFAAuxBuffers = 7, /* number of aux buffers */ 83 kCGLPFAColorSize = 8, /* number of color buffer bits */ 84 kCGLPFAAlphaSize = 11, /* number of alpha component bits */ 85 kCGLPFADepthSize = 12, /* number of depth buffer bits */ 86 kCGLPFAStencilSize = 13, /* number of stencil buffer bits */ 87 kCGLPFAAccumSize = 14, /* number of accum buffer bits */ 88 kCGLPFAMinimumPolicy = 51, /* never choose smaller buffers than requested */ 89 kCGLPFAMaximumPolicy = 52, /* choose largest buffers of type requested */ 90 kCGLPFAOffScreen = 53, /* choose an off-screen capable renderer */ 91 kCGLPFAFullScreen = 54, /* choose a full-screen capable renderer */ 92 kCGLPFASampleBuffers = 55, /* number of multi sample buffers */ 93 kCGLPFASamples = 56, /* number of samples per multi sample buffer */ 94 kCGLPFAAuxDepthStencil = 57, /* each aux buffer has its own depth stencil */ 95 kCGLPFAColorFloat = 58, /* color buffers store floating point pixels */ 96 kCGLPFAMultisample = 59, /* choose multisampling */ 97 kCGLPFASupersample = 60, /* choose supersampling */ 98 kCGLPFASampleAlpha = 61, /* request alpha filtering */ 99 100 kCGLPFARendererID = 70, /* request renderer by ID */ 101 kCGLPFASingleRenderer = 71, /* choose a single renderer for all screens */ 102 kCGLPFANoRecovery = 72, /* disable all failure recovery systems */ 103 kCGLPFAAccelerated = 73, /* choose a hardware accelerated renderer */ 104 kCGLPFAClosestPolicy = 74, /* choose the closest color buffer to request */ 105 kCGLPFARobust = 75, /* renderer does not need failure recovery */ 106 kCGLPFABackingStore = 76, /* back buffer contents are valid after swap */ 107 kCGLPFAMPSafe = 78, /* renderer is multi-processor safe */ 108 kCGLPFAWindow = 80, /* can be used to render to an onscreen window */ 109 kCGLPFAMultiScreen = 81, /* single window can span multiple screens */ 110 kCGLPFACompliant = 83, /* renderer is opengl compliant */ 111 kCGLPFADisplayMask = 84, /* mask limiting supported displays */ 112 kCGLPFAPBuffer = 90, /* can be used to render to a pbuffer */ 113 kCGLPFARemotePBuffer = 91, /* can be used to render offline to a pbuffer */ 114 kCGLPFAVirtualScreenCount = 128 /* number of virtual screens in this format */ 115 } 116 117 /* 118 ** Property names for CGLDescribeRenderer. 119 */ 120 enum CGLRendererProperty 121 { 122 kCGLRPOffScreen = 53, 123 kCGLRPFullScreen = 54, 124 kCGLRPRendererID = 70, 125 kCGLRPAccelerated = 73, 126 kCGLRPRobust = 75, 127 kCGLRPBackingStore = 76, 128 kCGLRPMPSafe = 78, 129 kCGLRPWindow = 80, 130 kCGLRPMultiScreen = 81, 131 kCGLRPCompliant = 83, 132 kCGLRPDisplayMask = 84, 133 kCGLRPBufferModes = 100, /* a bitfield of supported buffer modes */ 134 kCGLRPColorModes = 103, /* a bitfield of supported color buffer formats */ 135 kCGLRPAccumModes = 104, /* a bitfield of supported accum buffer formats */ 136 kCGLRPDepthModes = 105, /* a bitfield of supported depth buffer depths */ 137 kCGLRPStencilModes = 106, /* a bitfield of supported stencil buffer depths */ 138 kCGLRPMaxAuxBuffers = 107, /* maximum number of auxilliary buffers */ 139 kCGLRPMaxSampleBuffers = 108, /* maximum number of sample buffers */ 140 kCGLRPMaxSamples = 109, /* maximum number of samples */ 141 kCGLRPSampleModes = 110, /* a bitfield of supported sample modes */ 142 kCGLRPSampleAlpha = 111, /* support for alpha sampling */ 143 kCGLRPVideoMemory = 120, /* total video memory */ 144 kCGLRPTextureMemory = 121, /* video memory useable for texture storage */ 145 kCGLRPGPUVertProcCapable = 122, /* renderer capable of GPU vertex processing */ 146 kCGLRPGPUFragProcCapable = 123, /* renderer capable of GPU fragment processing */ 147 kCGLRPRendererCount = 128 /* the number of renderers in this renderer info */ 148 } 149 150 /* 151 ** Enable names for CGLEnable, CGLDisable, and CGLIsEnabled. 152 */ 153 enum CGLContextEnable 154 { 155 kCGLCESwapRectangle = 201, /* Enable or disable the swap rectangle */ 156 kCGLCESwapLimit = 203, /* Enable or disable the swap async limit */ 157 kCGLCERasterization = 221, /* Enable or disable all rasterization */ 158 kCGLCEStateValidation = 301, /* Validate state for multi-screen functionality */ 159 kCGLCESurfaceBackingSize = 305, /* Enable or disable surface backing size override */ 160 kCGLCEDisplayListOptimization = 307, /* Ability to turn off display list optimizer */ 161 kCGLCEMPEngine = 313 /* Enable or disable multi-threaded GL engine */ 162 } 163 164 /* 165 ** Parameter names for CGLSetParameter and CGLGetParameter. 166 */ 167 enum CGLContextParameter 168 { 169 kCGLCPSwapRectangle = 200, /* 4 params. Set or get the swap rectangle {x, y, w, h} */ 170 kCGLCPSwapInterval = 222, /* 1 param. 0 -> Don't sync, n -> Sync every n retrace */ 171 kCGLCPDispatchTableSize = 224, /* 1 param. Get the dispatch table size */ 172 /* Note: kCGLCPClientStorage is always a pointer-sized parameter, even though the API claims GLint. */ 173 kCGLCPClientStorage = 226, /* 1 param. Context specific generic storage */ 174 kCGLCPSurfaceTexture = 228, /* 3 params. SID, target, internal_format */ 175 /* - Used by AGL - */ 176 /* AGL_STATE_VALIDATION 230 */ 177 /* AGL_BUFFER_NAME 231 */ 178 /* AGL_ORDER_CONTEXT_TO_FRONT 232 */ 179 /* AGL_CONTEXT_SURFACE_ID 233 */ 180 /* AGL_CONTEXT_DISPLAY_ID 234 */ 181 kCGLCPSurfaceOrder = 235, /* 1 param. 1 -> Above window, -1 -> Below Window */ 182 kCGLCPSurfaceOpacity = 236, /* 1 param. 1 -> Surface is opaque (default), 0 -> non-opaque */ 183 /* - Used by AGL - */ 184 /* AGL_CLIP_REGION 254 */ 185 /* AGL_FS_CAPTURE_SINGLE 255 */ 186 kCGLCPSurfaceBackingSize = 304, /* 2 params. Width/height of surface backing size */ 187 /* AGL_SURFACE_VOLATILE 306 */ 188 kCGLCPSurfaceSurfaceVolatile = 306, /* 1 param. Surface volatile state */ 189 kCGLCPReclaimResources = 308, /* 0 params. */ 190 kCGLCPCurrentRendererID = 309, /* 1 param. Retrieves the current renderer ID */ 191 kCGLCPGPUVertexProcessing = 310, /* 1 param. Currently processing vertices with GPU (get) */ 192 kCGLCPGPUFragmentProcessing = 311, /* 1 param. Currently processing fragments with GPU (get) */ 193 } 194 195 /* 196 ** Option names for CGLSetOption and CGLGetOption. 197 */ 198 enum CGLGlobalOption 199 { 200 kCGLGOFormatCacheSize = 501, /* Set the size of the pixel format cache */ 201 kCGLGOClearFormatCache = 502, /* Reset the pixel format cache if true */ 202 kCGLGORetainRenderers = 503, /* Whether to retain loaded renderers in memory */ 203 kCGLGOResetLibrary = 504, /* *** DEPRECATED in MacOS X 10.4 *** */ 204 /* Do a soft reset of the CGL library if true */ 205 kCGLGOUseErrorHandler = 505, /* Call the Core Graphics handler on CGL errors */ 206 } 207 208 /* 209 ** Error return values from CGLGetError. 210 */ 211 enum CGLError 212 { 213 kCGLNoError = 0, /* no error */ 214 kCGLBadAttribute = 10000, /* invalid pixel format attribute */ 215 kCGLBadProperty = 10001, /* invalid renderer property */ 216 kCGLBadPixelFormat = 10002, /* invalid pixel format */ 217 kCGLBadRendererInfo = 10003, /* invalid renderer info */ 218 kCGLBadContext = 10004, /* invalid context */ 219 kCGLBadDrawable = 10005, /* invalid drawable */ 220 kCGLBadDisplay = 10006, /* invalid graphics device */ 221 kCGLBadState = 10007, /* invalid context state */ 222 kCGLBadValue = 10008, /* invalid numerical value */ 223 kCGLBadMatch = 10009, /* invalid share context */ 224 kCGLBadEnumeration = 10010, /* invalid enumerant */ 225 kCGLBadOffScreen = 10011, /* invalid offscreen drawable */ 226 kCGLBadFullScreen = 10012, /* invalid offscreen drawable */ 227 kCGLBadWindow = 10013, /* invalid window */ 228 kCGLBadAddress = 10014, /* invalid pointer */ 229 kCGLBadCodeModule = 10015, /* invalid code module */ 230 kCGLBadAlloc = 10016, /* invalid memory allocation */ 231 kCGLBadConnection = 10017 /* invalid CoreGraphics connection */ 232 } 233 234 235 extern (C) 236 { 237 238 mixin(gsharedString!() ~" 239 /* 240 ** Pixel format functions 241 */ 242 CGLError function(CGLPixelFormatAttribute*, CGLPixelFormatObj*, int*) CGLChoosePixelFormat; 243 CGLError function(CGLPixelFormatObj) CGLDestroyPixelFormat; 244 CGLError function(CGLPixelFormatObj, int, CGLPixelFormatAttribute, int*) CGLDescribePixelFormat; 245 246 /* 247 ** Renderer information functions 248 */ 249 CGLError function(uint, CGLRendererInfoObj*, int*) CGLQueryRendererInfo; 250 CGLError function(CGLRendererInfoObj) CGLDestroyRendererInfo; 251 CGLError function(CGLRendererInfoObj, int, CGLRendererProperty, int*) CGLDescribeRenderer; 252 253 /* 254 ** Context functions 255 */ 256 CGLError function(CGLPixelFormatObj, CGLContextObj, CGLContextObj*) CGLCreateContext; 257 CGLError function(CGLContextObj) CGLDestroyContext; 258 CGLError function(CGLContextObj, CGLContextObj, uint) CGLCopyContext; 259 260 /* 261 ** PBuffer functions 262 */ 263 // FIXME 264 // These functions use the AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER macro. See 265 // <AvailabilityMacros.h>. 266 version (Mac_OS_X_10_3_and_later) 267 { 268 CGLError function(int, int, uint, uint, int, CGLPBufferObj*) CGLCreatePBuffer; 269 CGLError function(CGLPBufferObj) CGLDestroyPBuffer; 270 CGLError function(CGLPBufferObj, int*, int*, uint*, uint*, int*) CGLDescribePBuffer; 271 CGLError function(CGLContextObj, CGLPBufferObj, uint) CGLTexImagePBuffer; 272 } 273 274 /* 275 ** Drawable Functions 276 */ 277 CGLError function(CGLContextObj, int, int, int, void*) CGLSetOffScreen; 278 CGLError function(CGLContextObj, int*, int*, int*, void **baseaddr) CGLGetOffScreen; 279 CGLError function(CGLContextObj) CGLSetFullScreen; 280 281 version (Mac_OS_X_10_3_and_later) 282 { 283 CGLError function(CGLContextObj, CGLPBufferObj, uint, int, int) CGLSetPBuffer; 284 CGLError function(CGLContextObj, CGLPBufferObj*, uint*, int*, int*) CGLGetPBuffer; 285 } 286 287 CGLError function(CGLContextObj) CGLClearDrawable; 288 CGLError function(CGLContextObj) CGLFlushDrawable; 289 290 /* 291 ** Per context enables and parameters 292 */ 293 CGLError function(CGLContextObj, CGLContextEnable) CGLEnable; 294 CGLError function(CGLContextObj, CGLContextEnable) CGLDisable; 295 CGLError function(CGLContextObj, CGLContextEnable, int*) CGLIsEnabled; 296 CGLError function(CGLContextObj, CGLContextParameter, int*) CGLSetParameter; 297 CGLError function(CGLContextObj, CGLContextParameter, int*) CGLGetParameter; 298 299 /* 300 ** Virtual screen functions 301 */ 302 CGLError function(CGLContextObj, int) CGLSetVirtualScreen; 303 CGLError function(CGLContextObj, int*) CGLGetVirtualScreen; 304 305 /* 306 ** Global library options 307 */ 308 CGLError function(CGLGlobalOption, int) CGLSetOption; 309 CGLError function(CGLGlobalOption, int*) CGLGetOption; 310 311 /* 312 ** Locking functions 313 */ 314 version (Mac_OS_X_10_4_and_later) 315 { 316 CGLError function(CGLContextObj) CGLLockContext; 317 CGLError function(CGLContextObj) CGLUnlockContext; 318 } 319 320 /* 321 ** Version numbers 322 */ 323 void function(int*, int*) CGLGetVersion; 324 325 /* 326 ** Convert an error code to a string 327 */ 328 char* function(CGLError) CGLErrorString; 329 330 /* 331 ** Current context functions 332 */ 333 CGLError function(CGLContextObj) CGLSetCurrentContext; 334 CGLContextObj function() CGLGetCurrentContext;"); 335 } 336 337 package 338 { 339 void loadPlatformGL(void delegate(void**, string, bool doThrow = true) bindFunc) 340 { 341 bindFunc(cast(void**)&CGLSetCurrentContext, "CGLSetCurrentContext"); 342 bindFunc(cast(void**)&CGLGetCurrentContext, "CGLGetCurrentContext"); 343 /* 344 ** Pixel format functions 345 */ 346 bindFunc(cast(void**)&CGLChoosePixelFormat, "CGLChoosePixelFormat"); 347 bindFunc(cast(void**)&CGLDestroyPixelFormat, "CGLDestroyPixelFormat"); 348 bindFunc(cast(void**)&CGLDescribePixelFormat, "CGLDescribePixelFormat"); 349 350 /* 351 ** Renderer information functions 352 */ 353 bindFunc(cast(void**)&CGLQueryRendererInfo, "CGLQueryRendererInfo"); 354 bindFunc(cast(void**)&CGLDestroyRendererInfo, "CGLDestroyRendererInfo"); 355 bindFunc(cast(void**)&CGLDescribeRenderer, "CGLDescribeRenderer"); 356 357 /* 358 ** Context functions 359 */ 360 bindFunc(cast(void**)&CGLCreateContext, "CGLCreateContext"); 361 bindFunc(cast(void**)&CGLDestroyContext, "CGLDestroyContext"); 362 bindFunc(cast(void**)&CGLCopyContext, "CGLCopyContext"); 363 364 /* 365 ** PBuffer functions 366 */ 367 // FIXME 368 // These functions use the AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER macro. See 369 // <AvailabilityMacros.h>. 370 version (Mac_OS_X_10_3_and_later) 371 { 372 bindFunc(cast(void**)&CGLCreatePBuffer, "CGLCreatePBuffer"); 373 374 bindFunc(cast(void**)&CGLDestroyPBuffer, "CGLDestroyPBuffer"); 375 376 bindFunc(cast(void**)&CGLDescribePBuffer, "CGLDescribePBuffer"); 377 378 bindFunc(cast(void**)&CGLTexImagePBuffer, "CGLTexImagePBuffer"); 379 } 380 381 /* 382 ** Drawable Functions 383 */ 384 bindFunc(cast(void**)&CGLSetOffScreen, "CGLSetOffScreen"); 385 bindFunc(cast(void**)&CGLGetOffScreen, "CGLGetOffScreen"); 386 bindFunc(cast(void**)&CGLSetFullScreen, "CGLSetFullScreen"); 387 388 version (Mac_OS_X_10_3_and_later) 389 { 390 bindFunc(cast(void**)&CGLSetPBuffer, "CGLSetPBuffer"); 391 392 bindFunc(cast(void**)&CGLGetPBuffer, "CGLGetPBuffer"); 393 } 394 395 bindFunc(cast(void**)&CGLClearDrawable, "CGLClearDrawable"); 396 bindFunc(cast(void**)&CGLFlushDrawable, "CGLFlushDrawable"); 397 398 /* 399 ** Per context enables and parameters 400 */ 401 bindFunc(cast(void**)&CGLEnable, "CGLEnable"); 402 bindFunc(cast(void**)&CGLDisable, "CGLDisable"); 403 bindFunc(cast(void**)&CGLIsEnabled, "CGLIsEnabled"); 404 bindFunc(cast(void**)&CGLSetParameter, "CGLSetParameter"); 405 bindFunc(cast(void**)&CGLGetParameter, "CGLGetParameter"); 406 407 /* 408 ** Virtual screen functions 409 */ 410 bindFunc(cast(void**)&CGLSetVirtualScreen, "CGLSetVirtualScreen"); 411 bindFunc(cast(void**)&CGLGetVirtualScreen, "CGLGetVirtualScreen"); 412 413 /* 414 ** Global library options 415 */ 416 bindFunc(cast(void**)&CGLSetOption, "CGLSetOption"); 417 bindFunc(cast(void**)&CGLGetOption, "CGLGetOption"); 418 419 /* 420 ** Locking functions 421 */ 422 version (Mac_OS_X_10_4_and_later) 423 { 424 bindFunc(cast(void**)&CGLLockContext, "CGLLockContext"); 425 426 bindFunc(cast(void**)&CGLUnlockContext, "CGLUnlockContext"); 427 } 428 429 /* 430 ** Version numbers 431 */ 432 bindFunc(cast(void**)&CGLGetVersion, "CGLGetVersion"); 433 434 /* 435 ** Convert an error code to a string 436 */ 437 bindFunc(cast(void**)&CGLErrorString, "CGLErrorString"); 438 439 /* 440 ** Current context functions 441 */ 442 bindFunc(cast(void**)&CGLSetCurrentContext, "CGLSetCurrentContext"); 443 bindFunc(cast(void**)&CGLGetCurrentContext, "CGLGetCurrentContext"); 444 } 445 } 446 }// version(CGL)