1 // x11-rs: Rust bindings for X11 libraries
2 // The X11 libraries are available under the MIT license.
3 // These bindings are public domain.
4 
5 use std::os::raw::{
6   c_char,
7   c_int,
8   c_uchar,
9   c_uint,
10   c_ulong,
11 };
12 
13 use ::xlib::{
14   Display,
15   XID,
16   XVisualInfo,
17 };
18 
19 
20 //
21 // functions
22 //
23 
24 
25 x11_link! { Glx, gl, ["libGL.so.1", "libGL.so"], 40,
26   pub fn glXChooseFBConfig (_4: *mut Display, _3: c_int, _2: *const c_int, _1: *mut c_int) -> *mut GLXFBConfig,
27   pub fn glXChooseVisual (_3: *mut Display, _2: c_int, _1: *mut c_int) -> *mut XVisualInfo,
28   pub fn glXCopyContext (_4: *mut Display, _3: GLXContext, _2: GLXContext, _1: c_ulong) -> (),
29   pub fn glXCreateContext (_4: *mut Display, _3: *mut XVisualInfo, _2: GLXContext, _1: c_int) -> GLXContext,
30   pub fn glXCreateGLXPixmap (_3: *mut Display, _2: *mut XVisualInfo, _1: c_ulong) -> c_ulong,
31   pub fn glXCreateNewContext (_5: *mut Display, _4: GLXFBConfig, _3: c_int, _2: GLXContext, _1: c_int) -> GLXContext,
32   pub fn glXCreatePbuffer (_3: *mut Display, _2: GLXFBConfig, _1: *const c_int) -> c_ulong,
33   pub fn glXCreatePixmap (_4: *mut Display, _3: GLXFBConfig, _2: c_ulong, _1: *const c_int) -> c_ulong,
34   pub fn glXCreateWindow (_4: *mut Display, _3: GLXFBConfig, _2: c_ulong, _1: *const c_int) -> c_ulong,
35   pub fn glXDestroyContext (_2: *mut Display, _1: GLXContext) -> (),
36   pub fn glXDestroyGLXPixmap (_2: *mut Display, _1: c_ulong) -> (),
37   pub fn glXDestroyPbuffer (_2: *mut Display, _1: c_ulong) -> (),
38   pub fn glXDestroyPixmap (_2: *mut Display, _1: c_ulong) -> (),
39   pub fn glXDestroyWindow (_2: *mut Display, _1: c_ulong) -> (),
40   pub fn glXGetClientString (_2: *mut Display, _1: c_int) -> *const c_char,
41   pub fn glXGetConfig (_4: *mut Display, _3: *mut XVisualInfo, _2: c_int, _1: *mut c_int) -> c_int,
42   pub fn glXGetCurrentContext () -> GLXContext,
43   pub fn glXGetCurrentDisplay () -> *mut Display,
44   pub fn glXGetCurrentDrawable () -> c_ulong,
45   pub fn glXGetCurrentReadDrawable () -> c_ulong,
46   pub fn glXGetFBConfigAttrib (_4: *mut Display, _3: GLXFBConfig, _2: c_int, _1: *mut c_int) -> c_int,
47   pub fn glXGetFBConfigs (_3: *mut Display, _2: c_int, _1: *mut c_int) -> *mut GLXFBConfig,
48   pub fn glXGetProcAddress (_1: *const c_uchar) -> Option<unsafe extern "C" fn ()>,
49   pub fn glXGetProcAddressARB (_1: *const c_uchar) -> Option<unsafe extern "C" fn ()>,
50   pub fn glXGetSelectedEvent (_3: *mut Display, _2: c_ulong, _1: *mut c_ulong) -> (),
51   pub fn glXGetVisualFromFBConfig (_2: *mut Display, _1: GLXFBConfig) -> *mut XVisualInfo,
52   pub fn glXIsDirect (_2: *mut Display, _1: GLXContext) -> c_int,
53   pub fn glXMakeContextCurrent (_4: *mut Display, _3: c_ulong, _2: c_ulong, _1: GLXContext) -> c_int,
54   pub fn glXMakeCurrent (_3: *mut Display, _2: c_ulong, _1: GLXContext) -> c_int,
55   pub fn glXQueryContext (_4: *mut Display, _3: GLXContext, _2: c_int, _1: *mut c_int) -> c_int,
56   pub fn glXQueryDrawable (_4: *mut Display, _3: c_ulong, _2: c_int, _1: *mut c_uint) -> (),
57   pub fn glXQueryExtension (_3: *mut Display, _2: *mut c_int, _1: *mut c_int) -> c_int,
58   pub fn glXQueryExtensionsString (_2: *mut Display, _1: c_int) -> *const c_char,
59   pub fn glXQueryServerString (_3: *mut Display, _2: c_int, _1: c_int) -> *const c_char,
60   pub fn glXQueryVersion (_3: *mut Display, _2: *mut c_int, _1: *mut c_int) -> c_int,
61   pub fn glXSelectEvent (_3: *mut Display, _2: c_ulong, _1: c_ulong) -> (),
62   pub fn glXSwapBuffers (_2: *mut Display, _1: c_ulong) -> (),
63   pub fn glXUseXFont (_4: c_ulong, _3: c_int, _2: c_int, _1: c_int) -> (),
64   pub fn glXWaitGL () -> (),
65   pub fn glXWaitX () -> (),
66 variadic:
67 globals:
68 }
69 
70 
71 //
72 // types
73 //
74 
75 
76 // opaque structures
77 #[repr(C)] pub struct __GLXcontextRec;
78 #[repr(C)] pub struct __GLXFBConfigRec;
79 
80 // types
81 pub type GLXContext = *mut __GLXcontextRec;
82 pub type GLXContextID = XID;
83 pub type GLXDrawable = XID;
84 pub type GLXFBConfig = *mut __GLXFBConfigRec;
85 pub type GLXFBConfigID = XID;
86 pub type GLXPbuffer = XID;
87 pub type GLXPixmap = XID;
88 pub type GLXWindow = XID;
89 
90 
91 //
92 // constants
93 //
94 
95 
96 // config caveats
97 pub const GLX_SLOW_CONFIG: c_int = 0x8001;
98 pub const GLX_NON_CONFORMANT_CONFIG: c_int = 0x800d;
99 
100 // drawable type mask
101 pub const GLX_WINDOW_BIT: c_int = 0x0001;
102 pub const GLX_PIXMAP_BIT: c_int = 0x0002;
103 pub const GLX_PBUFFER_BIT: c_int = 0x0004;
104 
105 // framebuffer attributes
106 pub const GLX_USE_GL: c_int = 0x0001;
107 pub const GLX_BUFFER_SIZE: c_int = 0x0002;
108 pub const GLX_LEVEL: c_int = 0x0003;
109 pub const GLX_RGBA: c_int = 0x0004;
110 pub const GLX_DOUBLEBUFFER: c_int = 0x0005;
111 pub const GLX_STEREO: c_int = 0x0006;
112 pub const GLX_AUX_BUFFERS: c_int = 0x0007;
113 pub const GLX_RED_SIZE: c_int = 0x0008;
114 pub const GLX_GREEN_SIZE: c_int = 0x0009;
115 pub const GLX_BLUE_SIZE: c_int = 0x000a;
116 pub const GLX_ALPHA_SIZE: c_int = 0x000b;
117 pub const GLX_DEPTH_SIZE: c_int = 0x000c;
118 pub const GLX_STENCIL_SIZE: c_int = 0x000d;
119 pub const GLX_ACCUM_RED_SIZE: c_int = 0x000e;
120 pub const GLX_ACCUM_GREEN_SIZE: c_int = 0x000f;
121 pub const GLX_ACCUM_BLUE_SIZE: c_int = 0x0010;
122 pub const GLX_ACCUM_ALPHA_SIZE: c_int = 0x0011;
123 pub const GLX_CONFIG_CAVEAT: c_int = 0x0020;
124 pub const GLX_X_VISUAL_TYPE: c_int = 0x0022;
125 pub const GLX_TRANSPARENT_TYPE: c_int = 0x0023;
126 pub const GLX_TRANSPARENT_INDEX_VALUE: c_int = 0x0024;
127 pub const GLX_TRANSPARENT_RED_VALUE: c_int = 0x0025;
128 pub const GLX_TRANSPARENT_GREEN_VALUE: c_int = 0x0026;
129 pub const GLX_TRANSPARENT_BLUE_VALUE: c_int = 0x0027;
130 pub const GLX_TRANSPARENT_ALPHA_VALUE: c_int = 0x0028;
131 pub const GLX_VISUAL_ID: c_int = 0x800B;
132 pub const GLX_SCREEN: c_int = 0x800C;
133 pub const GLX_DRAWABLE_TYPE: c_int = 0x8010;
134 pub const GLX_RENDER_TYPE: c_int = 0x8011;
135 pub const GLX_X_RENDERABLE: c_int = 0x8012;
136 pub const GLX_FBCONFIG_ID: c_int = 0x8013;
137 pub const GLX_MAX_PBUFFER_WIDTH: c_int = 0x8016;
138 pub const GLX_MAX_PBUFFER_HEIGHT: c_int = 0x8017;
139 pub const GLX_MAX_PBUFFER_PIXELS: c_int = 0x8018;
140 pub const GLX_SAMPLE_BUFFERS: c_int = 0x1_86a0;
141 pub const GLX_SAMPLES: c_int = 0x1_86a1;
142 
143 // misc
144 pub const GLX_DONT_CARE: c_int = -1;
145 pub const GLX_NONE: c_int = 0x8000;
146 
147 // render type mask
148 pub const GLX_RGBA_BIT: c_int = 0x0001;
149 pub const GLX_COLOR_INDEX_BIT: c_int = 0x0002;
150 
151 // transparent types
152 pub const GLX_TRANSPARENT_RGB: c_int = 0x8008;
153 pub const GLX_TRANSPARENT_INDEX: c_int = 0x8009;
154 
155 // visual types
156 pub const GLX_TRUE_COLOR: c_int = 0x8002;
157 pub const GLX_DIRECT_COLOR: c_int = 0x8003;
158 pub const GLX_PSEUDO_COLOR: c_int = 0x8004;
159 pub const GLX_STATIC_COLOR: c_int = 0x8005;
160 pub const GLX_GRAY_SCALE: c_int = 0x8006;
161 pub const GLX_STATIC_GRAY: c_int = 0x8007;
162 
163 // glXGetConfig errors
164 pub const GLX_BAD_SCREEN: c_int = 1;
165 pub const GLX_BAD_ATTRIBUTE: c_int = 2;
166 pub const GLX_NO_EXTENSION: c_int = 3;
167 pub const GLX_BAD_VISUAL: c_int = 4;
168 pub const GLX_BAD_CONTEXT: c_int = 5;
169 pub const GLX_BAD_VALUE: c_int = 6;
170 pub const GLX_BAD_ENUM: c_int = 7;
171 
172 // glXGetClientString names
173 pub const GLX_VENDOR: c_int = 1;
174 pub const GLX_VERSION: c_int = 2;
175 pub const GLX_EXTENSIONS: c_int = 3;
176 
177 // drawable type mask?
178 pub const GLX_FRONT_LEFT_BUFFER_BIT: c_uint = 0x0001;
179 pub const GLX_FRONT_RIGHT_BUFFER_BIT: c_uint = 0x0002;
180 pub const GLX_BACK_LEFT_BUFFER_BIT: c_uint = 0x0004;
181 pub const GLX_BACK_RIGHT_BUFFER_BIT: c_uint = 0x0008;
182 pub const GLX_AUX_BUFFERS_BIT: c_uint = 0x0010;
183 pub const GLX_DEPTH_BUFFER_BIT: c_uint = 0x0020;
184 pub const GLX_STENCIL_BUFFER_BIT: c_uint = 0x0040;
185 pub const GLX_ACCUM_BUFFER_BIT: c_uint = 0080;
186 
187 // render type for glXCreateNewContext
188 pub const GLX_RGBA_TYPE: c_int = 0x8014;
189 pub const GLX_COLOR_INDEX_TYPE: c_int = 0x8015;
190 
191 // drawable attributes
192 pub const GLX_PRESERVED_CONTENTS: c_int = 0x801B;
193 pub const GLX_LARGEST_PBUFFER: c_int = 0x801C;
194 pub const GLX_WIDTH: c_int = 0x801D;
195 pub const GLX_HEIGHT: c_int = 0x801E;
196 pub const GLX_PBUFFER_HEIGHT: c_int = 0x8040;
197 pub const GLX_PBUFFER_WIDTH: c_int = 0x8041;
198 
199 // other?
200 pub const GLX_EVENT_MASK: c_int = 0x801F;
201 
202 // event mask
203 pub const GLX_PBUFFER_CLOBBER_MASK: c_ulong = 0x0800_0000;
204 
205 // event types
206 pub const GLX_DAMAGED: c_int = 0x8020;
207 pub const GLX_SAVED: c_int = 0x8021;
208 
209 // drawable types
210 pub const GLX_WINDOW: c_int = 0x8022;
211 pub const GLX_PBUFFER: c_int = 0x8023;
212 
213 
214 //
215 // ARB extensions
216 //
217 
218 
219 pub mod arb {
220   use std::os::raw::c_int;
221 
222   // context attributes
223   pub const GLX_CONTEXT_MAJOR_VERSION_ARB: c_int = 0x2091;
224   pub const GLX_CONTEXT_MINOR_VERSION_ARB: c_int = 0x2092;
225   pub const GLX_CONTEXT_FLAGS_ARB: c_int = 0x2094;
226   pub const GLX_CONTEXT_PROFILE_MASK_ARB: c_int = 0x9126;
227 
228   // context flags
229   pub const GLX_CONTEXT_DEBUG_BIT_ARB: c_int = 0x0001;
230   pub const GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB: c_int = 0x0002;
231 
232   // context profile mask
233   pub const GLX_CONTEXT_CORE_PROFILE_BIT_ARB: c_int = 0x0001;
234   pub const GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB: c_int = 0x0002;
235 }
236 
237 
238 //
239 // EXT extensions
240 //
241 
242 
243 pub mod ext {
244   use std::os::raw::c_int;
245 
246   // drawable attributes
247   pub const GLX_SWAP_INTERVAL_EXT: c_int = 0x20f1;
248   pub const GLX_MAX_SWAP_INTERVAL_EXT: c_int = 0x20f2;
249 }
250