1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Main windowed and fullscreen graphics interface module. This module
// is used for both the software and OpenGL rendering versions of the
// Quake refresh engine.
#include "cl_local.h"
#include "vid_public.h"
#include "vid_local.h"
// Structure containing functions exported from refresh DLL
refAPI_t ref;
// Console variables that we need to access from this module
cvar_t *vid_ref; // Name of Refresh DLL loaded
cvar_t *vid_placement;
cvar_t *vid_modelist;
cvar_t *vid_fullscreen;
#define MODE_PLACEMENT 1
#define MODE_FULLSCREEN 2
#define MODE_MODELIST 4
#define MODE_REFRESH 8
static int mode_changed;
#ifdef REF_HARD_LINKED
qboolean Ref_APISetupCallback( api_type_t type, void *api );
#else
// Global variables used internally by this module
static void *reflib_library; // Handle to refresh DLL
#endif
/*
==========================================================================
HELPER FUNCTIONS
==========================================================================
*/
// 640x480 800x600 1024x768
// 640x480@75
// 640x480@75:32
// 640x480:32@75
void Video_GetModeFS( vrect_t *rc, int *freq, int *depth ) {
char *s = vid_modelist->string;
int mode = 1;
int w = 640, h = 480, hz = 0, bpp = 0;
while( *s ) {
w = strtoul( s, &s, 10 );
if( *s != 'x' ) {
Com_DPrintf( "Mode %d is malformed\n", mode );
goto malformed;
}
h = strtoul( s + 1, &s, 10 );
if( *s == '@' ) {
hz = strtoul( s + 1, &s, 10 );
if( *s == ':' ) {
bpp = strtoul( s + 1, &s, 10 );
}
} else if( *s == ':' ) {
bpp = strtoul( s + 1, &s, 10 );
if( *s == '@' ) {
hz = strtoul( s + 1, &s, 10 );
}
}
if( mode == vid_fullscreen->integer ) {
break;
}
if( *s == 0 ) {
Com_DPrintf( "Mode %d not found\n", vid_fullscreen->integer );
break;
}
s++;
mode++;
}
// sanity check
if( w < 64 || w > 8192 || h < 64 || h > 8192 ) {
Com_DPrintf( "Mode %dx%d doesn't look sane\n", w, h );
malformed:
w = 640;
h = 480;
hz = 0;
bpp = 0;
}
rc->x = 0;
rc->y = 0;
rc->width = w & ~7;
rc->height = h & ~1;
if( freq ) {
*freq = hz;
}
if( depth ) {
*depth = bpp;
}
}
// 640x480
// 640x480+0
// 640x480+0+0
void Video_GetPlacement( vrect_t *rc ) {
char *s = vid_placement->string;
int w = 640, h = 480, x = 0, y = 0;
w = strtoul( s, &s, 10 );
if( *s != 'x' ) {
Com_DPrintf( "Placement string is malformed\n" );
goto malformed;
}
h = strtoul( s + 1, &s, 10 );
if( *s == '+' ) {
x = strtoul( s + 1, &s, 10 );
if( *s == '+' ) {
y = strtoul( s + 1, &s, 10 );
}
}
// sanity check
if( x < 0 || x > 8192 || y < 0 || y > 8192 ) {
x = 0;
y = 0;
}
if( w < 64 || w > 8192 || h < 64 || h > 8192 ) {
malformed:
w = 640;
h = 480;
}
rc->x = x;
rc->y = y;
rc->width = w & ~7;
rc->height = h & ~1;
}
void Video_SetPlacement( vrect_t *rc ) {
char buffer[MAX_QPATH];
Com_sprintf( buffer, sizeof( buffer ), "%dx%d+%d+%d",
rc->width, rc->height, rc->x, rc->y );
Cvar_Set( "vid_placement", buffer );
}
/*
==========================================================================
LOADING / SHUTDOWN
==========================================================================
*/
/*
==============
CL_FreeRefresh
==============
*/
static void CL_FreeRefresh( void ) {
#ifndef REF_HARD_LINKED
Sys_FreeLibrary( reflib_library );
reflib_library = NULL;
#endif
memset( &ref, 0, sizeof( ref ) );
cls.ref_initialized = qfalse;
}
#ifndef REF_HARD_LINKED
/*
==============
CL_RefSetupCallback
==============
*/
static qboolean CL_RefSetupCallback( api_type_t type, void *api ) {
switch( type ) {
case API_CMD:
Cmd_FillAPI( ( cmdAPI_t * )api );
break;
case API_CVAR:
Cvar_FillAPI( ( cvarAPI_t * )api );
break;
case API_FS:
FS_FillAPI( ( fsAPI_t * )api );
break;
case API_COMMON:
Com_FillAPI( ( commonAPI_t * )api );
break;
case API_SYSTEM:
Sys_FillAPI( ( sysAPI_t * )api );
break;
case API_VIDEO_SOFTWARE:
Video_FillSWAPI( ( videoAPI_t * )api );
break;
case API_VIDEO_OPENGL:
Video_FillGLAPI( ( videoAPI_t * )api );
break;
default:
Com_Error( ERR_FATAL, "CL_RefSetupCallback: bad api type" );
}
return qtrue;
}
#endif
/*
==============
CL_LoadRefresh
==============
*/
static qboolean CL_LoadRefresh( const char *name ) {
#ifndef REF_HARD_LINKED
char path[MAX_OSPATH];
moduleEntry_t entry;
moduleInfo_t info;
moduleCapability_t caps;
APISetupCallback_t callback;
#endif
if( cls.ref_initialized ) {
ref.Shutdown( qtrue );
CL_FreeRefresh();
}
Com_Printf( "------- Loading %s -------\n", name );
#ifdef REF_HARD_LINKED
#ifdef SOFTWARE_RENDERER
Video_FillSWAPI( &video );
#else
Video_FillGLAPI( &video );
#endif
Ref_APISetupCallback( API_REFRESH, &ref );
#else
Q_concat( path, sizeof( path ), sys_refdir->string, PATH_SEP_STRING,
name, LIBSUFFIX, NULL );
entry = Sys_LoadLibrary( path, "moduleEntry", &reflib_library );
if( !entry ) {
Com_WPrintf( "Couldn't load %s\n", name );
return qfalse;
}
entry( MQ_GETINFO, &info );
if( info.api_version != MODULES_APIVERSION ) {
Com_WPrintf( "%s has incompatible api_version: %i, should be %i\n",
name, info.api_version, MODULES_APIVERSION );
goto fail;
}
caps = ( moduleCapability_t )entry( MQ_GETCAPS, NULL );
if( !( caps & MCP_REFRESH ) ) {
Com_WPrintf( "%s doesn't have REFRESH capability\n", name );
goto fail;
}
callback = ( APISetupCallback_t )entry( MQ_SETUPAPI, ( void * )CL_RefSetupCallback );
if( !callback ) {
Com_WPrintf( "%s returned NULL callback\n", name );
goto fail;
}
callback( API_REFRESH, &ref );
#endif
cls.ref_initialized = qtrue;
if( !ref.Init( qtrue ) ) {
goto fail;
}
Sys_FixFPCW();
Com_Printf( "------------------------------------\n" );
return qtrue;
fail:
CL_FreeRefresh();
return qfalse;
}
/*
============
CL_PumpEvents
============
*/
void CL_PumpEvents( void ) {
if( !cls.ref_initialized ) {
return;
}
Video_PumpEvents();
if( mode_changed ) {
#ifndef REF_HARD_LINKED
if( mode_changed & MODE_REFRESH ) {
Cbuf_AddText( "vid_restart\n" );
} else
#endif
if( mode_changed & MODE_FULLSCREEN ) {
Video_ModeChanged();
} else {
if( vid_fullscreen->integer ) {
if( mode_changed & MODE_MODELIST ) {
Video_ModeChanged();
}
} else {
if( mode_changed & MODE_PLACEMENT ) {
Video_ModeChanged();
}
}
}
mode_changed = 0;
}
}
static void vid_placement_changed( cvar_t *self ) {
mode_changed |= MODE_PLACEMENT;
}
static void vid_fullscreen_changed( cvar_t *self ) {
mode_changed |= MODE_FULLSCREEN;
}
static void vid_modelist_changed( cvar_t *self ) {
mode_changed |= MODE_MODELIST;
}
#ifndef REF_HARD_LINKED
static void vid_ref_changed( cvar_t *self ) {
mode_changed |= MODE_REFRESH;
}
#endif
/*
============
CL_InitRefresh
============
*/
void CL_InitRefresh( void ) {
if( cls.ref_initialized ) {
return;
}
// Create the video variables so we know how to start the graphics drivers
vid_placement = Cvar_Get( "vid_placement", "640x480", CVAR_ARCHIVE );
vid_fullscreen = Cvar_Get( "vid_fullscreen", "0", CVAR_ARCHIVE );
vid_modelist = Cvar_Get( "vid_modelist", "640x480", CVAR_ARCHIVE );
#ifdef REF_HARD_LINKED
vid_ref = Cvar_Get( "vid_ref", DEFAULT_REFRESH_DRIVER, CVAR_ROM );
if( !CL_LoadRefresh( "ref_" DEFAULT_REFRESH_DRIVER ) ) {
Com_Error( ERR_FATAL, "Couldn't load built-in video driver!" );
}
#else
vid_ref = Cvar_Get( "vid_ref", DEFAULT_REFRESH_DRIVER, CVAR_ARCHIVE );
// Start the graphics mode and load refresh DLL
while( 1 ) {
char buffer[MAX_QPATH];
Q_concat( buffer, sizeof( buffer ), "ref_", vid_ref->string, NULL );
if( CL_LoadRefresh( buffer ) ) {
break;
}
if( !strcmp( vid_ref->string, DEFAULT_REFRESH_DRIVER ) ) {
Com_Error( ERR_FATAL, "Couldn't fall back to %s driver!", buffer );
}
Com_Printf( "Falling back to default refresh...\n" );
Cvar_Set( "vid_ref", DEFAULT_REFRESH_DRIVER );
}
#endif
vid_placement->changed = vid_placement_changed;
vid_fullscreen->changed = vid_fullscreen_changed;
vid_modelist->changed = vid_modelist_changed;
#ifndef REF_HARD_LINKED
vid_ref->changed = vid_ref_changed;
#endif
mode_changed = 0;
}
/*
============
CL_ShutdownRefresh
============
*/
void CL_ShutdownRefresh( void ) {
if( !cls.ref_initialized ) {
return;
}
vid_placement->changed = NULL;
vid_fullscreen->changed = NULL;
vid_modelist->changed = NULL;
#ifndef REF_HARD_LINKED
vid_ref->changed = NULL;
#endif
ref.Shutdown( qtrue );
CL_FreeRefresh();
Z_LeakTest( TAG_RENDERER );
}
|