1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "software/r1_software_globals.hh"
|
---|
10 | #include "software/inline_fpu.hh"
|
---|
11 |
|
---|
12 | w32 *texture_perspective_lit_starter()
|
---|
13 | {
|
---|
14 | w32 returnval;
|
---|
15 | _asm
|
---|
16 | {
|
---|
17 | mov eax,OFFSET dumb_addr
|
---|
18 | dumb_addr:
|
---|
19 | mov returnval,eax
|
---|
20 | }
|
---|
21 | return (w32 *)returnval;
|
---|
22 | }
|
---|
23 |
|
---|
24 | void texture_scanline_perspective_lit(w16 *start_pixel,
|
---|
25 | sw32 start_x,
|
---|
26 | void *_left,//perspective_span *left,
|
---|
27 | sw32 width)
|
---|
28 | {
|
---|
29 | //temporary stuff for lighting calculations
|
---|
30 | w16 texel;
|
---|
31 | w32 t1,t2;
|
---|
32 | w32 l_lookup;
|
---|
33 |
|
---|
34 | start_pixel = (w16 *)((w8 *)start_pixel + start_x);
|
---|
35 |
|
---|
36 | perspective_span *left = (perspective_span *)_left;
|
---|
37 |
|
---|
38 | left_z = 1.f / left->ooz;
|
---|
39 | left_s = qftoi(left->soz * left_z) + cur_grads.s_adjust;
|
---|
40 | left_t = qftoi(left->toz * left_z) + cur_grads.t_adjust;
|
---|
41 |
|
---|
42 | //dont forget the lighting
|
---|
43 | left_l = left->l;
|
---|
44 |
|
---|
45 | sw32 had_subdivisions = width & (~15);
|
---|
46 |
|
---|
47 | num_subdivisions = width >> 4;
|
---|
48 | num_leftover = width & 15;
|
---|
49 |
|
---|
50 | if (num_subdivisions)
|
---|
51 | {
|
---|
52 | ooz_right = left->ooz + (cur_grads.doozdxspan);
|
---|
53 | soz_right = left->soz + (cur_grads.dsozdxspan);
|
---|
54 | toz_right = left->toz + (cur_grads.dtozdxspan);
|
---|
55 |
|
---|
56 | right_z = 1.f / ooz_right;
|
---|
57 |
|
---|
58 | while (num_subdivisions)
|
---|
59 | {
|
---|
60 |
|
---|
61 | right_s = qftoi(soz_right * right_z) + cur_grads.s_adjust;
|
---|
62 | if (right_s < 0)
|
---|
63 | right_s = 0;
|
---|
64 | else
|
---|
65 | if (right_s > s_mask)
|
---|
66 | right_s = s_mask;
|
---|
67 |
|
---|
68 | right_t = qftoi(toz_right * right_z) + cur_grads.t_adjust;
|
---|
69 | if (right_t < 0)
|
---|
70 | right_t = 0;
|
---|
71 | else
|
---|
72 | if (right_t > t_mask)
|
---|
73 | right_t = t_mask;
|
---|
74 |
|
---|
75 | temp_dsdx = (right_s - left_s) >> 4;
|
---|
76 | temp_dtdx = (right_t - left_t) >> 4;
|
---|
77 |
|
---|
78 | if (num_subdivisions!=1)
|
---|
79 | {
|
---|
80 | ooz_right += (cur_grads.doozdxspan);
|
---|
81 | soz_right += (cur_grads.dsozdxspan);
|
---|
82 | toz_right += (cur_grads.dtozdxspan);
|
---|
83 |
|
---|
84 | right_z = 1.f / ooz_right;
|
---|
85 | }
|
---|
86 |
|
---|
87 | width_global = 16;
|
---|
88 |
|
---|
89 | while (width_global)
|
---|
90 | {
|
---|
91 | texel = *( r1_software_texture_ptr + (left_s>>16) + ((left_t>>16) << r1_software_twidth_log2) );
|
---|
92 |
|
---|
93 | l_lookup = left_l & (NUM_LIGHT_SHADES<<8);
|
---|
94 |
|
---|
95 | //lookup low bits
|
---|
96 | t1 = ((w32 *)(0xDEADBEEF))[l_lookup + (texel & 0xFF)];
|
---|
97 |
|
---|
98 | //lookup high bits
|
---|
99 | t2 = ((w32 *)(0xDEADBEEF)+ctable_size)[l_lookup + (texel>>8)];
|
---|
100 |
|
---|
101 | *start_pixel = (w16)(t1+t2);
|
---|
102 |
|
---|
103 | start_pixel++;
|
---|
104 |
|
---|
105 | left_s += temp_dsdx;
|
---|
106 | left_t += temp_dtdx;
|
---|
107 | left_l += dldx_fixed;
|
---|
108 |
|
---|
109 | width_global--;
|
---|
110 | }
|
---|
111 |
|
---|
112 | left_s = right_s;
|
---|
113 | left_t = right_t;
|
---|
114 |
|
---|
115 | num_subdivisions--;
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | if (num_leftover)
|
---|
120 | {
|
---|
121 | if (num_leftover > 1)
|
---|
122 | {
|
---|
123 | if (had_subdivisions!=0)
|
---|
124 | {
|
---|
125 | ooz_right += (cur_grads.doozdx * num_leftover);
|
---|
126 | soz_right += (cur_grads.dsozdx * num_leftover);
|
---|
127 | toz_right += (cur_grads.dtozdx * num_leftover);
|
---|
128 |
|
---|
129 | right_z = 1.f / ooz_right;
|
---|
130 | }
|
---|
131 | else
|
---|
132 | {
|
---|
133 | ooz_right = left->ooz + (cur_grads.doozdx * num_leftover);
|
---|
134 | soz_right = left->soz + (cur_grads.dsozdx * num_leftover);
|
---|
135 | toz_right = left->toz + (cur_grads.dtozdx * num_leftover);
|
---|
136 |
|
---|
137 | right_z = 1.f / ooz_right;
|
---|
138 | }
|
---|
139 |
|
---|
140 | right_s = qftoi(soz_right * right_z) + cur_grads.s_adjust;
|
---|
141 | if (right_s < 0)
|
---|
142 | right_s = 0;
|
---|
143 | else
|
---|
144 | if (right_s > s_mask)
|
---|
145 | right_s = s_mask;
|
---|
146 |
|
---|
147 | right_t = qftoi(toz_right * right_z) + cur_grads.t_adjust;
|
---|
148 | if (right_t < 0)
|
---|
149 | right_t = 0;
|
---|
150 | else
|
---|
151 | if (right_t > t_mask)
|
---|
152 | right_t = t_mask;
|
---|
153 |
|
---|
154 | temp_dsdx = qftoi((float)(right_s - left_s) * inverse_leftover_lookup[num_leftover]);
|
---|
155 | temp_dtdx = qftoi((float)(right_t - left_t) * inverse_leftover_lookup[num_leftover]);
|
---|
156 |
|
---|
157 | while (num_leftover)
|
---|
158 | {
|
---|
159 | texel = *(r1_software_texture_ptr + (left_s>>16) + ((left_t>>16)<<r1_software_twidth_log2));
|
---|
160 |
|
---|
161 | l_lookup = left_l & (NUM_LIGHT_SHADES<<8);
|
---|
162 |
|
---|
163 | //lookup low bits
|
---|
164 | t1 = ((w32 *)(0xDEADBEEF))[l_lookup + (texel & 0xFF)];
|
---|
165 |
|
---|
166 | //lookup high bits
|
---|
167 | t2 = ((w32 *)(0xDEADBEEF)+ctable_size)[l_lookup + (texel>>8)];
|
---|
168 |
|
---|
169 | *start_pixel = (w16)(t1+t2);
|
---|
170 |
|
---|
171 | start_pixel++;
|
---|
172 |
|
---|
173 | left_s += temp_dsdx;
|
---|
174 | left_t += temp_dtdx;
|
---|
175 | left_l += dldx_fixed;
|
---|
176 |
|
---|
177 | num_leftover--;
|
---|
178 | }
|
---|
179 | }
|
---|
180 | else
|
---|
181 | {
|
---|
182 | texel = *(r1_software_texture_ptr + (left_s>>16) + ((left_t>>16)<<r1_software_twidth_log2));
|
---|
183 |
|
---|
184 | l_lookup = left_l & (NUM_LIGHT_SHADES<<8);
|
---|
185 |
|
---|
186 | //lookup low bits
|
---|
187 | t1 = ((w32 *)(0xDEADBEEF))[l_lookup + (texel & 0xFF)];
|
---|
188 |
|
---|
189 | //lookup high bits
|
---|
190 | t2 = ((w32 *)(0xDEADBEEF)+ctable_size)[l_lookup + (texel>>8)];
|
---|
191 |
|
---|
192 | *start_pixel = (w16)(t1+t2);
|
---|
193 | }
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | w32 *texture_perspective_lit_sentinel()
|
---|
198 | {
|
---|
199 | w32 returnval;
|
---|
200 | _asm
|
---|
201 | {
|
---|
202 | mov eax,OFFSET dumb_addr
|
---|
203 | dumb_addr:
|
---|
204 | mov returnval,eax
|
---|
205 | }
|
---|
206 | return (w32 *)returnval;
|
---|
207 | }
|
---|
208 |
|
---|
209 | void insert_color_modify_address_low(w32 *address);
|
---|
210 | void insert_color_modify_address_high(w32 *address);
|
---|
211 | extern w32 color_modify_list[];
|
---|
212 | extern sw32 num_color_modifies;
|
---|
213 |
|
---|
214 | void setup_color_modify_perspective_lit()
|
---|
215 | {
|
---|
216 | w32 *stop = texture_perspective_lit_sentinel();
|
---|
217 |
|
---|
218 | w32 *search = texture_perspective_lit_starter();
|
---|
219 | //start searching for 0xDEADBEEF
|
---|
220 | while (search < stop)
|
---|
221 | {
|
---|
222 | //casting craziness
|
---|
223 | search = (w32 *)((w8 *)search + 1);
|
---|
224 | if (*search==0xDEADBEEF)
|
---|
225 | {
|
---|
226 | insert_color_modify_address_low(search);
|
---|
227 | }
|
---|
228 | else
|
---|
229 | if (*search==(0xDEADBEEF + ctable_size_bytes))
|
---|
230 | {
|
---|
231 | insert_color_modify_address_high(search);
|
---|
232 | }
|
---|
233 | }
|
---|
234 | }
|
---|