aboutsummaryrefslogtreecommitdiffstats
path: root/src/glut/glx/glut_glxext.c
blob: 71b67e075d9537b8237405c49c6c11cca6b3c291 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

/* Copyright (c) Mark J. Kilgard, 1997. */

/* This program is freely distributable without licensing fees
   and is provided without guarantee or warrantee expressed or
   implied. This program is -not- in the public domain. */

#include <stdlib.h>
#include <string.h>
#include "glutint.h"

#if defined(GLX_VERSION_1_1)
int
__glutIsSupportedByGLX(char *extension)
{
  static const char *extensions = NULL;
  const char *start;
  char *where, *terminator;
  int major, minor;

  glXQueryVersion(__glutDisplay, &major, &minor);
  /* Be careful not to call glXQueryExtensionsString if it
     looks like the server doesn't support GLX 1.1.
     Unfortunately, the original GLX 1.0 didn't have the notion
     of GLX extensions. */
  if ((major == 1 && minor >= 1) || (major > 1)) {
    if (!extensions)
      extensions = glXQueryExtensionsString(__glutDisplay, __glutScreen);
    /* It takes a bit of care to be fool-proof about parsing
       the GLX extensions string.  Don't be fooled by
       sub-strings,  etc. */
    start = extensions;
    for (;;) {
      where = strstr(start, extension);
      if (!where)
        return 0;
      terminator = where + strlen(extension);
      if (where == start || *(where - 1) == ' ') {
        if (*terminator == ' ' || *terminator == '\0') {
          return 1;
        }
      }
      start = terminator;
    }
  }
  return 0;
}
#endif



/*
 * Wrapping of GLX extension functions.
 * Technically, we should do a runtime test to see if we've got the
 * glXGetProcAddressARB() function.  I think GLX_ARB_get_proc_address
 * is pretty widely supported now and any system that has
 * GLX_ARB_get_proc_address defined in its header files should be OK
 * at runtime.
 */

int
__glut_glXBindChannelToWindowSGIX(Display *dpy, int screen,
                                  int channel, Window window)
{
#ifdef GLX_ARB_get_proc_address
  typedef int (*glXBindChannelToWindowSGIX_t) (Display *, int, int, Window);
  static glXBindChannelToWindowSGIX_t glXBindChannelToWindowSGIX_ptr = NULL;
  if (!glXBindChannelToWindowSGIX_ptr) {
    glXBindChannelToWindowSGIX_ptr = (glXBindChannelToWindowSGIX_t)
      glXGetProcAddressARB((const GLubyte *) "glXBindChannelToWindowSGIX");
  }
  if (glXBindChannelToWindowSGIX_ptr)
    return (*glXBindChannelToWindowSGIX_ptr)(dpy, screen, channel, window);
  else
    return 0;
#elif defined(GLX_SGIX_video_resize)
  return glXBindChannelToWindowSGIX(dpy, screen, channel, window);
#else
  return 0;
#endif   
}


int
__glut_glXChannelRectSGIX(Display *dpy, int screen, int channel,
                          int x, int y, int w, int h)
{
#ifdef GLX_ARB_get_proc_address
  typedef int (*glXChannelRectSGIX_t)(Display *, int, int, int, int, int, int);
  static glXChannelRectSGIX_t glXChannelRectSGIX_ptr = NULL;
  if (!glXChannelRectSGIX_ptr) {
    glXChannelRectSGIX_ptr = (glXChannelRectSGIX_t)
      glXGetProcAddressARB((const GLubyte *) "glXChannelRectSGIX");
  }
  if (glXChannelRectSGIX_ptr)
    return (*glXChannelRectSGIX_ptr)(dpy, screen, channel, x, y, w, h);
  else
    return 0;
#elif defined(GLX_SGIX_video_resize)
  return glXChannelRectSGIX(dpy, screen, channel, x, y, w, h);
#else
  return 0;
#endif   
}


int
__glut_glXQueryChannelRectSGIX(Display *dpy, int screen, int channel,
                               int *x, int *y, int *w, int *h)
{
#ifdef GLX_ARB_get_proc_address
  typedef int (*glXQueryChannelRectSGIX_t)(Display *, int, int,
                                           int *, int *, int *, int *);
  static glXQueryChannelRectSGIX_t glXQueryChannelRectSGIX_ptr = NULL;
  if (!glXQueryChannelRectSGIX_ptr) {
    glXQueryChannelRectSGIX_ptr = (glXQueryChannelRectSGIX_t)
      glXGetProcAddressARB((const GLubyte *) "glXQueryChannelRectSGIX");
  }
  if (glXQueryChannelRectSGIX_ptr)
    return (*glXQueryChannelRectSGIX_ptr)(dpy, screen, channel, x, y, w, h);
  else
    return 0;
#elif defined(GLX_SGIX_video_resize)
  return glXQueryChannelRectSGIX(dpy, screen, channel, x, y, w, h);
#else
  return 0;
#endif   
}


int
__glut_glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel,
                                 int *dx, int *dy, int *dw, int *dh)
{
#ifdef GLX_ARB_get_proc_address
  typedef int (*glXQueryChannelDeltasSGIX_t)(Display *, int, int,
                                             int *, int *, int *, int *);
  static glXQueryChannelDeltasSGIX_t glXQueryChannelDeltasSGIX_ptr = NULL;
  if (!glXQueryChannelDeltasSGIX_ptr) {
    glXQueryChannelDeltasSGIX_ptr = (glXQueryChannelDeltasSGIX_t)
      glXGetProcAddressARB((const GLubyte *) "glXQueryChannelDeltasSGIX");
  }
  if (glXQueryChannelDeltasSGIX_ptr)
    return (*glXQueryChannelDeltasSGIX_ptr)(dpy, screen, channel,
                                            dx, dy, dw, dh);
  else
    return 0;
#elif defined(GLX_SGIX_video_resize)
  return glXQueryChannelDeltasSGIX(dpy, screen, channel, dx, dy, dw, dh);
#else
  return 0;
#endif   
}


int
__glut_glXChannelRectSyncSGIX(Display *dpy, int screen,
                              int channel, GLenum synctype)
{
#ifdef GLX_ARB_get_proc_address
  typedef int (*glXChannelRectSyncSGIX_t)(Display *, int, int, GLenum);
  static glXChannelRectSyncSGIX_t glXChannelRectSyncSGIX_ptr = NULL;
  if (!glXChannelRectSyncSGIX_ptr) {
    glXChannelRectSyncSGIX_ptr = (glXChannelRectSyncSGIX_t)
      glXGetProcAddressARB((const GLubyte *) "glXChannelRectSyncSGIX");
  }
  if (glXChannelRectSyncSGIX_ptr)
    return (*glXChannelRectSyncSGIX_ptr)(dpy, screen, channel, synctype);
  else
    return 0;
#elif defined(GLX_SGIX_video_resize)
  return glXChannelRectSyncSGIX(dpy, screen, channel, synctype);
#else
  return 0;
#endif   
}



GLXContext
__glut_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config,
                                      int render_type, GLXContext share_list,
                                      Bool direct)
{
#ifdef GLX_ARB_get_proc_address
  typedef GLXContext (*glXCreateContextWithConfigSGIX_t)(Display *,
                                 GLXFBConfigSGIX, int, GLXContext, Bool);
  static glXCreateContextWithConfigSGIX_t glXCreateContextWithConfig_ptr = NULL;
  if (!glXCreateContextWithConfig_ptr) {
    glXCreateContextWithConfig_ptr = (glXCreateContextWithConfigSGIX_t)
       glXGetProcAddressARB((const GLubyte *) "glXCreateContextWithConfigSGIX");
  }
  if (glXCreateContextWithConfig_ptr)
    return (*glXCreateContextWithConfig_ptr)(dpy, config, render_type,
                                             share_list, direct);
  else
    return 0;
#elif defined(GLX_SGIX_fbconfig)
  return glXCreateContextWithConfigSGIX(dpy, config, render_type,
                                        share_list, direct);
#else
  return 0;
#endif
}


int
__glut_glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config,
                                int attribute, int *value)
{
#ifdef GLX_ARB_get_proc_address
  typedef int (*glXGetFBConfigAttribSGIX_t)(Display *,
                                            GLXFBConfigSGIX, int, int *);
  static glXGetFBConfigAttribSGIX_t glXGetFBConfigAttrib_ptr = NULL;
  if (!glXGetFBConfigAttrib_ptr) {
    glXGetFBConfigAttrib_ptr = (glXGetFBConfigAttribSGIX_t)
       glXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
  }
  if (glXGetFBConfigAttrib_ptr)
    return (*glXGetFBConfigAttrib_ptr)(dpy, config, attribute, value);
  else
    return 0;
#elif defined(GLX_SGIX_fbconfig)
  return glXGetFBConfigAttribSGIX(dpy, config, attribute, value);
#else
  return 0;
#endif
}


GLXFBConfigSGIX
__glut_glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
{
#ifdef GLX_ARB_get_proc_address
  typedef GLXFBConfigSGIX (*glXGetFBConfigFromVisualSGIX_t)(Display *,
                                                            XVisualInfo *);
  static glXGetFBConfigFromVisualSGIX_t glXGetFBConfigFromVisual_ptr = NULL;
  if (!glXGetFBConfigFromVisual_ptr) {
    glXGetFBConfigFromVisual_ptr = (glXGetFBConfigFromVisualSGIX_t)
       glXGetProcAddressARB((const GLubyte *) "glXGetFBConfigFromVisualSGIX");
  }
  if (glXGetFBConfigFromVisual_ptr)
    return (*glXGetFBConfigFromVisual_ptr)(dpy, vis);
  else
    return 0;
#elif defined(GLX_SGIX_fbconfig)
  return glXGetFBConfigFromVisualSGIX(dpy, vis);
#else
  return 0;
#endif
}