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