1
2/* Copyright (c) Mark J. Kilgard, 1994, 1997, 1998. */
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 <assert.h>
9#include <stdlib.h>  /* SunOS 4 needs NULL defined for GETTIMEOFDAY macro. */
10#include "glutint.h"
11
12/* CENTRY */
13int GLUTAPIENTRY
14glutGet(GLenum param)
15{
16  Window win, root;
17  int x, y, value;
18  unsigned int width, height, border, depth;
19
20  switch (param) {
21  case GLUT_INIT_WINDOW_X:
22    return __glutInitX;
23  case GLUT_INIT_WINDOW_Y:
24    return __glutInitY;
25  case GLUT_INIT_WINDOW_WIDTH:
26    return __glutInitWidth;
27  case GLUT_INIT_WINDOW_HEIGHT:
28    return __glutInitHeight;
29  case GLUT_INIT_DISPLAY_MODE:
30    return __glutDisplayMode;
31  case GLUT_WINDOW_X:
32    XTranslateCoordinates(__glutDisplay, __glutCurrentWindow->win,
33      __glutRoot, 0, 0, &x, &y, &win);
34    return x;
35  case GLUT_WINDOW_Y:
36    XTranslateCoordinates(__glutDisplay, __glutCurrentWindow->win,
37      __glutRoot, 0, 0, &x, &y, &win);
38    return y;
39  case GLUT_WINDOW_WIDTH:
40    if (!__glutCurrentWindow->reshape) {
41      XGetGeometry(__glutDisplay, __glutCurrentWindow->win,
42        &root, &x, &y,
43        &width, &height, &border, &depth);
44      return width;
45    }
46    return __glutCurrentWindow->width;
47  case GLUT_WINDOW_HEIGHT:
48    if (!__glutCurrentWindow->reshape) {
49      XGetGeometry(__glutDisplay, __glutCurrentWindow->win,
50        &root, &x, &y,
51        &width, &height, &border, &depth);
52      return height;
53    }
54    return __glutCurrentWindow->height;
55
56#define GET_CONFIG(attrib) { \
57  if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) { \
58    glXGetConfig(__glutDisplay, __glutCurrentWindow->vis, \
59      attrib, &value); \
60  } else { \
61    glXGetConfig(__glutDisplay, __glutCurrentWindow->overlay->vis, \
62      attrib, &value); \
63  } \
64}
65
66  case GLUT_WINDOW_BUFFER_SIZE:
67    GET_CONFIG(GLX_BUFFER_SIZE);
68    return value;
69  case GLUT_WINDOW_STENCIL_SIZE:
70    GET_CONFIG(GLX_STENCIL_SIZE);
71    return value;
72  case GLUT_WINDOW_DEPTH_SIZE:
73    GET_CONFIG(GLX_DEPTH_SIZE);
74    return value;
75  case GLUT_WINDOW_RED_SIZE:
76    GET_CONFIG(GLX_RED_SIZE);
77    return value;
78  case GLUT_WINDOW_GREEN_SIZE:
79    GET_CONFIG(GLX_GREEN_SIZE);
80    return value;
81  case GLUT_WINDOW_BLUE_SIZE:
82    GET_CONFIG(GLX_BLUE_SIZE);
83    return value;
84  case GLUT_WINDOW_ALPHA_SIZE:
85    GET_CONFIG(GLX_ALPHA_SIZE);
86    return value;
87  case GLUT_WINDOW_ACCUM_RED_SIZE:
88    GET_CONFIG(GLX_ACCUM_RED_SIZE);
89    return value;
90  case GLUT_WINDOW_ACCUM_GREEN_SIZE:
91    GET_CONFIG(GLX_ACCUM_GREEN_SIZE);
92    return value;
93  case GLUT_WINDOW_ACCUM_BLUE_SIZE:
94    GET_CONFIG(GLX_ACCUM_BLUE_SIZE);
95    return value;
96  case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
97    GET_CONFIG(GLX_ACCUM_ALPHA_SIZE);
98    return value;
99  case GLUT_WINDOW_DOUBLEBUFFER:
100    GET_CONFIG(GLX_DOUBLEBUFFER);
101    return value;
102  case GLUT_WINDOW_RGBA:
103    GET_CONFIG(GLX_RGBA);
104    return value;
105  case GLUT_WINDOW_COLORMAP_SIZE:
106    GET_CONFIG(GLX_RGBA);
107    if (value) {
108      return 0;
109    } else {
110#if defined(_WIN32)
111      /* KLUDGE: we always assume 256 colors in CI mode on
112         Win32 */
113      return 256;
114#else
115      if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
116        return __glutCurrentWindow->vis->visual->map_entries;
117      } else {
118        return __glutCurrentWindow->overlay->vis->visual->map_entries;
119      }
120#endif /* _WIN32 */
121    }
122  case GLUT_WINDOW_PARENT:
123    return __glutCurrentWindow->parent ?
124      __glutCurrentWindow->parent->num + 1 : 0;
125  case GLUT_WINDOW_NUM_CHILDREN:
126    {
127      int num = 0;
128      GLUTwindow *children = __glutCurrentWindow->children;
129
130      while (children) {
131        num++;
132        children = children->siblings;
133      }
134      return num;
135    }
136  case GLUT_WINDOW_NUM_SAMPLES:
137#if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample)
138    if (__glutIsSupportedByGLX("GLX_SGIS_multisample")) {
139      GET_CONFIG(GLX_SAMPLES_SGIS);
140      return value;
141    } else {
142      return 0;
143    }
144#else
145    /* Independent of GLX server support, multisampling not
146       supported by GLX client-side. */
147    return 0;
148#endif
149  case GLUT_WINDOW_STEREO:
150    GET_CONFIG(GLX_STEREO);
151    return value;
152  case GLUT_WINDOW_CURSOR:
153    return __glutCurrentWindow->cursor;
154  case GLUT_SCREEN_WIDTH:
155    return DisplayWidth(__glutDisplay, __glutScreen);
156  case GLUT_SCREEN_HEIGHT:
157    return DisplayHeight(__glutDisplay, __glutScreen);
158  case GLUT_SCREEN_WIDTH_MM:
159    return DisplayWidthMM(__glutDisplay, __glutScreen);
160  case GLUT_SCREEN_HEIGHT_MM:
161    return DisplayHeightMM(__glutDisplay, __glutScreen);
162  case GLUT_MENU_NUM_ITEMS:
163    return __glutCurrentMenu->num;
164  case GLUT_DISPLAY_MODE_POSSIBLE:
165    {
166      XVisualInfo *vi;
167      Bool dummy, visAlloced;
168      void *fbc;
169
170#if defined(_WIN32)
171      /* Our fake glXChooseVisual (which is called by
172         __glutDetermineVisual) needs an HDC to work with, so grab one
173         from the "root" window. */
174      XHDC = GetDC(GetDesktopWindow());
175#endif
176      vi = __glutDetermineWindowVisual(&dummy, &visAlloced, &fbc);
177#if defined(_WIN32)
178      ReleaseDC(GetDesktopWindow(), XHDC);
179#endif
180      if (vi) {
181        if (visAlloced)
182          XFree(vi);
183        return 1;
184      }
185      return 0;
186    }
187  case GLUT_ELAPSED_TIME:
188    {
189#ifdef OLD_VMS
190       struct timeval6 elapsed, beginning, now;
191#else
192       struct timeval elapsed, beginning, now;
193#endif
194
195       __glutInitTime(&beginning);
196      GETTIMEOFDAY(&now);
197      TIMEDELTA(elapsed, now, beginning);
198      /* Return elapsed milliseconds. */
199#if defined(__vms) && ( __VMS_VER < 70000000 )
200      return (int) (elapsed.val / TICKS_PER_MILLISECOND);
201#else
202      return (int) ((elapsed.tv_sec * 1000) + (elapsed.tv_usec / 1000));
203#endif
204    }
205  case GLUT_WINDOW_FORMAT_ID:
206#if defined(_WIN32)
207    return GetPixelFormat(__glutCurrentWindow->hdc);
208#else
209    if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
210      return (int) __glutCurrentWindow->vis->visualid;
211    } else {
212      return (int) __glutCurrentWindow->overlay->vis->visualid;
213    }
214#endif
215  default:
216    __glutWarning("invalid glutGet parameter: %d", param);
217    return -1;
218  }
219}
220/* ENDCENTRY */
221