-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathr_draw.c
362 lines (279 loc) · 10.4 KB
/
r_draw.c
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
#include <stdlib.h>
#include <string.h>
#include "doomdef.h"
#include "d_think.h"
#include "p_pspr.h"
#include "doomstat.h"
#include "w_wad.h"
#include "r_main.h"
#include "r_draw.h"
#include "r_filter.h"
#include "v_video.h"
#include "st_stuff.h"
#include "g_game.h"
#include "z_zone.h"
#include "i_system.h"
#include "i_video.h"
#define FUZZTABLE 50
#define FUZZOFF 1
#define RDC_STANDARD 1
#define RDC_TRANSLATED 4
#define RDC_FUZZ 8
#define RDC_NOCOLMAP 16
#define RDC_DITHERZ 32
#define RDC_BILINEAR 64
#define RDC_ROUNDED 128
typedef enum
{
COL_NONE,
} columntype_e;
int viewwidth;
int viewheight;
int viewwindowx;
int viewwindowy;
byte *translationtables;
extern lighttable_t *(*c_zlight)[LIGHTLEVELS][MAXLIGHTZ];
static int temp_x = 0;
static int tempyl[4], tempyh[4];
static byte byte_tempbuf[MAX_SCREENHEIGHT * 4];
static int startx = 0;
static int temptype = COL_NONE;
static int commontop, commonbot;
static const byte *tempfuzzmap;
static const int fuzzoffset_org[FUZZTABLE] = {
FUZZOFF, -FUZZOFF, FUZZOFF, -FUZZOFF, FUZZOFF, FUZZOFF, -FUZZOFF, FUZZOFF,
FUZZOFF, -FUZZOFF, FUZZOFF, FUZZOFF, FUZZOFF, -FUZZOFF, FUZZOFF, FUZZOFF,
FUZZOFF, -FUZZOFF, -FUZZOFF, -FUZZOFF, -FUZZOFF, FUZZOFF, -FUZZOFF, -FUZZOFF,
FUZZOFF, FUZZOFF, FUZZOFF, FUZZOFF, -FUZZOFF, FUZZOFF, -FUZZOFF, FUZZOFF,
FUZZOFF, -FUZZOFF, -FUZZOFF, FUZZOFF, FUZZOFF, -FUZZOFF, -FUZZOFF, -FUZZOFF,
-FUZZOFF, FUZZOFF, FUZZOFF, FUZZOFF, FUZZOFF, -FUZZOFF, FUZZOFF, FUZZOFF,
-FUZZOFF, FUZZOFF
};
static int fuzzoffset[FUZZTABLE];
static int fuzzpos = 0;
draw_vars_t drawvars = {
NULL, 0,
RDRAW_FILTER_POINT,
RDRAW_FILTER_POINT,
RDRAW_FILTER_POINT,
RDRAW_FILTER_POINT,
RDRAW_FILTER_POINT,
RDRAW_MASKEDCOLUMNEDGE_SQUARE,
RDRAW_MASKEDCOLUMNEDGE_SQUARE,
49152
};
static void R_FlushWholeError(void)
{
I_Error("R_FlushWholeColumns called without being initialized.\n");
}
static void R_FlushHTError(void)
{
I_Error("R_FlushHTColumns called without being initialized.\n");
}
static void R_QuadFlushError(void)
{
I_Error("R_FlushQuadColumn called without being initialized.\n");
}
static void (*R_FlushWholeColumns)(void) = R_FlushWholeError;
static void (*R_FlushHTColumns)(void) = R_FlushHTError;
static void (*R_FlushQuadColumn)(void) = R_QuadFlushError;
static void R_FlushColumns(void)
{
if (temp_x != 4 || commontop >= commonbot)
{
R_FlushWholeColumns();
}
else
{
R_FlushHTColumns();
R_FlushQuadColumn();
}
temp_x = 0;
}
void R_ResetColumnBuffer(void)
{
if (temp_x)
R_FlushColumns();
temptype = COL_NONE;
R_FlushWholeColumns = R_FlushWholeError;
R_FlushHTColumns = R_FlushHTError;
R_FlushQuadColumn = R_QuadFlushError;
}
#define R_DRAWCOLUMN_PIPELINE RDC_STANDARD
#define R_FLUSHWHOLE_FUNCNAME R_FlushWhole8
#define R_FLUSHHEADTAIL_FUNCNAME R_FlushHT8
#define R_FLUSHQUAD_FUNCNAME R_FlushQuad8
#include "r_drawflush.inl"
#undef R_DRAWCOLUMN_PIPELINE
#undef R_FLUSHWHOLE_FUNCNAME
#undef R_FLUSHHEADTAIL_FUNCNAME
#undef R_FLUSHQUAD_FUNCNAME
#define R_DRAWCOLUMN_PIPELINE RDC_FUZZ
#define R_FLUSHWHOLE_FUNCNAME R_FlushWholeFuzz8
#define R_FLUSHHEADTAIL_FUNCNAME R_FlushHTFuzz8
#define R_FLUSHQUAD_FUNCNAME R_FlushQuadFuzz8
#include "r_drawflush.inl"
#undef R_DRAWCOLUMN_PIPELINE
#undef R_FLUSHWHOLE_FUNCNAME
#undef R_FLUSHHEADTAIL_FUNCNAME
#undef R_FLUSHQUAD_FUNCNAME
#define R_DRAWCOLUMN_PIPELINE_TYPE RDC_PIPELINE_STANDARD
#define R_DRAWCOLUMN_PIPELINE_BASE RDC_STANDARD
#define R_DRAWCOLUMN_FUNCNAME_COMPOSITE(postfix) R_DrawColumn8 ## postfix
#define R_FLUSHWHOLE_FUNCNAME R_FlushWhole8
#define R_FLUSHHEADTAIL_FUNCNAME R_FlushHT8
#define R_FLUSHQUAD_FUNCNAME R_FlushQuad8
#include "r_drawcolpipeline.inl"
#undef R_FLUSHWHOLE_FUNCNAME
#undef R_FLUSHHEADTAIL_FUNCNAME
#undef R_FLUSHQUAD_FUNCNAME
#undef R_DRAWCOLUMN_FUNCNAME_COMPOSITE
#undef R_DRAWCOLUMN_PIPELINE_BASE
#undef R_DRAWCOLUMN_PIPELINE_TYPE
#define R_DRAWCOLUMN_PIPELINE_TYPE RDC_PIPELINE_TRANSLATED
#define R_DRAWCOLUMN_PIPELINE_BASE RDC_TRANSLATED
#define R_DRAWCOLUMN_FUNCNAME_COMPOSITE(postfix) R_DrawTranslatedColumn8 ## postfix
#define R_FLUSHWHOLE_FUNCNAME R_FlushWhole8
#define R_FLUSHHEADTAIL_FUNCNAME R_FlushHT8
#define R_FLUSHQUAD_FUNCNAME R_FlushQuad8
#include "r_drawcolpipeline.inl"
#undef R_FLUSHWHOLE_FUNCNAME
#undef R_FLUSHHEADTAIL_FUNCNAME
#undef R_FLUSHQUAD_FUNCNAME
#undef R_DRAWCOLUMN_FUNCNAME_COMPOSITE
#undef R_DRAWCOLUMN_PIPELINE_BASE
#undef R_DRAWCOLUMN_PIPELINE_TYPE
#define R_DRAWCOLUMN_PIPELINE_TYPE RDC_PIPELINE_FUZZ
#define R_DRAWCOLUMN_PIPELINE_BASE RDC_FUZZ
#define R_DRAWCOLUMN_FUNCNAME_COMPOSITE(postfix) R_DrawFuzzColumn8 ## postfix
#define R_FLUSHWHOLE_FUNCNAME R_FlushWholeFuzz8
#define R_FLUSHHEADTAIL_FUNCNAME R_FlushHTFuzz8
#define R_FLUSHQUAD_FUNCNAME R_FlushQuadFuzz8
#include "r_drawcolpipeline.inl"
#undef R_FLUSHWHOLE_FUNCNAME
#undef R_FLUSHHEADTAIL_FUNCNAME
#undef R_FLUSHQUAD_FUNCNAME
#undef R_DRAWCOLUMN_FUNCNAME_COMPOSITE
#undef R_DRAWCOLUMN_PIPELINE_BASE
#undef R_DRAWCOLUMN_PIPELINE_TYPE
static R_DrawColumn_f drawcolumnfuncs[RDRAW_FILTER_MAXFILTERS][RDRAW_FILTER_MAXFILTERS][RDC_PIPELINE_MAXPIPELINES] = {
{
{NULL, NULL, NULL,},
{R_DrawColumn8_PointUV, R_DrawTranslatedColumn8_PointUV, R_DrawFuzzColumn8_PointUV,},
{R_DrawColumn8_LinearUV, R_DrawTranslatedColumn8_LinearUV, R_DrawFuzzColumn8_LinearUV,},
{R_DrawColumn8_RoundedUV, R_DrawTranslatedColumn8_RoundedUV, R_DrawFuzzColumn8_RoundedUV,},
},
{
{NULL, NULL, NULL,},
{R_DrawColumn8_PointUV_PointZ, R_DrawTranslatedColumn8_PointUV_PointZ, R_DrawFuzzColumn8_PointUV_PointZ,},
{R_DrawColumn8_LinearUV_PointZ, R_DrawTranslatedColumn8_LinearUV_PointZ, R_DrawFuzzColumn8_LinearUV_PointZ,},
{R_DrawColumn8_RoundedUV_PointZ, R_DrawTranslatedColumn8_RoundedUV_PointZ, R_DrawFuzzColumn8_RoundedUV_PointZ,},
},
{
{NULL, NULL, NULL,},
{R_DrawColumn8_PointUV_LinearZ, R_DrawTranslatedColumn8_PointUV_LinearZ, R_DrawFuzzColumn8_PointUV_LinearZ,},
{R_DrawColumn8_LinearUV_LinearZ, R_DrawTranslatedColumn8_LinearUV_LinearZ, R_DrawFuzzColumn8_LinearUV_LinearZ,},
{R_DrawColumn8_RoundedUV_LinearZ, R_DrawTranslatedColumn8_RoundedUV_LinearZ, R_DrawFuzzColumn8_RoundedUV_LinearZ,},
},
};
R_DrawColumn_f R_GetDrawColumnFunc(enum column_pipeline_e type, enum draw_filter_type_e filter, enum draw_filter_type_e filterz)
{
R_DrawColumn_f result = drawcolumnfuncs[filterz][filter][type];
if (result == NULL)
I_Error("R_GetDrawColumnFunc: undefined function (%d, %d, %d)", type, filter, filterz);
return result;
}
void R_SetDefaultDrawColumnVars(draw_column_vars_t *dcvars)
{
dcvars->x = dcvars->yl = dcvars->yh = dcvars->z = 0;
dcvars->iscale = dcvars->texturemid = dcvars->texheight = dcvars->texu = 0;
dcvars->source = dcvars->prevsource = dcvars->nextsource = NULL;
dcvars->colormap = dcvars->nextcolormap = colormaps[0];
dcvars->translation = NULL;
dcvars->edgeslope = dcvars->drawingmasked = 0;
dcvars->edgetype = drawvars.sprite_edges;
}
void R_InitTranslationTables(void)
{
int i;
#define MAXTRANS 3
byte transtocolour[MAXTRANS];
if (translationtables == NULL)
translationtables = Z_Malloc(256 * MAXTRANS, PU_STATIC, 0);
for (i = 0; i < MAXTRANS; i++)
transtocolour[i] = 255;
for (i = 0; i < 256; i++)
{
if (i >= 0x70 && i<= 0x7f)
{
translationtables[i] = colormaps[0][((i & 0xf) << 9) + transtocolour[0]];
translationtables[i + 256] = colormaps[0][((i & 0xf) << 9) + transtocolour[1]];
translationtables[i + 512] = colormaps[0][((i & 0xf) << 9) + transtocolour[2]];
}
else
{
translationtables[i] = translationtables[i + 256] = translationtables[i + 512] = i;
}
}
}
#define R_DRAWSPAN_FUNCNAME R_DrawSpan8_PointUV_PointZ
#define R_DRAWSPAN_PIPELINE (RDC_STANDARD)
#include "r_drawspan.inl"
#undef R_DRAWSPAN_PIPELINE
#undef R_DRAWSPAN_FUNCNAME
#define R_DRAWSPAN_FUNCNAME R_DrawSpan8_PointUV_LinearZ
#define R_DRAWSPAN_PIPELINE (RDC_STANDARD | RDC_DITHERZ)
#include "r_drawspan.inl"
#undef R_DRAWSPAN_PIPELINE
#undef R_DRAWSPAN_FUNCNAME
#define R_DRAWSPAN_FUNCNAME R_DrawSpan8_LinearUV_PointZ
#define R_DRAWSPAN_PIPELINE (RDC_STANDARD | RDC_BILINEAR)
#include "r_drawspan.inl"
#undef R_DRAWSPAN_PIPELINE
#undef R_DRAWSPAN_FUNCNAME
#define R_DRAWSPAN_FUNCNAME R_DrawSpan8_LinearUV_LinearZ
#define R_DRAWSPAN_PIPELINE (RDC_STANDARD | RDC_BILINEAR | RDC_DITHERZ)
#include "r_drawspan.inl"
#undef R_DRAWSPAN_PIPELINE
#undef R_DRAWSPAN_FUNCNAME
#define R_DRAWSPAN_FUNCNAME R_DrawSpan8_RoundedUV_PointZ
#define R_DRAWSPAN_PIPELINE (RDC_STANDARD | RDC_ROUNDED)
#include "r_drawspan.inl"
#undef R_DRAWSPAN_PIPELINE
#undef R_DRAWSPAN_FUNCNAME
#define R_DRAWSPAN_FUNCNAME R_DrawSpan8_RoundedUV_LinearZ
#define R_DRAWSPAN_PIPELINE (RDC_STANDARD | RDC_ROUNDED | RDC_DITHERZ)
#include "r_drawspan.inl"
#undef R_DRAWSPAN_PIPELINE
#undef R_DRAWSPAN_FUNCNAME
static R_DrawSpan_f drawspanfuncs[RDRAW_FILTER_MAXFILTERS][RDRAW_FILTER_MAXFILTERS] = {
{NULL, NULL, NULL, NULL,},
{NULL, R_DrawSpan8_PointUV_PointZ, R_DrawSpan8_LinearUV_PointZ, R_DrawSpan8_RoundedUV_PointZ,},
{NULL, R_DrawSpan8_PointUV_LinearZ, R_DrawSpan8_LinearUV_LinearZ, R_DrawSpan8_RoundedUV_LinearZ,},
{NULL, NULL, NULL, NULL,},
};
R_DrawSpan_f R_GetDrawSpanFunc(enum draw_filter_type_e filter, enum draw_filter_type_e filterz)
{
R_DrawSpan_f result = drawspanfuncs[filterz][filter];
if (result == NULL)
I_Error("R_GetDrawSpanFunc: undefined function (%d, %d)", filter, filterz);
return result;
}
void R_DrawSpan(draw_span_vars_t *dsvars)
{
R_GetDrawSpanFunc(drawvars.filterfloor, drawvars.filterz)(dsvars);
}
void R_InitBuffer(int width, int height)
{
int i = 0;
viewwindowx = (SCREENWIDTH-width) >> 1;
viewwindowy = width==SCREENWIDTH ? 0 : (SCREENHEIGHT-(ST_SCALED_HEIGHT-1)-height)>>1;
drawvars.byte_topleft = screens[0].data + viewwindowy*screens[0].byte_pitch + viewwindowx;
drawvars.byte_pitch = screens[0].byte_pitch;
for (i = 0; i < FUZZTABLE; i++)
fuzzoffset[i] = fuzzoffset_org[i] * screens[0].byte_pitch;
}
void R_VideoErase(int x, int y, int count)
{
memcpy(screens[0].data + y * screens[0].byte_pitch + x, screens[1].data + y * screens[1].byte_pitch + x, count);
}