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>
48 #define WARP_WIDTH 320
49 #define WARP_HEIGHT 200
52 //unsigned short d_8to16table[256];
53 unsigned d_8to24table[256];
54 unsigned char d_15to8table[65536];
56 cvar_t vid_mode = {"vid_mode","0",false};
58 viddef_t vid; // global video state
60 static void *dlhand = NULL;
62 static fxMesaContext fc = NULL;
63 static int scr_width, scr_height;
65 int VID_options_items = 0;
67 /*-----------------------------------------------------------------------*/
69 //int texture_mode = GL_NEAREST;
70 //int texture_mode = GL_NEAREST_MIPMAP_NEAREST;
71 //int texture_mode = GL_NEAREST_MIPMAP_LINEAR;
72 int texture_mode = GL_LINEAR;
73 //int texture_mode = GL_LINEAR_MIPMAP_NEAREST;
74 //int texture_mode = GL_LINEAR_MIPMAP_LINEAR;
76 int texture_extension_number = 1;
78 float gldepthmin, gldepthmax;
80 const char *gl_vendor;
81 const char *gl_renderer;
82 const char *gl_version;
83 const char *gl_extensions;
85 void (*qglColorTableEXT) (int, int, int, int, int, const void*);
86 void (*qgl3DfxSetPaletteEXT) (GLuint *);
87 void (*qglMTexCoord2f) (GLenum, GLfloat, GLfloat);
88 void (*qglSelectTexture) (GLenum);
92 // LordHavoc: in GLX these are never set, simply provided to make the rest of the code work
93 qboolean is8bit = false;
94 qboolean isPermedia = false;
95 qboolean isATI = false;
96 qboolean isG200 = false;
97 qboolean isRagePro = false;
98 qboolean gl_mtexable = false;
99 qboolean gl_arrays = false;
101 /*-----------------------------------------------------------------------*/
102 void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
106 void D_EndDirectRect (int x, int y, int width, int height)
110 void VID_Shutdown(void)
115 fxMesaDestroyContext(fc);
118 void signal_handler(int sig)
120 printf("Received signal %d, exiting...\n", sig);
129 signal(SIGHUP, signal_handler);
130 signal(SIGINT, signal_handler);
131 signal(SIGQUIT, signal_handler);
132 signal(SIGILL, signal_handler);
133 signal(SIGTRAP, signal_handler);
134 // signal(SIGIOT, signal_handler);
135 signal(SIGBUS, signal_handler);
136 // signal(SIGFPE, signal_handler);
137 signal(SIGSEGV, signal_handler);
138 signal(SIGTERM, signal_handler);
142 CheckMultiTextureExtensions
144 Check for ARB, SGIS, or EXT multitexture support
147 CheckMultiTextureExtensions ( void )
149 Con_Printf ("Checking for multitexture... ");
150 if (COM_CheckParm ("-nomtex"))
152 Con_Printf ("disabled\n");
155 dlhand = dlopen (NULL, RTLD_LAZY);
158 Con_Printf ("unable to check\n");
161 if (strstr(gl_extensions, "GL_ARB_multitexture "))
163 Con_Printf ("GL_ARB_multitexture\n");
164 qglMTexCoord2f = (void *)dlsym(dlhand, "glMultiTexCoord2fARB");
165 qglSelectTexture = (void *)dlsym(dlhand, "glActiveTextureARB");
166 gl_mtex_enum = GL_TEXTURE0_ARB;
168 } else if (strstr(gl_extensions, "GL_SGIS_multitexture "))
170 Con_Printf ("GL_SGIS_multitexture\n");
171 qglMTexCoord2f = (void *)dlsym(dlhand, "glMTexCoord2fSGIS");
172 qglSelectTexture = (void *)dlsym(dlhand, "glSelectTextureSGIS");
173 gl_mtex_enum = TEXTURE0_SGIS;
176 Con_Printf ("none found\n");
183 typedef void (GLAPIENTRY *gl3DfxSetDitherModeEXT_FUNC) (GrDitherMode_t mode);
192 gl_vendor = glGetString (GL_VENDOR);
193 Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
194 gl_renderer = glGetString (GL_RENDERER);
195 Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
197 gl_version = glGetString (GL_VERSION);
198 Con_Printf ("GL_VERSION: %s\n", gl_version);
199 gl_extensions = glGetString (GL_EXTENSIONS);
200 Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
202 CheckMultiTextureExtensions ();
204 glCullFace(GL_FRONT);
205 glEnable(GL_TEXTURE_2D);
207 glEnable(GL_ALPHA_TEST);
208 glAlphaFunc(GL_GREATER, 0.666);
210 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
211 glShadeModel (GL_FLAT);
213 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
214 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
215 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
216 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
218 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
220 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
222 Con_Printf ("Dithering: ");
224 dlhand = dlopen (NULL, RTLD_LAZY);
226 if (dlhand == NULL) {
227 Con_SafePrintf ("unable to set.\n");
231 if (strstr(gl_extensions, "3DFX_set_dither_mode")) {
232 gl3DfxSetDitherModeEXT_FUNC dither_select = NULL;
234 dither_select = (void *) dlsym(dlhand, "gl3DfxSetDitherModeEXT");
236 if (COM_CheckParm ("-dither_2x2")) {
237 dither_select(GR_DITHER_2x2);
238 Con_Printf ("2x2.\n");
239 } else if (COM_CheckParm ("-dither_4x4")) {
240 dither_select(GR_DITHER_4x4);
241 Con_Printf ("4x4.\n");
243 glDisable(GL_DITHER);
244 Con_Printf ("disabled.\n");
257 void GL_BeginRendering (int *x, int *y, int *width, int *height)
261 *height = scr_height;
263 // if (!wglMakeCurrent( maindc, baseRC ))
264 // Sys_Error ("wglMakeCurrent failed");
266 // glViewport (*x, *y, *width, *height);
270 void GL_EndRendering (void)
278 static int resolutions[][3]={
279 { 320, 200, GR_RESOLUTION_320x200 },
280 { 320, 240, GR_RESOLUTION_320x240 },
281 { 400, 256, GR_RESOLUTION_400x256 },
282 { 400, 300, GR_RESOLUTION_400x300 },
283 { 512, 256, GR_RESOLUTION_512x256 },
284 { 512, 384, GR_RESOLUTION_512x384 },
285 { 640, 200, GR_RESOLUTION_640x200 },
286 { 640, 350, GR_RESOLUTION_640x350 },
287 { 640, 400, GR_RESOLUTION_640x400 },
288 { 640, 480, GR_RESOLUTION_640x480 },
289 { 800, 600, GR_RESOLUTION_800x600 },
290 { 856, 480, GR_RESOLUTION_856x480 },
291 { 960, 720, GR_RESOLUTION_960x720 },
292 #ifdef GR_RESOLUTION_1024x768
293 { 1024, 768, GR_RESOLUTION_1024x768 },
295 #ifdef GR_RESOLUTION_1152x864
296 { 1152, 864, GR_RESOLUTION_1152x864 },
298 #ifdef GR_RESOLUTION_1280x960
299 { 1280, 960, GR_RESOLUTION_1280x960 },
301 #ifdef GR_RESOLUTION_1280x1024
302 { 1280, 1024, GR_RESOLUTION_1280x1024 },
304 #ifdef GR_RESOLUTION_1600x1024
305 { 1600, 1024, GR_RESOLUTION_1600x1024 },
307 #ifdef GR_RESOLUTION_1600x1200
308 { 1600, 1200, GR_RESOLUTION_1600x1200 },
310 #ifdef GR_RESOLUTION_1792x1344
311 { 1792, 1344, GR_RESOLUTION_1792x1344 },
313 #ifdef GR_RESOLUTION_1856x1392
314 { 1856, 1392, GR_RESOLUTION_1856x1392 },
316 #ifdef GR_RESOLUTION_1920x1440
317 { 1920, 1440, GR_RESOLUTION_1920x1440 },
319 #ifdef GR_RESOLUTION_2048x1536
320 { 2048, 1536, GR_RESOLUTION_2048x1536 },
322 #ifdef GR_RESOLUTION_2048x2048
323 { 2048, 2048, GR_RESOLUTION_2048x2048 }
327 #define NUM_RESOLUTIONS (sizeof(resolutions)/(sizeof(int)*3))
331 findres(int *width, int *height)
335 for(i=0; i < NUM_RESOLUTIONS; i++) {
336 if((*width <= resolutions[i][0]) &&
337 (*height <= resolutions[i][1])) {
338 *width = resolutions[i][0];
339 *height = resolutions[i][1];
340 return resolutions[i][2];
346 return GR_RESOLUTION_640x480;
349 qboolean VID_Is8bit(void)
354 typedef void (GLAPIENTRY *glColorTableEXT_FUNC) (GLenum, GLenum, GLsizei,
355 GLenum, GLenum, const GLvoid *);
356 typedef void (GLAPIENTRY *gl3DfxSetPaletteEXT_FUNC) (GLuint *pal);
358 void VID_Init8bitPalette()
360 // Check for 8bit Extensions and initialize them.
363 dlhand = dlopen (NULL, RTLD_LAZY);
365 Con_SafePrintf ("8-bit GL extensions: ");
367 if (dlhand == NULL) {
368 Con_SafePrintf ("unable to check.\n");
372 if (COM_CheckParm("-no8bit")) {
373 Con_SafePrintf("disabled.\n");
377 if (strstr(gl_extensions, "3DFX_set_global_palette") && (qgl3DfxSetPaletteEXT = dlsym(dlhand, "gl3DfxSetPaletteEXT")) != NULL)
379 GLubyte table[256][4];
382 Con_SafePrintf("3DFX_set_global_palette.\n");
383 glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
384 oldpal = (char *) d_8to24table; //d_8to24table3dfx;
387 table[i][2] = *oldpal++;
388 table[i][1] = *oldpal++;
389 table[i][0] = *oldpal++;
393 qgl3DfxSetPaletteEXT((GLuint *)table);
395 } else if (strstr(gl_extensions, "GL_EXT_shared_texture_palette")) {
396 char thePalette[256*3];
397 char *oldPalette, *newPalette;
398 glColorTableEXT_FUNC load_texture = NULL;
400 Con_SafePrintf("GL_EXT_shared.\n");
401 load_texture = (void *) dlsym(dlhand, "glColorTableEXT");
403 glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
404 oldPalette = (char *) d_8to24table; //d_8to24table3dfx;
405 newPalette = thePalette;
406 for (i=0;i<256;i++) {
407 *newPalette++ = *oldPalette++;
408 *newPalette++ = *oldPalette++;
409 *newPalette++ = *oldPalette++;
412 load_texture(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette);
415 Con_SafePrintf ("not found.\n");
422 extern void Check_Gamma (unsigned char *pal);
423 void VID_Setup15to8Palette ();
425 void VID_Init(unsigned char *palette)
429 char gldir[MAX_OSPATH];
430 int width = 640, height = 480;
432 // set vid parameters
433 attribs[0] = FXMESA_DOUBLEBUFFER;
434 attribs[1] = FXMESA_ALPHA_SIZE;
436 attribs[3] = FXMESA_DEPTH_SIZE;
438 attribs[5] = FXMESA_NONE;
440 if ((i = COM_CheckParm("-width")) != 0)
441 width = atoi(com_argv[i+1]);
442 if ((i = COM_CheckParm("-height")) != 0)
443 height = atoi(com_argv[i+1]);
445 if ((i = COM_CheckParm("-conwidth")) != 0)
446 vid.conwidth = atoi(com_argv[i+1]);
450 vid.conwidth &= 0xfff8; // make it a multiple of eight
452 if (vid.conwidth < 320)
455 // pick a conheight that matches with correct aspect
456 vid.conheight = vid.conwidth*3 / 4;
458 if ((i = COM_CheckParm("-conheight")) != 0)
459 vid.conheight = atoi(com_argv[i+1]);
460 if (vid.conheight < 200)
463 fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz,
466 Sys_Error("Unable to create 3DFX context.\n");
471 fxMesaMakeCurrent(fc);
473 if (vid.conheight > height)
474 vid.conheight = height;
475 if (vid.conwidth > width)
476 vid.conwidth = width;
477 vid.width = vid.conwidth;
478 vid.height = vid.conheight;
480 vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
482 InitSig(); // trap evil signals
486 snprintf(gldir, sizeof(gldir), "%s/glquake", com_gamedir);
489 VID_SetPalette(palette);
491 Check_Gamma(palette);
493 // Check for 3DFX Extensions and initialize them.
494 VID_Init8bitPalette();
496 if (is8bit) // LordHavoc: avoid calculating 15to8 table if it won't be used
497 VID_Setup15to8Palette ();
499 Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
501 vid.recalc_refdef = 1; // force a surface cache flush
504 void VID_ExtraOptionDraw(unsigned int options_draw_cursor)
506 /* Port specific Options menu entrys */
509 void VID_ExtraOptionCmd(int option_cursor)
512 switch(option_cursor)
514 case 12: // Always start with 12
519 void VID_InitCvars ()
523 void VID_SetCaption (char *text)
527 void VID_HandlePause (qboolean pause)