Add comment regarding sse disable
[mesa.git] / src / glut / beos / glutInit.cpp
1 /***********************************************************
2 * Copyright (C) 1997, Be Inc. All rights reserved.
3 *
4 * FILE: glutInit.cpp
5 *
6 * DESCRIPTION: initialize GLUT state
7 ***********************************************************/
8
9 /***********************************************************
10 * Headers
11 ***********************************************************/
12 #include <GL/glut.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include "glutint.h"
16 #include "glutState.h"
17 #include "beos_x11.h"
18
19 /***********************************************************
20 * Global variables
21 ***********************************************************/
22 GlutState gState;
23
24 /***********************************************************
25 * Private variables
26 ***********************************************************/
27 static int __glutArgc;
28 static char **__glutArgv;
29
30 /***********************************************************
31 * FUNCTION: __glutInitTime
32 *
33 * DESCRIPTION: set up start time variable
34 ***********************************************************/
35 void __glutInitTime(bigtime_t *beginning)
36 {
37 static int beenhere = 0;
38 static bigtime_t genesis;
39
40 if (!beenhere) {
41 genesis = system_time();
42 beenhere = 1;
43 }
44 *beginning = genesis;
45 }
46
47 /***********************************************************
48 * FUNCTION: removeArgs
49 *
50 * DESCRIPTION: helper function for glutInit to remove args
51 * from argv variable passed in
52 ***********************************************************/
53 static void
54 removeArgs(int *argcp, char **argv, int numToRemove)
55 {
56 int i, j;
57
58 for (i = 0, j = numToRemove; argv[j]; i++, j++) {
59 argv[i] = argv[j];
60 }
61 argv[i] = NULL;
62 *argcp -= numToRemove;
63 }
64
65 /***********************************************************
66 * FUNCTION: bAppThread
67 *
68 * DESCRIPTION: starts the BApplication message loop running
69 ***********************************************************/
70 static int32 bAppThread(void *arg) {
71 be_app->Lock();
72 return be_app->Run();
73 }
74
75 /***********************************************************
76 * FUNCTION: glutInit (2.1)
77 *
78 * DESCRIPTION: create BApplication, parse cmd-line arguments,
79 * and set up gState structure.
80 ***********************************************************/
81 void glutInit(int *argcp, char **argv) {
82 char *str, *geometry = NULL;
83 int i;
84
85 if (gState.display) {
86 __glutWarning("glutInit being called a second time.");
87 return;
88 }
89 /* Determine temporary program name. */
90 str = strrchr(argv[0], '/');
91 if (str == NULL) {
92 gState.programName = argv[0];
93 } else {
94 gState.programName = str + 1;
95 }
96
97 /* Make private copy of command line arguments. */
98 __glutArgc = *argcp;
99 __glutArgv = (char **) malloc(__glutArgc * sizeof(char *));
100 if (!__glutArgv)
101 __glutFatalError("out of memory.");
102 for (i = 0; i < __glutArgc; i++) {
103 __glutArgv[i] = strdup(argv[i]);
104 if (!__glutArgv[i])
105 __glutFatalError("out of memory.");
106 }
107
108 /* determine permanent program name */
109 str = strrchr(__glutArgv[0], '/');
110 if (str == NULL) {
111 gState.programName = __glutArgv[0];
112 } else {
113 gState.programName = str + 1;
114 }
115
116 /* parse arguments for standard options */
117 for (i = 1; i < __glutArgc; i++) {
118 if (!strcmp(__glutArgv[i], "-display")) {
119 __glutWarning("-display option only valid for X glut.");
120 if (++i >= __glutArgc) {
121 __glutFatalError(
122 "follow -display option with X display name.");
123 }
124 removeArgs(argcp, &argv[1], 2);
125 } else if (!strcmp(__glutArgv[i], "-geometry")) {
126 if (++i >= __glutArgc) {
127 __glutFatalError(
128 "follow -geometry option with geometry parameter.");
129 }
130 geometry = __glutArgv[i];
131 removeArgs(argcp, &argv[1], 2);
132 } else if (!strcmp(__glutArgv[i], "-direct")) {
133 __glutWarning("-direct option only valid for X glut.");
134 removeArgs(argcp, &argv[1], 1);
135 } else if (!strcmp(__glutArgv[i], "-indirect")) {
136 __glutWarning("-indirect option only valid for X glut.");
137 removeArgs(argcp, &argv[1], 1);
138 } else if (!strcmp(__glutArgv[i], "-iconic")) {
139 __glutWarning("-iconic option doesn't make sense in BeOS.");
140 removeArgs(argcp, &argv[1], 1);
141 } else if (!strcmp(__glutArgv[i], "-gldebug")) {
142 gState.debug = true;
143 removeArgs(argcp, &argv[1], 1);
144 } else if (!strcmp(__glutArgv[i], "-sync")) {
145 __glutWarning("-sync option only valid for X glut.");
146 removeArgs(argcp, &argv[1], 1);
147 } else {
148 /* Once unknown option encountered, stop command line
149 processing. */
150 break;
151 }
152 }
153
154 __glutInit(); /* Create BApplication first so DisplayWidth() works */
155 if (geometry) {
156 int flags, x, y, width, height;
157
158 /* Fix bogus "{width|height} may be used before set"
159 warning */
160 width = 0;
161 height = 0;
162
163 flags = XParseGeometry(geometry, &x, &y,
164 (unsigned int *) &width, (unsigned int *) &height);
165 if (WidthValue & flags) {
166 /* Careful because X does not allow zero or negative
167 width windows */
168 if (width > 0)
169 gState.initWidth = width;
170 }
171 if (HeightValue & flags) {
172 /* Careful because X does not allow zero or negative
173 height windows */
174 if (height > 0)
175 gState.initHeight = height;
176 }
177 if (XValue & flags) {
178 if (XNegative & flags)
179 x = DisplayWidth() + x - gState.initWidth;
180 /* Play safe: reject negative X locations */
181 if (x >= 0)
182 gState.initX = x;
183 }
184 if (YValue & flags) {
185 if (YNegative & flags)
186 y = DisplayHeight() + y - gState.initHeight;
187 /* Play safe: reject negative Y locations */
188 if (y >= 0)
189 gState.initY = y;
190 }
191 }
192 }
193
194 /***********************************************************
195 * FUNCTION: __glutInit
196 *
197 * DESCRIPTION: create BApplication, parse cmd-line arguments,
198 * and set up gState structure.
199 ***********************************************************/
200 void __glutInit() {
201 // open BApplication
202 gState.display = new BApplication("application/x-glut-demo");
203 be_app->Unlock();
204 thread_id appthread = spawn_thread(bAppThread, "BApplication", B_NORMAL_PRIORITY, 0);
205 resume_thread(appthread);
206
207 bigtime_t unused;
208 __glutInitTime(&unused);
209 }
210
211 /***********************************************************
212 * FUNCTION: glutInitWindowPosition (2.2)
213 *
214 * DESCRIPTION: set initial window position
215 ***********************************************************/
216 void glutInitWindowPosition(int x, int y) {
217 gState.initX = x;
218 gState.initY = y;
219 }
220
221 /***********************************************************
222 * FUNCTION: glutInitWindowSize (2.2)
223 *
224 * DESCRIPTION: set initial window size
225 ***********************************************************/
226 void glutInitWindowSize(int width, int height) {
227 gState.initWidth = width;
228 gState.initHeight = height;
229 }
230
231 /***********************************************************
232 * FUNCTION: glutInitDisplayMode (2.3)
233 *
234 * DESCRIPTION: set initial display mode
235 ***********************************************************/
236 void glutInitDisplayMode(unsigned int mode) {
237 gState.displayMode = mode;
238 }