Fix a problem that caused the new interface code to not actually be
[mesa.git] / src / glut / beos / glutGet.cpp
1 /***********************************************************
2 * Copyright (C) 1997, Be Inc. All rights reserved.
3 *
4 * FILE: glutGet.cpp
5 *
6 * DESCRIPTION: get state information from GL
7 ***********************************************************/
8
9 /***********************************************************
10 * Headers
11 ***********************************************************/
12 #include <GL/glut.h>
13 #include <string.h>
14 #include <Autolock.h>
15 #include "glutint.h"
16 #include "glutState.h"
17
18 /***********************************************************
19 * Global variables
20 ***********************************************************/
21 // rough guess, since we don't know how big the monitor really is
22 const float dots_per_mm = (72/25.4); // dots per millimeter
23
24 /***********************************************************
25 * FUNCTION: glutGet (9.1)
26 *
27 * DESCRIPTION: retrieve window and GL state
28 ***********************************************************/
29 int glutGet(GLenum state) {
30 switch(state) {
31 case GLUT_WINDOW_X:
32 {BAutolock winlock(gState.currentWindow->Window()); // need to lock the window
33 if (gState.currentWindow->parent)
34 return (int)gState.currentWindow->Frame().left;
35 else
36 return (int)gState.currentWindow->Window()->Frame().left;
37 }
38 case GLUT_WINDOW_Y:
39 {BAutolock winlock(gState.currentWindow->Window());
40 if (gState.currentWindow->parent)
41 return (int)gState.currentWindow->Frame().top;
42 else
43 return (int)gState.currentWindow->Window()->Frame().top;
44 }
45 case GLUT_WINDOW_WIDTH:
46 {BAutolock winlock(gState.currentWindow->Window());
47 return gState.currentWindow->m_width;
48 }
49 case GLUT_WINDOW_HEIGHT:
50 {BAutolock winlock(gState.currentWindow->Window());
51 return gState.currentWindow->m_height;
52 }
53 case GLUT_WINDOW_PARENT:
54 {BAutolock winlock(gState.currentWindow->Window());
55 if(gState.currentWindow->parent)
56 return gState.currentWindow->parent->num + 1;
57 else
58 return 0;
59 }
60 case GLUT_WINDOW_NUM_CHILDREN:
61 {BAutolock winlock(gState.currentWindow->Window());
62 int num = 0;
63 GlutWindow *children = gState.currentWindow->children;
64 while (children) {
65 num++;
66 children = children->siblings;
67 }
68 return num;
69 }
70 case GLUT_WINDOW_BUFFER_SIZE: // best guesses
71 case GLUT_WINDOW_DEPTH_SIZE:
72 return 32;
73
74 case GLUT_WINDOW_STENCIL_SIZE:
75 case GLUT_WINDOW_RED_SIZE: // always 24-bit color
76 case GLUT_WINDOW_GREEN_SIZE:
77 case GLUT_WINDOW_BLUE_SIZE:
78 case GLUT_WINDOW_ALPHA_SIZE:
79 case GLUT_WINDOW_ACCUM_RED_SIZE:
80 case GLUT_WINDOW_ACCUM_GREEN_SIZE:
81 case GLUT_WINDOW_ACCUM_BLUE_SIZE:
82 case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
83 return 8;
84
85 case GLUT_WINDOW_DOUBLEBUFFER: // always double-buffered RGBA
86 case GLUT_WINDOW_RGBA:
87 return 1;
88
89 case GLUT_WINDOW_COLORMAP_SIZE: // don't support these
90 case GLUT_WINDOW_NUM_SAMPLES:
91 case GLUT_WINDOW_STEREO:
92 return 0;
93
94 case GLUT_WINDOW_CURSOR:
95 return gState.currentWindow->cursor; // don't need to lock window since it won't change
96
97 case GLUT_SCREEN_WIDTH:
98 return (int)(BScreen().Frame().Width()) + 1;
99 case GLUT_SCREEN_HEIGHT:
100 return (int)(BScreen().Frame().Height()) + 1;
101 case GLUT_SCREEN_WIDTH_MM:
102 return (int)((BScreen().Frame().Width() + 1) / dots_per_mm);
103 case GLUT_SCREEN_HEIGHT_MM:
104 return (int)((BScreen().Frame().Height() + 1) / dots_per_mm);
105 case GLUT_MENU_NUM_ITEMS:
106 return gState.currentMenu->num;
107 case GLUT_DISPLAY_MODE_POSSIBLE:
108 return __glutConvertDisplayMode(0); // returns 1 if possible
109 case GLUT_INIT_DISPLAY_MODE:
110 return gState.displayMode;
111 case GLUT_INIT_WINDOW_X:
112 return gState.initX;
113 case GLUT_INIT_WINDOW_Y:
114 return gState.initY;
115 case GLUT_INIT_WINDOW_WIDTH:
116 return gState.initWidth;
117 case GLUT_INIT_WINDOW_HEIGHT:
118 return gState.initHeight;
119 case GLUT_ELAPSED_TIME:
120 bigtime_t elapsed, beginning, now;
121 __glutInitTime(&beginning);
122 now = system_time();
123 elapsed = now - beginning;
124 return (int) (elapsed / 1000); // 1000 ticks in a millisecond
125 default:
126 __glutWarning("invalid glutGet parameter: %d", state);
127 return -1;
128 }
129 }
130
131 /***********************************************************
132 * FUNCTION: glutLayerGet (9.2)
133 *
134 * DESCRIPTION: since we don't support layers, this is easy
135 ***********************************************************/
136 int glutLayerGet(GLenum info) {
137 switch(info) {
138 case GLUT_OVERLAY_POSSIBLE:
139 case GLUT_HAS_OVERLAY:
140 return 0;
141 case GLUT_LAYER_IN_USE:
142 return GLUT_NORMAL;
143 case GLUT_TRANSPARENT_INDEX:
144 return -1;
145 case GLUT_NORMAL_DAMAGED:
146 return gState.currentWindow->displayEvent;
147 case GLUT_OVERLAY_DAMAGED:
148 return -1;
149 default:
150 __glutWarning("invalid glutLayerGet param: %d", info);
151 return -1;
152 }
153 }
154
155 /***********************************************************
156 * FUNCTION: glutDeviceGet (9.3)
157 *
158 * DESCRIPTION: get info about I/O devices we support
159 * easy, since BeOS only supports a keyboard and mouse now
160 ***********************************************************/
161 int glutDeviceGet(GLenum info) {
162 switch(info) {
163 case GLUT_HAS_KEYBOARD:
164 case GLUT_HAS_MOUSE:
165 return 1;
166
167 case GLUT_HAS_SPACEBALL:
168 case GLUT_HAS_DIAL_AND_BUTTON_BOX:
169 case GLUT_HAS_TABLET:
170 case GLUT_NUM_SPACEBALL_BUTTONS:
171 case GLUT_NUM_BUTTON_BOX_BUTTONS:
172 case GLUT_NUM_DIALS:
173 case GLUT_NUM_TABLET_BUTTONS:
174 return 0;
175
176 case GLUT_NUM_MOUSE_BUTTONS:
177 {
178 int32 mouseButtons = 3; // good guess
179 if(get_mouse_type(&mouseButtons) != B_OK) {
180 __glutWarning("error getting number of mouse buttons");
181 }
182 return mouseButtons;
183 }
184
185 default:
186 __glutWarning("invalid glutDeviceGet parameter: %d", info);
187 return -1;
188 }
189 }
190
191 /***********************************************************
192 * FUNCTION: glutGetModifiers (9.4)
193 *
194 * DESCRIPTION: get the modifier key state for the current window
195 ***********************************************************/
196 int glutGetModifiers() {
197 if(gState.modifierKeys == (int) ~0) {
198 __glutWarning(
199 "glutCurrentModifiers: do not call outside core input callback.");
200 return 0;
201 }
202 return gState.modifierKeys;
203 }
204
205 /***********************************************************
206 * FUNCTION: glutExtensionSupported (9.5)
207 *
208 * DESCRIPTION: is an OpenGL extension supported (from glut_ext.c)
209 ***********************************************************/
210 int glutExtensionSupported(const char *extension) {
211 static const GLubyte *extensions = NULL;
212 const GLubyte *start;
213 GLubyte *where, *terminator;
214
215 /* Extension names should not have spaces. */
216 where = (GLubyte *) strchr(extension, ' ');
217 if (where || *extension == '\0')
218 return 0;
219
220 if (!extensions)
221 extensions = glGetString(GL_EXTENSIONS);
222 /* It takes a bit of care to be fool-proof about parsing the
223 OpenGL extensions string. Don't be fooled by sub-strings,
224
225 etc. */
226 start = extensions;
227 for (;;) {
228 where = (GLubyte *) strstr((const char *) start, extension);
229 if (!where)
230 break;
231 terminator = where + strlen(extension);
232 if (where == start || *(where - 1) == ' ') {
233 if (*terminator == ' ' || *terminator == '\0') {
234 return 1;
235 }
236 }
237 start = terminator;
238 }
239 return 0;
240 }