2 * Mesa 3-D graphics library
4 * Copyright (C) 1995-2006 Brian Paul
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Library for glut using mesa fbdev driver
24 * Written by Sean D'Epagnier (c) 2006
39 static int ModePossible
, DispChanged
;
40 static struct fb_var_screeninfo NormVarInfo
, GameVarInfo
;
42 static GLFBDevContextPtr GameContext
;
43 static GLFBDevVisualPtr NormVisual
;
45 /* storage for non-gamemode callbacks */
46 void (*KeyFuncs
[2])(unsigned char key
, int x
, int y
);
47 static void (*NormFuncs
[8])();
49 static const char*SetOpers(const char *p
, unsigned int *min
, unsigned int *max
)
52 int comp
= *p
, val
, neq
= 0;
59 val
= strtol(p
+1, &endptr
, 10);
81 void glutGameModeString(const char *string
)
83 const char *p
= string
;
84 unsigned int minb
= 15, maxb
= 32;
85 unsigned int minw
= 0, maxw
= -1;
86 unsigned int minh
, maxh
= -1;
87 unsigned int minf
= 0, maxf
= MAX_VSYNC
;
93 if(DisplayMode
& GLUT_INDEX
)
98 if((val
= strtol(p
, &endptr
, 10)) && *endptr
=='x') {
101 maxh
= minh
= strtol(p
, &endptr
, 10);
107 minb
= strtol(p
+1, &endptr
, 10);
109 if(DisplayMode
& GLUT_INDEX
) {
113 if(minb
!= 15 && minb
!= 16 && minb
!= 24 && minb
!= 32)
120 minf
= strtol(p
+1, &endptr
, 10) - 5;
131 if(memcmp(p
, "bpp", 3) == 0)
132 p
= SetOpers(p
+3, &minb
, &maxb
);
134 if(memcmp(p
, "height", 6) == 0)
135 p
= SetOpers(p
+6, &minh
, &maxh
);
137 if(memcmp(p
, "hertz", 5) == 0)
138 p
= SetOpers(p
+5, &minf
, &maxf
);
140 if(memcmp(p
, "width", 5) == 0)
141 p
= SetOpers(p
+5, &minw
, &maxw
);
143 if(p
= strchr(p
, ' '))
149 NormVarInfo
= VarInfo
;
150 if(!ParseFBModes(minw
, maxw
, minh
, maxh
, minf
, maxf
))
153 GameVarInfo
= VarInfo
;
154 VarInfo
= NormVarInfo
;
156 /* determine optimal bitdepth, make sure we have enough video memory */
157 if(VarInfo
.bits_per_pixel
&& VarInfo
.bits_per_pixel
<= maxb
)
158 GameVarInfo
.bits_per_pixel
= VarInfo
.bits_per_pixel
;
160 GameVarInfo
.bits_per_pixel
= maxb
;
162 while(FixedInfo
.smem_len
< GameVarInfo
.xres
* GameVarInfo
.yres
163 * GameVarInfo
.bits_per_pixel
/ 8) {
164 if(GameVarInfo
.bits_per_pixel
< minb
)
166 GameVarInfo
.bits_per_pixel
= ((GameVarInfo
.bits_per_pixel
+1)/8)*8-8;
172 int glutEnterGameMode(void)
181 if(!memcmp(&GameVarInfo
, &VarInfo
, sizeof VarInfo
)) {
188 if (ioctl(FrameBufferFD
, FBIOPUT_VSCREENINFO
, &GameVarInfo
))
191 NormVarInfo
= VarInfo
;
192 VarInfo
= GameVarInfo
;
199 if(!(GameContext
= glFBDevCreateContext(Visual
, NULL
))) {
200 sprintf(exiterror
, "Failure to create Context\n");
204 if(!glFBDevMakeCurrent( GameContext
, Buffer
, Buffer
)) {
205 sprintf(exiterror
, "Failure to Make Game Current\n");
211 KeyFuncs
[0] = KeyboardFunc
;
212 KeyFuncs
[1] = KeyboardUpFunc
;
214 NormFuncs
[0] = DisplayFunc
;
215 NormFuncs
[1] = ReshapeFunc
;
216 NormFuncs
[2] = MouseFunc
;
217 NormFuncs
[3] = MotionFunc
;
218 NormFuncs
[4] = PassiveMotionFunc
;
219 NormFuncs
[5] = VisibilityFunc
;
220 NormFuncs
[6] = SpecialFunc
;
221 NormFuncs
[7] = SpecialUpFunc
;
226 KeyboardUpFunc
= NULL
;
229 PassiveMotionFunc
= NULL
;
230 VisibilityFunc
= NULL
;
231 SpecialFunc
= SpecialUpFunc
= NULL
;
241 void glutLeaveGameMode(void)
246 glFBDevDestroyContext(GameContext
);
247 glFBDevDestroyVisual(Visual
);
249 VarInfo
= NormVarInfo
;
256 if(!glFBDevMakeCurrent( Context
, Buffer
, Buffer
)) {
257 sprintf(exiterror
, "Failure to Make Current\n");
264 KeyboardFunc
= KeyFuncs
[0];
265 KeyboardUpFunc
= KeyFuncs
[1];
267 DisplayFunc
= NormFuncs
[0];
268 ReshapeFunc
= NormFuncs
[1];
269 MouseFunc
= NormFuncs
[2];
270 MotionFunc
= NormFuncs
[3];
271 PassiveMotionFunc
= NormFuncs
[4];
272 VisibilityFunc
= NormFuncs
[5];
273 SpecialFunc
= NormFuncs
[6];
274 SpecialUpFunc
= NormFuncs
[7];
279 int glutGameModeGet(GLenum mode
) {
281 case GLUT_GAME_MODE_ACTIVE
:
283 case GLUT_GAME_MODE_POSSIBLE
:
285 case GLUT_GAME_MODE_DISPLAY_CHANGED
:
293 case GLUT_GAME_MODE_WIDTH
:
294 return GameVarInfo
.xres
;
295 case GLUT_GAME_MODE_HEIGHT
:
296 return GameVarInfo
.yres
;
297 case GLUT_GAME_MODE_PIXEL_DEPTH
:
298 return GameVarInfo
.bits_per_pixel
;
299 case GLUT_GAME_MODE_REFRESH_RATE
:
300 return 1E12
/GameVarInfo
.pixclock
301 / (GameVarInfo
.left_margin
+ GameVarInfo
.xres
302 + GameVarInfo
.right_margin
+ GameVarInfo
.hsync_len
)
303 / (GameVarInfo
.upper_margin
+ GameVarInfo
.yres
304 + GameVarInfo
.lower_margin
+ GameVarInfo
.vsync_len
);