reenabled loading plaques (and cleaned up that code a lot)
[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 const char *gl_vendor;
61 const char *gl_renderer;
62 const char *gl_version;
63 const char *gl_extensions;
64
65 /*-----------------------------------------------------------------------*/
66 void D_BeginDirectRect (int x, int y, qbyte *pbitmap, int width, int height)
67 {
68 }
69
70 void D_EndDirectRect (int x, int y, int width, int height)
71 {
72 }
73
74 void VID_Shutdown(void)
75 {
76         if (!fc)
77                 return;
78
79         fxMesaDestroyContext(fc);
80 }
81
82 void signal_handler(int sig)
83 {
84         printf("Received signal %d, exiting...\n", sig);
85         Host_Shutdown();
86         abort();
87         //Sys_Quit();
88         exit(0);
89 }
90
91 void InitSig(void)
92 {
93         signal(SIGHUP, signal_handler);
94         signal(SIGINT, signal_handler);
95         signal(SIGQUIT, signal_handler);
96         signal(SIGILL, signal_handler);
97         signal(SIGTRAP, signal_handler);
98 //      signal(SIGIOT, signal_handler);
99         signal(SIGBUS, signal_handler);
100 //      signal(SIGFPE, signal_handler);
101         signal(SIGSEGV, signal_handler);
102         signal(SIGTERM, signal_handler);
103 }
104
105 typedef void (GLAPIENTRY *gl3DfxSetDitherModeEXT_FUNC) (GrDitherMode_t mode);
106
107 void VID_SetupDithering(void)
108 {
109         Con_Printf ("Dithering: ");
110
111         dlhand = dlopen (NULL, RTLD_LAZY);
112
113         if (dlhand == NULL) {
114                 Con_SafePrintf ("unable to set.\n");
115                 return;
116         }
117
118         if (strstr(gl_extensions, "3DFX_set_dither_mode")) {
119                 gl3DfxSetDitherModeEXT_FUNC dither_select = NULL;
120
121                 dither_select = (void *) dlsym(dlhand, "gl3DfxSetDitherModeEXT");
122
123                 if (COM_CheckParm ("-dither_2x2")) {
124                         dither_select(GR_DITHER_2x2);
125                         Con_Printf ("2x2.\n");
126                 } else if (COM_CheckParm ("-dither_4x4")) {
127                         dither_select(GR_DITHER_4x4);
128                         Con_Printf ("4x4.\n");
129                 } else {
130                         glDisable(GL_DITHER);
131                         Con_Printf ("disabled.\n");
132                 }
133         }
134         dlclose(dlhand);
135         dlhand = NULL;
136 }
137
138 /*
139 =================
140 VID_GetWindowSize
141 =================
142 */
143 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
144 {
145         *x = *y = 0;
146         *width = scr_width;
147         *height = scr_height;
148 }
149
150 void VID_Finish (void)
151 {
152         if (r_render.integer)
153         {
154                 glFinish();
155                 fxMesaSwapBuffers();
156         }
157 }
158
159 static int resolutions[][3]={
160         { 320,  200,    GR_RESOLUTION_320x200 },
161         { 320,  240,    GR_RESOLUTION_320x240 },
162         { 400,  256,    GR_RESOLUTION_400x256 },
163         { 400,  300,    GR_RESOLUTION_400x300 },
164         { 512,  256,    GR_RESOLUTION_512x256 },
165         { 512,  384,    GR_RESOLUTION_512x384 },
166         { 640,  200,    GR_RESOLUTION_640x200 },
167         { 640,  350,    GR_RESOLUTION_640x350 },
168         { 640,  400,    GR_RESOLUTION_640x400 },
169         { 640,  480,    GR_RESOLUTION_640x480 },
170         { 800,  600,    GR_RESOLUTION_800x600 },
171         { 856,  480,    GR_RESOLUTION_856x480 },
172         { 960,  720,    GR_RESOLUTION_960x720 },
173 #ifdef GR_RESOLUTION_1024x768
174         { 1024, 768,    GR_RESOLUTION_1024x768 },
175 #endif
176 #ifdef GR_RESOLUTION_1152x864
177         { 1152, 864,    GR_RESOLUTION_1152x864 },
178 #endif
179 #ifdef GR_RESOLUTION_1280x960
180         { 1280, 960,    GR_RESOLUTION_1280x960 },
181 #endif
182 #ifdef GR_RESOLUTION_1280x1024
183         { 1280, 1024,   GR_RESOLUTION_1280x1024 },
184 #endif
185 #ifdef GR_RESOLUTION_1600x1024
186         { 1600, 1024,   GR_RESOLUTION_1600x1024 },
187 #endif
188 #ifdef GR_RESOLUTION_1600x1200
189         { 1600, 1200,   GR_RESOLUTION_1600x1200 },
190 #endif
191 #ifdef GR_RESOLUTION_1792x1344
192         { 1792, 1344,   GR_RESOLUTION_1792x1344 },
193 #endif
194 #ifdef GR_RESOLUTION_1856x1392
195         { 1856, 1392,   GR_RESOLUTION_1856x1392 },
196 #endif
197 #ifdef GR_RESOLUTION_1920x1440
198         { 1920, 1440,   GR_RESOLUTION_1920x1440 },
199 #endif
200 #ifdef GR_RESOLUTION_2048x1536
201         { 2048, 1536,   GR_RESOLUTION_2048x1536 },
202 #endif
203 #ifdef GR_RESOLUTION_2048x2048
204         { 2048, 2048,   GR_RESOLUTION_2048x2048 }
205 #endif
206 };
207
208 #define NUM_RESOLUTIONS         (sizeof(resolutions)/(sizeof(int)*3))
209
210
211 static int
212 findres(int *width, int *height)
213 {
214         int i;
215
216         for(i=0; i < NUM_RESOLUTIONS; i++) {
217                 if((*width <= resolutions[i][0]) &&
218                    (*height <= resolutions[i][1])) {
219                         *width = resolutions[i][0];
220                         *height = resolutions[i][1];
221                         return resolutions[i][2];
222                 }
223         }
224
225         *width = 640;
226         *height = 480;
227         return GR_RESOLUTION_640x480;
228 }
229
230 int VID_SetGamma(float prescale, float gamma, float scale, float base)
231 {
232         return FALSE;
233 }
234
235 void VID_Init(void)
236 {
237         int i;
238         GLint attribs[32];
239         int width = 640, height = 480;
240
241 // set vid parameters
242         attribs[0] = FXMESA_DOUBLEBUFFER;
243         attribs[1] = FXMESA_ALPHA_SIZE;
244         attribs[2] = 1;
245         attribs[3] = FXMESA_DEPTH_SIZE;
246         attribs[4] = 1;
247         attribs[5] = FXMESA_NONE;
248
249         if ((i = COM_CheckParm("-width")) != 0)
250                 width = atoi(com_argv[i+1]);
251         if ((i = COM_CheckParm("-height")) != 0)
252                 height = atoi(com_argv[i+1]);
253
254         if ((i = COM_CheckParm("-conwidth")) != 0)
255                 vid.conwidth = atoi(com_argv[i+1]);
256         else
257                 vid.conwidth = 640;
258
259         vid.conwidth &= 0xfff8; // make it a multiple of eight
260
261         if (vid.conwidth < 320)
262                 vid.conwidth = 320;
263
264         // pick a conheight that matches with correct aspect
265         vid.conheight = vid.conwidth*3 / 4;
266
267         if ((i = COM_CheckParm("-conheight")) != 0)
268                 vid.conheight = atoi(com_argv[i+1]);
269         if (vid.conheight < 200)
270                 vid.conheight = 200;
271
272         fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz,
273                 attribs);
274         if (!fc)
275                 Sys_Error("Unable to create 3DFX context.\n");
276
277         scr_width = width;
278         scr_height = height;
279
280         fxMesaMakeCurrent(fc);
281
282         if (vid.conheight > height)
283                 vid.conheight = height;
284         if (vid.conwidth > width)
285                 vid.conwidth = width;
286
287         InitSig(); // trap evil signals
288
289         GL_Init();
290
291         VID_SetupDithering(); // 3DFX specific
292
293         Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
294
295 //      vid.recalc_refdef = 1;                          // force a surface cache flush
296 }
297
298 void VID_ExtraOptionDraw(unsigned int options_draw_cursor)
299 {
300 /* Port specific Options menu entrys */
301 }
302
303 void VID_ExtraOptionCmd(int option_cursor)
304 {
305 /*
306         switch(option_cursor)
307         {
308         case 12:  // Always start with 12
309         break;
310         }
311 */
312 }
313
314 void VID_SetCaption (char *text)
315 {
316 }
317
318 void VID_HandlePause (qboolean pause)
319 {
320 }