1 /*
2 	d_init.c
3 
4 	rasterization driver initialization
5 
6 	Copyright (C) 1996-1997  Id Software, Inc.
7 
8 	This program is free software; you can redistribute it and/or
9 	modify it under the terms of the GNU General Public License
10 	as published by the Free Software Foundation; either version 2
11 	of the License, or (at your option) any later version.
12 
13 	This program is distributed in the hope that it will be useful,
14 	but WITHOUT ANY WARRANTY; without even the implied warranty of
15 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 	See the GNU General Public License for more details.
18 
19 	You should have received a copy of the GNU General Public License
20 	along with this program; if not, write to:
21 
22 		Free Software Foundation, Inc.
23 		59 Temple Place - Suite 330
24 		Boston, MA  02111-1307, USA
25 
26 */
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30 
31 #define NH_DEFINE
32 #include "namehack.h"
33 
34 #include "QF/cvar.h"
35 #include "QF/render.h"
36 
37 #include "compat.h"
38 #include "d_local.h"
39 #include "r_internal.h"
40 #include "vid_internal.h"
41 
42 #define NUM_MIPS	4
43 
44 surfcache_t *sw32_d_initial_rover;
45 qboolean     sw32_d_roverwrapped;
46 int          sw32_d_minmip;
47 float        sw32_d_scalemip[NUM_MIPS - 1];
48 
49 static float basemip[NUM_MIPS - 1] = { 1.0, 0.5 * 0.8, 0.25 * 0.8 };
50 
51 
52 float        sw32_d_zitable[65536];
53 
54 
55 void
sw32_D_Init(void)56 sw32_D_Init (void)
57 {
58 	sw32_r_drawpolys = false;
59 	sw32_r_worldpolysbacktofront = false;
60 
61 	// LordHavoc: compute 1/zi table for use in rendering code everywhere
62 	if (!sw32_d_zitable[1]) {
63 		int i;
64 		sw32_d_zitable[0] = 0;
65 		for (i = 1;i < 65536;i++)
66 			sw32_d_zitable[i] = (65536.0 * 65536.0 / (double) i);
67 	}
68 
69 	vr_data.vid->surf_cache_size = sw32_D_SurfaceCacheForRes;
70 	vr_data.vid->flush_caches = sw32_D_FlushCaches;
71 	vr_data.vid->init_caches = sw32_D_InitCaches;
72 
73 	VID_InitBuffers ();
74 }
75 
76 void
sw32_D_EnableBackBufferAccess(void)77 sw32_D_EnableBackBufferAccess (void)
78 {
79 	VID_LockBuffer ();
80 }
81 
82 void
sw32_D_TurnZOn(void)83 sw32_D_TurnZOn (void)
84 {
85 	// not needed for software version
86 }
87 
88 void
sw32_D_DisableBackBufferAccess(void)89 sw32_D_DisableBackBufferAccess (void)
90 {
91 	VID_UnlockBuffer ();
92 }
93 
94 void
sw32_D_SetupFrame(void)95 sw32_D_SetupFrame (void)
96 {
97 	int         i;
98 
99 	if (sw32_r_dowarp)
100 		sw32_d_viewbuffer = sw32_r_warpbuffer;
101 	else
102 		sw32_d_viewbuffer = vid.buffer;
103 
104 	if (sw32_r_dowarp)
105 		sw32_screenwidth = WARP_WIDTH;
106 	else
107 		sw32_screenwidth = vid.rowbytes / sw32_r_pixbytes;
108 
109 	sw32_d_roverwrapped = false;
110 	sw32_d_initial_rover = sw32_sc_rover;
111 
112 	sw32_d_minmip = bound (0, d_mipcap->value, 3);
113 
114 	for (i = 0; i < (NUM_MIPS - 1); i++)
115 		sw32_d_scalemip[i] = basemip[i] * d_mipscale->value;
116 }
117 
118 void
sw32_D_UpdateRects(vrect_t * prect)119 sw32_D_UpdateRects (vrect_t *prect)
120 {
121 	// the software driver draws these directly to the vid buffer
122 }
123