4 OpenGL device driver for 3Dfx chipsets running Linux
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
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.
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.
20 See the GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to:
25 Free Software Foundation, Inc.
26 59 Temple Place - Suite 330
27 Boston, MA 02111-1307, USA
45 #include <GL/fxmesa.h>
46 #include <glide/sst1vid.h>
49 unsigned d_8to24table[256];
50 unsigned char d_15to8table[65536];
52 cvar_t vid_mode = {"vid_mode","0",false};
54 viddef_t vid; // global video state
56 static void *dlhand = NULL;
58 static fxMesaContext fc = NULL;
59 static int scr_width, scr_height;
61 int VID_options_items = 0;
63 /*-----------------------------------------------------------------------*/
65 int texture_extension_number = 1;
67 float gldepthmin, gldepthmax;
69 const char *gl_vendor;
70 const char *gl_renderer;
71 const char *gl_version;
72 const char *gl_extensions;
74 void (*qglMTexCoord2f) (GLenum, GLfloat, GLfloat);
75 void (*qglSelectTexture) (GLenum);
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;
85 /*-----------------------------------------------------------------------*/
86 void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
90 void D_EndDirectRect (int x, int y, int width, int height)
94 void VID_Shutdown(void)
99 fxMesaDestroyContext(fc);
102 void signal_handler(int sig)
104 printf("Received signal %d, exiting...\n", sig);
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);
125 // LordHavoc: FIXME or something?
126 void VID_CheckVertexArrays()
131 VID_CheckMultitexture
133 Check for ARB, SGIS, or EXT multitexture support
135 void VID_CheckMultitexture()
137 Con_Printf ("Checking for multitexture... ");
138 if (COM_CheckParm ("-nomtex"))
140 Con_Printf ("disabled\n");
143 dlhand = dlopen (NULL, RTLD_LAZY);
146 Con_Printf ("unable to check\n");
149 if (strstr(gl_extensions, "GL_ARB_multitexture "))
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;
157 else if (strstr(gl_extensions, "GL_SGIS_multitexture "))
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;
166 Con_Printf ("none found\n");
172 typedef void (GLAPIENTRY *gl3DfxSetDitherModeEXT_FUNC) (GrDitherMode_t mode);
174 void VID_SetupDithering()
176 Con_Printf ("Dithering: ");
178 dlhand = dlopen (NULL, RTLD_LAZY);
180 if (dlhand == NULL) {
181 Con_SafePrintf ("unable to set.\n");
185 if (strstr(gl_extensions, "3DFX_set_dither_mode")) {
186 gl3DfxSetDitherModeEXT_FUNC dither_select = NULL;
188 dither_select = (void *) dlsym(dlhand, "gl3DfxSetDitherModeEXT");
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");
197 glDisable(GL_DITHER);
198 Con_Printf ("disabled.\n");
211 void GL_BeginRendering (int *x, int *y, int *width, int *height)
215 *height = scr_height;
217 // if (!wglMakeCurrent( maindc, baseRC ))
218 // Sys_Error ("wglMakeCurrent failed");
220 // glViewport (*x, *y, *width, *height);
224 void GL_EndRendering (void)
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 },
249 #ifdef GR_RESOLUTION_1152x864
250 { 1152, 864, GR_RESOLUTION_1152x864 },
252 #ifdef GR_RESOLUTION_1280x960
253 { 1280, 960, GR_RESOLUTION_1280x960 },
255 #ifdef GR_RESOLUTION_1280x1024
256 { 1280, 1024, GR_RESOLUTION_1280x1024 },
258 #ifdef GR_RESOLUTION_1600x1024
259 { 1600, 1024, GR_RESOLUTION_1600x1024 },
261 #ifdef GR_RESOLUTION_1600x1200
262 { 1600, 1200, GR_RESOLUTION_1600x1200 },
264 #ifdef GR_RESOLUTION_1792x1344
265 { 1792, 1344, GR_RESOLUTION_1792x1344 },
267 #ifdef GR_RESOLUTION_1856x1392
268 { 1856, 1392, GR_RESOLUTION_1856x1392 },
270 #ifdef GR_RESOLUTION_1920x1440
271 { 1920, 1440, GR_RESOLUTION_1920x1440 },
273 #ifdef GR_RESOLUTION_2048x1536
274 { 2048, 1536, GR_RESOLUTION_2048x1536 },
276 #ifdef GR_RESOLUTION_2048x2048
277 { 2048, 2048, GR_RESOLUTION_2048x2048 }
281 #define NUM_RESOLUTIONS (sizeof(resolutions)/(sizeof(int)*3))
285 findres(int *width, int *height)
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];
300 return GR_RESOLUTION_640x480;
307 char gldir[MAX_OSPATH];
308 int width = 640, height = 480;
310 // set vid parameters
311 attribs[0] = FXMESA_DOUBLEBUFFER;
312 attribs[1] = FXMESA_ALPHA_SIZE;
314 attribs[3] = FXMESA_DEPTH_SIZE;
316 attribs[5] = FXMESA_NONE;
318 if ((i = COM_CheckParm("-width")) != 0)
319 width = atoi(com_argv[i+1]);
320 if ((i = COM_CheckParm("-height")) != 0)
321 height = atoi(com_argv[i+1]);
323 if ((i = COM_CheckParm("-conwidth")) != 0)
324 vid.conwidth = atoi(com_argv[i+1]);
328 vid.conwidth &= 0xfff8; // make it a multiple of eight
330 if (vid.conwidth < 320)
333 // pick a conheight that matches with correct aspect
334 vid.conheight = vid.conwidth*3 / 4;
336 if ((i = COM_CheckParm("-conheight")) != 0)
337 vid.conheight = atoi(com_argv[i+1]);
338 if (vid.conheight < 200)
341 fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz,
344 Sys_Error("Unable to create 3DFX context.\n");
349 fxMesaMakeCurrent(fc);
351 if (vid.conheight > height)
352 vid.conheight = height;
353 if (vid.conwidth > width)
354 vid.conwidth = width;
355 vid.width = vid.conwidth;
356 vid.height = vid.conheight;
358 vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
360 InitSig(); // trap evil signals
364 VID_SetupDithering(); // 3DFX specific
366 Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
368 vid.recalc_refdef = 1; // force a surface cache flush
371 void VID_ExtraOptionDraw(unsigned int options_draw_cursor)
373 /* Port specific Options menu entrys */
376 void VID_ExtraOptionCmd(int option_cursor)
379 switch(option_cursor)
381 case 12: // Always start with 12
386 void VID_InitCvars ()
390 void VID_SetCaption (char *text)
394 void VID_HandlePause (qboolean pause)