glut: Include X11 headers and libraries in SCons build.
[mesa.git] / src / glut / glx / glut_glxext.c
1
2 /* Copyright (c) Mark J. Kilgard, 1997. */
3
4 /* This program is freely distributable without licensing fees
5 and is provided without guarantee or warrantee expressed or
6 implied. This program is -not- in the public domain. */
7
8 #include <stdlib.h>
9 #include <string.h>
10 #include "glutint.h"
11
12 #if defined(GLX_VERSION_1_1)
13 int
14 __glutIsSupportedByGLX(char *extension)
15 {
16 static const char *extensions = NULL;
17 const char *start;
18 char *where, *terminator;
19 int major, minor;
20
21 glXQueryVersion(__glutDisplay, &major, &minor);
22 /* Be careful not to call glXQueryExtensionsString if it
23 looks like the server doesn't support GLX 1.1.
24 Unfortunately, the original GLX 1.0 didn't have the notion
25 of GLX extensions. */
26 if ((major == 1 && minor >= 1) || (major > 1)) {
27 if (!extensions)
28 extensions = glXQueryExtensionsString(__glutDisplay, __glutScreen);
29 /* It takes a bit of care to be fool-proof about parsing
30 the GLX extensions string. Don't be fooled by
31 sub-strings, etc. */
32 start = extensions;
33 for (;;) {
34 where = strstr(start, extension);
35 if (!where)
36 return 0;
37 terminator = where + strlen(extension);
38 if (where == start || *(where - 1) == ' ') {
39 if (*terminator == ' ' || *terminator == '\0') {
40 return 1;
41 }
42 }
43 start = terminator;
44 }
45 }
46 return 0;
47 }
48 #endif
49
50
51
52 /*
53 * Wrapping of GLX extension functions.
54 * Technically, we should do a runtime test to see if we've got the
55 * glXGetProcAddressARB() function. I think GLX_ARB_get_proc_address
56 * is pretty widely supported now and any system that has
57 * GLX_ARB_get_proc_address defined in its header files should be OK
58 * at runtime.
59 */
60
61 int
62 __glut_glXBindChannelToWindowSGIX(Display *dpy, int screen,
63 int channel, Window window)
64 {
65 #ifdef GLX_ARB_get_proc_address
66 typedef int (*glXBindChannelToWindowSGIX_t) (Display *, int, int, Window);
67 static glXBindChannelToWindowSGIX_t glXBindChannelToWindowSGIX_ptr = NULL;
68 if (!glXBindChannelToWindowSGIX_ptr) {
69 glXBindChannelToWindowSGIX_ptr = (glXBindChannelToWindowSGIX_t)
70 glXGetProcAddressARB((const GLubyte *) "glXBindChannelToWindowSGIX");
71 }
72 if (glXBindChannelToWindowSGIX_ptr)
73 return (*glXBindChannelToWindowSGIX_ptr)(dpy, screen, channel, window);
74 else
75 return 0;
76 #elif defined(GLX_SGIX_video_resize)
77 return glXBindChannelToWindowSGIX(dpy, screen, channel, window);
78 #else
79 return 0;
80 #endif
81 }
82
83
84 int
85 __glut_glXChannelRectSGIX(Display *dpy, int screen, int channel,
86 int x, int y, int w, int h)
87 {
88 #ifdef GLX_ARB_get_proc_address
89 typedef int (*glXChannelRectSGIX_t)(Display *, int, int, int, int, int, int);
90 static glXChannelRectSGIX_t glXChannelRectSGIX_ptr = NULL;
91 if (!glXChannelRectSGIX_ptr) {
92 glXChannelRectSGIX_ptr = (glXChannelRectSGIX_t)
93 glXGetProcAddressARB((const GLubyte *) "glXChannelRectSGIX");
94 }
95 if (glXChannelRectSGIX_ptr)
96 return (*glXChannelRectSGIX_ptr)(dpy, screen, channel, x, y, w, h);
97 else
98 return 0;
99 #elif defined(GLX_SGIX_video_resize)
100 return glXChannelRectSGIX(dpy, screen, channel, x, y, w, h);
101 #else
102 return 0;
103 #endif
104 }
105
106
107 int
108 __glut_glXQueryChannelRectSGIX(Display *dpy, int screen, int channel,
109 int *x, int *y, int *w, int *h)
110 {
111 #ifdef GLX_ARB_get_proc_address
112 typedef int (*glXQueryChannelRectSGIX_t)(Display *, int, int,
113 int *, int *, int *, int *);
114 static glXQueryChannelRectSGIX_t glXQueryChannelRectSGIX_ptr = NULL;
115 if (!glXQueryChannelRectSGIX_ptr) {
116 glXQueryChannelRectSGIX_ptr = (glXQueryChannelRectSGIX_t)
117 glXGetProcAddressARB((const GLubyte *) "glXQueryChannelRectSGIX");
118 }
119 if (glXQueryChannelRectSGIX_ptr)
120 return (*glXQueryChannelRectSGIX_ptr)(dpy, screen, channel, x, y, w, h);
121 else
122 return 0;
123 #elif defined(GLX_SGIX_video_resize)
124 return glXQueryChannelRectSGIX(dpy, screen, channel, x, y, w, h);
125 #else
126 return 0;
127 #endif
128 }
129
130
131 int
132 __glut_glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel,
133 int *dx, int *dy, int *dw, int *dh)
134 {
135 #ifdef GLX_ARB_get_proc_address
136 typedef int (*glXQueryChannelDeltasSGIX_t)(Display *, int, int,
137 int *, int *, int *, int *);
138 static glXQueryChannelDeltasSGIX_t glXQueryChannelDeltasSGIX_ptr = NULL;
139 if (!glXQueryChannelDeltasSGIX_ptr) {
140 glXQueryChannelDeltasSGIX_ptr = (glXQueryChannelDeltasSGIX_t)
141 glXGetProcAddressARB((const GLubyte *) "glXQueryChannelDeltasSGIX");
142 }
143 if (glXQueryChannelDeltasSGIX_ptr)
144 return (*glXQueryChannelDeltasSGIX_ptr)(dpy, screen, channel,
145 dx, dy, dw, dh);
146 else
147 return 0;
148 #elif defined(GLX_SGIX_video_resize)
149 return glXQueryChannelDeltasSGIX(dpy, screen, channel, dx, dy, dw, dh);
150 #else
151 return 0;
152 #endif
153 }
154
155
156 int
157 __glut_glXChannelRectSyncSGIX(Display *dpy, int screen,
158 int channel, GLenum synctype)
159 {
160 #ifdef GLX_ARB_get_proc_address
161 typedef int (*glXChannelRectSyncSGIX_t)(Display *, int, int, GLenum);
162 static glXChannelRectSyncSGIX_t glXChannelRectSyncSGIX_ptr = NULL;
163 if (!glXChannelRectSyncSGIX_ptr) {
164 glXChannelRectSyncSGIX_ptr = (glXChannelRectSyncSGIX_t)
165 glXGetProcAddressARB((const GLubyte *) "glXChannelRectSyncSGIX");
166 }
167 if (glXChannelRectSyncSGIX_ptr)
168 return (*glXChannelRectSyncSGIX_ptr)(dpy, screen, channel, synctype);
169 else
170 return 0;
171 #elif defined(GLX_SGIX_video_resize)
172 return glXChannelRectSyncSGIX(dpy, screen, channel, synctype);
173 #else
174 return 0;
175 #endif
176 }
177
178
179
180 GLXContext
181 __glut_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config,
182 int render_type, GLXContext share_list,
183 Bool direct)
184 {
185 #ifdef GLX_ARB_get_proc_address
186 typedef GLXContext (*glXCreateContextWithConfigSGIX_t)(Display *,
187 GLXFBConfigSGIX, int, GLXContext, Bool);
188 static glXCreateContextWithConfigSGIX_t glXCreateContextWithConfig_ptr = NULL;
189 if (!glXCreateContextWithConfig_ptr) {
190 glXCreateContextWithConfig_ptr = (glXCreateContextWithConfigSGIX_t)
191 glXGetProcAddressARB((const GLubyte *) "glXCreateContextWithConfigSGIX");
192 }
193 if (glXCreateContextWithConfig_ptr)
194 return (*glXCreateContextWithConfig_ptr)(dpy, config, render_type,
195 share_list, direct);
196 else
197 return 0;
198 #elif defined(GLX_SGIX_fbconfig)
199 return glXCreateContextWithConfigSGIX(dpy, config, render_type,
200 share_list, direct);
201 #else
202 return 0;
203 #endif
204 }
205
206
207 int
208 __glut_glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config,
209 int attribute, int *value)
210 {
211 #ifdef GLX_ARB_get_proc_address
212 typedef int (*glXGetFBConfigAttribSGIX_t)(Display *,
213 GLXFBConfigSGIX, int, int *);
214 static glXGetFBConfigAttribSGIX_t glXGetFBConfigAttrib_ptr = NULL;
215 if (!glXGetFBConfigAttrib_ptr) {
216 glXGetFBConfigAttrib_ptr = (glXGetFBConfigAttribSGIX_t)
217 glXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
218 }
219 if (glXGetFBConfigAttrib_ptr)
220 return (*glXGetFBConfigAttrib_ptr)(dpy, config, attribute, value);
221 else
222 return 0;
223 #elif defined(GLX_SGIX_fbconfig)
224 return glXGetFBConfigAttribSGIX(dpy, config, attribute, value);
225 #else
226 return 0;
227 #endif
228 }
229
230
231 GLXFBConfigSGIX
232 __glut_glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
233 {
234 #ifdef GLX_ARB_get_proc_address
235 typedef GLXFBConfigSGIX (*glXGetFBConfigFromVisualSGIX_t)(Display *,
236 XVisualInfo *);
237 static glXGetFBConfigFromVisualSGIX_t glXGetFBConfigFromVisual_ptr = NULL;
238 if (!glXGetFBConfigFromVisual_ptr) {
239 glXGetFBConfigFromVisual_ptr = (glXGetFBConfigFromVisualSGIX_t)
240 glXGetProcAddressARB((const GLubyte *) "glXGetFBConfigFromVisualSGIX");
241 }
242 if (glXGetFBConfigFromVisual_ptr)
243 return (*glXGetFBConfigFromVisual_ptr)(dpy, vis);
244 else
245 return 0;
246 #elif defined(GLX_SGIX_fbconfig)
247 return glXGetFBConfigFromVisualSGIX(dpy, vis);
248 #else
249 return 0;
250 #endif
251 }
252
253
254
255