added in_pitch_min and in_pitch_max cvars to limit pitch (default: -90 to +90)
[divverent/darkplaces.git] / vid_3dfxsvga.c
1 /*
2         vid_3dfxsvga.c
3
4         OpenGL device driver for 3Dfx chipsets running Linux
5
6         Copyright (C) 1996-1997  Id Software, Inc.
7         Copyright (C) 1999,2000  Nelson Rush.
8         Copyright (C) 1999,2000  contributors of the QuakeForge project
9         Please see the file "AUTHORS" for a list of contributors
10
11         This program is free software; you can redistribute it and/or
12         modify it under the terms of the GNU General Public License
13         as published by the Free Software Foundation; either version 2
14         of the License, or (at your option) any later version.
15
16         This program is distributed in the hope that it will be useful,
17         but WITHOUT ANY WARRANTY; without even the implied warranty of
18         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
20         See the GNU General Public License for more details.
21
22         You should have received a copy of the GNU General Public License
23         along with this program; if not, write to:
24
25                 Free Software Foundation, Inc.
26                 59 Temple Place - Suite 330
27                 Boston, MA  02111-1307, USA
28
29         $Id$
30 */
31
32 #include "quakedef.h"
33 #include "sys.h"
34 #include "console.h"
35 #include "sbar.h"
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <signal.h>
40 #include <string.h>
41
42 #include <dlfcn.h>
43
44 #include <GL/gl.h>
45 #include <GL/fxmesa.h>
46 #include <glide/sst1vid.h>
47
48
49 viddef_t        vid;    // global video state
50
51 static void     *dlhand = NULL;
52
53 static fxMesaContext fc = NULL;
54 static int      scr_width, scr_height;
55
56 int     VID_options_items = 0;
57
58 /*-----------------------------------------------------------------------*/
59
60 float           gldepthmin, gldepthmax;
61
62 const char *gl_vendor;
63 const char *gl_renderer;
64 const char *gl_version;
65 const char *gl_extensions;
66
67 /*-----------------------------------------------------------------------*/
68 void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
69 {
70 }
71
72 void D_EndDirectRect (int x, int y, int width, int height)
73 {
74 }
75
76 void VID_Shutdown(void)
77 {
78         if (!fc)
79                 return;
80
81         fxMesaDestroyContext(fc);
82 }
83
84 void signal_handler(int sig)
85 {
86         printf("Received signal %d, exiting...\n", sig);
87         Host_Shutdown();
88         abort();
89         //Sys_Quit();
90         exit(0);
91 }
92
93 void InitSig(void)
94 {
95         signal(SIGHUP, signal_handler);
96         signal(SIGINT, signal_handler);
97         signal(SIGQUIT, signal_handler);
98         signal(SIGILL, signal_handler);
99         signal(SIGTRAP, signal_handler);
100 //      signal(SIGIOT, signal_handler);
101         signal(SIGBUS, signal_handler);
102 //      signal(SIGFPE, signal_handler);
103         signal(SIGSEGV, signal_handler);
104         signal(SIGTERM, signal_handler);
105 }
106
107 typedef void (GLAPIENTRY *gl3DfxSetDitherModeEXT_FUNC) (GrDitherMode_t mode);
108
109 void VID_SetupDithering(void)
110 {
111         Con_Printf ("Dithering: ");
112
113         dlhand = dlopen (NULL, RTLD_LAZY);
114
115         if (dlhand == NULL) {
116                 Con_SafePrintf ("unable to set.\n");
117                 return;
118         }
119
120         if (strstr(gl_extensions, "3DFX_set_dither_mode")) {
121                 gl3DfxSetDitherModeEXT_FUNC dither_select = NULL;
122
123                 dither_select = (void *) dlsym(dlhand, "gl3DfxSetDitherModeEXT");
124
125                 if (COM_CheckParm ("-dither_2x2")) {
126                         dither_select(GR_DITHER_2x2);
127                         Con_Printf ("2x2.\n");
128                 } else if (COM_CheckParm ("-dither_4x4")) {
129                         dither_select(GR_DITHER_4x4);
130                         Con_Printf ("4x4.\n");
131                 } else {
132                         glDisable(GL_DITHER);
133                         Con_Printf ("disabled.\n");
134                 }
135         }
136         dlclose(dlhand);
137         dlhand = NULL;
138 }
139
140 /*
141 =================
142 VID_GetWindowSize
143 =================
144 */
145 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
146 {
147         *x = *y = 0;
148         *width = scr_width;
149         *height = scr_height;
150 }
151
152 void VID_Finish (void)
153 {
154         if (r_render.integer)
155         {
156                 glFinish();
157                 fxMesaSwapBuffers();
158         }
159 }
160
161 static int resolutions[][3]={
162         { 320,  200,    GR_RESOLUTION_320x200 },
163         { 320,  240,    GR_RESOLUTION_320x240 },
164         { 400,  256,    GR_RESOLUTION_400x256 },
165         { 400,  300,    GR_RESOLUTION_400x300 },
166         { 512,  256,    GR_RESOLUTION_512x256 },
167         { 512,  384,    GR_RESOLUTION_512x384 },
168         { 640,  200,    GR_RESOLUTION_640x200 },
169         { 640,  350,    GR_RESOLUTION_640x350 },
170         { 640,  400,    GR_RESOLUTION_640x400 },
171         { 640,  480,    GR_RESOLUTION_640x480 },
172         { 800,  600,    GR_RESOLUTION_800x600 },
173         { 856,  480,    GR_RESOLUTION_856x480 },
174         { 960,  720,    GR_RESOLUTION_960x720 },
175 #ifdef GR_RESOLUTION_1024x768
176         { 1024, 768,    GR_RESOLUTION_1024x768 },
177 #endif
178 #ifdef GR_RESOLUTION_1152x864
179         { 1152, 864,    GR_RESOLUTION_1152x864 },
180 #endif
181 #ifdef GR_RESOLUTION_1280x960
182         { 1280, 960,    GR_RESOLUTION_1280x960 },
183 #endif
184 #ifdef GR_RESOLUTION_1280x1024
185         { 1280, 1024,   GR_RESOLUTION_1280x1024 },
186 #endif
187 #ifdef GR_RESOLUTION_1600x1024
188         { 1600, 1024,   GR_RESOLUTION_1600x1024 },
189 #endif
190 #ifdef GR_RESOLUTION_1600x1200
191         { 1600, 1200,   GR_RESOLUTION_1600x1200 },
192 #endif
193 #ifdef GR_RESOLUTION_1792x1344
194         { 1792, 1344,   GR_RESOLUTION_1792x1344 },
195 #endif
196 #ifdef GR_RESOLUTION_1856x1392
197         { 1856, 1392,   GR_RESOLUTION_1856x1392 },
198 #endif
199 #ifdef GR_RESOLUTION_1920x1440
200         { 1920, 1440,   GR_RESOLUTION_1920x1440 },
201 #endif
202 #ifdef GR_RESOLUTION_2048x1536
203         { 2048, 1536,   GR_RESOLUTION_2048x1536 },
204 #endif
205 #ifdef GR_RESOLUTION_2048x2048
206         { 2048, 2048,   GR_RESOLUTION_2048x2048 }
207 #endif
208 };
209
210 #define NUM_RESOLUTIONS         (sizeof(resolutions)/(sizeof(int)*3))
211
212
213 static int
214 findres(int *width, int *height)
215 {
216         int i;
217
218         for(i=0; i < NUM_RESOLUTIONS; i++) {
219                 if((*width <= resolutions[i][0]) &&
220                    (*height <= resolutions[i][1])) {
221                         *width = resolutions[i][0];
222                         *height = resolutions[i][1];
223                         return resolutions[i][2];
224                 }
225         }
226
227         *width = 640;
228         *height = 480;
229         return GR_RESOLUTION_640x480;
230 }
231
232 int VID_SetGamma(float prescale, float gamma, float scale, float base)
233 {
234         return FALSE;
235 }
236
237 void VID_Init(void)
238 {
239         int i;
240         GLint attribs[32];
241         int width = 640, height = 480;
242
243 // set vid parameters
244         attribs[0] = FXMESA_DOUBLEBUFFER;
245         attribs[1] = FXMESA_ALPHA_SIZE;
246         attribs[2] = 1;
247         attribs[3] = FXMESA_DEPTH_SIZE;
248         attribs[4] = 1;
249         attribs[5] = FXMESA_NONE;
250
251         if ((i = COM_CheckParm("-width")) != 0)
252                 width = atoi(com_argv[i+1]);
253         if ((i = COM_CheckParm("-height")) != 0)
254                 height = atoi(com_argv[i+1]);
255
256         if ((i = COM_CheckParm("-conwidth")) != 0)
257                 vid.conwidth = atoi(com_argv[i+1]);
258         else
259                 vid.conwidth = 640;
260
261         vid.conwidth &= 0xfff8; // make it a multiple of eight
262
263         if (vid.conwidth < 320)
264                 vid.conwidth = 320;
265
266         // pick a conheight that matches with correct aspect
267         vid.conheight = vid.conwidth*3 / 4;
268
269         if ((i = COM_CheckParm("-conheight")) != 0)
270                 vid.conheight = atoi(com_argv[i+1]);
271         if (vid.conheight < 200)
272                 vid.conheight = 200;
273
274         fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz,
275                 attribs);
276         if (!fc)
277                 Sys_Error("Unable to create 3DFX context.\n");
278
279         scr_width = width;
280         scr_height = height;
281
282         fxMesaMakeCurrent(fc);
283
284         if (vid.conheight > height)
285                 vid.conheight = height;
286         if (vid.conwidth > width)
287                 vid.conwidth = width;
288
289         InitSig(); // trap evil signals
290
291         GL_Init();
292
293         VID_SetupDithering(); // 3DFX specific
294
295         Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
296
297 //      vid.recalc_refdef = 1;                          // force a surface cache flush
298 }
299
300 void VID_ExtraOptionDraw(unsigned int options_draw_cursor)
301 {
302 /* Port specific Options menu entrys */
303 }
304
305 void VID_ExtraOptionCmd(int option_cursor)
306 {
307 /*
308         switch(option_cursor)
309         {
310         case 12:  // Always start with 12
311         break;
312         }
313 */
314 }
315
316 void VID_SetCaption (char *text)
317 {
318 }
319
320 void VID_HandlePause (qboolean pause)
321 {
322 }