Revert some accidental cross-merge changes. Remove i915GetString. Migrate
[mesa.git] / src / glut / dos / state.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 3.4
4 * Copyright (C) 1995-1998 Brian Paul
5 *
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.
10 *
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.
15 *
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.
19 */
20
21 /*
22 * DOS/DJGPP glut driver v1.4 for Mesa
23 *
24 * Copyright (C) 2002 - Borca Daniel
25 * Email : dborca@yahoo.com
26 * Web : http://www.geocities.com/dborca
27 */
28
29
30 #include <stdio.h>
31
32 #include "glutint.h"
33
34
35
36 #define FREQUENCY 100
37
38
39
40 static int timer_installed;
41 static volatile int ticks;
42
43
44
45 static void ticks_timer (void *p)
46 {
47 (void)p;
48 ticks++;
49 } ENDOFUNC(ticks_timer)
50
51
52
53 int APIENTRY glutGet (GLenum type)
54 {
55 switch (type) {
56 case GLUT_WINDOW_X:
57 return g_curwin->xpos;
58 case GLUT_WINDOW_Y:
59 return g_curwin->ypos;
60 case GLUT_WINDOW_WIDTH:
61 return g_curwin->width;
62 case GLUT_WINDOW_HEIGHT:
63 return g_curwin->height;
64 case GLUT_WINDOW_STENCIL_SIZE:
65 return g_stencil;
66 case GLUT_WINDOW_DEPTH_SIZE:
67 return g_depth;
68 case GLUT_WINDOW_RGBA:
69 return !(g_display_mode & GLUT_INDEX);
70 case GLUT_WINDOW_COLORMAP_SIZE:
71 return (g_display_mode & GLUT_INDEX) ? (256 - RESERVED_COLORS) : 0;
72 case GLUT_SCREEN_WIDTH:
73 return g_screen_w;
74 case GLUT_SCREEN_HEIGHT:
75 return g_screen_h;
76 case GLUT_INIT_WINDOW_X:
77 return g_init_x;
78 case GLUT_INIT_WINDOW_Y:
79 return g_init_y;
80 case GLUT_INIT_WINDOW_WIDTH:
81 return g_init_w;
82 case GLUT_INIT_WINDOW_HEIGHT:
83 return g_init_h;
84 case GLUT_INIT_DISPLAY_MODE:
85 return g_display_mode;
86 case GLUT_ELAPSED_TIME:
87 if (!timer_installed) {
88 timer_installed = GL_TRUE;
89 LOCKDATA(ticks);
90 LOCKFUNC(ticks_timer);
91 pc_install_int(ticks_timer, NULL, FREQUENCY);
92 }
93 return ticks*1000/FREQUENCY;
94 default:
95 return -1;
96 }
97 }
98
99
100
101 int APIENTRY glutDeviceGet (GLenum type)
102 {
103 switch (type) {
104 case GLUT_HAS_KEYBOARD:
105 return GL_TRUE;
106 case GLUT_HAS_MOUSE:
107 return (g_mouse != 0);
108 case GLUT_NUM_MOUSE_BUTTONS:
109 return g_mouse;
110 case GLUT_HAS_SPACEBALL:
111 case GLUT_HAS_DIAL_AND_BUTTON_BOX:
112 case GLUT_HAS_TABLET:
113 return GL_FALSE;
114 case GLUT_NUM_SPACEBALL_BUTTONS:
115 case GLUT_NUM_BUTTON_BOX_BUTTONS:
116 case GLUT_NUM_DIALS:
117 case GLUT_NUM_TABLET_BUTTONS:
118 return 0;
119 default:
120 return -1;
121 }
122 }
123
124
125
126 int APIENTRY glutGetModifiers (void)
127 {
128 int mod = 0;
129 int shifts = pc_keyshifts();
130
131 if (shifts & (KB_SHIFT_FLAG | KB_CAPSLOCK_FLAG)) {
132 mod |= GLUT_ACTIVE_SHIFT;
133 }
134
135 if (shifts & KB_ALT_FLAG) {
136 mod |= GLUT_ACTIVE_ALT;
137 }
138
139 if (shifts & KB_CTRL_FLAG) {
140 mod |= GLUT_ACTIVE_CTRL;
141 }
142
143 return mod;
144 }
145
146
147
148 /* GAME MODE
149 * Hack alert: incomplete... what is GameMode, anyway?
150 */
151 GLint g_game;
152 static GLboolean game_possible;
153 static GLboolean game_active;
154 static GLuint game_width;
155 static GLuint game_height;
156 static GLuint game_bpp;
157 static GLuint game_refresh;
158
159
160
161 void APIENTRY glutGameModeString (const char *string)
162 {
163 if (sscanf(string, "%ux%u:%u@%u", &game_width, &game_height, &game_bpp, &game_refresh) == 4) {
164 game_possible = GL_TRUE;
165 }
166 }
167
168
169
170 int APIENTRY glutGameModeGet (GLenum mode)
171 {
172 switch (mode) {
173 case GLUT_GAME_MODE_ACTIVE:
174 return game_active;
175 case GLUT_GAME_MODE_POSSIBLE:
176 return game_possible && !g_curwin;
177 case GLUT_GAME_MODE_WIDTH:
178 return game_active ? (int)game_width : -1;
179 case GLUT_GAME_MODE_HEIGHT:
180 return game_active ? (int)game_height : -1;
181 case GLUT_GAME_MODE_PIXEL_DEPTH:
182 return game_active ? (int)game_bpp : -1;
183 case GLUT_GAME_MODE_REFRESH_RATE:
184 return game_active ? (int)game_refresh : -1;
185 default:
186 return -1;
187 }
188 }
189
190
191
192 int APIENTRY glutEnterGameMode (void)
193 {
194 if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
195 g_bpp = game_bpp;
196 g_refresh = game_refresh;
197
198 glutInitWindowSize(game_width, game_height);
199
200 if ((g_game = glutCreateWindow("<game>")) > 0) {
201 game_active = GL_TRUE;
202 }
203
204 return g_game;
205 } else {
206 return 0;
207 }
208 }
209
210
211
212 void GLUTAPIENTRY glutLeaveGameMode (void)
213 {
214 if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) {
215 game_active = GL_FALSE;
216
217 glutDestroyWindow(g_game);
218 }
219 }