summaryrefslogtreecommitdiff
path: root/src/glut/beos/glutGet.cpp
blob: 33355afb835b820a4d2332a94788b892f7ec61af (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
/***********************************************************
 *	Copyright (C) 1997, Be Inc.  All rights reserved.
 *
 *  FILE:	glutGet.cpp
 *
 *	DESCRIPTION:	get state information from GL
 ***********************************************************/

/***********************************************************
 *	Headers
 ***********************************************************/
#include <GL/glut.h>
#include <string.h>
#include <Autolock.h>
#include "glutint.h"
#include "glutState.h"

/***********************************************************
 *	Global variables
 ***********************************************************/
// rough guess, since we don't know how big the monitor really is
const float dots_per_mm = (72/25.4);	// dots per millimeter

/***********************************************************
 *	FUNCTION:	glutGet (9.1)
 *
 *	DESCRIPTION:  retrieve window and GL state
 ***********************************************************/
int glutGet(GLenum state) {
	switch(state) {
	case GLUT_WINDOW_X:
		{BAutolock winlock(gState.currentWindow->Window());	// need to lock the window
		if (gState.currentWindow->parent)
			return (int)gState.currentWindow->Frame().left;
		else
			return (int)gState.currentWindow->Window()->Frame().left;
		}
	case GLUT_WINDOW_Y:
		{BAutolock winlock(gState.currentWindow->Window());
		if (gState.currentWindow->parent)
			return (int)gState.currentWindow->Frame().top;
		else
			return (int)gState.currentWindow->Window()->Frame().top;
		}
	case GLUT_WINDOW_WIDTH:
		{BAutolock winlock(gState.currentWindow->Window());
		return gState.currentWindow->m_width;
		}
	case GLUT_WINDOW_HEIGHT:
		{BAutolock winlock(gState.currentWindow->Window());
		return gState.currentWindow->m_height;
		}
	case GLUT_WINDOW_PARENT:
		{BAutolock winlock(gState.currentWindow->Window());
		if(gState.currentWindow->parent)
			return gState.currentWindow->parent->num + 1;
		else
			return 0;
		}
	case GLUT_WINDOW_NUM_CHILDREN:
		{BAutolock winlock(gState.currentWindow->Window());
		int num = 0;
		GlutWindow *children = gState.currentWindow->children;
		while (children) {
			num++;
			children = children->siblings;
		}
		return num; 
		}
  case GLUT_WINDOW_BUFFER_SIZE:	// best guesses
  case GLUT_WINDOW_DEPTH_SIZE:
        return 32;

  case GLUT_WINDOW_STENCIL_SIZE:
  case GLUT_WINDOW_RED_SIZE:		// always 24-bit color
  case GLUT_WINDOW_GREEN_SIZE:
  case GLUT_WINDOW_BLUE_SIZE:
  case GLUT_WINDOW_ALPHA_SIZE:
  case GLUT_WINDOW_ACCUM_RED_SIZE:
  case GLUT_WINDOW_ACCUM_GREEN_SIZE:
  case GLUT_WINDOW_ACCUM_BLUE_SIZE:
  case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
        return 8;

  case GLUT_WINDOW_DOUBLEBUFFER:	// always double-buffered RGBA
  case GLUT_WINDOW_RGBA:
        return 1;

  case GLUT_WINDOW_COLORMAP_SIZE:	// don't support these
  case GLUT_WINDOW_NUM_SAMPLES:
  case GLUT_WINDOW_STEREO:
        return 0;
 
 	case GLUT_WINDOW_CURSOR:
 		return gState.currentWindow->cursor;	// don't need to lock window since it won't change

	case GLUT_SCREEN_WIDTH:
		return (int)(BScreen().Frame().Width()) + 1;
	case GLUT_SCREEN_HEIGHT:
		return (int)(BScreen().Frame().Height()) + 1;
	case GLUT_SCREEN_WIDTH_MM:
		return (int)((BScreen().Frame().Width() + 1) / dots_per_mm);
	case GLUT_SCREEN_HEIGHT_MM:
		return (int)((BScreen().Frame().Height() + 1) / dots_per_mm);
	case GLUT_MENU_NUM_ITEMS:
		return gState.currentMenu->num;
	case GLUT_DISPLAY_MODE_POSSIBLE:
		return __glutConvertDisplayMode(0);	// returns 1 if possible
	case GLUT_INIT_DISPLAY_MODE:
		return gState.displayMode;
	case GLUT_INIT_WINDOW_X:
		return gState.initX;
	case GLUT_INIT_WINDOW_Y:
		return gState.initY;
	case GLUT_INIT_WINDOW_WIDTH:
		return gState.initWidth;
	case GLUT_INIT_WINDOW_HEIGHT:
		return gState.initHeight;
	case GLUT_ELAPSED_TIME:
		bigtime_t elapsed, beginning, now;
		__glutInitTime(&beginning);
		now = system_time();
		elapsed = now - beginning;
		return (int) (elapsed / 1000);	// 1000 ticks in a millisecond
	default:
		__glutWarning("invalid glutGet parameter: %d", state);
		return -1;
	}
}

/***********************************************************
 *	FUNCTION:	glutLayerGet (9.2)
 *
 *	DESCRIPTION:  since we don't support layers, this is easy
 ***********************************************************/
int glutLayerGet(GLenum info) {
	switch(info) {
	case GLUT_OVERLAY_POSSIBLE:
	case GLUT_HAS_OVERLAY:
		return 0;
	case GLUT_LAYER_IN_USE:
		return GLUT_NORMAL;
	case GLUT_TRANSPARENT_INDEX:
		return -1;
	case GLUT_NORMAL_DAMAGED:
		return gState.currentWindow->displayEvent;
	case GLUT_OVERLAY_DAMAGED:
		return -1;
	default:
		__glutWarning("invalid glutLayerGet param: %d", info);
		return -1;
	}
}

/***********************************************************
 *	FUNCTION:	glutDeviceGet (9.3)
 *
 *	DESCRIPTION:  get info about I/O devices we support
 *		easy, since BeOS only supports a keyboard and mouse now
 ***********************************************************/
int glutDeviceGet(GLenum info) {
	switch(info) {
	case GLUT_HAS_KEYBOARD:
	case GLUT_HAS_MOUSE:
		return 1;

	case GLUT_HAS_SPACEBALL:
	case GLUT_HAS_DIAL_AND_BUTTON_BOX:
	case GLUT_HAS_TABLET:
	case GLUT_NUM_SPACEBALL_BUTTONS:
	case GLUT_NUM_BUTTON_BOX_BUTTONS:
	case GLUT_NUM_DIALS:
	case GLUT_NUM_TABLET_BUTTONS:
		return 0;
	
	case GLUT_NUM_MOUSE_BUTTONS:
	    {
		int32 mouseButtons = 3;		// good guess
		if(get_mouse_type(&mouseButtons) != B_OK) {
			__glutWarning("error getting number of mouse buttons");
		}
		return mouseButtons;
	    }

	default:
		__glutWarning("invalid glutDeviceGet parameter: %d", info);
		return -1;
	}
}

/***********************************************************
 *	FUNCTION:	glutGetModifiers (9.4)
 *
 *	DESCRIPTION:  get the modifier key state for the current window
 ***********************************************************/
int glutGetModifiers() {
	if(gState.modifierKeys == (int) ~0) {
	  __glutWarning(
		"glutCurrentModifiers: do not call outside core input callback.");
    return 0;
	}
	return gState.modifierKeys;
}

/***********************************************************
 *	FUNCTION:	glutExtensionSupported (9.5)
 *
 *	DESCRIPTION:  is an OpenGL extension supported (from glut_ext.c)
 ***********************************************************/
int glutExtensionSupported(const char *extension) {
  static const GLubyte *extensions = NULL;
  const GLubyte *start;
  GLubyte *where, *terminator;

  /* Extension names should not have spaces. */
  where = (GLubyte *) strchr(extension, ' ');
  if (where || *extension == '\0')
    return 0;

  if (!extensions)
    extensions = glGetString(GL_EXTENSIONS);
  /* It takes a bit of care to be fool-proof about parsing the
     OpenGL extensions string.  Don't be fooled by sub-strings, 

     etc. */
  start = extensions;
  for (;;) {
    where = (GLubyte *) strstr((const char *) start, extension);
    if (!where)
      break;
    terminator = where + strlen(extension);
    if (where == start || *(where - 1) == ' ') {
      if (*terminator == ' ' || *terminator == '\0') {
        return 1;
      }
    }
    start = terminator;
  }
  return 0;
}