]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - vid_3dfxsvga.c
removed unused gldir string
[xonotic/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 unsigned                d_8to24table[256];
50 unsigned char   d_15to8table[65536];
51
52 cvar_t          vid_mode = {"vid_mode","0",false};
53
54 viddef_t        vid;    // global video state
55
56 static void     *dlhand = NULL;
57
58 static fxMesaContext fc = NULL;
59 static int      scr_width, scr_height;
60
61 int     VID_options_items = 0;
62
63 /*-----------------------------------------------------------------------*/
64
65 int     texture_extension_number = 1;
66
67 float           gldepthmin, gldepthmax;
68
69 const char *gl_vendor;
70 const char *gl_renderer;
71 const char *gl_version;
72 const char *gl_extensions;
73
74 void (*qglMTexCoord2f) (GLenum, GLfloat, GLfloat);
75 void (*qglSelectTexture) (GLenum);
76
77 int gl_mtex_enum = 0;
78
79 // LordHavoc: in GLX these are never set, simply provided to make the rest of the code work
80 qboolean isG200 = false;
81 qboolean isRagePro = false;
82 qboolean gl_mtexable = false;
83 qboolean gl_arrays = false;
84
85 /*-----------------------------------------------------------------------*/
86 void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
87 {
88 }
89
90 void D_EndDirectRect (int x, int y, int width, int height)
91 {
92 }
93
94 void VID_Shutdown(void)
95 {
96         if (!fc)
97                 return;
98
99         fxMesaDestroyContext(fc);
100 }
101
102 void signal_handler(int sig)
103 {
104         printf("Received signal %d, exiting...\n", sig);
105         Host_Shutdown();
106         abort();
107         //Sys_Quit();
108         exit(0);
109 }
110
111 void InitSig(void)
112 {
113         signal(SIGHUP, signal_handler);
114         signal(SIGINT, signal_handler);
115         signal(SIGQUIT, signal_handler);
116         signal(SIGILL, signal_handler);
117         signal(SIGTRAP, signal_handler);
118 //      signal(SIGIOT, signal_handler);
119         signal(SIGBUS, signal_handler);
120 //      signal(SIGFPE, signal_handler);
121         signal(SIGSEGV, signal_handler);
122         signal(SIGTERM, signal_handler);
123 }
124
125 // LordHavoc: FIXME or something?
126 void VID_CheckVertexArrays()
127 {
128 }
129
130 /*
131         VID_CheckMultitexture
132
133         Check for ARB, SGIS, or EXT multitexture support
134 */
135 void VID_CheckMultitexture()
136 {
137         Con_Printf ("Checking for multitexture... ");
138         if (COM_CheckParm ("-nomtex"))
139         {
140                 Con_Printf ("disabled\n");
141                 return;
142         }
143         dlhand = dlopen (NULL, RTLD_LAZY);
144         if (dlhand == NULL)
145         {
146                 Con_Printf ("unable to check\n");
147                 return;
148         }
149         if (strstr(gl_extensions, "GL_ARB_multitexture "))
150         {
151                 Con_Printf ("GL_ARB_multitexture\n");
152                 qglMTexCoord2f = (void *)dlsym(dlhand, "glMultiTexCoord2fARB");
153                 qglSelectTexture = (void *)dlsym(dlhand, "glActiveTextureARB");
154                 gl_mtex_enum = GL_TEXTURE0_ARB;
155                 gl_mtexable = true;
156         }
157         else if (strstr(gl_extensions, "GL_SGIS_multitexture "))
158         {
159                 Con_Printf ("GL_SGIS_multitexture\n");
160                 qglMTexCoord2f = (void *)dlsym(dlhand, "glMTexCoord2fSGIS");
161                 qglSelectTexture = (void *)dlsym(dlhand, "glSelectTextureSGIS");
162                 gl_mtex_enum = TEXTURE0_SGIS;
163                 gl_mtexable = true;
164         }
165         else
166                 Con_Printf ("none found\n");
167         dlclose(dlhand);
168         dlhand = NULL;          
169 }
170
171
172 typedef void (GLAPIENTRY *gl3DfxSetDitherModeEXT_FUNC) (GrDitherMode_t mode);
173
174 void VID_SetupDithering()
175 {
176         Con_Printf ("Dithering: ");
177
178         dlhand = dlopen (NULL, RTLD_LAZY);
179
180         if (dlhand == NULL) {
181                 Con_SafePrintf ("unable to set.\n");
182                 return;
183         }
184
185         if (strstr(gl_extensions, "3DFX_set_dither_mode")) {
186                 gl3DfxSetDitherModeEXT_FUNC dither_select = NULL;
187
188                 dither_select = (void *) dlsym(dlhand, "gl3DfxSetDitherModeEXT");
189
190                 if (COM_CheckParm ("-dither_2x2")) {
191                         dither_select(GR_DITHER_2x2);
192                         Con_Printf ("2x2.\n");
193                 } else if (COM_CheckParm ("-dither_4x4")) {
194                         dither_select(GR_DITHER_4x4);
195                         Con_Printf ("4x4.\n");
196                 } else {
197                         glDisable(GL_DITHER);
198                         Con_Printf ("disabled.\n");
199                 }
200         }
201         dlclose(dlhand);
202         dlhand = NULL;
203 }
204
205 /*
206 =================
207 GL_BeginRendering
208
209 =================
210 */
211 void GL_BeginRendering (int *x, int *y, int *width, int *height)
212 {
213         *x = *y = 0;
214         *width = scr_width;
215         *height = scr_height;
216
217 //    if (!wglMakeCurrent( maindc, baseRC ))
218 //              Sys_Error ("wglMakeCurrent failed");
219
220 //      glViewport (*x, *y, *width, *height);
221 }
222
223
224 void GL_EndRendering (void)
225 {
226         if (!r_render.value)
227                 return;
228         glFlush();
229         fxMesaSwapBuffers();
230 }
231
232 static int resolutions[][3]={
233         { 320,  200,    GR_RESOLUTION_320x200 },
234         { 320,  240,    GR_RESOLUTION_320x240 },
235         { 400,  256,    GR_RESOLUTION_400x256 },
236         { 400,  300,    GR_RESOLUTION_400x300 },
237         { 512,  256,    GR_RESOLUTION_512x256 },
238         { 512,  384,    GR_RESOLUTION_512x384 },
239         { 640,  200,    GR_RESOLUTION_640x200 },
240         { 640,  350,    GR_RESOLUTION_640x350 },
241         { 640,  400,    GR_RESOLUTION_640x400 },
242         { 640,  480,    GR_RESOLUTION_640x480 },
243         { 800,  600,    GR_RESOLUTION_800x600 },
244         { 856,  480,    GR_RESOLUTION_856x480 },
245         { 960,  720,    GR_RESOLUTION_960x720 },
246 #ifdef GR_RESOLUTION_1024x768
247         { 1024, 768,    GR_RESOLUTION_1024x768 },
248 #endif
249 #ifdef GR_RESOLUTION_1152x864
250         { 1152, 864,    GR_RESOLUTION_1152x864 },
251 #endif
252 #ifdef GR_RESOLUTION_1280x960
253         { 1280, 960,    GR_RESOLUTION_1280x960 },
254 #endif
255 #ifdef GR_RESOLUTION_1280x1024
256         { 1280, 1024,   GR_RESOLUTION_1280x1024 },
257 #endif
258 #ifdef GR_RESOLUTION_1600x1024
259         { 1600, 1024,   GR_RESOLUTION_1600x1024 },
260 #endif
261 #ifdef GR_RESOLUTION_1600x1200
262         { 1600, 1200,   GR_RESOLUTION_1600x1200 },
263 #endif
264 #ifdef GR_RESOLUTION_1792x1344
265         { 1792, 1344,   GR_RESOLUTION_1792x1344 },
266 #endif
267 #ifdef GR_RESOLUTION_1856x1392
268         { 1856, 1392,   GR_RESOLUTION_1856x1392 },
269 #endif
270 #ifdef GR_RESOLUTION_1920x1440
271         { 1920, 1440,   GR_RESOLUTION_1920x1440 },
272 #endif
273 #ifdef GR_RESOLUTION_2048x1536
274         { 2048, 1536,   GR_RESOLUTION_2048x1536 },
275 #endif
276 #ifdef GR_RESOLUTION_2048x2048
277         { 2048, 2048,   GR_RESOLUTION_2048x2048 }
278 #endif
279 };
280
281 #define NUM_RESOLUTIONS         (sizeof(resolutions)/(sizeof(int)*3))
282
283
284 static int
285 findres(int *width, int *height)
286 {
287         int i;
288
289         for(i=0; i < NUM_RESOLUTIONS; i++) {
290                 if((*width <= resolutions[i][0]) &&
291                    (*height <= resolutions[i][1])) {
292                         *width = resolutions[i][0];
293                         *height = resolutions[i][1];
294                         return resolutions[i][2];
295                 }
296         }
297
298         *width = 640;
299         *height = 480;
300         return GR_RESOLUTION_640x480;
301 }
302
303 void VID_Init()
304 {
305         int i;
306         GLint attribs[32];
307         int width = 640, height = 480;
308
309 // set vid parameters
310         attribs[0] = FXMESA_DOUBLEBUFFER;
311         attribs[1] = FXMESA_ALPHA_SIZE;
312         attribs[2] = 1;
313         attribs[3] = FXMESA_DEPTH_SIZE;
314         attribs[4] = 1;
315         attribs[5] = FXMESA_NONE;
316
317         if ((i = COM_CheckParm("-width")) != 0)
318                 width = atoi(com_argv[i+1]);
319         if ((i = COM_CheckParm("-height")) != 0)
320                 height = atoi(com_argv[i+1]);
321
322         if ((i = COM_CheckParm("-conwidth")) != 0)
323                 vid.conwidth = atoi(com_argv[i+1]);
324         else
325                 vid.conwidth = 640;
326
327         vid.conwidth &= 0xfff8; // make it a multiple of eight
328
329         if (vid.conwidth < 320)
330                 vid.conwidth = 320;
331
332         // pick a conheight that matches with correct aspect
333         vid.conheight = vid.conwidth*3 / 4;
334
335         if ((i = COM_CheckParm("-conheight")) != 0)
336                 vid.conheight = atoi(com_argv[i+1]);
337         if (vid.conheight < 200)
338                 vid.conheight = 200;
339
340         fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz,
341                 attribs);
342         if (!fc)
343                 Sys_Error("Unable to create 3DFX context.\n");
344
345         scr_width = width;
346         scr_height = height;
347
348         fxMesaMakeCurrent(fc);
349
350         if (vid.conheight > height)
351                 vid.conheight = height;
352         if (vid.conwidth > width)
353                 vid.conwidth = width;
354         vid.width = vid.conwidth;
355         vid.height = vid.conheight;
356
357         vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
358
359         InitSig(); // trap evil signals
360
361         GL_Init();
362
363         VID_SetupDithering(); // 3DFX specific
364
365         Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
366
367         vid.recalc_refdef = 1;                          // force a surface cache flush
368 }
369
370 void VID_ExtraOptionDraw(unsigned int options_draw_cursor)
371 {
372 /* Port specific Options menu entrys */
373 }
374
375 void VID_ExtraOptionCmd(int option_cursor)
376 {
377 /*
378         switch(option_cursor)
379         {
380         case 12:  // Always start with 12
381         break;
382         }
383 */
384 }
385 void VID_InitCvars ()
386 {
387 }
388
389 void VID_SetCaption (char *text)
390 {
391 }
392
393 void VID_HandlePause (qboolean pause)
394 {
395 }