]> icculus.org git repositories - divverent/darkplaces.git/blob - vid_3dfxsvga.c
converted script loading to use COM_LoadMallocFile instead of COM_LoadHunkFile
[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 /*
108         VID_CheckMultitexture
109
110         Check for ARB, SGIS, or EXT multitexture support
111 */
112 void VID_CheckMultitexture(void)
113 {
114         Con_Printf ("Checking for multitexture... ");
115         if (COM_CheckParm ("-nomtex"))
116         {
117                 Con_Printf ("disabled\n");
118                 return;
119         }
120         dlhand = dlopen (NULL, RTLD_LAZY);
121         if (dlhand == NULL)
122         {
123                 Con_Printf ("unable to check\n");
124                 return;
125         }
126         if (strstr(gl_extensions, "GL_ARB_multitexture "))
127         {
128                 Con_Printf ("GL_ARB_multitexture\n");
129                 qglMTexCoord2f = (void *)dlsym(dlhand, "glMultiTexCoord2fARB");
130                 qglSelectTexture = (void *)dlsym(dlhand, "glActiveTextureARB");
131                 gl_mtex_enum = GL_TEXTURE0_ARB;
132                 gl_mtexable = true;
133         }
134         else if (strstr(gl_extensions, "GL_SGIS_multitexture "))
135         {
136                 Con_Printf ("GL_SGIS_multitexture\n");
137                 qglMTexCoord2f = (void *)dlsym(dlhand, "glMTexCoord2fSGIS");
138                 qglSelectTexture = (void *)dlsym(dlhand, "glSelectTextureSGIS");
139                 gl_mtex_enum = TEXTURE0_SGIS;
140                 gl_mtexable = true;
141         }
142         else
143                 Con_Printf ("none found\n");
144         dlclose(dlhand);
145         dlhand = NULL;
146 }
147
148 void VID_CheckCVA(void)
149 {
150         qglLockArraysEXT = NULL;
151         qglUnlockArraysEXT = NULL;
152         gl_supportslockarrays = false;
153         if (COM_CheckParm("-nocva"))
154         {
155                 Con_Printf("...compiled vertex arrays disabled\n");
156                 return;
157         }
158         dlhand = dlopen (NULL, RTLD_LAZY);
159         if (dlhand == NULL)
160         {
161                 Con_Printf("Unable to open symbol list for main program.\n");
162                 return;
163         }
164         if (strstr(gl_extensions, "GL_EXT_compiled_vertex_array"))
165         {
166                 Con_Printf("...using compiled vertex arrays\n");
167                 qglLockArraysEXT = (void *) dlsym(dlhand, "glLockArraysEXT");
168                 qglUnlockArraysEXT = (void *) dlsym(dlhand, "glUnlockArraysEXT");
169                 gl_supportslockarrays = true;
170         }
171         dlclose(dlhand);
172         dlhand = NULL;
173 }
174
175
176 typedef void (GLAPIENTRY *gl3DfxSetDitherModeEXT_FUNC) (GrDitherMode_t mode);
177
178 void VID_SetupDithering(void)
179 {
180         Con_Printf ("Dithering: ");
181
182         dlhand = dlopen (NULL, RTLD_LAZY);
183
184         if (dlhand == NULL) {
185                 Con_SafePrintf ("unable to set.\n");
186                 return;
187         }
188
189         if (strstr(gl_extensions, "3DFX_set_dither_mode")) {
190                 gl3DfxSetDitherModeEXT_FUNC dither_select = NULL;
191
192                 dither_select = (void *) dlsym(dlhand, "gl3DfxSetDitherModeEXT");
193
194                 if (COM_CheckParm ("-dither_2x2")) {
195                         dither_select(GR_DITHER_2x2);
196                         Con_Printf ("2x2.\n");
197                 } else if (COM_CheckParm ("-dither_4x4")) {
198                         dither_select(GR_DITHER_4x4);
199                         Con_Printf ("4x4.\n");
200                 } else {
201                         glDisable(GL_DITHER);
202                         Con_Printf ("disabled.\n");
203                 }
204         }
205         dlclose(dlhand);
206         dlhand = NULL;
207 }
208
209 /*
210 =================
211 GL_BeginRendering
212
213 =================
214 */
215 void GL_BeginRendering (int *x, int *y, int *width, int *height)
216 {
217         *x = *y = 0;
218         *width = scr_width;
219         *height = scr_height;
220
221 //    if (!wglMakeCurrent( maindc, baseRC ))
222 //              Sys_Error ("wglMakeCurrent failed");
223
224 //      glViewport (*x, *y, *width, *height);
225 }
226
227
228 void GL_EndRendering (void)
229 {
230         if (!r_render.value)
231                 return;
232         glFlush();
233         fxMesaSwapBuffers();
234 }
235
236 static int resolutions[][3]={
237         { 320,  200,    GR_RESOLUTION_320x200 },
238         { 320,  240,    GR_RESOLUTION_320x240 },
239         { 400,  256,    GR_RESOLUTION_400x256 },
240         { 400,  300,    GR_RESOLUTION_400x300 },
241         { 512,  256,    GR_RESOLUTION_512x256 },
242         { 512,  384,    GR_RESOLUTION_512x384 },
243         { 640,  200,    GR_RESOLUTION_640x200 },
244         { 640,  350,    GR_RESOLUTION_640x350 },
245         { 640,  400,    GR_RESOLUTION_640x400 },
246         { 640,  480,    GR_RESOLUTION_640x480 },
247         { 800,  600,    GR_RESOLUTION_800x600 },
248         { 856,  480,    GR_RESOLUTION_856x480 },
249         { 960,  720,    GR_RESOLUTION_960x720 },
250 #ifdef GR_RESOLUTION_1024x768
251         { 1024, 768,    GR_RESOLUTION_1024x768 },
252 #endif
253 #ifdef GR_RESOLUTION_1152x864
254         { 1152, 864,    GR_RESOLUTION_1152x864 },
255 #endif
256 #ifdef GR_RESOLUTION_1280x960
257         { 1280, 960,    GR_RESOLUTION_1280x960 },
258 #endif
259 #ifdef GR_RESOLUTION_1280x1024
260         { 1280, 1024,   GR_RESOLUTION_1280x1024 },
261 #endif
262 #ifdef GR_RESOLUTION_1600x1024
263         { 1600, 1024,   GR_RESOLUTION_1600x1024 },
264 #endif
265 #ifdef GR_RESOLUTION_1600x1200
266         { 1600, 1200,   GR_RESOLUTION_1600x1200 },
267 #endif
268 #ifdef GR_RESOLUTION_1792x1344
269         { 1792, 1344,   GR_RESOLUTION_1792x1344 },
270 #endif
271 #ifdef GR_RESOLUTION_1856x1392
272         { 1856, 1392,   GR_RESOLUTION_1856x1392 },
273 #endif
274 #ifdef GR_RESOLUTION_1920x1440
275         { 1920, 1440,   GR_RESOLUTION_1920x1440 },
276 #endif
277 #ifdef GR_RESOLUTION_2048x1536
278         { 2048, 1536,   GR_RESOLUTION_2048x1536 },
279 #endif
280 #ifdef GR_RESOLUTION_2048x2048
281         { 2048, 2048,   GR_RESOLUTION_2048x2048 }
282 #endif
283 };
284
285 #define NUM_RESOLUTIONS         (sizeof(resolutions)/(sizeof(int)*3))
286
287
288 static int
289 findres(int *width, int *height)
290 {
291         int i;
292
293         for(i=0; i < NUM_RESOLUTIONS; i++) {
294                 if((*width <= resolutions[i][0]) &&
295                    (*height <= resolutions[i][1])) {
296                         *width = resolutions[i][0];
297                         *height = resolutions[i][1];
298                         return resolutions[i][2];
299                 }
300         }
301
302         *width = 640;
303         *height = 480;
304         return GR_RESOLUTION_640x480;
305 }
306
307 int VID_SetGamma(float prescale, float gamma, float scale, float base)
308 {
309         return FALSE;
310 }
311
312 void VID_Init(void)
313 {
314         int i;
315         GLint attribs[32];
316         int width = 640, height = 480;
317
318 // set vid parameters
319         attribs[0] = FXMESA_DOUBLEBUFFER;
320         attribs[1] = FXMESA_ALPHA_SIZE;
321         attribs[2] = 1;
322         attribs[3] = FXMESA_DEPTH_SIZE;
323         attribs[4] = 1;
324         attribs[5] = FXMESA_NONE;
325
326         if ((i = COM_CheckParm("-width")) != 0)
327                 width = atoi(com_argv[i+1]);
328         if ((i = COM_CheckParm("-height")) != 0)
329                 height = atoi(com_argv[i+1]);
330
331         if ((i = COM_CheckParm("-conwidth")) != 0)
332                 vid.conwidth = atoi(com_argv[i+1]);
333         else
334                 vid.conwidth = 640;
335
336         vid.conwidth &= 0xfff8; // make it a multiple of eight
337
338         if (vid.conwidth < 320)
339                 vid.conwidth = 320;
340
341         // pick a conheight that matches with correct aspect
342         vid.conheight = vid.conwidth*3 / 4;
343
344         if ((i = COM_CheckParm("-conheight")) != 0)
345                 vid.conheight = atoi(com_argv[i+1]);
346         if (vid.conheight < 200)
347                 vid.conheight = 200;
348
349         fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz,
350                 attribs);
351         if (!fc)
352                 Sys_Error("Unable to create 3DFX context.\n");
353
354         scr_width = width;
355         scr_height = height;
356
357         fxMesaMakeCurrent(fc);
358
359         if (vid.conheight > height)
360                 vid.conheight = height;
361         if (vid.conwidth > width)
362                 vid.conwidth = width;
363         vid.width = vid.conwidth;
364         vid.height = vid.conheight;
365
366         vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
367
368         InitSig(); // trap evil signals
369
370         GL_Init();
371
372         VID_SetupDithering(); // 3DFX specific
373
374         Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
375
376         vid.recalc_refdef = 1;                          // force a surface cache flush
377 }
378
379 void VID_ExtraOptionDraw(unsigned int options_draw_cursor)
380 {
381 /* Port specific Options menu entrys */
382 }
383
384 void VID_ExtraOptionCmd(int option_cursor)
385 {
386 /*
387         switch(option_cursor)
388         {
389         case 12:  // Always start with 12
390         break;
391         }
392 */
393 }
394
395 void VID_SetCaption (char *text)
396 {
397 }
398
399 void VID_HandlePause (qboolean pause)
400 {
401 }