| 1 |
// Copyright 2013 The Servo Project Developers. See the COPYRIGHT |
| 2 |
// file at the top-level directory of this distribution. |
| 3 |
// |
| 4 |
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 5 |
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 6 |
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 7 |
// option. This file may not be copied, modified, or distributed |
| 8 |
// except according to those terms. |
| 9 |
|
| 10 |
// Mac-specific OpenGL bindings. |
| 11 |
|
| 12 |
#![allow(non_upper_case_globals)] |
| 13 |
|
| 14 |
use libc::{c_void, c_int, c_char}; |
| 15 |
use std::os::raw; |
| 16 |
|
| 17 |
pub type GLenum = raw::c_uint; |
| 18 |
pub type GLint = raw::c_int; |
| 19 |
pub type GLsizei = raw::c_int; |
| 20 |
pub type GLuint = raw::c_uint; |
| 21 |
|
| 22 |
pub type CGLPixelFormatAttribute = c_int; |
| 23 |
pub type CGLContextParameter = c_int; |
| 24 |
pub type CGLContextEnable = c_int; |
| 25 |
pub type CGLGlobalOption = c_int; |
| 26 |
pub type CGLError = c_int; |
| 27 |
|
| 28 |
pub type CGLPixelFormatObj = *mut c_void; |
| 29 |
pub type CGLContextObj = *mut c_void; |
| 30 |
pub type CGLShareGroupObj = *mut c_void; |
| 31 |
pub type IOSurfaceRef = *mut c_void; |
| 32 |
|
| 33 |
pub const kCGLNoError: CGLError = 0; |
| 34 |
|
| 35 |
pub const kCGLPFAAllRenderers: CGLPixelFormatAttribute = 1; |
| 36 |
pub const kCGLPFADoubleBuffer: CGLPixelFormatAttribute = 5; |
| 37 |
pub const kCGLPFAStereo: CGLPixelFormatAttribute = 6; |
| 38 |
pub const kCGLPFAAuxBuffers: CGLPixelFormatAttribute = 7; |
| 39 |
pub const kCGLPFAColorSize: CGLPixelFormatAttribute = 8; |
| 40 |
pub const kCGLPFAAlphaSize: CGLPixelFormatAttribute = 11; |
| 41 |
pub const kCGLPFADepthSize: CGLPixelFormatAttribute = 12; |
| 42 |
pub const kCGLPFAStencilSize: CGLPixelFormatAttribute = 13; |
| 43 |
pub const kCGLPFAAccumSize: CGLPixelFormatAttribute = 14; |
| 44 |
pub const kCGLPFAMinimumPolicy: CGLPixelFormatAttribute = 51; |
| 45 |
pub const kCGLPFAMaximumPolicy: CGLPixelFormatAttribute = 52; |
| 46 |
pub const kCGLPFAOffScreen: CGLPixelFormatAttribute = 53; |
| 47 |
pub const kCGLPFAFullScreen: CGLPixelFormatAttribute = 54; |
| 48 |
pub const kCGLPFASampleBuffers: CGLPixelFormatAttribute = 55; |
| 49 |
pub const kCGLPFASamples: CGLPixelFormatAttribute = 56; |
| 50 |
pub const kCGLPFAAuxDepthStencil: CGLPixelFormatAttribute = 57; |
| 51 |
pub const kCGLPFAColorFloat: CGLPixelFormatAttribute = 58; |
| 52 |
pub const kCGLPFAMultisample: CGLPixelFormatAttribute = 59; |
| 53 |
pub const kCGLPFASupersample: CGLPixelFormatAttribute = 60; |
| 54 |
pub const kCGLPFASampleAlpha: CGLPixelFormatAttribute = 61; |
| 55 |
pub const kCGLPFARendererID: CGLPixelFormatAttribute = 70; |
| 56 |
pub const kCGLPFASingleRenderer: CGLPixelFormatAttribute = 71; |
| 57 |
pub const kCGLPFANoRecovery: CGLPixelFormatAttribute = 72; |
| 58 |
pub const kCGLPFAAccelerated: CGLPixelFormatAttribute = 73; |
| 59 |
pub const kCGLPFAClosestPolicy: CGLPixelFormatAttribute = 74; |
| 60 |
pub const kCGLPFARobust: CGLPixelFormatAttribute = 75; |
| 61 |
pub const kCGLPFABackingStore: CGLPixelFormatAttribute = 76; |
| 62 |
pub const kCGLPFAMPSafe: CGLPixelFormatAttribute = 78; |
| 63 |
pub const kCGLPFAWindow: CGLPixelFormatAttribute = 80; |
| 64 |
pub const kCGLPFAMultiScreen: CGLPixelFormatAttribute = 81; |
| 65 |
pub const kCGLPFACompliant: CGLPixelFormatAttribute = 83; |
| 66 |
pub const kCGLPFADisplayMask: CGLPixelFormatAttribute = 84; |
| 67 |
pub const kCGLPFAPBuffer: CGLPixelFormatAttribute = 90; |
| 68 |
pub const kCGLPFARemotePBuffer: CGLPixelFormatAttribute = 91; |
| 69 |
pub const kCGLPFAAllowOfflineRenderers: CGLPixelFormatAttribute = 96; |
| 70 |
pub const kCGLPFAAcceleratedCompute: CGLPixelFormatAttribute = 97; |
| 71 |
pub const kCGLPFAOpenGLProfile: CGLPixelFormatAttribute = 99; |
| 72 |
pub const kCGLPFAVirtualScreenCount: CGLPixelFormatAttribute = 128; |
| 73 |
|
| 74 |
pub const kCGLCESwapRectangle: CGLContextEnable = 201; |
| 75 |
pub const kCGLCESwapLimit: CGLContextEnable = 203; |
| 76 |
pub const kCGLCERasterization: CGLContextEnable = 221; |
| 77 |
pub const kCGLCEStateValidation: CGLContextEnable = 301; |
| 78 |
pub const kCGLCESurfaceBackingSize: CGLContextEnable = 305; |
| 79 |
pub const kCGLCEDisplayListOptimization: CGLContextEnable = 307; |
| 80 |
pub const kCGLCEMPEngine: CGLContextEnable = 313; |
| 81 |
pub const kCGLCECrashOnRemovedFunctions: CGLContextEnable = 316; |
| 82 |
|
| 83 |
pub const kCGLCPSwapRectangle: CGLContextParameter = 200; |
| 84 |
pub const kCGLCPSwapInterval: CGLContextParameter = 222; |
| 85 |
pub const kCGLCPDispatchTableSize: CGLContextParameter = 224; |
| 86 |
pub const kCGLCPClientStorage: CGLContextParameter = 226; |
| 87 |
pub const kCGLCPSurfaceTexture: CGLContextParameter = 228; |
| 88 |
pub const kCGLCPSurfaceOrder: CGLContextParameter = 235; |
| 89 |
pub const kCGLCPSurfaceOpacity: CGLContextParameter = 236; |
| 90 |
pub const kCGLCPSurfaceBackingSize: CGLContextParameter = 304; |
| 91 |
pub const kCGLCPSurfaceSurfaceVolatile: CGLContextParameter = 306; |
| 92 |
pub const kCGLCPReclaimResources: CGLContextParameter = 308; |
| 93 |
pub const kCGLCPCurrentRendererID: CGLContextParameter = 309; |
| 94 |
pub const kCGLCPGPUVertexProcessing: CGLContextParameter = 310; |
| 95 |
pub const kCGLCPGPUFragmentProcessing: CGLContextParameter = 311; |
| 96 |
pub const kCGLCPHasDrawable: CGLContextParameter = 314; |
| 97 |
pub const kCGLCPMPSwapsInFlight: CGLContextParameter = 315; |
| 98 |
|
| 99 |
pub const kCGLGOFormatCacheSize: CGLGlobalOption = 501; |
| 100 |
pub const kCGLGOClearFormatCache: CGLGlobalOption = 502; |
| 101 |
pub const kCGLGORetainRenderers: CGLGlobalOption = 503; |
| 102 |
pub const kCGLGOResetLibrary: CGLGlobalOption = 504; |
| 103 |
pub const kCGLGOUseErrorHandler: CGLGlobalOption = 505; |
| 104 |
pub const kCGLGOUseBuildCache: CGLGlobalOption = 506; |
| 105 |
|
| 106 |
pub const CORE_BOOLEAN_ATTRIBUTES: &'static [CGLPixelFormatAttribute] = |
| 107 |
&[kCGLPFAAllRenderers, |
| 108 |
kCGLPFADoubleBuffer, |
| 109 |
kCGLPFAStereo, |
| 110 |
kCGLPFAAuxBuffers, |
| 111 |
kCGLPFAMinimumPolicy, |
| 112 |
kCGLPFAMaximumPolicy, |
| 113 |
kCGLPFAOffScreen, |
| 114 |
kCGLPFAFullScreen, |
| 115 |
kCGLPFAAuxDepthStencil, |
| 116 |
kCGLPFAColorFloat, |
| 117 |
kCGLPFAMultisample, |
| 118 |
kCGLPFASupersample, |
| 119 |
kCGLPFASampleAlpha, |
| 120 |
kCGLPFASingleRenderer, |
| 121 |
kCGLPFANoRecovery, |
| 122 |
kCGLPFAAccelerated, |
| 123 |
kCGLPFAClosestPolicy, |
| 124 |
kCGLPFARobust, |
| 125 |
kCGLPFABackingStore, |
| 126 |
kCGLPFAMPSafe, |
| 127 |
kCGLPFAWindow, |
| 128 |
kCGLPFAMultiScreen, |
| 129 |
kCGLPFACompliant, |
| 130 |
kCGLPFAPBuffer, |
| 131 |
kCGLPFARemotePBuffer, |
| 132 |
kCGLPFAAllowOfflineRenderers, |
| 133 |
kCGLPFAAcceleratedCompute]; |
| 134 |
|
| 135 |
pub const CORE_INTEGER_ATTRIBUTES: &'static [CGLPixelFormatAttribute] = |
| 136 |
&[kCGLPFAColorSize, |
| 137 |
kCGLPFAAlphaSize, |
| 138 |
kCGLPFADepthSize, |
| 139 |
kCGLPFAStencilSize, |
| 140 |
kCGLPFAAccumSize, |
| 141 |
kCGLPFASampleBuffers, |
| 142 |
kCGLPFASamples, |
| 143 |
kCGLPFARendererID, |
| 144 |
kCGLPFADisplayMask, |
| 145 |
kCGLPFAOpenGLProfile, |
| 146 |
kCGLPFAVirtualScreenCount]; |
| 147 |
|
| 148 |
#[link(name = "OpenGL", kind = "framework")] |
| 149 |
extern { |
| 150 |
// CGLCurrent.h |
| 151 |
|
| 152 |
pub fn CGLSetCurrentContext(ctx: CGLContextObj) -> CGLError; |
| 153 |
pub fn CGLGetCurrentContext() -> CGLContextObj; |
| 154 |
pub fn CGLGetShareGroup(context: CGLContextObj) -> CGLShareGroupObj; |
| 155 |
|
| 156 |
// OpenGL.h |
| 157 |
|
| 158 |
// Pixel format functions |
| 159 |
pub fn CGLChoosePixelFormat(attribs: *const CGLPixelFormatAttribute, |
| 160 |
pix: *mut CGLPixelFormatObj, |
| 161 |
npix: *mut GLint) -> CGLError; |
| 162 |
pub fn CGLDescribePixelFormat(pix: CGLPixelFormatObj, |
| 163 |
pix_num: GLint, |
| 164 |
attrib: CGLPixelFormatAttribute, |
| 165 |
value: *mut GLint) -> CGLError; |
| 166 |
pub fn CGLDestroyPixelFormat(pix: CGLPixelFormatObj) -> CGLError; |
| 167 |
pub fn CGLReleasePixelFormat(pix: CGLPixelFormatObj); |
| 168 |
pub fn CGLRetainPixelFormat(pix: CGLPixelFormatObj) -> CGLPixelFormatObj; |
| 169 |
pub fn CGLGetPixelFormatRetainCount(pix: CGLPixelFormatObj) -> GLuint; |
| 170 |
|
| 171 |
// Context functions |
| 172 |
pub fn CGLCreateContext(pix: CGLPixelFormatObj, share: CGLContextObj, ctx: *mut CGLContextObj) -> |
| 173 |
CGLError; |
| 174 |
pub fn CGLDestroyContext(ctx: CGLContextObj) -> CGLError; |
| 175 |
pub fn CGLGetPixelFormat(ctx: CGLContextObj) -> CGLPixelFormatObj; |
| 176 |
|
| 177 |
// Getting and Setting Context Options |
| 178 |
pub fn CGLEnable(ctx: CGLContextObj, pname: CGLContextEnable) -> CGLError; |
| 179 |
pub fn CGLDisable(ctx: CGLContextObj, pname: CGLContextEnable) -> CGLError; |
| 180 |
pub fn CGLIsEnabled(ctx: CGLContextObj, pname: CGLContextEnable, enable: &mut GLint) -> CGLError; |
| 181 |
pub fn CGLSetParameter(ctx: CGLContextObj, pname: CGLContextParameter, params: &GLint) -> CGLError; |
| 182 |
pub fn CGLGetParameter(ctx: CGLContextObj, pname: CGLContextParameter, params: &mut GLint) -> CGLError; |
| 183 |
|
| 184 |
// Locking functions |
| 185 |
pub fn CGLLockContext(ctx: CGLContextObj) -> CGLError; |
| 186 |
pub fn CGLUnlockContext(ctx: CGLContextObj) -> CGLError; |
| 187 |
|
| 188 |
// Getting and Setting Global Information |
| 189 |
pub fn CGLSetOption(pname: CGLGlobalOption, param: &GLint) -> CGLError; |
| 190 |
pub fn CGLGetOption(pname: CGLGlobalOption, param: &mut GLint) -> CGLError; |
| 191 |
pub fn CGLSetGlobalOption(pname: CGLGlobalOption, param: &GLint) -> CGLError; |
| 192 |
pub fn CGLGetGlobalOption(pname: CGLGlobalOption, param: &mut GLint) -> CGLError; |
| 193 |
pub fn CGLGetVersion (major: &mut GLint, minor: &mut GLint) -> CGLError; |
| 194 |
|
| 195 |
// CGLIOSurface.h |
| 196 |
|
| 197 |
pub fn CGLTexImageIOSurface2D(ctx: CGLContextObj, target: GLenum, internal_format: GLenum, |
| 198 |
width: GLsizei, height: GLsizei, format: GLenum, ty: GLenum, |
| 199 |
ioSurface: IOSurfaceRef, plane: GLuint) -> CGLError; |
| 200 |
|
| 201 |
// https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGL_OpenGL/#//apple_ref/c/func/CGLErrorString |
| 202 |
|
| 203 |
pub fn CGLErrorString(error: CGLError) -> *const c_char; |
| 204 |
} |