1 /* Emacs style mode select   -*- C++ -*-
2  *-----------------------------------------------------------------------------
3  *
4  *
5  *  PrBoom: a Doom port merged with LxDoom and LSDLDoom
6  *  based on BOOM, a modified and improved DOOM engine
7  *  Copyright (C) 1999 by
8  *  id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9  *  Copyright (C) 1999-2000 by
10  *  Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11  *  Copyright 2005, 2006 by
12  *  Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13  *
14  *  This program is free software; you can redistribute it and/or
15  *  modify it under the terms of the GNU General Public License
16  *  as published by the Free Software Foundation; either version 2
17  *  of the License, or (at your option) any later version.
18  *
19  *  This program is distributed in the hope that it will be useful,
20  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *  GNU General Public License for more details.
23  *
24  *  You should have received a copy of the GNU General Public License
25  *  along with this program; if not, write to the Free Software
26  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27  *  02111-1307, USA.
28  *
29  * DESCRIPTION:
30  *      The actual span/column drawing functions.
31  *      Here find the main potential for optimization,
32  *       e.g. inline assembly, different algorithms.
33  *
34  *-----------------------------------------------------------------------------*/
35 
36 #include "doomstat.h"
37 #include "w_wad.h"
38 #include "r_main.h"
39 #include "r_draw.h"
40 #include "r_filter.h"
41 #include "v_video.h"
42 #include "st_stuff.h"
43 #include "g_game.h"
44 #include "am_map.h"
45 #include "lprintf.h"
46 
47 //
48 // All drawing to the view buffer is accomplished in this file.
49 // The other refresh files only know about ccordinates,
50 //  not the architecture of the frame buffer.
51 // Conveniently, the frame buffer is a linear one,
52 //  and we need only the base address,
53 //  and the total size == width*height*depth/8.,
54 //
55 
56 uint8_t *viewimage;
57 int  viewwidth;
58 int  scaledviewwidth;
59 int  viewheight;
60 
61 // Color tables for different players,
62 //  translate a limited part to another
63 //  (color ramps used for  suit colors).
64 //
65 
66 //
67 // R_DrawColumn
68 // Source is the top of the column to scale.
69 //
70 
71 // SoM: OPTIMIZE for ANYRES
72 typedef enum
73 {
74    COL_NONE,
75    COL_OPAQUE,
76    COL_TRANS,
77    COL_FLEXTRANS,
78    COL_FUZZ,
79    COL_FLEXADD
80 } columntype_e;
81 
82 static int    temp_x = 0;
83 static int    tempyl[4], tempyh[4];
84 static uint16_t short_tempbuf[MAX_SCREENHEIGHT * 4];
85 static int    startx = 0;
86 static int    temptype = COL_NONE;
87 static int    commontop, commonbot;
88 // SoM 7-28-04: Fix the fuzz problem.
89 static const uint8_t   *tempfuzzmap;
90 
91 //
92 // Spectre/Invisibility.
93 //
94 
95 #define FUZZTABLE 50
96 #define FUZZOFF 1
97 
98 static const int fuzzoffset_org[FUZZTABLE] = {
99   FUZZOFF,-FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,
100   FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,
101   FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,
102   FUZZOFF,-FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,
103   FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,-FUZZOFF,FUZZOFF,
104   FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,
105   FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF
106 };
107 
108 static int fuzzoffset[FUZZTABLE];
109 
110 static int fuzzpos = 0;
111 
112 // render pipelines
113 #define RDC_STANDARD      1
114 #define RDC_TRANSLATED    4
115 #define RDC_FUZZ          8
116 // no color mapping
117 #define RDC_NOCOLMAP     16
118 // filter modes
119 #define RDC_DITHERZ      32
120 #define RDC_BILINEAR     64
121 #define RDC_ROUNDED     128
122 
123 draw_vars_t drawvars = {
124   NULL, // short_topleft
125   NULL, // int_topleft
126   RDRAW_FILTER_POINT, // filterwall
127   RDRAW_FILTER_POINT, // filterfloor
128   RDRAW_FILTER_POINT, // filtersprite
129   RDRAW_FILTER_POINT, // filterz
130   RDRAW_FILTER_POINT, // filterpatch
131 
132   RDRAW_MASKEDCOLUMNEDGE_SQUARE, // sprite_edges
133   RDRAW_MASKEDCOLUMNEDGE_SQUARE, // patch_edges
134 
135   // 49152 = FRACUNIT * 0.75
136   // 81920 = FRACUNIT * 1.25
137   49152 // mag_threshold
138 };
139 
140 //
141 // Error functions that will abort if R_FlushColumns tries to flush
142 // columns without a column type.
143 //
144 
R_FlushWholeError(void)145 static void R_FlushWholeError(void)
146 {
147    I_Error("R_FlushWholeColumns called without being initialized.\n");
148 }
149 
R_FlushHTError(void)150 static void R_FlushHTError(void)
151 {
152    I_Error("R_FlushHTColumns called without being initialized.\n");
153 }
154 
R_QuadFlushError(void)155 static void R_QuadFlushError(void)
156 {
157    I_Error("R_FlushQuadColumn called without being initialized.\n");
158 }
159 
160 static void (*R_FlushWholeColumns)(void) = R_FlushWholeError;
161 static void (*R_FlushHTColumns)(void)    = R_FlushHTError;
162 static void (*R_FlushQuadColumn)(void) = R_QuadFlushError;
163 
R_FlushColumns(void)164 static void R_FlushColumns(void)
165 {
166    if(temp_x != 4 || commontop >= commonbot)
167       R_FlushWholeColumns();
168    else
169    {
170       R_FlushHTColumns();
171       R_FlushQuadColumn();
172    }
173    temp_x = 0;
174 }
175 
176 //
177 // R_ResetColumnBuffer
178 //
179 // haleyjd 09/13/04: new function to call from main rendering loop
180 // which gets rid of the unnecessary reset of various variables during
181 // column drawing.
182 //
R_ResetColumnBuffer(void)183 void R_ResetColumnBuffer(void)
184 {
185    // haleyjd 10/06/05: this must not be done if temp_x == 0!
186    if(temp_x)
187       R_FlushColumns();
188 
189    temptype            = COL_NONE;
190    R_FlushWholeColumns = R_FlushWholeError;
191    R_FlushHTColumns    = R_FlushHTError;
192    R_FlushQuadColumn   = R_QuadFlushError;
193 }
194 
195 /*
196  * R_FlushWhole16
197  *
198  * Flushes the entire columns in the buffer, one at a time.
199  * This is used when a quad flush isn't possible.
200  * Opaque version -- no remapping whatsoever.
201 */
R_FlushWhole16(void)202 static void R_FlushWhole16(void)
203 {
204    while(--temp_x >= 0)
205    {
206       int yl           = tempyl[temp_x];
207       uint16_t *source = &short_tempbuf[temp_x + (yl << 2)];
208       uint16_t *dest   = drawvars.short_topleft + yl * SURFACE_SHORT_PITCH + startx + temp_x;
209       int   count      = tempyh[temp_x] - yl + 1;
210 
211       while(--count >= 0)
212       {
213          *dest   = *source;
214          source += 4;
215          dest   += SURFACE_SHORT_PITCH;
216       }
217    }
218 }
219 
220 //
221 // R_FlushHT16
222 //
223 // Flushes the head and tail of columns in the buffer in
224 // preparation for a quad flush.
225 // Opaque version -- no remapping whatsoever.
226 //
R_FlushHT16(void)227 static void R_FlushHT16(void)
228 {
229    uint16_t *source;
230    uint16_t *dest;
231    int count, colnum = 0;
232    int yl, yh;
233 
234    while(colnum < 4)
235    {
236       yl = tempyl[colnum];
237       yh = tempyh[colnum];
238 
239       // flush column head
240       if(yl < commontop)
241       {
242          source = &short_tempbuf[colnum + (yl << 2)];
243          dest   = drawvars.short_topleft + yl * SURFACE_SHORT_PITCH + startx + colnum;
244          count  = commontop - yl;
245 
246          while(--count >= 0)
247          {
248             *dest = *source;
249             source += 4;
250             dest += SURFACE_SHORT_PITCH;
251          }
252       }
253 
254       // flush column tail
255       if(yh > commonbot)
256       {
257          source = &short_tempbuf[colnum + ((commonbot + 1) << 2)];
258          dest   = drawvars.short_topleft + (commonbot + 1) * SURFACE_SHORT_PITCH + startx + colnum;
259          count  = yh - commonbot;
260 
261          while(--count >= 0)
262          {
263             *dest = *source;
264 
265             source += 4;
266             dest += SURFACE_SHORT_PITCH;
267          }
268       }
269       ++colnum;
270    }
271 }
272 
R_FlushQuad16(void)273 static void R_FlushQuad16(void)
274 {
275    uint16_t *source = &short_tempbuf[commontop << 2];
276    uint16_t *dest   = drawvars.short_topleft + commontop * SURFACE_SHORT_PITCH + startx;
277    int        count = commonbot - commontop + 1;
278 
279    while(--count >= 0)
280    {
281       dest[0] = source[0];
282       dest[1] = source[1];
283       dest[2] = source[2];
284       dest[3] = source[3];
285       source += 4;
286       dest += SURFACE_SHORT_PITCH;
287    }
288 }
289 
290 /*
291  * R_FlushWholeFuzz16
292  *
293  * Flushes the entire columns in the buffer, one at a time.
294  * This is used when a quad flush isn't possible.
295  * Opaque version -- no remapping whatsoever.
296 */
R_FlushWholeFuzz16(void)297 static void R_FlushWholeFuzz16(void)
298 {
299    uint16_t *source;
300    uint16_t *dest;
301    int  count, yl;
302 
303    while(--temp_x >= 0)
304    {
305       yl     = tempyl[temp_x];
306       source = &short_tempbuf[temp_x + (yl << 2)];
307       dest   = drawvars.short_topleft + yl * SURFACE_SHORT_PITCH + startx + temp_x;
308       count  = tempyh[temp_x] - yl + 1;
309 
310       while(--count >= 0)
311       {
312          // SoM 7-28-04: Fix the fuzz problem.
313          *dest = GETBLENDED16_9406(dest[fuzzoffset[fuzzpos]], 0);
314 
315          // Clamp table lookup index.
316          if(++fuzzpos == FUZZTABLE)
317             fuzzpos = 0;
318 
319          source += 4;
320          dest += SURFACE_SHORT_PITCH;
321       }
322    }
323 }
324 
325 //
326 // R_FlushHTFuzz16
327 //
328 // Flushes the head and tail of columns in the buffer in
329 // preparation for a quad flush.
330 // Opaque version -- no remapping whatsoever.
331 //
R_FlushHTFuzz16(void)332 static void R_FlushHTFuzz16(void)
333 {
334    uint16_t *source;
335    uint16_t *dest;
336    int count, colnum = 0;
337    int yl, yh;
338 
339    while(colnum < 4)
340    {
341       yl = tempyl[colnum];
342       yh = tempyh[colnum];
343 
344       // flush column head
345       if(yl < commontop)
346       {
347          source = &short_tempbuf[colnum + (yl << 2)];
348          dest   = drawvars.short_topleft + yl * SURFACE_SHORT_PITCH + startx + colnum;
349          count  = commontop - yl;
350 
351          while(--count >= 0)
352          {
353             // SoM 7-28-04: Fix the fuzz problem.
354             *dest = GETBLENDED16_9406(dest[fuzzoffset[fuzzpos]], 0);
355 
356             // Clamp table lookup index.
357             if(++fuzzpos == FUZZTABLE)
358                fuzzpos = 0;
359 
360             source += 4;
361             dest += SURFACE_SHORT_PITCH;
362          }
363       }
364 
365       // flush column tail
366       if(yh > commonbot)
367       {
368          source = &short_tempbuf[colnum + ((commonbot + 1) << 2)];
369          dest   = drawvars.short_topleft + (commonbot + 1) * SURFACE_SHORT_PITCH + startx + colnum;
370          count  = yh - commonbot;
371 
372          while(--count >= 0)
373          {
374             // SoM 7-28-04: Fix the fuzz problem.
375             *dest = GETBLENDED16_9406(dest[fuzzoffset[fuzzpos]], 0);
376 
377             // Clamp table lookup index.
378             if(++fuzzpos == FUZZTABLE)
379                fuzzpos = 0;
380 
381             source += 4;
382             dest += SURFACE_SHORT_PITCH;
383          }
384       }
385       ++colnum;
386    }
387 }
388 
R_FlushQuadFuzz16(void)389 static void R_FlushQuadFuzz16(void)
390 {
391    uint16_t *source = &short_tempbuf[commontop << 2];
392    uint16_t *dest   = drawvars.short_topleft + commontop * SURFACE_SHORT_PITCH + startx;
393    int fuzz1        = fuzzpos;
394    int fuzz2        = (fuzz1 + tempyl[1]) % FUZZTABLE;
395    int fuzz3        = (fuzz2 + tempyl[2]) % FUZZTABLE;
396    int fuzz4        = (fuzz3 + tempyl[3]) % FUZZTABLE;
397    int count        = commonbot - commontop + 1;
398 
399    while(--count >= 0)
400    {
401       dest[0] = GETBLENDED16_9406(dest[0 + fuzzoffset[fuzz1]], 0);
402       dest[1] = GETBLENDED16_9406(dest[1 + fuzzoffset[fuzz2]], 0);
403       dest[2] = GETBLENDED16_9406(dest[2 + fuzzoffset[fuzz3]], 0);
404       dest[3] = GETBLENDED16_9406(dest[3 + fuzzoffset[fuzz4]], 0);
405       fuzz1 = (fuzz1 + 1) % FUZZTABLE;
406       fuzz2 = (fuzz2 + 1) % FUZZTABLE;
407       fuzz3 = (fuzz3 + 1) % FUZZTABLE;
408       fuzz4 = (fuzz4 + 1) % FUZZTABLE;
409       source += 4 * sizeof(uint8_t);
410       dest += SURFACE_SHORT_PITCH * sizeof(uint8_t);
411    }
412 }
413 
414 //
415 // R_DrawColumn
416 //
417 
418 //
419 // A column is a vertical slice/span from a wall texture that,
420 //  given the DOOM style restrictions on the view orientation,
421 //  will always have constant z depth.
422 // Thus a special case loop for very fast rendering can
423 //  be used. It has also been used with Wolfenstein 3D.
424 //
425 
426 uint8_t *translationtables;
427 
428 // no color mapping
R_DrawColumn16_PointUV(draw_column_vars_t * dcvars)429 static void R_DrawColumn16_PointUV(draw_column_vars_t *dcvars)
430 {
431    int count;
432 
433    uint16_t *dest;
434 
435    fixed_t frac;
436    const fixed_t fracstep = dcvars->iscale;
437    const fixed_t slope_texu = dcvars->texu;
438    count = dcvars->yh - dcvars->yl;
439 
440    if (count < 0)
441       return;
442 
443    frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
444 
445    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
446    {
447       if (dcvars->yl != 0) {
448          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
449 
450             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
451             dcvars->yl += shift;
452             count -= shift;
453             frac += 0xffff-(slope_texu & 0xffff);
454          }
455          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
456 
457             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
458             dcvars->yl += shift;
459             count -= shift;
460             frac += slope_texu & 0xffff;
461          }
462       }
463       if (dcvars->yh != viewheight-1) {
464          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
465 
466             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
467             dcvars->yh -= shift;
468             count -= shift;
469          }
470          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
471 
472             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
473             dcvars->yh -= shift;
474             count -= shift;
475          }
476       }
477       if (count <= 0) return;
478    }
479 
480    if(temp_x == 4 ||
481          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
482       R_FlushColumns();
483 
484    if(!temp_x)
485    {
486       startx = dcvars->x;
487       tempyl[0] = commontop = dcvars->yl;
488       tempyh[0] = commonbot = dcvars->yh;
489       temptype = (COL_OPAQUE);
490 
491 
492 
493 
494 
495       R_FlushWholeColumns = R_FlushWhole16;
496       R_FlushHTColumns = R_FlushHT16;
497       R_FlushQuadColumn = R_FlushQuad16;
498 
499       dest = &short_tempbuf[dcvars->yl << 2];
500 
501    }
502    else
503    {
504       tempyl[temp_x] = dcvars->yl;
505       tempyh[temp_x] = dcvars->yh;
506 
507       if(dcvars->yl > commontop)
508          commontop = dcvars->yl;
509       if(dcvars->yh < commonbot)
510          commonbot = dcvars->yh;
511 
512 
513       dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
514 
515    }
516    temp_x += 1;
517 
518    {
519       const uint8_t *source = dcvars->source;
520       count++;
521 
522       if (dcvars->texheight == 128)
523       {
524 
525          while(count--)
526          {
527             *dest = (V_Palette16[ ((source[(frac & ((127<<16)|0xffff))>>16]))*64 + ((64 -1)) ]);
528             ;
529             dest += 4;
530             frac += fracstep;
531          }
532       }
533       else if (dcvars->texheight == 0)
534       {
535 
536          while (count--)
537          {
538             *dest = (V_Palette16[ ((source[(frac)>>16]))*64 + ((64 -1)) ]);
539             ;
540             dest += 4;
541             frac += fracstep;
542          }
543       }
544       else
545       {
546          unsigned heightmask = dcvars->texheight-1;
547          if (! (dcvars->texheight & heightmask))
548          {
549             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
550             while ((count-=2)>=0)
551             {
552                *dest = (V_Palette16[ ((source[(frac & fixedt_heightmask)>>16]))*64 + ((64 -1)) ]);
553                ;
554                dest += 4;
555                frac += fracstep;
556                *dest = (V_Palette16[ ((source[(frac & fixedt_heightmask)>>16]))*64 + ((64 -1)) ]);
557                ;
558                dest += 4;
559                frac += fracstep;
560             }
561             if (count & 1)
562                *dest = (V_Palette16[ ((source[(frac & fixedt_heightmask)>>16]))*64 + ((64 -1)) ]);
563             ;
564          }
565          else
566          {
567             heightmask++;
568             heightmask <<= 16;
569 
570             if (frac < 0)
571                while ((frac += heightmask) < 0);
572             else
573                while (frac >= (int)heightmask)
574                   frac -= heightmask;
575             while (count--)
576             {
577 
578 
579 
580 
581 
582                *dest = (V_Palette16[ ((source[(frac)>>16]))*64 + ((64 -1)) ]);
583                ;
584                dest += 4;
585                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
586 
587 
588 
589             }
590          }
591       }
592    }
593 }
594 
595 // simple depth color mapping
R_DrawColumn16_PointUV_PointZ(draw_column_vars_t * dcvars)596 static void R_DrawColumn16_PointUV_PointZ(draw_column_vars_t *dcvars)
597 {
598    uint16_t *dest;
599 
600    fixed_t frac;
601    const fixed_t   fracstep = dcvars->iscale;
602    const fixed_t slope_texu = dcvars->texu;
603    int                count = dcvars->yh - dcvars->yl;
604 
605    if (count < 0)
606       return;
607 
608    frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
609 
610    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
611    {
612       if (dcvars->yl != 0) {
613          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
614 
615             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
616             dcvars->yl += shift;
617             count -= shift;
618             frac += 0xffff-(slope_texu & 0xffff);
619          }
620          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
621 
622             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
623             dcvars->yl += shift;
624             count -= shift;
625             frac += slope_texu & 0xffff;
626          }
627       }
628       if (dcvars->yh != viewheight-1) {
629          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
630 
631             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
632             dcvars->yh -= shift;
633             count -= shift;
634          }
635          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
636 
637             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
638             dcvars->yh -= shift;
639             count -= shift;
640          }
641       }
642       if (count <= 0) return;
643    }
644 
645    if(temp_x == 4 ||
646          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
647       R_FlushColumns();
648 
649    if(!temp_x)
650    {
651       startx = dcvars->x;
652       tempyl[0] = commontop = dcvars->yl;
653       tempyh[0] = commonbot = dcvars->yh;
654       temptype = (COL_OPAQUE);
655 
656 
657 
658 
659 
660       R_FlushWholeColumns = R_FlushWhole16;
661       R_FlushHTColumns = R_FlushHT16;
662       R_FlushQuadColumn = R_FlushQuad16;
663 
664       dest = &short_tempbuf[dcvars->yl << 2];
665 
666    }
667    else
668    {
669       tempyl[temp_x] = dcvars->yl;
670       tempyh[temp_x] = dcvars->yh;
671 
672       if(dcvars->yl > commontop)
673          commontop = dcvars->yl;
674       if(dcvars->yh < commonbot)
675          commonbot = dcvars->yh;
676 
677 
678       dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
679 
680    }
681    temp_x += 1;
682 
683 
684 
685    {
686       const uint8_t *source = dcvars->source;
687       const lighttable_t *colormap = dcvars->colormap;
688       count++;
689 
690       if (dcvars->texheight == 128)
691       {
692 
693          while(count--)
694          {
695             *dest = (V_Palette16[ (colormap[(source[(frac & ((127<<16)|0xffff))>>16])])*64 + ((64 -1)) ]);
696             ;
697             dest += 4;
698             frac += fracstep;
699          }
700       }
701       else if (dcvars->texheight == 0)
702       {
703 
704          while (count--)
705          {
706             *dest = (V_Palette16[ (colormap[(source[(frac)>>16])])*64 + ((64 -1)) ]);
707             ;
708             dest += 4;
709             frac += fracstep;
710          }
711       }
712       else
713       {
714          unsigned heightmask = dcvars->texheight-1;
715          if (! (dcvars->texheight & heightmask))
716          {
717             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
718             while ((count-=2)>=0)
719             {
720                *dest = (V_Palette16[ (colormap[(source[(frac & fixedt_heightmask)>>16])])*64 + ((64 -1)) ]);
721                ;
722                dest += 4;
723                frac += fracstep;
724                *dest = (V_Palette16[ (colormap[(source[(frac & fixedt_heightmask)>>16])])*64 + ((64 -1)) ]);
725                ;
726                dest += 4;
727                frac += fracstep;
728             }
729             if (count & 1)
730                *dest = (V_Palette16[ (colormap[(source[(frac & fixedt_heightmask)>>16])])*64 + ((64 -1)) ]);
731             ;
732          }
733          else
734          {
735             heightmask++;
736             heightmask <<= 16;
737 
738             if (frac < 0)
739                while ((frac += heightmask) < 0);
740             else
741                while (frac >= (int)heightmask)
742                   frac -= heightmask;
743             while (count--)
744             {
745 
746 
747 
748 
749 
750                *dest = (V_Palette16[ (colormap[(source[(frac)>>16])])*64 + ((64 -1)) ]);
751                ;
752                dest += 4;
753                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
754 
755 
756 
757             }
758          }
759       }
760    }
761 
762 }
763 
764 // z-dither
R_DrawColumn16_PointUV_LinearZ(draw_column_vars_t * dcvars)765 static void R_DrawColumn16_PointUV_LinearZ(draw_column_vars_t *dcvars)
766 {
767    uint16_t *dest;
768 
769    fixed_t frac;
770    const fixed_t fracstep = dcvars->iscale;
771    const fixed_t slope_texu = dcvars->texu;
772    int count = dcvars->yh - dcvars->yl;
773 
774    if (count < 0)
775       return;
776 
777    frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
778 
779    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
780    {
781       if (dcvars->yl != 0) {
782          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
783 
784             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
785             dcvars->yl += shift;
786             count -= shift;
787             frac += 0xffff-(slope_texu & 0xffff);
788          }
789          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
790 
791             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
792             dcvars->yl += shift;
793             count -= shift;
794             frac += slope_texu & 0xffff;
795          }
796       }
797       if (dcvars->yh != viewheight-1) {
798          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
799 
800             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
801             dcvars->yh -= shift;
802             count -= shift;
803          }
804          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
805 
806             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
807             dcvars->yh -= shift;
808             count -= shift;
809          }
810       }
811       if (count <= 0) return;
812    }
813 
814       if(temp_x == 4 ||
815             (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
816          R_FlushColumns();
817 
818       if(!temp_x)
819       {
820          startx = dcvars->x;
821          tempyl[0] = commontop = dcvars->yl;
822          tempyh[0] = commonbot = dcvars->yh;
823          temptype = (COL_OPAQUE);
824 
825 
826 
827 
828 
829          R_FlushWholeColumns = R_FlushWhole16;
830          R_FlushHTColumns = R_FlushHT16;
831          R_FlushQuadColumn = R_FlushQuad16;
832 
833          dest = &short_tempbuf[dcvars->yl << 2];
834 
835       }
836       else
837       {
838          tempyl[temp_x] = dcvars->yl;
839          tempyh[temp_x] = dcvars->yh;
840 
841          if(dcvars->yl > commontop)
842             commontop = dcvars->yl;
843          if(dcvars->yh < commonbot)
844             commonbot = dcvars->yh;
845 
846 
847          dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
848 
849       }
850       temp_x += 1;
851 
852    {
853       const uint8_t *source = dcvars->source;
854 
855       int y = dcvars->yl;
856       const int x = dcvars->x;
857 
858 
859       const int fracz = (dcvars->z >> 6) & 255;
860       const uint8_t *dither_colormaps[2] = { dcvars->colormap, dcvars->nextcolormap };
861       count++;
862 
863 
864 
865 
866 
867 
868 
869       if (dcvars->texheight == 128)
870       {
871 
872          while(count--)
873          {
874             *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(frac & ((127<<16)|0xffff))>>16])]))*64 + ((64 -1)) ]);
875             (y++);
876             dest += 4;
877             frac += fracstep;
878          }
879       }
880       else if (dcvars->texheight == 0)
881       {
882 
883          while (count--)
884          {
885             *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(frac)>>16])]))*64 + ((64 -1)) ]);
886             (y++);
887             dest += 4;
888             frac += fracstep;
889          }
890       }
891       else
892       {
893          unsigned heightmask = dcvars->texheight-1;
894          if (! (dcvars->texheight & heightmask))
895          {
896             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
897             while ((count-=2)>=0)
898             {
899                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(frac & fixedt_heightmask)>>16])]))*64 + ((64 -1)) ]);
900                (y++);
901                dest += 4;
902                frac += fracstep;
903                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(frac & fixedt_heightmask)>>16])]))*64 + ((64 -1)) ]);
904                (y++);
905                dest += 4;
906                frac += fracstep;
907             }
908             if (count & 1)
909                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(frac & fixedt_heightmask)>>16])]))*64 + ((64 -1)) ]);
910             (y++);
911          }
912          else
913          {
914             heightmask++;
915             heightmask <<= 16;
916 
917             if (frac < 0)
918                while ((frac += heightmask) < 0);
919             else
920                while (frac >= (int)heightmask)
921                   frac -= heightmask;
922             while (count--)
923             {
924 
925 
926 
927 
928 
929                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(frac)>>16])]))*64 + ((64 -1)) ]);
930                (y++);
931                dest += 4;
932                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
933 
934 
935 
936             }
937          }
938       }
939    }
940 
941 }
942 
943 // bilinear with no color mapping
R_DrawColumn16_LinearUV(draw_column_vars_t * dcvars)944 static void R_DrawColumn16_LinearUV(draw_column_vars_t *dcvars)
945 {
946    int count;
947 
948    uint16_t *dest;
949 
950    fixed_t frac;
951    const fixed_t fracstep = dcvars->iscale;
952 
953    const fixed_t slope_texu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
954 
955    if (dcvars->iscale > drawvars.mag_threshold)
956    {
957       R_GetDrawColumnFunc(RDC_PIPELINE_STANDARD,
958             RDRAW_FILTER_POINT,
959             drawvars.filterz)(dcvars);
960       return;
961    }
962 
963    count = dcvars->yh - dcvars->yl;
964 
965    if (count < 0)
966       return;
967 
968    frac = dcvars->texturemid - ((1<<16)>>1) + (dcvars->yl-centery)*fracstep;
969 
970    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
971    {
972       if (dcvars->yl != 0) {
973          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
974 
975             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
976             dcvars->yl += shift;
977             count -= shift;
978             frac += 0xffff-(slope_texu & 0xffff);
979          }
980          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
981 
982             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
983             dcvars->yl += shift;
984             count -= shift;
985             frac += slope_texu & 0xffff;
986          }
987       }
988       if (dcvars->yh != viewheight-1) {
989          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
990 
991             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
992             dcvars->yh -= shift;
993             count -= shift;
994          }
995          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
996 
997             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
998             dcvars->yh -= shift;
999             count -= shift;
1000          }
1001       }
1002       if (count <= 0) return;
1003    }
1004 
1005 
1006    if(temp_x == 4 ||
1007          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
1008       R_FlushColumns();
1009 
1010    if(!temp_x)
1011    {
1012       startx = dcvars->x;
1013       tempyl[0] = commontop = dcvars->yl;
1014       tempyh[0] = commonbot = dcvars->yh;
1015       temptype = (COL_OPAQUE);
1016 
1017 
1018 
1019 
1020 
1021       R_FlushWholeColumns = R_FlushWhole16;
1022       R_FlushHTColumns = R_FlushHT16;
1023       R_FlushQuadColumn = R_FlushQuad16;
1024 
1025       dest = &short_tempbuf[dcvars->yl << 2];
1026 
1027    }
1028    else
1029    {
1030       tempyl[temp_x] = dcvars->yl;
1031       tempyh[temp_x] = dcvars->yh;
1032 
1033       if(dcvars->yl > commontop)
1034          commontop = dcvars->yl;
1035       if(dcvars->yh < commonbot)
1036          commonbot = dcvars->yh;
1037 
1038 
1039       dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
1040 
1041    }
1042    temp_x += 1;
1043 
1044 
1045 
1046    {
1047       const uint8_t *source = dcvars->source;
1048 
1049       int y = dcvars->yl;
1050 
1051       const uint8_t *nextsource = dcvars->nextsource;
1052       const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
1053 
1054 
1055 
1056 
1057 
1058 
1059 
1060       count++;
1061 
1062 
1063 
1064 
1065 
1066 
1067 
1068       if (dcvars->texheight == 128)
1069       {
1070 
1071          while(count--)
1072          {
1073             *dest = (( V_Palette16[ ((nextsource[((frac+(1<<16)) & ((127<<16)|0xffff))>>16]))*64 + ((filter_fracu*((frac & ((127<<16)|0xffff))&0xffff))>>(32-6)) ] + V_Palette16[ ((source[((frac+(1<<16)) & ((127<<16)|0xffff))>>16]))*64 + (((0xffff-filter_fracu)*((frac & ((127<<16)|0xffff))&0xffff))>>(32-6)) ] + V_Palette16[ ((source[(frac & ((127<<16)|0xffff))>>16]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & ((127<<16)|0xffff))&0xffff)))>>(32-6)) ] + V_Palette16[ ((nextsource[(frac & ((127<<16)|0xffff))>>16]))*64 + ((filter_fracu*(0xffff-((frac & ((127<<16)|0xffff))&0xffff)))>>(32-6)) ]));
1074             (y++);
1075             dest += 4;
1076             frac += fracstep;
1077          }
1078       }
1079       else if (dcvars->texheight == 0)
1080       {
1081 
1082          while (count--)
1083          {
1084             *dest = (( V_Palette16[ ((nextsource[((frac+(1<<16)))>>16]))*64 + ((filter_fracu*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((source[((frac+(1<<16)))>>16]))*64 + (((0xffff-filter_fracu)*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((source[(frac)>>16]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac)&0xffff)))>>(32-6)) ] + V_Palette16[ ((nextsource[(frac)>>16]))*64 + ((filter_fracu*(0xffff-((frac)&0xffff)))>>(32-6)) ]));
1085             (y++);
1086             dest += 4;
1087             frac += fracstep;
1088          }
1089       }
1090       else
1091       {
1092          unsigned heightmask = dcvars->texheight-1;
1093          if (! (dcvars->texheight & heightmask))
1094          {
1095             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
1096             while ((count-=2)>=0)
1097             {
1098                *dest = (( V_Palette16[ ((nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16]))*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((source[((frac+(1<<16)) & fixedt_heightmask)>>16]))*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((source[(frac & fixedt_heightmask)>>16]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ ((nextsource[(frac & fixedt_heightmask)>>16]))*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
1099                (y++);
1100                dest += 4;
1101                frac += fracstep;
1102                *dest = (( V_Palette16[ ((nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16]))*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((source[((frac+(1<<16)) & fixedt_heightmask)>>16]))*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((source[(frac & fixedt_heightmask)>>16]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ ((nextsource[(frac & fixedt_heightmask)>>16]))*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
1103                (y++);
1104                dest += 4;
1105                frac += fracstep;
1106             }
1107             if (count & 1)
1108                *dest = (( V_Palette16[ ((nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16]))*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((source[((frac+(1<<16)) & fixedt_heightmask)>>16]))*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((source[(frac & fixedt_heightmask)>>16]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ ((nextsource[(frac & fixedt_heightmask)>>16]))*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
1109             (y++);
1110          }
1111          else
1112          {
1113             fixed_t nextfrac = 0;
1114 
1115             heightmask++;
1116             heightmask <<= 16;
1117 
1118             if (frac < 0)
1119                while ((frac += heightmask) < 0);
1120             else
1121                while (frac >= (int)heightmask)
1122                   frac -= heightmask;
1123 
1124 
1125             nextfrac = frac + (1<<16);
1126             while (nextfrac >= (int)heightmask)
1127                nextfrac -= heightmask;
1128 
1129 
1130 
1131 
1132             while (count--)
1133             {
1134 
1135 
1136 
1137 
1138 
1139                *dest = (( V_Palette16[ ((nextsource[(nextfrac)>>16]))*64 + ((filter_fracu*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((source[(nextfrac)>>16]))*64 + (((0xffff-filter_fracu)*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((source[(frac)>>16]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac)&0xffff)))>>(32-6)) ] + V_Palette16[ ((nextsource[(frac)>>16]))*64 + ((filter_fracu*(0xffff-((frac)&0xffff)))>>(32-6)) ]));
1140                (y++);
1141                dest += 4;
1142                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
1143 
1144                if ((nextfrac += fracstep) >= (int)heightmask) nextfrac -= heightmask;;
1145 
1146             }
1147          }
1148       }
1149    }
1150 
1151 }
1152 
1153 // bilinear with simple depth color mapping
R_DrawColumn16_LinearUV_PointZ(draw_column_vars_t * dcvars)1154 static void R_DrawColumn16_LinearUV_PointZ(draw_column_vars_t *dcvars)
1155 {
1156    int count;
1157 
1158    uint16_t *dest;
1159 
1160    fixed_t frac;
1161    const fixed_t fracstep = dcvars->iscale;
1162 
1163    const fixed_t slope_texu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
1164 
1165    if (dcvars->iscale > drawvars.mag_threshold)
1166    {
1167       R_GetDrawColumnFunc(RDC_PIPELINE_STANDARD,
1168             RDRAW_FILTER_POINT,
1169             drawvars.filterz)(dcvars);
1170       return;
1171    }
1172 
1173    count = dcvars->yh - dcvars->yl;
1174 
1175    if (count < 0)
1176       return;
1177 
1178    frac = dcvars->texturemid - ((1<<16)>>1) + (dcvars->yl-centery)*fracstep;
1179 
1180    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
1181    {
1182       if (dcvars->yl != 0) {
1183          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
1184 
1185             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
1186             dcvars->yl += shift;
1187             count -= shift;
1188             frac += 0xffff-(slope_texu & 0xffff);
1189          }
1190          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
1191 
1192             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
1193             dcvars->yl += shift;
1194             count -= shift;
1195             frac += slope_texu & 0xffff;
1196          }
1197       }
1198       if (dcvars->yh != viewheight-1) {
1199          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
1200 
1201             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
1202             dcvars->yh -= shift;
1203             count -= shift;
1204          }
1205          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
1206 
1207             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
1208             dcvars->yh -= shift;
1209             count -= shift;
1210          }
1211       }
1212       if (count <= 0) return;
1213    }
1214 
1215    if(temp_x == 4 ||
1216          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
1217       R_FlushColumns();
1218 
1219    if(!temp_x)
1220    {
1221       startx = dcvars->x;
1222       tempyl[0] = commontop = dcvars->yl;
1223       tempyh[0] = commonbot = dcvars->yh;
1224       temptype = (COL_OPAQUE);
1225 
1226 
1227 
1228 
1229 
1230       R_FlushWholeColumns = R_FlushWhole16;
1231       R_FlushHTColumns = R_FlushHT16;
1232       R_FlushQuadColumn = R_FlushQuad16;
1233 
1234       dest = &short_tempbuf[dcvars->yl << 2];
1235 
1236    }
1237    else
1238    {
1239       tempyl[temp_x] = dcvars->yl;
1240       tempyh[temp_x] = dcvars->yh;
1241 
1242       if(dcvars->yl > commontop)
1243          commontop = dcvars->yl;
1244       if(dcvars->yh < commonbot)
1245          commonbot = dcvars->yh;
1246 
1247 
1248       dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
1249 
1250    }
1251    temp_x += 1;
1252 
1253 
1254 
1255    {
1256       const uint8_t *source = dcvars->source;
1257       const lighttable_t *colormap = dcvars->colormap;
1258 
1259       int y = dcvars->yl;
1260 
1261       const uint8_t *nextsource = dcvars->nextsource;
1262       const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
1263 
1264       count++;
1265 
1266       if (dcvars->texheight == 128)
1267       {
1268 
1269          while(count--)
1270          {
1271             *dest = (( V_Palette16[ (colormap[(nextsource[((frac+(1<<16)) & ((127<<16)|0xffff))>>16])])*64 + ((filter_fracu*((frac & ((127<<16)|0xffff))&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[((frac+(1<<16)) & ((127<<16)|0xffff))>>16])])*64 + (((0xffff-filter_fracu)*((frac & ((127<<16)|0xffff))&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[(frac & ((127<<16)|0xffff))>>16])])*64 + (((0xffff-filter_fracu)*(0xffff-((frac & ((127<<16)|0xffff))&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(nextsource[(frac & ((127<<16)|0xffff))>>16])])*64 + ((filter_fracu*(0xffff-((frac & ((127<<16)|0xffff))&0xffff)))>>(32-6)) ]));
1272             (y++);
1273             dest += 4;
1274             frac += fracstep;
1275          }
1276       }
1277       else if (dcvars->texheight == 0)
1278       {
1279 
1280          while (count--)
1281          {
1282             *dest = (( V_Palette16[ (colormap[(nextsource[((frac+(1<<16)))>>16])])*64 + ((filter_fracu*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[((frac+(1<<16)))>>16])])*64 + (((0xffff-filter_fracu)*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[(frac)>>16])])*64 + (((0xffff-filter_fracu)*(0xffff-((frac)&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(nextsource[(frac)>>16])])*64 + ((filter_fracu*(0xffff-((frac)&0xffff)))>>(32-6)) ]));
1283             (y++);
1284             dest += 4;
1285             frac += fracstep;
1286          }
1287       }
1288       else
1289       {
1290          unsigned heightmask = dcvars->texheight-1;
1291          if (! (dcvars->texheight & heightmask))
1292          {
1293             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
1294             while ((count-=2)>=0)
1295             {
1296                *dest = (( V_Palette16[ (colormap[(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])])*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[((frac+(1<<16)) & fixedt_heightmask)>>16])])*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[(frac & fixedt_heightmask)>>16])])*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(nextsource[(frac & fixedt_heightmask)>>16])])*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
1297                (y++);
1298                dest += 4;
1299                frac += fracstep;
1300                *dest = (( V_Palette16[ (colormap[(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])])*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[((frac+(1<<16)) & fixedt_heightmask)>>16])])*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[(frac & fixedt_heightmask)>>16])])*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(nextsource[(frac & fixedt_heightmask)>>16])])*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
1301                (y++);
1302                dest += 4;
1303                frac += fracstep;
1304             }
1305             if (count & 1)
1306                *dest = (( V_Palette16[ (colormap[(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])])*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[((frac+(1<<16)) & fixedt_heightmask)>>16])])*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[(frac & fixedt_heightmask)>>16])])*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(nextsource[(frac & fixedt_heightmask)>>16])])*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
1307             (y++);
1308          }
1309          else
1310          {
1311             fixed_t nextfrac = 0;
1312 
1313             heightmask++;
1314             heightmask <<= 16;
1315 
1316             if (frac < 0)
1317                while ((frac += heightmask) < 0);
1318             else
1319                while (frac >= (int)heightmask)
1320                   frac -= heightmask;
1321 
1322 
1323             nextfrac = frac + (1<<16);
1324             while (nextfrac >= (int)heightmask)
1325                nextfrac -= heightmask;
1326 
1327             while (count--)
1328             {
1329                *dest = (( V_Palette16[ (colormap[(nextsource[(nextfrac)>>16])])*64 + ((filter_fracu*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[(nextfrac)>>16])])*64 + (((0xffff-filter_fracu)*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[(frac)>>16])])*64 + (((0xffff-filter_fracu)*(0xffff-((frac)&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(nextsource[(frac)>>16])])*64 + ((filter_fracu*(0xffff-((frac)&0xffff)))>>(32-6)) ]));
1330                (y++);
1331                dest += 4;
1332                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
1333 
1334                if ((nextfrac += fracstep) >= (int)heightmask) nextfrac -= heightmask;;
1335 
1336             }
1337          }
1338       }
1339    }
1340 }
1341 
1342 // bilinear + z-dither
R_DrawColumn16_LinearUV_LinearZ(draw_column_vars_t * dcvars)1343 static void R_DrawColumn16_LinearUV_LinearZ(draw_column_vars_t *dcvars)
1344 {
1345    int count;
1346 
1347    uint16_t *dest;
1348 
1349    fixed_t frac;
1350    const fixed_t fracstep = dcvars->iscale;
1351 
1352    const fixed_t slope_texu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
1353 
1354    if (dcvars->iscale > drawvars.mag_threshold)
1355    {
1356       R_GetDrawColumnFunc(RDC_PIPELINE_STANDARD,
1357             RDRAW_FILTER_POINT,
1358             drawvars.filterz)(dcvars);
1359       return;
1360    }
1361 
1362    count = dcvars->yh - dcvars->yl;
1363 
1364    if (count < 0)
1365       return;
1366 
1367    frac = dcvars->texturemid - ((1<<16)>>1) + (dcvars->yl-centery)*fracstep;
1368 
1369    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
1370    {
1371       if (dcvars->yl != 0) {
1372          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
1373 
1374             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
1375             dcvars->yl += shift;
1376             count -= shift;
1377             frac += 0xffff-(slope_texu & 0xffff);
1378          }
1379          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
1380 
1381             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
1382             dcvars->yl += shift;
1383             count -= shift;
1384             frac += slope_texu & 0xffff;
1385          }
1386       }
1387       if (dcvars->yh != viewheight-1) {
1388          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
1389 
1390             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
1391             dcvars->yh -= shift;
1392             count -= shift;
1393          }
1394          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
1395 
1396             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
1397             dcvars->yh -= shift;
1398             count -= shift;
1399          }
1400       }
1401       if (count <= 0) return;
1402    }
1403 
1404    if(temp_x == 4 ||
1405          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
1406       R_FlushColumns();
1407 
1408    if(!temp_x)
1409    {
1410       startx = dcvars->x;
1411       tempyl[0] = commontop = dcvars->yl;
1412       tempyh[0] = commonbot = dcvars->yh;
1413       temptype = (COL_OPAQUE);
1414 
1415 
1416 
1417 
1418 
1419       R_FlushWholeColumns = R_FlushWhole16;
1420       R_FlushHTColumns = R_FlushHT16;
1421       R_FlushQuadColumn = R_FlushQuad16;
1422 
1423       dest = &short_tempbuf[dcvars->yl << 2];
1424 
1425    }
1426    else
1427    {
1428       tempyl[temp_x] = dcvars->yl;
1429       tempyh[temp_x] = dcvars->yh;
1430 
1431       if(dcvars->yl > commontop)
1432          commontop = dcvars->yl;
1433       if(dcvars->yh < commonbot)
1434          commonbot = dcvars->yh;
1435 
1436 
1437       dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
1438 
1439    }
1440    temp_x += 1;
1441 
1442 
1443 
1444    {
1445       const uint8_t *source = dcvars->source;
1446 
1447       int y = dcvars->yl;
1448       const int x = dcvars->x;
1449 
1450 
1451       const int fracz = (dcvars->z >> 6) & 255;
1452       const uint8_t *dither_colormaps[2] = { dcvars->colormap, dcvars->nextcolormap };
1453 
1454 
1455       const uint8_t *nextsource = dcvars->nextsource;
1456       const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
1457 
1458       count++;
1459 
1460       if (dcvars->texheight == 128)
1461       {
1462 
1463          while(count--)
1464          {
1465             *dest = (( V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(nextsource[((frac+(1<<16)) & ((127<<16)|0xffff))>>16])]))*64 + ((filter_fracu*((frac & ((127<<16)|0xffff))&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[((frac+(1<<16)) & ((127<<16)|0xffff))>>16])]))*64 + (((0xffff-filter_fracu)*((frac & ((127<<16)|0xffff))&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(frac & ((127<<16)|0xffff))>>16])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & ((127<<16)|0xffff))&0xffff)))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(nextsource[(frac & ((127<<16)|0xffff))>>16])]))*64 + ((filter_fracu*(0xffff-((frac & ((127<<16)|0xffff))&0xffff)))>>(32-6)) ]));
1466             (y++);
1467             dest += 4;
1468             frac += fracstep;
1469          }
1470       }
1471       else if (dcvars->texheight == 0)
1472       {
1473 
1474          while (count--)
1475          {
1476             *dest = (( V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(nextsource[((frac+(1<<16)))>>16])]))*64 + ((filter_fracu*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[((frac+(1<<16)))>>16])]))*64 + (((0xffff-filter_fracu)*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(frac)>>16])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac)&0xffff)))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(nextsource[(frac)>>16])]))*64 + ((filter_fracu*(0xffff-((frac)&0xffff)))>>(32-6)) ]));
1477             (y++);
1478             dest += 4;
1479             frac += fracstep;
1480          }
1481       }
1482       else
1483       {
1484          unsigned heightmask = dcvars->texheight-1;
1485          if (! (dcvars->texheight & heightmask))
1486          {
1487             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
1488             while ((count-=2)>=0)
1489             {
1490                *dest = (( V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])]))*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[((frac+(1<<16)) & fixedt_heightmask)>>16])]))*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(frac & fixedt_heightmask)>>16])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(nextsource[(frac & fixedt_heightmask)>>16])]))*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
1491                (y++);
1492                dest += 4;
1493                frac += fracstep;
1494                *dest = (( V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])]))*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[((frac+(1<<16)) & fixedt_heightmask)>>16])]))*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(frac & fixedt_heightmask)>>16])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(nextsource[(frac & fixedt_heightmask)>>16])]))*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
1495                (y++);
1496                dest += 4;
1497                frac += fracstep;
1498             }
1499             if (count & 1)
1500                *dest = (( V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])]))*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[((frac+(1<<16)) & fixedt_heightmask)>>16])]))*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(frac & fixedt_heightmask)>>16])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(nextsource[(frac & fixedt_heightmask)>>16])]))*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
1501             (y++);
1502          }
1503          else
1504          {
1505             fixed_t nextfrac = 0;
1506 
1507             heightmask++;
1508             heightmask <<= 16;
1509 
1510             if (frac < 0)
1511                while ((frac += heightmask) < 0);
1512             else
1513                while (frac >= (int)heightmask)
1514                   frac -= heightmask;
1515 
1516 
1517             nextfrac = frac + (1<<16);
1518             while (nextfrac >= (int)heightmask)
1519                nextfrac -= heightmask;
1520 
1521 
1522 
1523 
1524             while (count--)
1525             {
1526 
1527 
1528 
1529 
1530 
1531                *dest = (( V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(nextsource[(nextfrac)>>16])]))*64 + ((filter_fracu*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(nextfrac)>>16])]))*64 + (((0xffff-filter_fracu)*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(source[(frac)>>16])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac)&0xffff)))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(nextsource[(frac)>>16])]))*64 + ((filter_fracu*(0xffff-((frac)&0xffff)))>>(32-6)) ]));
1532                (y++);
1533                dest += 4;
1534                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
1535 
1536                if ((nextfrac += fracstep) >= (int)heightmask) nextfrac -= heightmask;;
1537 
1538             }
1539          }
1540       }
1541    }
1542 
1543 }
1544 
1545 /* rounded with no color mapping */
R_DrawColumn16_RoundedUV(draw_column_vars_t * dcvars)1546 static void R_DrawColumn16_RoundedUV(draw_column_vars_t *dcvars)
1547 {
1548   int count;
1549 
1550   uint16_t *dest;
1551 
1552   fixed_t frac;
1553   const fixed_t fracstep = dcvars->iscale;
1554   const fixed_t slope_texu = dcvars->texu;
1555 
1556   if (dcvars->iscale > drawvars.mag_threshold)
1557   {
1558     R_GetDrawColumnFunc(RDC_PIPELINE_STANDARD,
1559                         RDRAW_FILTER_POINT,
1560                         drawvars.filterz)(dcvars);
1561     return;
1562   }
1563   count = dcvars->yh - dcvars->yl;
1564 
1565   if (count < 0)
1566     return;
1567 
1568   frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
1569 
1570   if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
1571   {
1572      if (dcvars->yl != 0) {
1573         if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
1574 
1575            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
1576            dcvars->yl += shift;
1577            count -= shift;
1578            frac += 0xffff-(slope_texu & 0xffff);
1579         }
1580         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
1581 
1582            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
1583            dcvars->yl += shift;
1584            count -= shift;
1585            frac += slope_texu & 0xffff;
1586         }
1587      }
1588      if (dcvars->yh != viewheight-1) {
1589         if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
1590 
1591            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
1592            dcvars->yh -= shift;
1593            count -= shift;
1594         }
1595         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
1596 
1597            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
1598            dcvars->yh -= shift;
1599            count -= shift;
1600         }
1601      }
1602      if (count <= 0) return;
1603   }
1604 
1605 
1606 
1607    {
1608 
1609       if(temp_x == 4 ||
1610          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
1611          R_FlushColumns();
1612 
1613       if(!temp_x)
1614       {
1615          startx = dcvars->x;
1616          tempyl[0] = commontop = dcvars->yl;
1617          tempyh[0] = commonbot = dcvars->yh;
1618          temptype = (COL_OPAQUE);
1619 
1620 
1621 
1622 
1623 
1624          R_FlushWholeColumns = R_FlushWhole16;
1625          R_FlushHTColumns = R_FlushHT16;
1626          R_FlushQuadColumn = R_FlushQuad16;
1627 
1628          dest = &short_tempbuf[dcvars->yl << 2];
1629 
1630       }
1631       else
1632       {
1633          tempyl[temp_x] = dcvars->yl;
1634          tempyh[temp_x] = dcvars->yh;
1635 
1636          if(dcvars->yl > commontop)
1637             commontop = dcvars->yl;
1638          if(dcvars->yh < commonbot)
1639             commonbot = dcvars->yh;
1640 
1641 
1642          dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
1643 
1644       }
1645       temp_x += 1;
1646    }
1647 
1648 
1649 
1650    {
1651       const uint8_t *source = dcvars->source;
1652 
1653       int y = dcvars->yl;
1654       const uint8_t *prevsource = dcvars->prevsource;
1655       const uint8_t *nextsource = dcvars->nextsource;
1656       const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : (dcvars->texu>>8) & 0xff;
1657 
1658 
1659       count++;
1660 
1661 
1662 
1663 
1664 
1665 
1666 
1667       if (dcvars->texheight == 128)
1668       {
1669 
1670          while(count--)
1671          {
1672             *dest = (V_Palette16[ ((filter_getScale2xQuadColors( source[ ((frac & ((127<<16)|0xffff))>>16) ], source[ (((0)>(((frac & ((127<<16)|0xffff))>>16)-1)?(0):(((frac & ((127<<16)|0xffff))>>16)-1))) ], nextsource[ ((frac & ((127<<16)|0xffff))>>16) ], source[ (((frac+(1<<16)) & ((127<<16)|0xffff))>>16) ], prevsource[ ((frac & ((127<<16)|0xffff))>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & ((127<<16)|0xffff))>>8) & 0xff)>>(8-6)) ] ]))*64 + ((64 -1)) ]);
1673             (y++);
1674             dest += 4;
1675             frac += fracstep;
1676          }
1677       }
1678       else if (dcvars->texheight == 0)
1679       {
1680 
1681          while (count--)
1682          {
1683             *dest = (V_Palette16[ ((filter_getScale2xQuadColors( source[ ((frac)>>16) ], source[ (((0)>(((frac)>>16)-1)?(0):(((frac)>>16)-1))) ], nextsource[ ((frac)>>16) ], source[ (((frac+(1<<16)))>>16) ], prevsource[ ((frac)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac)>>8) & 0xff)>>(8-6)) ] ]))*64 + ((64 -1)) ]);
1684             (y++);
1685             dest += 4;
1686             frac += fracstep;
1687          }
1688       }
1689       else
1690       {
1691          unsigned heightmask = dcvars->texheight-1;
1692          if (! (dcvars->texheight & heightmask))
1693          {
1694             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
1695             while ((count-=2)>=0)
1696             {
1697                *dest = (V_Palette16[ ((filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ]))*64 + ((64 -1)) ]);
1698                (y++);
1699                dest += 4;
1700                frac += fracstep;
1701                *dest = (V_Palette16[ ((filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ]))*64 + ((64 -1)) ]);
1702                (y++);
1703                dest += 4;
1704                frac += fracstep;
1705             }
1706             if (count & 1)
1707                *dest = (V_Palette16[ ((filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ]))*64 + ((64 -1)) ]);
1708             (y++);
1709          }
1710          else
1711          {
1712             fixed_t nextfrac = 0;
1713 
1714             heightmask++;
1715             heightmask <<= 16;
1716 
1717             if (frac < 0)
1718                while ((frac += heightmask) < 0);
1719             else
1720                while (frac >= (int)heightmask)
1721                   frac -= heightmask;
1722 
1723 
1724             nextfrac = frac + (1<<16);
1725             while (nextfrac >= (int)heightmask)
1726                nextfrac -= heightmask;
1727 
1728 
1729 
1730 
1731             while (count--)
1732             {
1733 
1734 
1735 
1736 
1737 
1738                *dest = (V_Palette16[ ((filter_getScale2xQuadColors( source[ ((frac)>>16) ], source[ (((0)>(((frac)>>16)-1)?(0):(((frac)>>16)-1))) ], nextsource[ ((frac)>>16) ], source[ ((nextfrac)>>16) ], prevsource[ ((frac)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac)>>8) & 0xff)>>(8-6)) ] ]))*64 + ((64 -1)) ]);
1739                (y++);
1740                dest += 4;
1741                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
1742 
1743                if ((nextfrac += fracstep) >= (int)heightmask) nextfrac -= heightmask;;
1744 
1745             }
1746          }
1747       }
1748    }
1749 
1750 }
1751 
1752 /* rounded with simple depth color mapping */
R_DrawColumn16_RoundedUV_PointZ(draw_column_vars_t * dcvars)1753 static void R_DrawColumn16_RoundedUV_PointZ(draw_column_vars_t *dcvars)
1754 {
1755    int count;
1756 
1757    uint16_t *dest;
1758 
1759    fixed_t frac;
1760    const fixed_t fracstep = dcvars->iscale;
1761    const fixed_t slope_texu = dcvars->texu;
1762 
1763    if (dcvars->iscale > drawvars.mag_threshold)
1764    {
1765       R_GetDrawColumnFunc(RDC_PIPELINE_STANDARD,
1766             RDRAW_FILTER_POINT,
1767             drawvars.filterz)(dcvars);
1768       return;
1769    }
1770    count = dcvars->yh - dcvars->yl;
1771 
1772    if (count < 0)
1773       return;
1774 
1775    frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
1776 
1777 
1778    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED) {
1779 
1780 
1781 
1782       if (dcvars->yl != 0) {
1783          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
1784 
1785             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
1786             dcvars->yl += shift;
1787             count -= shift;
1788             frac += 0xffff-(slope_texu & 0xffff);
1789          }
1790          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
1791 
1792             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
1793             dcvars->yl += shift;
1794             count -= shift;
1795             frac += slope_texu & 0xffff;
1796          }
1797       }
1798       if (dcvars->yh != viewheight-1) {
1799          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
1800 
1801             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
1802             dcvars->yh -= shift;
1803             count -= shift;
1804          }
1805          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
1806 
1807             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
1808             dcvars->yh -= shift;
1809             count -= shift;
1810          }
1811       }
1812       if (count <= 0) return;
1813    }
1814 
1815 
1816 
1817    {
1818 
1819       if(temp_x == 4 ||
1820             (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
1821          R_FlushColumns();
1822 
1823       if(!temp_x)
1824       {
1825          startx = dcvars->x;
1826          tempyl[0] = commontop = dcvars->yl;
1827          tempyh[0] = commonbot = dcvars->yh;
1828          temptype = (COL_OPAQUE);
1829 
1830 
1831 
1832 
1833 
1834          R_FlushWholeColumns = R_FlushWhole16;
1835          R_FlushHTColumns = R_FlushHT16;
1836          R_FlushQuadColumn = R_FlushQuad16;
1837 
1838          dest = &short_tempbuf[dcvars->yl << 2];
1839 
1840       }
1841       else
1842       {
1843          tempyl[temp_x] = dcvars->yl;
1844          tempyh[temp_x] = dcvars->yh;
1845 
1846          if(dcvars->yl > commontop)
1847             commontop = dcvars->yl;
1848          if(dcvars->yh < commonbot)
1849             commonbot = dcvars->yh;
1850 
1851 
1852          dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
1853 
1854       }
1855       temp_x += 1;
1856    }
1857 
1858 
1859 
1860    {
1861       const uint8_t *source = dcvars->source;
1862       const lighttable_t *colormap = dcvars->colormap;
1863 
1864       int y = dcvars->yl;
1865       const uint8_t *prevsource = dcvars->prevsource;
1866       const uint8_t *nextsource = dcvars->nextsource;
1867       const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : (dcvars->texu>>8) & 0xff;
1868 
1869 
1870       count++;
1871 
1872 
1873 
1874 
1875 
1876 
1877 
1878       if (dcvars->texheight == 128)
1879       {
1880 
1881          while(count--)
1882          {
1883             *dest = (V_Palette16[ (colormap[(filter_getScale2xQuadColors( source[ ((frac & ((127<<16)|0xffff))>>16) ], source[ (((0)>(((frac & ((127<<16)|0xffff))>>16)-1)?(0):(((frac & ((127<<16)|0xffff))>>16)-1))) ], nextsource[ ((frac & ((127<<16)|0xffff))>>16) ], source[ (((frac+(1<<16)) & ((127<<16)|0xffff))>>16) ], prevsource[ ((frac & ((127<<16)|0xffff))>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & ((127<<16)|0xffff))>>8) & 0xff)>>(8-6)) ] ])])*64 + ((64 -1)) ]);
1884             (y++);
1885             dest += 4;
1886             frac += fracstep;
1887          }
1888       }
1889       else if (dcvars->texheight == 0)
1890       {
1891 
1892          while (count--)
1893          {
1894             *dest = (V_Palette16[ (colormap[(filter_getScale2xQuadColors( source[ ((frac)>>16) ], source[ (((0)>(((frac)>>16)-1)?(0):(((frac)>>16)-1))) ], nextsource[ ((frac)>>16) ], source[ (((frac+(1<<16)))>>16) ], prevsource[ ((frac)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac)>>8) & 0xff)>>(8-6)) ] ])])*64 + ((64 -1)) ]);
1895             (y++);
1896             dest += 4;
1897             frac += fracstep;
1898          }
1899       }
1900       else
1901       {
1902          unsigned heightmask = dcvars->texheight-1;
1903          if (! (dcvars->texheight & heightmask))
1904          {
1905             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
1906             while ((count-=2)>=0)
1907             {
1908                *dest = (V_Palette16[ (colormap[(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])])*64 + ((64 -1)) ]);
1909                (y++);
1910                dest += 4;
1911                frac += fracstep;
1912                *dest = (V_Palette16[ (colormap[(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])])*64 + ((64 -1)) ]);
1913                (y++);
1914                dest += 4;
1915                frac += fracstep;
1916             }
1917             if (count & 1)
1918                *dest = (V_Palette16[ (colormap[(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])])*64 + ((64 -1)) ]);
1919             (y++);
1920          }
1921          else
1922          {
1923             fixed_t nextfrac = 0;
1924 
1925             heightmask++;
1926             heightmask <<= 16;
1927 
1928             if (frac < 0)
1929                while ((frac += heightmask) < 0);
1930             else
1931                while (frac >= (int)heightmask)
1932                   frac -= heightmask;
1933 
1934 
1935             nextfrac = frac + (1<<16);
1936             while (nextfrac >= (int)heightmask)
1937                nextfrac -= heightmask;
1938 
1939 
1940 
1941 
1942             while (count--)
1943             {
1944 
1945 
1946 
1947 
1948 
1949                *dest = (V_Palette16[ (colormap[(filter_getScale2xQuadColors( source[ ((frac)>>16) ], source[ (((0)>(((frac)>>16)-1)?(0):(((frac)>>16)-1))) ], nextsource[ ((frac)>>16) ], source[ ((nextfrac)>>16) ], prevsource[ ((frac)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac)>>8) & 0xff)>>(8-6)) ] ])])*64 + ((64 -1)) ]);
1950                (y++);
1951                dest += 4;
1952                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
1953 
1954                if ((nextfrac += fracstep) >= (int)heightmask) nextfrac -= heightmask;;
1955 
1956             }
1957          }
1958       }
1959    }
1960 
1961 }
1962 
1963 /* rounded + z-dither */
R_DrawColumn16_RoundedUV_LinearZ(draw_column_vars_t * dcvars)1964 static void R_DrawColumn16_RoundedUV_LinearZ(draw_column_vars_t *dcvars)
1965 {
1966    int count;
1967 
1968    uint16_t *dest;
1969 
1970    fixed_t frac;
1971    const fixed_t fracstep = dcvars->iscale;
1972    const fixed_t slope_texu = dcvars->texu;
1973 
1974    if (dcvars->iscale > drawvars.mag_threshold)
1975    {
1976       R_GetDrawColumnFunc(RDC_PIPELINE_STANDARD,
1977             RDRAW_FILTER_POINT,
1978             drawvars.filterz)(dcvars);
1979       return;
1980    }
1981 
1982    count = dcvars->yh - dcvars->yl;
1983 
1984    if (count < 0)
1985       return;
1986 
1987    frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
1988 
1989 
1990    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED) {
1991 
1992 
1993 
1994       if (dcvars->yl != 0) {
1995          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
1996 
1997             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
1998             dcvars->yl += shift;
1999             count -= shift;
2000             frac += 0xffff-(slope_texu & 0xffff);
2001          }
2002          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
2003 
2004             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
2005             dcvars->yl += shift;
2006             count -= shift;
2007             frac += slope_texu & 0xffff;
2008          }
2009       }
2010       if (dcvars->yh != viewheight-1) {
2011          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
2012 
2013             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
2014             dcvars->yh -= shift;
2015             count -= shift;
2016          }
2017          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
2018 
2019             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
2020             dcvars->yh -= shift;
2021             count -= shift;
2022          }
2023       }
2024       if (count <= 0) return;
2025    }
2026 
2027 
2028 
2029    {
2030 
2031       if(temp_x == 4 ||
2032             (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
2033          R_FlushColumns();
2034 
2035       if(!temp_x)
2036       {
2037          startx = dcvars->x;
2038          tempyl[0] = commontop = dcvars->yl;
2039          tempyh[0] = commonbot = dcvars->yh;
2040          temptype = (COL_OPAQUE);
2041 
2042 
2043 
2044 
2045 
2046          R_FlushWholeColumns = R_FlushWhole16;
2047          R_FlushHTColumns = R_FlushHT16;
2048          R_FlushQuadColumn = R_FlushQuad16;
2049 
2050          dest = &short_tempbuf[dcvars->yl << 2];
2051 
2052       }
2053       else
2054       {
2055          tempyl[temp_x] = dcvars->yl;
2056          tempyh[temp_x] = dcvars->yh;
2057 
2058          if(dcvars->yl > commontop)
2059             commontop = dcvars->yl;
2060          if(dcvars->yh < commonbot)
2061             commonbot = dcvars->yh;
2062 
2063 
2064          dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
2065 
2066       }
2067       temp_x += 1;
2068    }
2069 
2070 
2071 
2072    {
2073       const uint8_t *source = dcvars->source;
2074 
2075       int y = dcvars->yl;
2076       const int x = dcvars->x;
2077 
2078 
2079       const int fracz = (dcvars->z >> 6) & 255;
2080       const uint8_t *dither_colormaps[2] = { dcvars->colormap, dcvars->nextcolormap };
2081 
2082 
2083 
2084 
2085 
2086 
2087       const uint8_t *prevsource = dcvars->prevsource;
2088       const uint8_t *nextsource = dcvars->nextsource;
2089       const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : (dcvars->texu>>8) & 0xff;
2090 
2091 
2092       count++;
2093 
2094 
2095 
2096 
2097 
2098 
2099 
2100       if (dcvars->texheight == 128)
2101       {
2102 
2103          while(count--)
2104          {
2105             *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(filter_getScale2xQuadColors( source[ ((frac & ((127<<16)|0xffff))>>16) ], source[ (((0)>(((frac & ((127<<16)|0xffff))>>16)-1)?(0):(((frac & ((127<<16)|0xffff))>>16)-1))) ], nextsource[ ((frac & ((127<<16)|0xffff))>>16) ], source[ (((frac+(1<<16)) & ((127<<16)|0xffff))>>16) ], prevsource[ ((frac & ((127<<16)|0xffff))>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & ((127<<16)|0xffff))>>8) & 0xff)>>(8-6)) ] ])]))*64 + ((64 -1)) ]);
2106             (y++);
2107             dest += 4;
2108             frac += fracstep;
2109          }
2110       }
2111       else if (dcvars->texheight == 0)
2112       {
2113 
2114          while (count--)
2115          {
2116             *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(filter_getScale2xQuadColors( source[ ((frac)>>16) ], source[ (((0)>(((frac)>>16)-1)?(0):(((frac)>>16)-1))) ], nextsource[ ((frac)>>16) ], source[ (((frac+(1<<16)))>>16) ], prevsource[ ((frac)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac)>>8) & 0xff)>>(8-6)) ] ])]))*64 + ((64 -1)) ]);
2117             (y++);
2118             dest += 4;
2119             frac += fracstep;
2120          }
2121       }
2122       else
2123       {
2124          unsigned heightmask = dcvars->texheight-1;
2125          if (! (dcvars->texheight & heightmask))
2126          {
2127             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
2128             while ((count-=2)>=0)
2129             {
2130                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])]))*64 + ((64 -1)) ]);
2131                (y++);
2132                dest += 4;
2133                frac += fracstep;
2134                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])]))*64 + ((64 -1)) ]);
2135                (y++);
2136                dest += 4;
2137                frac += fracstep;
2138             }
2139             if (count & 1)
2140                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])]))*64 + ((64 -1)) ]);
2141             (y++);
2142          }
2143          else
2144          {
2145             fixed_t nextfrac = 0;
2146 
2147             heightmask++;
2148             heightmask <<= 16;
2149 
2150             if (frac < 0)
2151                while ((frac += heightmask) < 0);
2152             else
2153                while (frac >= (int)heightmask)
2154                   frac -= heightmask;
2155 
2156 
2157             nextfrac = frac + (1<<16);
2158             while (nextfrac >= (int)heightmask)
2159                nextfrac -= heightmask;
2160 
2161 
2162 
2163 
2164             while (count--)
2165             {
2166 
2167 
2168 
2169 
2170 
2171                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(filter_getScale2xQuadColors( source[ ((frac)>>16) ], source[ (((0)>(((frac)>>16)-1)?(0):(((frac)>>16)-1))) ], nextsource[ ((frac)>>16) ], source[ ((nextfrac)>>16) ], prevsource[ ((frac)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac)>>8) & 0xff)>>(8-6)) ] ])]))*64 + ((64 -1)) ]);
2172                (y++);
2173                dest += 4;
2174                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
2175 
2176                if ((nextfrac += fracstep) >= (int)heightmask) nextfrac -= heightmask;;
2177 
2178             }
2179          }
2180       }
2181    }
2182 }
2183 
2184 //
2185 // R_DrawTranslatedColumn
2186 // Used to draw player sprites
2187 //  with the green colorramp mapped to others.
2188 // Could be used with different translation
2189 //  tables, e.g. the lighter colored version
2190 //  of the BaronOfHell, the HellKnight, uses
2191 //  identical sprites, kinda brightened up.
2192 //
2193 
R_DrawTranslatedColumn16_PointUV(draw_column_vars_t * dcvars)2194 static void R_DrawTranslatedColumn16_PointUV(draw_column_vars_t *dcvars)
2195 {
2196    int count;
2197 
2198    uint16_t *dest;
2199 
2200    fixed_t frac;
2201    const fixed_t fracstep = dcvars->iscale;
2202    const fixed_t slope_texu = dcvars->texu;
2203    count = dcvars->yh - dcvars->yl;
2204 
2205    if (count < 0)
2206       return;
2207 
2208    frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
2209 
2210    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
2211    {
2212       if (dcvars->yl != 0) {
2213          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
2214 
2215             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
2216             dcvars->yl += shift;
2217             count -= shift;
2218             frac += 0xffff-(slope_texu & 0xffff);
2219          }
2220          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
2221 
2222             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
2223             dcvars->yl += shift;
2224             count -= shift;
2225             frac += slope_texu & 0xffff;
2226          }
2227       }
2228       if (dcvars->yh != viewheight-1) {
2229          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
2230 
2231             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
2232             dcvars->yh -= shift;
2233             count -= shift;
2234          }
2235          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
2236 
2237             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
2238             dcvars->yh -= shift;
2239             count -= shift;
2240          }
2241       }
2242       if (count <= 0) return;
2243    }
2244 
2245    if(temp_x == 4 ||
2246          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
2247       R_FlushColumns();
2248 
2249    if(!temp_x)
2250    {
2251       startx = dcvars->x;
2252       tempyl[0] = commontop = dcvars->yl;
2253       tempyh[0] = commonbot = dcvars->yh;
2254       temptype = (COL_OPAQUE);
2255 
2256 
2257 
2258 
2259 
2260       R_FlushWholeColumns = R_FlushWhole16;
2261       R_FlushHTColumns = R_FlushHT16;
2262       R_FlushQuadColumn = R_FlushQuad16;
2263 
2264       dest = &short_tempbuf[dcvars->yl << 2];
2265 
2266    }
2267    else
2268    {
2269       tempyl[temp_x] = dcvars->yl;
2270       tempyh[temp_x] = dcvars->yh;
2271 
2272       if(dcvars->yl > commontop)
2273          commontop = dcvars->yl;
2274       if(dcvars->yh < commonbot)
2275          commonbot = dcvars->yh;
2276 
2277 
2278       dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
2279 
2280    }
2281    temp_x += 1;
2282 
2283 
2284 
2285    {
2286       const uint8_t *source = dcvars->source;
2287       const uint8_t *translation = dcvars->translation;
2288       count++;
2289 
2290 
2291 
2292 
2293 
2294 
2295 
2296       if (dcvars->texheight == 128)
2297       {
2298 
2299          while(count--)
2300          {
2301             *dest = (V_Palette16[ ((translation[(source[(frac & ((127<<16)|0xffff))>>16])]))*64 + ((64 -1)) ]);
2302             ;
2303             dest += 4;
2304             frac += fracstep;
2305          }
2306       }
2307       else if (dcvars->texheight == 0)
2308       {
2309 
2310          while (count--)
2311          {
2312             *dest = (V_Palette16[ ((translation[(source[(frac)>>16])]))*64 + ((64 -1)) ]);
2313             ;
2314             dest += 4;
2315             frac += fracstep;
2316          }
2317       }
2318       else
2319       {
2320          unsigned heightmask = dcvars->texheight-1;
2321          if (! (dcvars->texheight & heightmask))
2322          {
2323             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
2324             while ((count-=2)>=0)
2325             {
2326                *dest = (V_Palette16[ ((translation[(source[(frac & fixedt_heightmask)>>16])]))*64 + ((64 -1)) ]);
2327                ;
2328                dest += 4;
2329                frac += fracstep;
2330                *dest = (V_Palette16[ ((translation[(source[(frac & fixedt_heightmask)>>16])]))*64 + ((64 -1)) ]);
2331                ;
2332                dest += 4;
2333                frac += fracstep;
2334             }
2335             if (count & 1)
2336                *dest = (V_Palette16[ ((translation[(source[(frac & fixedt_heightmask)>>16])]))*64 + ((64 -1)) ]);
2337             ;
2338          }
2339          else
2340          {
2341             heightmask++;
2342             heightmask <<= 16;
2343 
2344             if (frac < 0)
2345                while ((frac += heightmask) < 0);
2346             else
2347                while (frac >= (int)heightmask)
2348                   frac -= heightmask;
2349             while (count--)
2350             {
2351 
2352 
2353 
2354 
2355 
2356                *dest = (V_Palette16[ ((translation[(source[(frac)>>16])]))*64 + ((64 -1)) ]);
2357                ;
2358                dest += 4;
2359                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
2360 
2361 
2362 
2363             }
2364          }
2365       }
2366    }
2367 
2368 }
2369 
R_DrawTranslatedColumn16_PointUV_PointZ(draw_column_vars_t * dcvars)2370 static void R_DrawTranslatedColumn16_PointUV_PointZ(draw_column_vars_t *dcvars)
2371 {
2372    int count;
2373 
2374    uint16_t *dest;
2375 
2376    fixed_t frac;
2377    const fixed_t fracstep = dcvars->iscale;
2378    const fixed_t slope_texu = dcvars->texu;
2379    count = dcvars->yh - dcvars->yl;
2380 
2381    if (count < 0)
2382       return;
2383 
2384    frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
2385 
2386    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
2387    {
2388       if (dcvars->yl != 0) {
2389          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
2390 
2391             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
2392             dcvars->yl += shift;
2393             count -= shift;
2394             frac += 0xffff-(slope_texu & 0xffff);
2395          }
2396          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
2397 
2398             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
2399             dcvars->yl += shift;
2400             count -= shift;
2401             frac += slope_texu & 0xffff;
2402          }
2403       }
2404       if (dcvars->yh != viewheight-1) {
2405          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
2406 
2407             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
2408             dcvars->yh -= shift;
2409             count -= shift;
2410          }
2411          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
2412 
2413             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
2414             dcvars->yh -= shift;
2415             count -= shift;
2416          }
2417       }
2418       if (count <= 0) return;
2419    }
2420 
2421    if(temp_x == 4 ||
2422          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
2423       R_FlushColumns();
2424 
2425    if(!temp_x)
2426    {
2427       startx = dcvars->x;
2428       tempyl[0] = commontop = dcvars->yl;
2429       tempyh[0] = commonbot = dcvars->yh;
2430       temptype = (COL_OPAQUE);
2431 
2432 
2433 
2434 
2435 
2436       R_FlushWholeColumns = R_FlushWhole16;
2437       R_FlushHTColumns = R_FlushHT16;
2438       R_FlushQuadColumn = R_FlushQuad16;
2439 
2440       dest = &short_tempbuf[dcvars->yl << 2];
2441 
2442    }
2443    else
2444    {
2445       tempyl[temp_x] = dcvars->yl;
2446       tempyh[temp_x] = dcvars->yh;
2447 
2448       if(dcvars->yl > commontop)
2449          commontop = dcvars->yl;
2450       if(dcvars->yh < commonbot)
2451          commonbot = dcvars->yh;
2452 
2453 
2454       dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
2455 
2456    }
2457    temp_x += 1;
2458 
2459 
2460 
2461    {
2462       const uint8_t *source = dcvars->source;
2463       const lighttable_t *colormap = dcvars->colormap;
2464       const uint8_t *translation = dcvars->translation;
2465       count++;
2466 
2467 
2468 
2469 
2470 
2471 
2472 
2473       if (dcvars->texheight == 128)
2474       {
2475 
2476          while(count--)
2477          {
2478             *dest = (V_Palette16[ (colormap[(translation[(source[(frac & ((127<<16)|0xffff))>>16])])])*64 + ((64 -1)) ]);
2479             ;
2480             dest += 4;
2481             frac += fracstep;
2482          }
2483       }
2484       else if (dcvars->texheight == 0)
2485       {
2486 
2487          while (count--)
2488          {
2489             *dest = (V_Palette16[ (colormap[(translation[(source[(frac)>>16])])])*64 + ((64 -1)) ]);
2490             ;
2491             dest += 4;
2492             frac += fracstep;
2493          }
2494       }
2495       else
2496       {
2497          unsigned heightmask = dcvars->texheight-1;
2498          if (! (dcvars->texheight & heightmask))
2499          {
2500             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
2501             while ((count-=2)>=0)
2502             {
2503                *dest = (V_Palette16[ (colormap[(translation[(source[(frac & fixedt_heightmask)>>16])])])*64 + ((64 -1)) ]);
2504                ;
2505                dest += 4;
2506                frac += fracstep;
2507                *dest = (V_Palette16[ (colormap[(translation[(source[(frac & fixedt_heightmask)>>16])])])*64 + ((64 -1)) ]);
2508                ;
2509                dest += 4;
2510                frac += fracstep;
2511             }
2512             if (count & 1)
2513                *dest = (V_Palette16[ (colormap[(translation[(source[(frac & fixedt_heightmask)>>16])])])*64 + ((64 -1)) ]);
2514             ;
2515          }
2516          else
2517          {
2518             heightmask++;
2519             heightmask <<= 16;
2520 
2521             if (frac < 0)
2522                while ((frac += heightmask) < 0);
2523             else
2524                while (frac >= (int)heightmask)
2525                   frac -= heightmask;
2526             while (count--)
2527             {
2528                *dest = (V_Palette16[ (colormap[(translation[(source[(frac)>>16])])])*64 + ((64 -1)) ]);
2529                ;
2530                dest += 4;
2531                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
2532             }
2533          }
2534       }
2535    }
2536 
2537 }
2538 
2539 
R_DrawTranslatedColumn16_PointUV_LinearZ(draw_column_vars_t * dcvars)2540 static void R_DrawTranslatedColumn16_PointUV_LinearZ(draw_column_vars_t *dcvars)
2541 {
2542   int count;
2543 
2544   uint16_t *dest;
2545 
2546   fixed_t frac;
2547   const fixed_t fracstep = dcvars->iscale;
2548   const fixed_t slope_texu = dcvars->texu;
2549   count = dcvars->yh - dcvars->yl;
2550 
2551   if (count < 0)
2552     return;
2553 
2554   frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
2555 
2556   if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
2557   {
2558      if (dcvars->yl != 0) {
2559         if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
2560 
2561            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
2562            dcvars->yl += shift;
2563            count -= shift;
2564            frac += 0xffff-(slope_texu & 0xffff);
2565         }
2566         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
2567 
2568            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
2569            dcvars->yl += shift;
2570            count -= shift;
2571            frac += slope_texu & 0xffff;
2572         }
2573      }
2574      if (dcvars->yh != viewheight-1) {
2575         if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
2576 
2577            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
2578            dcvars->yh -= shift;
2579            count -= shift;
2580         }
2581         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
2582 
2583            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
2584            dcvars->yh -= shift;
2585            count -= shift;
2586         }
2587      }
2588      if (count <= 0) return;
2589   }
2590 
2591 
2592 
2593    {
2594 
2595       if(temp_x == 4 ||
2596          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
2597          R_FlushColumns();
2598 
2599       if(!temp_x)
2600       {
2601          startx = dcvars->x;
2602          tempyl[0] = commontop = dcvars->yl;
2603          tempyh[0] = commonbot = dcvars->yh;
2604          temptype = (COL_OPAQUE);
2605 
2606 
2607 
2608 
2609 
2610          R_FlushWholeColumns = R_FlushWhole16;
2611          R_FlushHTColumns = R_FlushHT16;
2612          R_FlushQuadColumn = R_FlushQuad16;
2613 
2614          dest = &short_tempbuf[dcvars->yl << 2];
2615 
2616       }
2617       else
2618       {
2619          tempyl[temp_x] = dcvars->yl;
2620          tempyh[temp_x] = dcvars->yh;
2621 
2622          if(dcvars->yl > commontop)
2623             commontop = dcvars->yl;
2624          if(dcvars->yh < commonbot)
2625             commonbot = dcvars->yh;
2626 
2627 
2628          dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
2629 
2630       }
2631       temp_x += 1;
2632    }
2633 
2634 
2635 
2636    {
2637       const uint8_t *source = dcvars->source;
2638       const uint8_t *translation = dcvars->translation;
2639 
2640       int y = dcvars->yl;
2641       const int x = dcvars->x;
2642 
2643 
2644       const int fracz = (dcvars->z >> 6) & 255;
2645       const uint8_t *dither_colormaps[2] = { dcvars->colormap, dcvars->nextcolormap };
2646       count++;
2647 
2648 
2649 
2650 
2651 
2652 
2653 
2654       if (dcvars->texheight == 128)
2655       {
2656 
2657          while(count--)
2658          {
2659             *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(frac & ((127<<16)|0xffff))>>16])])]))*64 + ((64 -1)) ]);
2660             (y++);
2661             dest += 4;
2662             frac += fracstep;
2663          }
2664       }
2665       else if (dcvars->texheight == 0)
2666       {
2667 
2668          while (count--)
2669          {
2670             *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(frac)>>16])])]))*64 + ((64 -1)) ]);
2671             (y++);
2672             dest += 4;
2673             frac += fracstep;
2674          }
2675       }
2676       else
2677       {
2678          unsigned heightmask = dcvars->texheight-1;
2679          if (! (dcvars->texheight & heightmask))
2680          {
2681             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
2682             while ((count-=2)>=0)
2683             {
2684                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(frac & fixedt_heightmask)>>16])])]))*64 + ((64 -1)) ]);
2685                (y++);
2686                dest += 4;
2687                frac += fracstep;
2688                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(frac & fixedt_heightmask)>>16])])]))*64 + ((64 -1)) ]);
2689                (y++);
2690                dest += 4;
2691                frac += fracstep;
2692             }
2693             if (count & 1)
2694                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(frac & fixedt_heightmask)>>16])])]))*64 + ((64 -1)) ]);
2695             (y++);
2696          }
2697          else
2698          {
2699             heightmask++;
2700             heightmask <<= 16;
2701 
2702             if (frac < 0)
2703                while ((frac += heightmask) < 0);
2704             else
2705                while (frac >= (int)heightmask)
2706                   frac -= heightmask;
2707             while (count--)
2708             {
2709 
2710 
2711 
2712 
2713 
2714                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(frac)>>16])])]))*64 + ((64 -1)) ]);
2715                (y++);
2716                dest += 4;
2717                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
2718 
2719 
2720 
2721             }
2722          }
2723       }
2724    }
2725 
2726 }
2727 
R_DrawTranslatedColumn16_LinearUV(draw_column_vars_t * dcvars)2728 static void R_DrawTranslatedColumn16_LinearUV(draw_column_vars_t *dcvars)
2729 {
2730   int count;
2731 
2732   uint16_t *dest;
2733 
2734   fixed_t frac;
2735   const fixed_t fracstep = dcvars->iscale;
2736 
2737   const fixed_t slope_texu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
2738 
2739 
2740 
2741 
2742 
2743 
2744   if (dcvars->iscale > drawvars.mag_threshold) {
2745     R_GetDrawColumnFunc(RDC_PIPELINE_TRANSLATED,
2746                         RDRAW_FILTER_POINT,
2747                         drawvars.filterz)(dcvars);
2748     return;
2749   }
2750   count = dcvars->yh - dcvars->yl;
2751 
2752 
2753 
2754 
2755 
2756 
2757 
2758   if (count < 0)
2759     return;
2760 
2761   frac = dcvars->texturemid - ((1<<16)>>1) + (dcvars->yl-centery)*fracstep;
2762 
2763   if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED) {
2764 
2765 
2766 
2767     if (dcvars->yl != 0) {
2768       if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
2769 
2770         int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
2771         dcvars->yl += shift;
2772         count -= shift;
2773         frac += 0xffff-(slope_texu & 0xffff);
2774       }
2775       else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
2776 
2777         int shift = ((slope_texu & 0xffff)/dcvars->iscale);
2778         dcvars->yl += shift;
2779         count -= shift;
2780         frac += slope_texu & 0xffff;
2781       }
2782     }
2783     if (dcvars->yh != viewheight-1) {
2784       if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
2785 
2786         int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
2787         dcvars->yh -= shift;
2788         count -= shift;
2789       }
2790       else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
2791 
2792         int shift = ((slope_texu & 0xffff)/dcvars->iscale);
2793         dcvars->yh -= shift;
2794         count -= shift;
2795       }
2796     }
2797     if (count <= 0) return;
2798   }
2799 
2800 
2801 
2802    {
2803 
2804       if(temp_x == 4 ||
2805          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
2806          R_FlushColumns();
2807 
2808       if(!temp_x)
2809       {
2810          startx = dcvars->x;
2811          tempyl[0] = commontop = dcvars->yl;
2812          tempyh[0] = commonbot = dcvars->yh;
2813          temptype = (COL_OPAQUE);
2814 
2815 
2816 
2817 
2818 
2819          R_FlushWholeColumns = R_FlushWhole16;
2820          R_FlushHTColumns = R_FlushHT16;
2821          R_FlushQuadColumn = R_FlushQuad16;
2822 
2823          dest = &short_tempbuf[dcvars->yl << 2];
2824 
2825       }
2826       else
2827       {
2828          tempyl[temp_x] = dcvars->yl;
2829          tempyh[temp_x] = dcvars->yh;
2830 
2831          if(dcvars->yl > commontop)
2832             commontop = dcvars->yl;
2833          if(dcvars->yh < commonbot)
2834             commonbot = dcvars->yh;
2835 
2836 
2837          dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
2838 
2839       }
2840       temp_x += 1;
2841    }
2842 
2843 
2844 
2845    {
2846       const uint8_t *source = dcvars->source;
2847       const uint8_t *translation = dcvars->translation;
2848 
2849       int y = dcvars->yl;
2850 
2851       const uint8_t *nextsource = dcvars->nextsource;
2852       const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
2853 
2854 
2855 
2856 
2857 
2858 
2859 
2860       count++;
2861 
2862 
2863 
2864 
2865 
2866 
2867 
2868       if (dcvars->texheight == 128)
2869       {
2870 
2871          while(count--)
2872          {
2873             *dest = (( V_Palette16[ ((translation[(nextsource[((frac+(1<<16)) & ((127<<16)|0xffff))>>16])]))*64 + ((filter_fracu*((frac & ((127<<16)|0xffff))&0xffff))>>(32-6)) ] + V_Palette16[ ((translation[(source[((frac+(1<<16)) & ((127<<16)|0xffff))>>16])]))*64 + (((0xffff-filter_fracu)*((frac & ((127<<16)|0xffff))&0xffff))>>(32-6)) ] + V_Palette16[ ((translation[(source[(frac & ((127<<16)|0xffff))>>16])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & ((127<<16)|0xffff))&0xffff)))>>(32-6)) ] + V_Palette16[ ((translation[(nextsource[(frac & ((127<<16)|0xffff))>>16])]))*64 + ((filter_fracu*(0xffff-((frac & ((127<<16)|0xffff))&0xffff)))>>(32-6)) ]));
2874             (y++);
2875             dest += 4;
2876             frac += fracstep;
2877          }
2878       }
2879       else if (dcvars->texheight == 0)
2880       {
2881 
2882          while (count--)
2883          {
2884             *dest = (( V_Palette16[ ((translation[(nextsource[((frac+(1<<16)))>>16])]))*64 + ((filter_fracu*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((translation[(source[((frac+(1<<16)))>>16])]))*64 + (((0xffff-filter_fracu)*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((translation[(source[(frac)>>16])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac)&0xffff)))>>(32-6)) ] + V_Palette16[ ((translation[(nextsource[(frac)>>16])]))*64 + ((filter_fracu*(0xffff-((frac)&0xffff)))>>(32-6)) ]));
2885             (y++);
2886             dest += 4;
2887             frac += fracstep;
2888          }
2889       }
2890       else
2891       {
2892          unsigned heightmask = dcvars->texheight-1;
2893          if (! (dcvars->texheight & heightmask))
2894          {
2895             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
2896             while ((count-=2)>=0)
2897             {
2898                *dest = (( V_Palette16[ ((translation[(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])]))*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((translation[(source[((frac+(1<<16)) & fixedt_heightmask)>>16])]))*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((translation[(source[(frac & fixedt_heightmask)>>16])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ ((translation[(nextsource[(frac & fixedt_heightmask)>>16])]))*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
2899                (y++);
2900                dest += 4;
2901                frac += fracstep;
2902                *dest = (( V_Palette16[ ((translation[(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])]))*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((translation[(source[((frac+(1<<16)) & fixedt_heightmask)>>16])]))*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((translation[(source[(frac & fixedt_heightmask)>>16])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ ((translation[(nextsource[(frac & fixedt_heightmask)>>16])]))*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
2903                (y++);
2904                dest += 4;
2905                frac += fracstep;
2906             }
2907             if (count & 1)
2908                *dest = (( V_Palette16[ ((translation[(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])]))*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((translation[(source[((frac+(1<<16)) & fixedt_heightmask)>>16])]))*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((translation[(source[(frac & fixedt_heightmask)>>16])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ ((translation[(nextsource[(frac & fixedt_heightmask)>>16])]))*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
2909             (y++);
2910          }
2911          else
2912          {
2913             fixed_t nextfrac = 0;
2914 
2915             heightmask++;
2916             heightmask <<= 16;
2917 
2918             if (frac < 0)
2919                while ((frac += heightmask) < 0);
2920             else
2921                while (frac >= (int)heightmask)
2922                   frac -= heightmask;
2923 
2924 
2925             nextfrac = frac + (1<<16);
2926             while (nextfrac >= (int)heightmask)
2927                nextfrac -= heightmask;
2928 
2929 
2930 
2931 
2932             while (count--)
2933             {
2934 
2935 
2936 
2937 
2938 
2939                *dest = (( V_Palette16[ ((translation[(nextsource[(nextfrac)>>16])]))*64 + ((filter_fracu*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((translation[(source[(nextfrac)>>16])]))*64 + (((0xffff-filter_fracu)*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((translation[(source[(frac)>>16])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac)&0xffff)))>>(32-6)) ] + V_Palette16[ ((translation[(nextsource[(frac)>>16])]))*64 + ((filter_fracu*(0xffff-((frac)&0xffff)))>>(32-6)) ]));
2940                (y++);
2941                dest += 4;
2942                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
2943 
2944                if ((nextfrac += fracstep) >= (int)heightmask) nextfrac -= heightmask;;
2945 
2946             }
2947          }
2948       }
2949    }
2950 
2951 }
2952 
R_DrawTranslatedColumn16_LinearUV_PointZ(draw_column_vars_t * dcvars)2953 static void R_DrawTranslatedColumn16_LinearUV_PointZ(draw_column_vars_t *dcvars)
2954 {
2955   int count;
2956 
2957   uint16_t *dest;
2958 
2959   fixed_t frac;
2960   const fixed_t fracstep = dcvars->iscale;
2961 
2962   const fixed_t slope_texu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
2963 
2964   if (dcvars->iscale > drawvars.mag_threshold) {
2965     R_GetDrawColumnFunc(RDC_PIPELINE_TRANSLATED,
2966                         RDRAW_FILTER_POINT,
2967                         drawvars.filterz)(dcvars);
2968     return;
2969   }
2970   count = dcvars->yh - dcvars->yl;
2971 
2972   if (count < 0)
2973     return;
2974 
2975   frac = dcvars->texturemid - ((1<<16)>>1) + (dcvars->yl-centery)*fracstep;
2976 
2977   if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
2978   {
2979      if (dcvars->yl != 0) {
2980         if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
2981 
2982            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
2983            dcvars->yl += shift;
2984            count -= shift;
2985            frac += 0xffff-(slope_texu & 0xffff);
2986         }
2987         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
2988 
2989            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
2990            dcvars->yl += shift;
2991            count -= shift;
2992            frac += slope_texu & 0xffff;
2993         }
2994      }
2995      if (dcvars->yh != viewheight-1) {
2996         if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
2997 
2998            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
2999            dcvars->yh -= shift;
3000            count -= shift;
3001         }
3002         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
3003 
3004            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
3005            dcvars->yh -= shift;
3006            count -= shift;
3007         }
3008      }
3009      if (count <= 0) return;
3010   }
3011 
3012 
3013 
3014    {
3015 
3016       if(temp_x == 4 ||
3017          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
3018          R_FlushColumns();
3019 
3020       if(!temp_x)
3021       {
3022          startx = dcvars->x;
3023          tempyl[0] = commontop = dcvars->yl;
3024          tempyh[0] = commonbot = dcvars->yh;
3025          temptype = (COL_OPAQUE);
3026 
3027 
3028 
3029 
3030 
3031          R_FlushWholeColumns = R_FlushWhole16;
3032          R_FlushHTColumns = R_FlushHT16;
3033          R_FlushQuadColumn = R_FlushQuad16;
3034 
3035          dest = &short_tempbuf[dcvars->yl << 2];
3036 
3037       }
3038       else
3039       {
3040          tempyl[temp_x] = dcvars->yl;
3041          tempyh[temp_x] = dcvars->yh;
3042 
3043          if(dcvars->yl > commontop)
3044             commontop = dcvars->yl;
3045          if(dcvars->yh < commonbot)
3046             commonbot = dcvars->yh;
3047 
3048 
3049          dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
3050 
3051       }
3052       temp_x += 1;
3053    }
3054 
3055 
3056 
3057    {
3058       const uint8_t *source = dcvars->source;
3059       const lighttable_t *colormap = dcvars->colormap;
3060       const uint8_t *translation = dcvars->translation;
3061 
3062       int y = dcvars->yl;
3063 
3064       const uint8_t *nextsource = dcvars->nextsource;
3065       const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
3066 
3067 
3068 
3069 
3070 
3071 
3072 
3073       count++;
3074 
3075 
3076 
3077 
3078 
3079 
3080 
3081       if (dcvars->texheight == 128)
3082       {
3083 
3084          while(count--)
3085          {
3086             *dest = (( V_Palette16[ (colormap[(translation[(nextsource[((frac+(1<<16)) & ((127<<16)|0xffff))>>16])])])*64 + ((filter_fracu*((frac & ((127<<16)|0xffff))&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(source[((frac+(1<<16)) & ((127<<16)|0xffff))>>16])])])*64 + (((0xffff-filter_fracu)*((frac & ((127<<16)|0xffff))&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(source[(frac & ((127<<16)|0xffff))>>16])])])*64 + (((0xffff-filter_fracu)*(0xffff-((frac & ((127<<16)|0xffff))&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(nextsource[(frac & ((127<<16)|0xffff))>>16])])])*64 + ((filter_fracu*(0xffff-((frac & ((127<<16)|0xffff))&0xffff)))>>(32-6)) ]));
3087             (y++);
3088             dest += 4;
3089             frac += fracstep;
3090          }
3091       }
3092       else if (dcvars->texheight == 0)
3093       {
3094 
3095          while (count--)
3096          {
3097             *dest = (( V_Palette16[ (colormap[(translation[(nextsource[((frac+(1<<16)))>>16])])])*64 + ((filter_fracu*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(source[((frac+(1<<16)))>>16])])])*64 + (((0xffff-filter_fracu)*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(source[(frac)>>16])])])*64 + (((0xffff-filter_fracu)*(0xffff-((frac)&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(nextsource[(frac)>>16])])])*64 + ((filter_fracu*(0xffff-((frac)&0xffff)))>>(32-6)) ]));
3098             (y++);
3099             dest += 4;
3100             frac += fracstep;
3101          }
3102       }
3103       else
3104       {
3105          unsigned heightmask = dcvars->texheight-1;
3106          if (! (dcvars->texheight & heightmask))
3107          {
3108             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
3109             while ((count-=2)>=0)
3110             {
3111                *dest = (( V_Palette16[ (colormap[(translation[(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])])])*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(source[((frac+(1<<16)) & fixedt_heightmask)>>16])])])*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(source[(frac & fixedt_heightmask)>>16])])])*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(nextsource[(frac & fixedt_heightmask)>>16])])])*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
3112                (y++);
3113                dest += 4;
3114                frac += fracstep;
3115                *dest = (( V_Palette16[ (colormap[(translation[(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])])])*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(source[((frac+(1<<16)) & fixedt_heightmask)>>16])])])*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(source[(frac & fixedt_heightmask)>>16])])])*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(nextsource[(frac & fixedt_heightmask)>>16])])])*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
3116                (y++);
3117                dest += 4;
3118                frac += fracstep;
3119             }
3120             if (count & 1)
3121                *dest = (( V_Palette16[ (colormap[(translation[(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])])])*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(source[((frac+(1<<16)) & fixedt_heightmask)>>16])])])*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(source[(frac & fixedt_heightmask)>>16])])])*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(nextsource[(frac & fixedt_heightmask)>>16])])])*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
3122             (y++);
3123          }
3124          else
3125          {
3126             fixed_t nextfrac = 0;
3127 
3128             heightmask++;
3129             heightmask <<= 16;
3130 
3131             if (frac < 0)
3132                while ((frac += heightmask) < 0);
3133             else
3134                while (frac >= (int)heightmask)
3135                   frac -= heightmask;
3136 
3137 
3138             nextfrac = frac + (1<<16);
3139             while (nextfrac >= (int)heightmask)
3140                nextfrac -= heightmask;
3141 
3142 
3143 
3144 
3145             while (count--)
3146             {
3147 
3148 
3149 
3150 
3151 
3152                *dest = (( V_Palette16[ (colormap[(translation[(nextsource[(nextfrac)>>16])])])*64 + ((filter_fracu*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(source[(nextfrac)>>16])])])*64 + (((0xffff-filter_fracu)*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(source[(frac)>>16])])])*64 + (((0xffff-filter_fracu)*(0xffff-((frac)&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(translation[(nextsource[(frac)>>16])])])*64 + ((filter_fracu*(0xffff-((frac)&0xffff)))>>(32-6)) ]));
3153                (y++);
3154                dest += 4;
3155                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
3156 
3157                if ((nextfrac += fracstep) >= (int)heightmask) nextfrac -= heightmask;;
3158 
3159             }
3160          }
3161       }
3162    }
3163 
3164 }
3165 
R_DrawTranslatedColumn16_LinearUV_LinearZ(draw_column_vars_t * dcvars)3166 static void R_DrawTranslatedColumn16_LinearUV_LinearZ(draw_column_vars_t *dcvars)
3167 {
3168   int count;
3169 
3170   uint16_t *dest;
3171 
3172   fixed_t frac;
3173   const fixed_t fracstep = dcvars->iscale;
3174 
3175   const fixed_t slope_texu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
3176 
3177   if (dcvars->iscale > drawvars.mag_threshold)
3178   {
3179      R_GetDrawColumnFunc(RDC_PIPELINE_TRANSLATED,
3180            RDRAW_FILTER_POINT,
3181            drawvars.filterz)(dcvars);
3182      return;
3183   }
3184 
3185   count = dcvars->yh - dcvars->yl;
3186 
3187   if (count < 0)
3188     return;
3189 
3190   frac = dcvars->texturemid - ((1<<16)>>1) + (dcvars->yl-centery)*fracstep;
3191 
3192   if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED) {
3193 
3194 
3195 
3196     if (dcvars->yl != 0) {
3197       if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
3198 
3199         int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
3200         dcvars->yl += shift;
3201         count -= shift;
3202         frac += 0xffff-(slope_texu & 0xffff);
3203       }
3204       else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
3205 
3206         int shift = ((slope_texu & 0xffff)/dcvars->iscale);
3207         dcvars->yl += shift;
3208         count -= shift;
3209         frac += slope_texu & 0xffff;
3210       }
3211     }
3212     if (dcvars->yh != viewheight-1) {
3213       if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
3214 
3215         int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
3216         dcvars->yh -= shift;
3217         count -= shift;
3218       }
3219       else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
3220 
3221         int shift = ((slope_texu & 0xffff)/dcvars->iscale);
3222         dcvars->yh -= shift;
3223         count -= shift;
3224       }
3225     }
3226     if (count <= 0) return;
3227   }
3228 
3229 
3230 
3231    {
3232 
3233       if(temp_x == 4 ||
3234          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
3235          R_FlushColumns();
3236 
3237       if(!temp_x)
3238       {
3239          startx = dcvars->x;
3240          tempyl[0] = commontop = dcvars->yl;
3241          tempyh[0] = commonbot = dcvars->yh;
3242          temptype = (COL_OPAQUE);
3243 
3244 
3245 
3246 
3247 
3248          R_FlushWholeColumns = R_FlushWhole16;
3249          R_FlushHTColumns = R_FlushHT16;
3250          R_FlushQuadColumn = R_FlushQuad16;
3251 
3252          dest = &short_tempbuf[dcvars->yl << 2];
3253 
3254       }
3255       else
3256       {
3257          tempyl[temp_x] = dcvars->yl;
3258          tempyh[temp_x] = dcvars->yh;
3259 
3260          if(dcvars->yl > commontop)
3261             commontop = dcvars->yl;
3262          if(dcvars->yh < commonbot)
3263             commonbot = dcvars->yh;
3264 
3265 
3266          dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
3267 
3268       }
3269       temp_x += 1;
3270    }
3271 
3272 
3273 
3274    {
3275       const uint8_t *source = dcvars->source;
3276       const uint8_t *translation = dcvars->translation;
3277 
3278       int y = dcvars->yl;
3279       const int x = dcvars->x;
3280 
3281 
3282       const int fracz = (dcvars->z >> 6) & 255;
3283       const uint8_t *dither_colormaps[2] = { dcvars->colormap, dcvars->nextcolormap };
3284 
3285 
3286       const uint8_t *nextsource = dcvars->nextsource;
3287       const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
3288 
3289 
3290 
3291 
3292 
3293 
3294 
3295       count++;
3296 
3297 
3298 
3299 
3300 
3301 
3302 
3303       if (dcvars->texheight == 128)
3304       {
3305 
3306          while(count--)
3307          {
3308             *dest = (( V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(nextsource[((frac+(1<<16)) & ((127<<16)|0xffff))>>16])])]))*64 + ((filter_fracu*((frac & ((127<<16)|0xffff))&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[((frac+(1<<16)) & ((127<<16)|0xffff))>>16])])]))*64 + (((0xffff-filter_fracu)*((frac & ((127<<16)|0xffff))&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(frac & ((127<<16)|0xffff))>>16])])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & ((127<<16)|0xffff))&0xffff)))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(nextsource[(frac & ((127<<16)|0xffff))>>16])])]))*64 + ((filter_fracu*(0xffff-((frac & ((127<<16)|0xffff))&0xffff)))>>(32-6)) ]));
3309             (y++);
3310             dest += 4;
3311             frac += fracstep;
3312          }
3313       }
3314       else if (dcvars->texheight == 0)
3315       {
3316 
3317          while (count--)
3318          {
3319             *dest = (( V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(nextsource[((frac+(1<<16)))>>16])])]))*64 + ((filter_fracu*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[((frac+(1<<16)))>>16])])]))*64 + (((0xffff-filter_fracu)*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(frac)>>16])])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac)&0xffff)))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(nextsource[(frac)>>16])])]))*64 + ((filter_fracu*(0xffff-((frac)&0xffff)))>>(32-6)) ]));
3320             (y++);
3321             dest += 4;
3322             frac += fracstep;
3323          }
3324       }
3325       else
3326       {
3327          unsigned heightmask = dcvars->texheight-1;
3328          if (! (dcvars->texheight & heightmask))
3329          {
3330             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
3331             while ((count-=2)>=0)
3332             {
3333                *dest = (( V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])])]))*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[((frac+(1<<16)) & fixedt_heightmask)>>16])])]))*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(frac & fixedt_heightmask)>>16])])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(nextsource[(frac & fixedt_heightmask)>>16])])]))*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
3334                (y++);
3335                dest += 4;
3336                frac += fracstep;
3337                *dest = (( V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])])]))*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[((frac+(1<<16)) & fixedt_heightmask)>>16])])]))*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(frac & fixedt_heightmask)>>16])])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(nextsource[(frac & fixedt_heightmask)>>16])])]))*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
3338                (y++);
3339                dest += 4;
3340                frac += fracstep;
3341             }
3342             if (count & 1)
3343                *dest = (( V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(nextsource[((frac+(1<<16)) & fixedt_heightmask)>>16])])]))*64 + ((filter_fracu*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[((frac+(1<<16)) & fixedt_heightmask)>>16])])]))*64 + (((0xffff-filter_fracu)*((frac & fixedt_heightmask)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(frac & fixedt_heightmask)>>16])])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(nextsource[(frac & fixedt_heightmask)>>16])])]))*64 + ((filter_fracu*(0xffff-((frac & fixedt_heightmask)&0xffff)))>>(32-6)) ]));
3344             (y++);
3345          }
3346          else
3347          {
3348             fixed_t nextfrac = 0;
3349 
3350             heightmask++;
3351             heightmask <<= 16;
3352 
3353             if (frac < 0)
3354                while ((frac += heightmask) < 0);
3355             else
3356                while (frac >= (int)heightmask)
3357                   frac -= heightmask;
3358 
3359 
3360             nextfrac = frac + (1<<16);
3361             while (nextfrac >= (int)heightmask)
3362                nextfrac -= heightmask;
3363 
3364 
3365 
3366 
3367             while (count--)
3368             {
3369 
3370 
3371 
3372 
3373 
3374                *dest = (( V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(nextsource[(nextfrac)>>16])])]))*64 + ((filter_fracu*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(nextfrac)>>16])])]))*64 + (((0xffff-filter_fracu)*((frac)&0xffff))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(source[(frac)>>16])])]))*64 + (((0xffff-filter_fracu)*(0xffff-((frac)&0xffff)))>>(32-6)) ] + V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(nextsource[(frac)>>16])])]))*64 + ((filter_fracu*(0xffff-((frac)&0xffff)))>>(32-6)) ]));
3375                (y++);
3376                dest += 4;
3377                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
3378 
3379                if ((nextfrac += fracstep) >= (int)heightmask) nextfrac -= heightmask;;
3380 
3381             }
3382          }
3383       }
3384    }
3385 
3386 }
3387 
R_DrawTranslatedColumn16_RoundedUV(draw_column_vars_t * dcvars)3388 static void R_DrawTranslatedColumn16_RoundedUV(draw_column_vars_t *dcvars)
3389 {
3390   int count;
3391   uint16_t *dest;
3392   fixed_t frac;
3393   const fixed_t fracstep = dcvars->iscale;
3394   const fixed_t slope_texu = dcvars->texu;
3395 
3396   if (dcvars->iscale > drawvars.mag_threshold)
3397   {
3398     R_GetDrawColumnFunc(RDC_PIPELINE_TRANSLATED,
3399                         RDRAW_FILTER_POINT,
3400                         drawvars.filterz)(dcvars);
3401     return;
3402   }
3403   count = dcvars->yh - dcvars->yl;
3404 
3405   if (count < 0)
3406     return;
3407 
3408   frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
3409 
3410   if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
3411   {
3412      if (dcvars->yl != 0) {
3413         if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
3414 
3415            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
3416            dcvars->yl += shift;
3417            count -= shift;
3418            frac += 0xffff-(slope_texu & 0xffff);
3419         }
3420         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
3421 
3422            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
3423            dcvars->yl += shift;
3424            count -= shift;
3425            frac += slope_texu & 0xffff;
3426         }
3427      }
3428      if (dcvars->yh != viewheight-1) {
3429         if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
3430 
3431            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
3432            dcvars->yh -= shift;
3433            count -= shift;
3434         }
3435         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
3436 
3437            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
3438            dcvars->yh -= shift;
3439            count -= shift;
3440         }
3441      }
3442      if (count <= 0) return;
3443   }
3444 
3445    {
3446 
3447       if(temp_x == 4 ||
3448          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
3449          R_FlushColumns();
3450 
3451       if(!temp_x)
3452       {
3453          startx = dcvars->x;
3454          tempyl[0] = commontop = dcvars->yl;
3455          tempyh[0] = commonbot = dcvars->yh;
3456          temptype = (COL_OPAQUE);
3457 
3458 
3459 
3460 
3461 
3462          R_FlushWholeColumns = R_FlushWhole16;
3463          R_FlushHTColumns = R_FlushHT16;
3464          R_FlushQuadColumn = R_FlushQuad16;
3465 
3466          dest = &short_tempbuf[dcvars->yl << 2];
3467 
3468       }
3469       else
3470       {
3471          tempyl[temp_x] = dcvars->yl;
3472          tempyh[temp_x] = dcvars->yh;
3473 
3474          if(dcvars->yl > commontop)
3475             commontop = dcvars->yl;
3476          if(dcvars->yh < commonbot)
3477             commonbot = dcvars->yh;
3478 
3479 
3480          dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
3481 
3482       }
3483       temp_x += 1;
3484    }
3485 
3486 
3487 
3488    {
3489       const uint8_t *source = dcvars->source;
3490       const uint8_t *translation = dcvars->translation;
3491 
3492       int y = dcvars->yl;
3493       const uint8_t *prevsource = dcvars->prevsource;
3494       const uint8_t *nextsource = dcvars->nextsource;
3495       const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : (dcvars->texu>>8) & 0xff;
3496 
3497 
3498       count++;
3499 
3500 
3501 
3502 
3503 
3504 
3505 
3506       if (dcvars->texheight == 128)
3507       {
3508 
3509          while(count--)
3510          {
3511             *dest = (V_Palette16[ ((translation[(filter_getScale2xQuadColors( source[ ((frac & ((127<<16)|0xffff))>>16) ], source[ (((0)>(((frac & ((127<<16)|0xffff))>>16)-1)?(0):(((frac & ((127<<16)|0xffff))>>16)-1))) ], nextsource[ ((frac & ((127<<16)|0xffff))>>16) ], source[ (((frac+(1<<16)) & ((127<<16)|0xffff))>>16) ], prevsource[ ((frac & ((127<<16)|0xffff))>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & ((127<<16)|0xffff))>>8) & 0xff)>>(8-6)) ] ])]))*64 + ((64 -1)) ]);
3512             (y++);
3513             dest += 4;
3514             frac += fracstep;
3515          }
3516       }
3517       else if (dcvars->texheight == 0)
3518       {
3519 
3520          while (count--)
3521          {
3522             *dest = (V_Palette16[ ((translation[(filter_getScale2xQuadColors( source[ ((frac)>>16) ], source[ (((0)>(((frac)>>16)-1)?(0):(((frac)>>16)-1))) ], nextsource[ ((frac)>>16) ], source[ (((frac+(1<<16)))>>16) ], prevsource[ ((frac)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac)>>8) & 0xff)>>(8-6)) ] ])]))*64 + ((64 -1)) ]);
3523             (y++);
3524             dest += 4;
3525             frac += fracstep;
3526          }
3527       }
3528       else
3529       {
3530          unsigned heightmask = dcvars->texheight-1;
3531          if (! (dcvars->texheight & heightmask))
3532          {
3533             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
3534             while ((count-=2)>=0)
3535             {
3536                *dest = (V_Palette16[ ((translation[(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])]))*64 + ((64 -1)) ]);
3537                (y++);
3538                dest += 4;
3539                frac += fracstep;
3540                *dest = (V_Palette16[ ((translation[(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])]))*64 + ((64 -1)) ]);
3541                (y++);
3542                dest += 4;
3543                frac += fracstep;
3544             }
3545             if (count & 1)
3546                *dest = (V_Palette16[ ((translation[(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])]))*64 + ((64 -1)) ]);
3547             (y++);
3548          }
3549          else
3550          {
3551             fixed_t nextfrac = 0;
3552 
3553             heightmask++;
3554             heightmask <<= 16;
3555 
3556             if (frac < 0)
3557                while ((frac += heightmask) < 0);
3558             else
3559                while (frac >= (int)heightmask)
3560                   frac -= heightmask;
3561 
3562 
3563             nextfrac = frac + (1<<16);
3564             while (nextfrac >= (int)heightmask)
3565                nextfrac -= heightmask;
3566 
3567 
3568 
3569 
3570             while (count--)
3571             {
3572 
3573 
3574 
3575 
3576 
3577                *dest = (V_Palette16[ ((translation[(filter_getScale2xQuadColors( source[ ((frac)>>16) ], source[ (((0)>(((frac)>>16)-1)?(0):(((frac)>>16)-1))) ], nextsource[ ((frac)>>16) ], source[ ((nextfrac)>>16) ], prevsource[ ((frac)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac)>>8) & 0xff)>>(8-6)) ] ])]))*64 + ((64 -1)) ]);
3578                (y++);
3579                dest += 4;
3580                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
3581 
3582                if ((nextfrac += fracstep) >= (int)heightmask) nextfrac -= heightmask;;
3583 
3584             }
3585          }
3586       }
3587    }
3588 
3589 }
3590 
R_DrawTranslatedColumn16_RoundedUV_PointZ(draw_column_vars_t * dcvars)3591 static void R_DrawTranslatedColumn16_RoundedUV_PointZ(draw_column_vars_t *dcvars)
3592 {
3593   int count;
3594 
3595   uint16_t *dest;
3596 
3597   fixed_t frac;
3598   const fixed_t fracstep = dcvars->iscale;
3599   const fixed_t slope_texu = dcvars->texu;
3600 
3601   if (dcvars->iscale > drawvars.mag_threshold) {
3602     R_GetDrawColumnFunc(RDC_PIPELINE_TRANSLATED,
3603                         RDRAW_FILTER_POINT,
3604                         drawvars.filterz)(dcvars);
3605     return;
3606   }
3607   count = dcvars->yh - dcvars->yl;
3608 
3609 
3610 
3611 
3612 
3613 
3614 
3615   if (count < 0)
3616     return;
3617 
3618   frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
3619 
3620   if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
3621   {
3622      if (dcvars->yl != 0) {
3623         if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
3624 
3625            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
3626            dcvars->yl += shift;
3627            count -= shift;
3628            frac += 0xffff-(slope_texu & 0xffff);
3629         }
3630         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
3631 
3632            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
3633            dcvars->yl += shift;
3634            count -= shift;
3635            frac += slope_texu & 0xffff;
3636         }
3637      }
3638      if (dcvars->yh != viewheight-1) {
3639         if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
3640 
3641            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
3642            dcvars->yh -= shift;
3643            count -= shift;
3644         }
3645         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
3646 
3647            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
3648            dcvars->yh -= shift;
3649            count -= shift;
3650         }
3651      }
3652      if (count <= 0) return;
3653   }
3654 
3655 
3656 
3657    {
3658 
3659       if(temp_x == 4 ||
3660          (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
3661          R_FlushColumns();
3662 
3663       if(!temp_x)
3664       {
3665          startx = dcvars->x;
3666          tempyl[0] = commontop = dcvars->yl;
3667          tempyh[0] = commonbot = dcvars->yh;
3668          temptype = (COL_OPAQUE);
3669 
3670 
3671 
3672 
3673 
3674          R_FlushWholeColumns = R_FlushWhole16;
3675          R_FlushHTColumns = R_FlushHT16;
3676          R_FlushQuadColumn = R_FlushQuad16;
3677 
3678          dest = &short_tempbuf[dcvars->yl << 2];
3679 
3680       }
3681       else
3682       {
3683          tempyl[temp_x] = dcvars->yl;
3684          tempyh[temp_x] = dcvars->yh;
3685 
3686          if(dcvars->yl > commontop)
3687             commontop = dcvars->yl;
3688          if(dcvars->yh < commonbot)
3689             commonbot = dcvars->yh;
3690 
3691 
3692          dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
3693 
3694       }
3695       temp_x += 1;
3696    }
3697 
3698 
3699 
3700    {
3701       const uint8_t *source = dcvars->source;
3702       const lighttable_t *colormap = dcvars->colormap;
3703       const uint8_t *translation = dcvars->translation;
3704 
3705       int y = dcvars->yl;
3706       const uint8_t *prevsource = dcvars->prevsource;
3707       const uint8_t *nextsource = dcvars->nextsource;
3708       const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : (dcvars->texu>>8) & 0xff;
3709 
3710 
3711       count++;
3712 
3713 
3714 
3715 
3716 
3717 
3718 
3719       if (dcvars->texheight == 128)
3720       {
3721 
3722          while(count--)
3723          {
3724             *dest = (V_Palette16[ (colormap[(translation[(filter_getScale2xQuadColors( source[ ((frac & ((127<<16)|0xffff))>>16) ], source[ (((0)>(((frac & ((127<<16)|0xffff))>>16)-1)?(0):(((frac & ((127<<16)|0xffff))>>16)-1))) ], nextsource[ ((frac & ((127<<16)|0xffff))>>16) ], source[ (((frac+(1<<16)) & ((127<<16)|0xffff))>>16) ], prevsource[ ((frac & ((127<<16)|0xffff))>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & ((127<<16)|0xffff))>>8) & 0xff)>>(8-6)) ] ])])])*64 + ((64 -1)) ]);
3725             (y++);
3726             dest += 4;
3727             frac += fracstep;
3728          }
3729       }
3730       else if (dcvars->texheight == 0)
3731       {
3732 
3733          while (count--)
3734          {
3735             *dest = (V_Palette16[ (colormap[(translation[(filter_getScale2xQuadColors( source[ ((frac)>>16) ], source[ (((0)>(((frac)>>16)-1)?(0):(((frac)>>16)-1))) ], nextsource[ ((frac)>>16) ], source[ (((frac+(1<<16)))>>16) ], prevsource[ ((frac)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac)>>8) & 0xff)>>(8-6)) ] ])])])*64 + ((64 -1)) ]);
3736             (y++);
3737             dest += 4;
3738             frac += fracstep;
3739          }
3740       }
3741       else
3742       {
3743          unsigned heightmask = dcvars->texheight-1;
3744          if (! (dcvars->texheight & heightmask))
3745          {
3746             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
3747             while ((count-=2)>=0)
3748             {
3749                *dest = (V_Palette16[ (colormap[(translation[(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])])])*64 + ((64 -1)) ]);
3750                (y++);
3751                dest += 4;
3752                frac += fracstep;
3753                *dest = (V_Palette16[ (colormap[(translation[(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])])])*64 + ((64 -1)) ]);
3754                (y++);
3755                dest += 4;
3756                frac += fracstep;
3757             }
3758             if (count & 1)
3759                *dest = (V_Palette16[ (colormap[(translation[(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])])])*64 + ((64 -1)) ]);
3760             (y++);
3761          }
3762          else
3763          {
3764             fixed_t nextfrac = 0;
3765 
3766             heightmask++;
3767             heightmask <<= 16;
3768 
3769             if (frac < 0)
3770                while ((frac += heightmask) < 0);
3771             else
3772                while (frac >= (int)heightmask)
3773                   frac -= heightmask;
3774 
3775 
3776             nextfrac = frac + (1<<16);
3777             while (nextfrac >= (int)heightmask)
3778                nextfrac -= heightmask;
3779 
3780 
3781 
3782 
3783             while (count--)
3784             {
3785 
3786 
3787 
3788 
3789 
3790                *dest = (V_Palette16[ (colormap[(translation[(filter_getScale2xQuadColors( source[ ((frac)>>16) ], source[ (((0)>(((frac)>>16)-1)?(0):(((frac)>>16)-1))) ], nextsource[ ((frac)>>16) ], source[ ((nextfrac)>>16) ], prevsource[ ((frac)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac)>>8) & 0xff)>>(8-6)) ] ])])])*64 + ((64 -1)) ]);
3791                (y++);
3792                dest += 4;
3793                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
3794 
3795                if ((nextfrac += fracstep) >= (int)heightmask) nextfrac -= heightmask;;
3796 
3797             }
3798          }
3799       }
3800    }
3801 
3802 }
3803 
R_DrawTranslatedColumn16_RoundedUV_LinearZ(draw_column_vars_t * dcvars)3804 static void R_DrawTranslatedColumn16_RoundedUV_LinearZ(draw_column_vars_t *dcvars)
3805 {
3806    int count;
3807    uint16_t *dest;
3808    fixed_t frac;
3809    const fixed_t fracstep = dcvars->iscale;
3810    const fixed_t slope_texu = dcvars->texu;
3811 
3812    if (dcvars->iscale > drawvars.mag_threshold)
3813    {
3814       R_GetDrawColumnFunc(RDC_PIPELINE_TRANSLATED,
3815             RDRAW_FILTER_POINT,
3816             drawvars.filterz)(dcvars);
3817       return;
3818    }
3819 
3820    count = dcvars->yh - dcvars->yl;
3821 
3822    if (count < 0)
3823       return;
3824 
3825    frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
3826 
3827 
3828    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED) {
3829 
3830 
3831 
3832       if (dcvars->yl != 0) {
3833          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
3834 
3835             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
3836             dcvars->yl += shift;
3837             count -= shift;
3838             frac += 0xffff-(slope_texu & 0xffff);
3839          }
3840          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
3841 
3842             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
3843             dcvars->yl += shift;
3844             count -= shift;
3845             frac += slope_texu & 0xffff;
3846          }
3847       }
3848       if (dcvars->yh != viewheight-1) {
3849          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
3850 
3851             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
3852             dcvars->yh -= shift;
3853             count -= shift;
3854          }
3855          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
3856 
3857             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
3858             dcvars->yh -= shift;
3859             count -= shift;
3860          }
3861       }
3862       if (count <= 0) return;
3863    }
3864 
3865 
3866 
3867    {
3868 
3869       if(temp_x == 4 ||
3870             (temp_x && (temptype != (COL_OPAQUE) || temp_x + startx != dcvars->x)))
3871          R_FlushColumns();
3872 
3873       if(!temp_x)
3874       {
3875          startx = dcvars->x;
3876          tempyl[0] = commontop = dcvars->yl;
3877          tempyh[0] = commonbot = dcvars->yh;
3878          temptype = (COL_OPAQUE);
3879 
3880 
3881 
3882 
3883 
3884          R_FlushWholeColumns = R_FlushWhole16;
3885          R_FlushHTColumns = R_FlushHT16;
3886          R_FlushQuadColumn = R_FlushQuad16;
3887 
3888          dest = &short_tempbuf[dcvars->yl << 2];
3889 
3890       }
3891       else
3892       {
3893          tempyl[temp_x] = dcvars->yl;
3894          tempyh[temp_x] = dcvars->yh;
3895 
3896          if(dcvars->yl > commontop)
3897             commontop = dcvars->yl;
3898          if(dcvars->yh < commonbot)
3899             commonbot = dcvars->yh;
3900 
3901 
3902          dest = &short_tempbuf[(dcvars->yl << 2) + temp_x];
3903 
3904       }
3905       temp_x += 1;
3906    }
3907 
3908    {
3909       const uint8_t *source = dcvars->source;
3910       const uint8_t *translation = dcvars->translation;
3911 
3912       int y = dcvars->yl;
3913       const int x = dcvars->x;
3914 
3915 
3916       const int fracz = (dcvars->z >> 6) & 255;
3917       const uint8_t *dither_colormaps[2] = { dcvars->colormap, dcvars->nextcolormap };
3918 
3919 
3920 
3921 
3922 
3923 
3924       const uint8_t *prevsource = dcvars->prevsource;
3925       const uint8_t *nextsource = dcvars->nextsource;
3926       const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : (dcvars->texu>>8) & 0xff;
3927 
3928 
3929       count++;
3930 
3931 
3932 
3933 
3934 
3935 
3936 
3937       if (dcvars->texheight == 128)
3938       {
3939 
3940          while(count--)
3941          {
3942             *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(filter_getScale2xQuadColors( source[ ((frac & ((127<<16)|0xffff))>>16) ], source[ (((0)>(((frac & ((127<<16)|0xffff))>>16)-1)?(0):(((frac & ((127<<16)|0xffff))>>16)-1))) ], nextsource[ ((frac & ((127<<16)|0xffff))>>16) ], source[ (((frac+(1<<16)) & ((127<<16)|0xffff))>>16) ], prevsource[ ((frac & ((127<<16)|0xffff))>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & ((127<<16)|0xffff))>>8) & 0xff)>>(8-6)) ] ])])]))*64 + ((64 -1)) ]);
3943             (y++);
3944             dest += 4;
3945             frac += fracstep;
3946          }
3947       }
3948       else if (dcvars->texheight == 0)
3949       {
3950 
3951          while (count--)
3952          {
3953             *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(filter_getScale2xQuadColors( source[ ((frac)>>16) ], source[ (((0)>(((frac)>>16)-1)?(0):(((frac)>>16)-1))) ], nextsource[ ((frac)>>16) ], source[ (((frac+(1<<16)))>>16) ], prevsource[ ((frac)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac)>>8) & 0xff)>>(8-6)) ] ])])]))*64 + ((64 -1)) ]);
3954             (y++);
3955             dest += 4;
3956             frac += fracstep;
3957          }
3958       }
3959       else
3960       {
3961          unsigned heightmask = dcvars->texheight-1;
3962          if (! (dcvars->texheight & heightmask))
3963          {
3964             fixed_t fixedt_heightmask = (heightmask<<16)|0xffff;
3965             while ((count-=2)>=0)
3966             {
3967                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])])]))*64 + ((64 -1)) ]);
3968                (y++);
3969                dest += 4;
3970                frac += fracstep;
3971                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])])]))*64 + ((64 -1)) ]);
3972                (y++);
3973                dest += 4;
3974                frac += fracstep;
3975             }
3976             if (count & 1)
3977                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(filter_getScale2xQuadColors( source[ ((frac & fixedt_heightmask)>>16) ], source[ (((0)>(((frac & fixedt_heightmask)>>16)-1)?(0):(((frac & fixedt_heightmask)>>16)-1))) ], nextsource[ ((frac & fixedt_heightmask)>>16) ], source[ (((frac+(1<<16)) & fixedt_heightmask)>>16) ], prevsource[ ((frac & fixedt_heightmask)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac & fixedt_heightmask)>>8) & 0xff)>>(8-6)) ] ])])]))*64 + ((64 -1)) ]);
3978             (y++);
3979          }
3980          else
3981          {
3982             fixed_t nextfrac = 0;
3983 
3984             heightmask++;
3985             heightmask <<= 16;
3986 
3987             if (frac < 0)
3988                while ((frac += heightmask) < 0);
3989             else
3990                while (frac >= (int)heightmask)
3991                   frac -= heightmask;
3992 
3993 
3994             nextfrac = frac + (1<<16);
3995             while (nextfrac >= (int)heightmask)
3996                nextfrac -= heightmask;
3997 
3998 
3999 
4000 
4001             while (count--)
4002             {
4003 
4004 
4005 
4006 
4007 
4008                *dest = (V_Palette16[ ((dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x)&(4 -1)] < (fracz)) ? 1 : 0)][(translation[(filter_getScale2xQuadColors( source[ ((frac)>>16) ], source[ (((0)>(((frac)>>16)-1)?(0):(((frac)>>16)-1))) ], nextsource[ ((frac)>>16) ], source[ ((nextfrac)>>16) ], prevsource[ ((frac)>>16) ] ) [ filter_roundedUVMap[ ((filter_fracu>>(8-6))<<6) + ((((frac)>>8) & 0xff)>>(8-6)) ] ])])]))*64 + ((64 -1)) ]);
4009                (y++);
4010                dest += 4;
4011                if ((frac += fracstep) >= (int)heightmask) frac -= heightmask;;
4012 
4013                if ((nextfrac += fracstep) >= (int)heightmask) nextfrac -= heightmask;;
4014 
4015             }
4016          }
4017       }
4018    }
4019 }
4020 
4021 //
4022 // Framebuffer postprocessing.
4023 // Creates a fuzzy image by copying pixels
4024 //  from adjacent ones to left and right.
4025 // Used with an all black colormap, this
4026 //  could create the SHADOW effect,
4027 //  i.e. spectres and invisible players.
4028 //
4029 
R_DrawFuzzColumn16_PointUV(draw_column_vars_t * dcvars)4030 static void R_DrawFuzzColumn16_PointUV(draw_column_vars_t *dcvars)
4031 {
4032    int count;
4033    fixed_t frac;
4034    const fixed_t fracstep = dcvars->iscale;
4035    const fixed_t slope_texu = dcvars->texu;
4036 
4037    if (!dcvars->yl)
4038       dcvars->yl = 1;
4039 
4040    if (dcvars->yh == viewheight-1)
4041       dcvars->yh = viewheight - 2;
4042 
4043    count = dcvars->yh - dcvars->yl;
4044 
4045    if (count < 0)
4046       return;
4047 
4048    frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
4049 
4050    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
4051    {
4052       if (dcvars->yl != 0) {
4053          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
4054 
4055             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4056             dcvars->yl += shift;
4057             count -= shift;
4058             frac += 0xffff-(slope_texu & 0xffff);
4059          }
4060          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
4061 
4062             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4063             dcvars->yl += shift;
4064             count -= shift;
4065             frac += slope_texu & 0xffff;
4066          }
4067       }
4068       if (dcvars->yh != viewheight-1) {
4069          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
4070 
4071             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4072             dcvars->yh -= shift;
4073             count -= shift;
4074          }
4075          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
4076 
4077             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4078             dcvars->yh -= shift;
4079             count -= shift;
4080          }
4081       }
4082       if (count <= 0) return;
4083    }
4084 
4085    if(temp_x == 4 ||
4086          (temp_x && (temptype != (COL_FUZZ) || temp_x + startx != dcvars->x)))
4087       R_FlushColumns();
4088 
4089    if(!temp_x)
4090    {
4091       startx = dcvars->x;
4092       tempyl[0] = commontop = dcvars->yl;
4093       tempyh[0] = commonbot = dcvars->yh;
4094       temptype = (COL_FUZZ);
4095 
4096       tempfuzzmap = fullcolormap;
4097 
4098       R_FlushWholeColumns = R_FlushWholeFuzz16;
4099       R_FlushHTColumns = R_FlushHTFuzz16;
4100       R_FlushQuadColumn = R_FlushQuadFuzz16;
4101    }
4102    else
4103    {
4104       tempyl[temp_x] = dcvars->yl;
4105       tempyh[temp_x] = dcvars->yh;
4106 
4107       if(dcvars->yl > commontop)
4108          commontop = dcvars->yl;
4109       if(dcvars->yh < commonbot)
4110          commonbot = dcvars->yh;
4111    }
4112    temp_x += 1;
4113 }
4114 
R_DrawFuzzColumn16_PointUV_PointZ(draw_column_vars_t * dcvars)4115 static void R_DrawFuzzColumn16_PointUV_PointZ(draw_column_vars_t *dcvars)
4116 {
4117   int count;
4118   fixed_t frac;
4119   const fixed_t fracstep = dcvars->iscale;
4120   const fixed_t slope_texu = dcvars->texu;
4121 
4122   if (!dcvars->yl)
4123     dcvars->yl = 1;
4124 
4125   if (dcvars->yh == viewheight-1)
4126     dcvars->yh = viewheight - 2;
4127 
4128   count = dcvars->yh - dcvars->yl;
4129 
4130   if (count < 0)
4131     return;
4132 
4133   frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
4134 
4135   if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
4136   {
4137 
4138      if (dcvars->yl != 0) {
4139         if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
4140 
4141            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4142            dcvars->yl += shift;
4143            count -= shift;
4144            frac += 0xffff-(slope_texu & 0xffff);
4145         }
4146         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
4147 
4148            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4149            dcvars->yl += shift;
4150            count -= shift;
4151            frac += slope_texu & 0xffff;
4152         }
4153      }
4154      if (dcvars->yh != viewheight-1) {
4155         if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
4156 
4157            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4158            dcvars->yh -= shift;
4159            count -= shift;
4160         }
4161         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
4162 
4163            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4164            dcvars->yh -= shift;
4165            count -= shift;
4166         }
4167      }
4168      if (count <= 0) return;
4169   }
4170 
4171   if(temp_x == 4 ||
4172         (temp_x && (temptype != (COL_FUZZ) || temp_x + startx != dcvars->x)))
4173      R_FlushColumns();
4174 
4175   if(!temp_x)
4176   {
4177      startx = dcvars->x;
4178      tempyl[0] = commontop = dcvars->yl;
4179      tempyh[0] = commonbot = dcvars->yh;
4180      temptype = (COL_FUZZ);
4181 
4182      tempfuzzmap = fullcolormap;
4183 
4184      R_FlushWholeColumns = R_FlushWholeFuzz16;
4185      R_FlushHTColumns = R_FlushHTFuzz16;
4186      R_FlushQuadColumn = R_FlushQuadFuzz16;
4187   }
4188   else
4189   {
4190      tempyl[temp_x] = dcvars->yl;
4191      tempyh[temp_x] = dcvars->yh;
4192 
4193      if(dcvars->yl > commontop)
4194         commontop = dcvars->yl;
4195      if(dcvars->yh < commonbot)
4196         commonbot = dcvars->yh;
4197   }
4198   temp_x += 1;
4199 }
4200 
R_DrawFuzzColumn16_PointUV_LinearZ(draw_column_vars_t * dcvars)4201 static void R_DrawFuzzColumn16_PointUV_LinearZ(draw_column_vars_t *dcvars)
4202 {
4203   int count;
4204   fixed_t frac;
4205   const fixed_t fracstep = dcvars->iscale;
4206   const fixed_t slope_texu = dcvars->texu;
4207 
4208   if (!dcvars->yl)
4209     dcvars->yl = 1;
4210 
4211   if (dcvars->yh == viewheight-1)
4212     dcvars->yh = viewheight - 2;
4213 
4214   count = dcvars->yh - dcvars->yl;
4215 
4216   if (count < 0)
4217     return;
4218 
4219   frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
4220 
4221   if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
4222   {
4223      if (dcvars->yl != 0) {
4224         if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
4225 
4226            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4227            dcvars->yl += shift;
4228            count -= shift;
4229            frac += 0xffff-(slope_texu & 0xffff);
4230         }
4231         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
4232 
4233            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4234            dcvars->yl += shift;
4235            count -= shift;
4236            frac += slope_texu & 0xffff;
4237         }
4238      }
4239      if (dcvars->yh != viewheight-1) {
4240         if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
4241 
4242            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4243            dcvars->yh -= shift;
4244            count -= shift;
4245         }
4246         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
4247 
4248            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4249            dcvars->yh -= shift;
4250            count -= shift;
4251         }
4252      }
4253      if (count <= 0) return;
4254   }
4255 
4256   if(temp_x == 4 ||
4257         (temp_x && (temptype != (COL_FUZZ) || temp_x + startx != dcvars->x)))
4258      R_FlushColumns();
4259 
4260   if(!temp_x)
4261   {
4262      startx = dcvars->x;
4263      tempyl[0] = commontop = dcvars->yl;
4264      tempyh[0] = commonbot = dcvars->yh;
4265      temptype = (COL_FUZZ);
4266 
4267 
4268 
4269      tempfuzzmap = fullcolormap;
4270 
4271      R_FlushWholeColumns = R_FlushWholeFuzz16;
4272      R_FlushHTColumns = R_FlushHTFuzz16;
4273      R_FlushQuadColumn = R_FlushQuadFuzz16;
4274 
4275 
4276 
4277   }
4278   else
4279   {
4280      tempyl[temp_x] = dcvars->yl;
4281      tempyh[temp_x] = dcvars->yh;
4282 
4283      if(dcvars->yl > commontop)
4284         commontop = dcvars->yl;
4285      if(dcvars->yh < commonbot)
4286         commonbot = dcvars->yh;
4287 
4288 
4289 
4290 
4291   }
4292   temp_x += 1;
4293 }
4294 
R_DrawFuzzColumn16_LinearUV(draw_column_vars_t * dcvars)4295 static void R_DrawFuzzColumn16_LinearUV(draw_column_vars_t *dcvars)
4296 {
4297   int count;
4298   fixed_t frac;
4299   const fixed_t fracstep = dcvars->iscale;
4300   const fixed_t slope_texu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
4301 
4302   if (dcvars->iscale > drawvars.mag_threshold)
4303   {
4304     R_GetDrawColumnFunc(RDC_PIPELINE_FUZZ,
4305                         RDRAW_FILTER_POINT,
4306                         drawvars.filterz)(dcvars);
4307     return;
4308   }
4309 
4310   if (!dcvars->yl)
4311     dcvars->yl = 1;
4312 
4313 
4314   if (dcvars->yh == viewheight-1)
4315     dcvars->yh = viewheight - 2;
4316 
4317   count = dcvars->yh - dcvars->yl;
4318 
4319   if (count < 0)
4320     return;
4321 
4322   frac = dcvars->texturemid - ((1<<16)>>1) + (dcvars->yl-centery)*fracstep;
4323 
4324   if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
4325   {
4326      if (dcvars->yl != 0) {
4327         if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
4328 
4329            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4330            dcvars->yl += shift;
4331            count -= shift;
4332            frac += 0xffff-(slope_texu & 0xffff);
4333         }
4334         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
4335 
4336            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4337            dcvars->yl += shift;
4338            count -= shift;
4339            frac += slope_texu & 0xffff;
4340         }
4341      }
4342      if (dcvars->yh != viewheight-1) {
4343         if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
4344 
4345            int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4346            dcvars->yh -= shift;
4347            count -= shift;
4348         }
4349         else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
4350 
4351            int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4352            dcvars->yh -= shift;
4353            count -= shift;
4354         }
4355      }
4356      if (count <= 0) return;
4357   }
4358 
4359   if(temp_x == 4 ||
4360         (temp_x && (temptype != (COL_FUZZ) || temp_x + startx != dcvars->x)))
4361      R_FlushColumns();
4362 
4363   if(!temp_x)
4364   {
4365      startx = dcvars->x;
4366      tempyl[0] = commontop = dcvars->yl;
4367      tempyh[0] = commonbot = dcvars->yh;
4368      temptype = (COL_FUZZ);
4369 
4370 
4371 
4372      tempfuzzmap = fullcolormap;
4373 
4374      R_FlushWholeColumns = R_FlushWholeFuzz16;
4375      R_FlushHTColumns = R_FlushHTFuzz16;
4376      R_FlushQuadColumn = R_FlushQuadFuzz16;
4377 
4378 
4379 
4380   }
4381   else
4382   {
4383      tempyl[temp_x] = dcvars->yl;
4384      tempyh[temp_x] = dcvars->yh;
4385 
4386      if(dcvars->yl > commontop)
4387         commontop = dcvars->yl;
4388      if(dcvars->yh < commonbot)
4389         commonbot = dcvars->yh;
4390 
4391 
4392 
4393 
4394   }
4395   temp_x += 1;
4396 }
4397 
R_DrawFuzzColumn16_LinearUV_PointZ(draw_column_vars_t * dcvars)4398 static void R_DrawFuzzColumn16_LinearUV_PointZ(draw_column_vars_t *dcvars)
4399 {
4400    int count;
4401    fixed_t frac;
4402    const fixed_t fracstep = dcvars->iscale;
4403    const fixed_t slope_texu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
4404 
4405    if (dcvars->iscale > drawvars.mag_threshold)
4406    {
4407       R_GetDrawColumnFunc(RDC_PIPELINE_FUZZ,
4408             RDRAW_FILTER_POINT,
4409             drawvars.filterz)(dcvars);
4410       return;
4411    }
4412 
4413 
4414 
4415 
4416    if (!dcvars->yl)
4417       dcvars->yl = 1;
4418 
4419 
4420    if (dcvars->yh == viewheight-1)
4421       dcvars->yh = viewheight - 2;
4422 
4423    count = dcvars->yh - dcvars->yl;
4424    if (count < 0)
4425       return;
4426 
4427    frac = dcvars->texturemid - ((1<<16)>>1) + (dcvars->yl-centery)*fracstep;
4428 
4429    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
4430    {
4431       if (dcvars->yl != 0) {
4432          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
4433 
4434             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4435             dcvars->yl += shift;
4436             count -= shift;
4437             frac += 0xffff-(slope_texu & 0xffff);
4438          }
4439          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
4440 
4441             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4442             dcvars->yl += shift;
4443             count -= shift;
4444             frac += slope_texu & 0xffff;
4445          }
4446       }
4447       if (dcvars->yh != viewheight-1) {
4448          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
4449 
4450             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4451             dcvars->yh -= shift;
4452             count -= shift;
4453          }
4454          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
4455 
4456             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4457             dcvars->yh -= shift;
4458             count -= shift;
4459          }
4460       }
4461       if (count <= 0) return;
4462    }
4463 
4464    if(temp_x == 4 ||
4465          (temp_x && (temptype != (COL_FUZZ) || temp_x + startx != dcvars->x)))
4466       R_FlushColumns();
4467 
4468    if(!temp_x)
4469    {
4470       startx = dcvars->x;
4471       tempyl[0] = commontop = dcvars->yl;
4472       tempyh[0] = commonbot = dcvars->yh;
4473       temptype = (COL_FUZZ);
4474 
4475 
4476 
4477       tempfuzzmap = fullcolormap;
4478 
4479       R_FlushWholeColumns = R_FlushWholeFuzz16;
4480       R_FlushHTColumns = R_FlushHTFuzz16;
4481       R_FlushQuadColumn = R_FlushQuadFuzz16;
4482 
4483 
4484 
4485    }
4486    else
4487    {
4488       tempyl[temp_x] = dcvars->yl;
4489       tempyh[temp_x] = dcvars->yh;
4490 
4491       if(dcvars->yl > commontop)
4492          commontop = dcvars->yl;
4493       if(dcvars->yh < commonbot)
4494          commonbot = dcvars->yh;
4495 
4496 
4497 
4498 
4499    }
4500    temp_x += 1;
4501 }
4502 
R_DrawFuzzColumn16_LinearUV_LinearZ(draw_column_vars_t * dcvars)4503 static void R_DrawFuzzColumn16_LinearUV_LinearZ(draw_column_vars_t *dcvars)
4504 {
4505   int count;
4506 
4507 
4508 
4509   fixed_t frac;
4510   const fixed_t fracstep = dcvars->iscale;
4511 
4512   const fixed_t slope_texu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
4513 
4514 
4515 
4516 
4517 
4518 
4519   if (dcvars->iscale > drawvars.mag_threshold) {
4520     R_GetDrawColumnFunc(RDC_PIPELINE_FUZZ,
4521                         RDRAW_FILTER_POINT,
4522                         drawvars.filterz)(dcvars);
4523     return;
4524   }
4525 
4526 
4527 
4528 
4529   if (!dcvars->yl)
4530     dcvars->yl = 1;
4531 
4532 
4533   if (dcvars->yh == viewheight-1)
4534     dcvars->yh = viewheight - 2;
4535 
4536   count = dcvars->yh - dcvars->yl;
4537 
4538   if (count < 0)
4539     return;
4540 
4541   frac = dcvars->texturemid - ((1<<16)>>1) + (dcvars->yl-centery)*fracstep;
4542 
4543   if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED) {
4544 
4545 
4546 
4547     if (dcvars->yl != 0) {
4548       if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
4549 
4550         int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4551         dcvars->yl += shift;
4552         count -= shift;
4553         frac += 0xffff-(slope_texu & 0xffff);
4554       }
4555       else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
4556 
4557         int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4558         dcvars->yl += shift;
4559         count -= shift;
4560         frac += slope_texu & 0xffff;
4561       }
4562     }
4563     if (dcvars->yh != viewheight-1) {
4564       if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
4565 
4566         int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4567         dcvars->yh -= shift;
4568         count -= shift;
4569       }
4570       else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
4571 
4572         int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4573         dcvars->yh -= shift;
4574         count -= shift;
4575       }
4576     }
4577     if (count <= 0) return;
4578   }
4579 
4580 
4581 
4582    {
4583 
4584       if(temp_x == 4 ||
4585          (temp_x && (temptype != (COL_FUZZ) || temp_x + startx != dcvars->x)))
4586          R_FlushColumns();
4587 
4588       if(!temp_x)
4589       {
4590          startx = dcvars->x;
4591          tempyl[0] = commontop = dcvars->yl;
4592          tempyh[0] = commonbot = dcvars->yh;
4593          temptype = (COL_FUZZ);
4594 
4595 
4596 
4597          tempfuzzmap = fullcolormap;
4598 
4599          R_FlushWholeColumns = R_FlushWholeFuzz16;
4600          R_FlushHTColumns = R_FlushHTFuzz16;
4601          R_FlushQuadColumn = R_FlushQuadFuzz16;
4602 
4603 
4604 
4605       }
4606       else
4607       {
4608          tempyl[temp_x] = dcvars->yl;
4609          tempyh[temp_x] = dcvars->yh;
4610 
4611          if(dcvars->yl > commontop)
4612             commontop = dcvars->yl;
4613          if(dcvars->yh < commonbot)
4614             commonbot = dcvars->yh;
4615 
4616 
4617 
4618 
4619       }
4620       temp_x += 1;
4621    }
4622 }
4623 
R_DrawFuzzColumn16_RoundedUV(draw_column_vars_t * dcvars)4624 static void R_DrawFuzzColumn16_RoundedUV(draw_column_vars_t *dcvars)
4625 {
4626    int count;
4627    fixed_t frac;
4628    const fixed_t fracstep = dcvars->iscale;
4629    const fixed_t slope_texu = dcvars->texu;
4630 
4631    if (dcvars->iscale > drawvars.mag_threshold)
4632    {
4633       R_GetDrawColumnFunc(RDC_PIPELINE_FUZZ,
4634             RDRAW_FILTER_POINT,
4635             drawvars.filterz)(dcvars);
4636       return;
4637    }
4638 
4639    if (!dcvars->yl)
4640       dcvars->yl = 1;
4641 
4642    if (dcvars->yh == viewheight-1)
4643       dcvars->yh = viewheight - 2;
4644 
4645    count = dcvars->yh - dcvars->yl;
4646 
4647    if (count < 0)
4648       return;
4649 
4650    frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
4651 
4652    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
4653    {
4654       if (dcvars->yl != 0) {
4655          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
4656 
4657             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4658             dcvars->yl += shift;
4659             count -= shift;
4660             frac += 0xffff-(slope_texu & 0xffff);
4661          }
4662          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
4663 
4664             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4665             dcvars->yl += shift;
4666             count -= shift;
4667             frac += slope_texu & 0xffff;
4668          }
4669       }
4670       if (dcvars->yh != viewheight-1) {
4671          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
4672 
4673             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4674             dcvars->yh -= shift;
4675             count -= shift;
4676          }
4677          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
4678 
4679             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4680             dcvars->yh -= shift;
4681             count -= shift;
4682          }
4683       }
4684       if (count <= 0) return;
4685    }
4686 
4687    if(temp_x == 4 ||
4688          (temp_x && (temptype != (COL_FUZZ) || temp_x + startx != dcvars->x)))
4689       R_FlushColumns();
4690 
4691    if(!temp_x)
4692    {
4693       startx = dcvars->x;
4694       tempyl[0] = commontop = dcvars->yl;
4695       tempyh[0] = commonbot = dcvars->yh;
4696       temptype = (COL_FUZZ);
4697 
4698 
4699 
4700       tempfuzzmap = fullcolormap;
4701 
4702       R_FlushWholeColumns = R_FlushWholeFuzz16;
4703       R_FlushHTColumns = R_FlushHTFuzz16;
4704       R_FlushQuadColumn = R_FlushQuadFuzz16;
4705    }
4706    else
4707    {
4708       tempyl[temp_x] = dcvars->yl;
4709       tempyh[temp_x] = dcvars->yh;
4710 
4711       if(dcvars->yl > commontop)
4712          commontop = dcvars->yl;
4713       if(dcvars->yh < commonbot)
4714          commonbot = dcvars->yh;
4715    }
4716    temp_x += 1;
4717 }
4718 
R_DrawFuzzColumn16_RoundedUV_PointZ(draw_column_vars_t * dcvars)4719 static void R_DrawFuzzColumn16_RoundedUV_PointZ(draw_column_vars_t *dcvars)
4720 {
4721    int count;
4722    fixed_t frac;
4723    const fixed_t fracstep = dcvars->iscale;
4724    const fixed_t slope_texu = dcvars->texu;
4725 
4726    if (dcvars->iscale > drawvars.mag_threshold)
4727    {
4728       R_GetDrawColumnFunc(RDC_PIPELINE_FUZZ,
4729             RDRAW_FILTER_POINT,
4730             drawvars.filterz)(dcvars);
4731       return;
4732    }
4733 
4734    if (!dcvars->yl)
4735       dcvars->yl = 1;
4736 
4737    if (dcvars->yh == viewheight-1)
4738       dcvars->yh = viewheight - 2;
4739 
4740    count = dcvars->yh - dcvars->yl;
4741 
4742    if (count < 0)
4743       return;
4744 
4745    frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
4746 
4747    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
4748    {
4749       if (dcvars->yl != 0)
4750       {
4751          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP)
4752          {
4753 
4754             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4755             dcvars->yl += shift;
4756             count -= shift;
4757             frac += 0xffff-(slope_texu & 0xffff);
4758          }
4759          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
4760 
4761             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4762             dcvars->yl += shift;
4763             count -= shift;
4764             frac += slope_texu & 0xffff;
4765          }
4766       }
4767       if (dcvars->yh != viewheight-1) {
4768          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
4769 
4770             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4771             dcvars->yh -= shift;
4772             count -= shift;
4773          }
4774          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
4775 
4776             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4777             dcvars->yh -= shift;
4778             count -= shift;
4779          }
4780       }
4781       if (count <= 0)
4782          return;
4783    }
4784 
4785    if(temp_x == 4 ||
4786          (temp_x && (temptype != (COL_FUZZ) || temp_x + startx != dcvars->x)))
4787       R_FlushColumns();
4788 
4789    if(!temp_x)
4790    {
4791       startx = dcvars->x;
4792       tempyl[0] = commontop = dcvars->yl;
4793       tempyh[0] = commonbot = dcvars->yh;
4794       temptype = (COL_FUZZ);
4795 
4796 
4797 
4798       tempfuzzmap = fullcolormap;
4799 
4800       R_FlushWholeColumns = R_FlushWholeFuzz16;
4801       R_FlushHTColumns = R_FlushHTFuzz16;
4802       R_FlushQuadColumn = R_FlushQuadFuzz16;
4803 
4804 
4805 
4806    }
4807    else
4808    {
4809       tempyl[temp_x] = dcvars->yl;
4810       tempyh[temp_x] = dcvars->yh;
4811 
4812       if(dcvars->yl > commontop)
4813          commontop = dcvars->yl;
4814       if(dcvars->yh < commonbot)
4815          commonbot = dcvars->yh;
4816 
4817 
4818 
4819 
4820    }
4821    temp_x += 1;
4822 }
4823 
R_DrawFuzzColumn16_RoundedUV_LinearZ(draw_column_vars_t * dcvars)4824 static void R_DrawFuzzColumn16_RoundedUV_LinearZ(draw_column_vars_t *dcvars)
4825 {
4826    int count;
4827    fixed_t frac;
4828    const fixed_t fracstep = dcvars->iscale;
4829    const fixed_t slope_texu = dcvars->texu;
4830 
4831    if (dcvars->iscale > drawvars.mag_threshold)
4832    {
4833       R_GetDrawColumnFunc(RDC_PIPELINE_FUZZ,
4834             RDRAW_FILTER_POINT,
4835             drawvars.filterz)(dcvars);
4836       return;
4837    }
4838 
4839    if (!dcvars->yl)
4840       dcvars->yl = 1;
4841 
4842    if (dcvars->yh == viewheight-1)
4843       dcvars->yh = viewheight - 2;
4844 
4845    count = dcvars->yh - dcvars->yl;
4846 
4847    if (count < 0)
4848       return;
4849 
4850    frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
4851 
4852    if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED)
4853    {
4854       if (dcvars->yl != 0)
4855       {
4856          if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
4857 
4858             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4859             dcvars->yl += shift;
4860             count -= shift;
4861             frac += 0xffff-(slope_texu & 0xffff);
4862          }
4863          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
4864 
4865             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4866             dcvars->yl += shift;
4867             count -= shift;
4868             frac += slope_texu & 0xffff;
4869          }
4870       }
4871       if (dcvars->yh != viewheight-1) {
4872          if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
4873 
4874             int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
4875             dcvars->yh -= shift;
4876             count -= shift;
4877          }
4878          else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
4879 
4880             int shift = ((slope_texu & 0xffff)/dcvars->iscale);
4881             dcvars->yh -= shift;
4882             count -= shift;
4883          }
4884       }
4885       if (count <= 0) return;
4886    }
4887 
4888    if(temp_x == 4 ||
4889          (temp_x && (temptype != (COL_FUZZ) || temp_x + startx != dcvars->x)))
4890       R_FlushColumns();
4891 
4892    if(!temp_x)
4893    {
4894       startx = dcvars->x;
4895       tempyl[0] = commontop = dcvars->yl;
4896       tempyh[0] = commonbot = dcvars->yh;
4897       temptype = (COL_FUZZ);
4898 
4899       tempfuzzmap = fullcolormap;
4900 
4901       R_FlushWholeColumns = R_FlushWholeFuzz16;
4902       R_FlushHTColumns = R_FlushHTFuzz16;
4903       R_FlushQuadColumn = R_FlushQuadFuzz16;
4904    }
4905    else
4906    {
4907       tempyl[temp_x] = dcvars->yl;
4908       tempyh[temp_x] = dcvars->yh;
4909 
4910       if(dcvars->yl > commontop)
4911          commontop = dcvars->yl;
4912       if(dcvars->yh < commonbot)
4913          commonbot = dcvars->yh;
4914    }
4915    temp_x += 1;
4916 }
4917 
4918 static R_DrawColumn_f drawcolumnfuncs[RDRAW_FILTER_MAXFILTERS][RDRAW_FILTER_MAXFILTERS][RDC_PIPELINE_MAXPIPELINES] = {
4919     {
4920       {NULL, NULL, NULL},
4921       {R_DrawColumn16_PointUV,
4922        R_DrawTranslatedColumn16_PointUV,
4923        R_DrawFuzzColumn16_PointUV,},
4924       {R_DrawColumn16_LinearUV,
4925        R_DrawTranslatedColumn16_LinearUV,
4926        R_DrawFuzzColumn16_LinearUV,},
4927       {R_DrawColumn16_RoundedUV,
4928        R_DrawTranslatedColumn16_RoundedUV,
4929        R_DrawFuzzColumn16_RoundedUV,},
4930     },
4931     {
4932       {NULL, NULL, NULL},
4933       {R_DrawColumn16_PointUV_PointZ,
4934        R_DrawTranslatedColumn16_PointUV_PointZ,
4935        R_DrawFuzzColumn16_PointUV_PointZ,},
4936       {R_DrawColumn16_LinearUV_PointZ,
4937        R_DrawTranslatedColumn16_LinearUV_PointZ,
4938        R_DrawFuzzColumn16_LinearUV_PointZ,},
4939       {R_DrawColumn16_RoundedUV_PointZ,
4940        R_DrawTranslatedColumn16_RoundedUV_PointZ,
4941        R_DrawFuzzColumn16_RoundedUV_PointZ,},
4942     },
4943     {
4944       {NULL, NULL, NULL},
4945       {R_DrawColumn16_PointUV_LinearZ,
4946        R_DrawTranslatedColumn16_PointUV_LinearZ,
4947        R_DrawFuzzColumn16_PointUV_LinearZ,},
4948       {R_DrawColumn16_LinearUV_LinearZ,
4949        R_DrawTranslatedColumn16_LinearUV_LinearZ,
4950        R_DrawFuzzColumn16_LinearUV_LinearZ,},
4951       {R_DrawColumn16_RoundedUV_LinearZ,
4952        R_DrawTranslatedColumn16_RoundedUV_LinearZ,
4953        R_DrawFuzzColumn16_RoundedUV_LinearZ,},
4954     },
4955 };
4956 
R_GetDrawColumnFunc(enum column_pipeline_e type,enum draw_filter_type_e filter,enum draw_filter_type_e filterz)4957 R_DrawColumn_f R_GetDrawColumnFunc(enum column_pipeline_e type,
4958                                    enum draw_filter_type_e filter,
4959                                    enum draw_filter_type_e filterz) {
4960   R_DrawColumn_f result = drawcolumnfuncs[filterz][filter][type];
4961   if (result == NULL)
4962     I_Error("R_GetDrawColumnFunc: undefined function (%d, %d, %d)",
4963             type, filter, filterz);
4964   return result;
4965 }
4966 
R_SetDefaultDrawColumnVars(draw_column_vars_t * dcvars)4967 void R_SetDefaultDrawColumnVars(draw_column_vars_t *dcvars)
4968 {
4969    dcvars->x             = 0;
4970    dcvars->yl            = 0;
4971    dcvars->yh            = 0;
4972    dcvars->z             = 0;
4973    dcvars->iscale        = 0;
4974    dcvars->texturemid    = 0;
4975    dcvars->texheight     = 0;
4976    dcvars->texu          = 0;
4977    dcvars->source        = NULL;
4978    dcvars->prevsource    = NULL;
4979    dcvars->nextsource    = NULL;
4980    dcvars->colormap      = colormaps[0];
4981    dcvars->nextcolormap  = colormaps[0];
4982    dcvars->translation   = NULL;
4983    dcvars->edgeslope     = 0;
4984    dcvars->drawingmasked = 0;
4985    dcvars->edgetype      = drawvars.sprite_edges;
4986 }
4987 
4988 //
4989 // R_InitTranslationTables
4990 // Creates the translation tables to map
4991 //  the green color ramp to gray, brown, red.
4992 // Assumes a given structure of the PLAYPAL.
4993 // Could be read from a lump instead.
4994 //
4995 
4996 uint8_t playernumtotrans[MAXPLAYERS];
4997 extern lighttable_t *(*c_zlight)[LIGHTLEVELS][MAXLIGHTZ];
4998 
R_InitTranslationTables(void)4999 void R_InitTranslationTables (void)
5000 {
5001    int i, j;
5002 #define MAXTRANS 3
5003    uint8_t transtocolour[MAXTRANS];
5004 
5005    // killough 5/2/98:
5006    // Remove dependency of colormaps aligned on 256-byte boundary
5007 
5008    if (!translationtables) // CPhipps - allow multiple calls
5009       translationtables = Z_Malloc(256*MAXTRANS, PU_STATIC, 0);
5010 
5011    for (i=0; i<MAXTRANS; i++)
5012       transtocolour[i] = 255;
5013 
5014    for (i=0; i<MAXPLAYERS; i++)
5015    {
5016       uint8_t wantcolour = mapcolor_plyr[i];
5017       playernumtotrans[i] = 0;
5018       if (wantcolour != 0x70) // Not green, would like translation
5019          for (j=0; j<MAXTRANS; j++)
5020          {
5021             if (transtocolour[j] == 255)
5022             {
5023                transtocolour[j] = wantcolour;
5024                playernumtotrans[i] = j+1;
5025                break;
5026             }
5027          }
5028    }
5029 
5030    // translate just the 16 green colors
5031    for (i=0; i<256; i++)
5032    {
5033       if (i >= 0x70 && i<= 0x7f)
5034       {
5035          // CPhipps - configurable player colours
5036          translationtables[i]     = colormaps[0][((i&0xf)<<9) + transtocolour[0]];
5037          translationtables[i+256] = colormaps[0][((i&0xf)<<9) + transtocolour[1]];
5038          translationtables[i+512] = colormaps[0][((i&0xf)<<9) + transtocolour[2]];
5039       }
5040       else  // Keep all other colors as is.
5041       {
5042          translationtables[i]     = i;
5043          translationtables[i+256] = i;
5044          translationtables[i+512] = i;
5045       }
5046    }
5047 }
5048 
5049 //
5050 // R_DrawSpan
5051 // With DOOM style restrictions on view orientation,
5052 //  the floors and ceilings consist of horizontal slices
5053 //  or spans with constant z depth.
5054 // However, rotation around the world z axis is possible,
5055 //  thus this mapping, while simpler and faster than
5056 //  perspective correct texture mapping, has to traverse
5057 //  the texture at an angle in all but a few cases.
5058 // In consequence, flats are not stored by column (like walls),
5059 //  and the inner loop has to step in texture space u and v.
5060 //
5061 
R_DrawSpan16_PointUV_PointZ(draw_span_vars_t * dsvars)5062 static void R_DrawSpan16_PointUV_PointZ(draw_span_vars_t *dsvars)
5063 {
5064    unsigned count = dsvars->x2 - dsvars->x1 + 1;
5065    fixed_t xfrac = dsvars->xfrac;
5066    fixed_t yfrac = dsvars->yfrac;
5067    const fixed_t xstep = dsvars->xstep;
5068    const fixed_t ystep = dsvars->ystep;
5069    const uint8_t *source = dsvars->source;
5070 
5071 
5072    const uint8_t *colormap = dsvars->colormap;
5073 
5074    uint16_t *dest = drawvars.short_topleft + dsvars->y* SCREENWIDTH + dsvars->x1;
5075    while (count)
5076    {
5077       const fixed_t xtemp = (xfrac >> 16) & 63;
5078       const fixed_t ytemp = (yfrac >> 10) & 4032;
5079 
5080       const fixed_t spot = xtemp | ytemp;
5081       xfrac += xstep;
5082       yfrac += ystep;
5083       *dest++ = V_Palette16[ (colormap[(source[spot])])*64 + ((64 -1)) ];
5084       count--;
5085    }
5086 }
5087 
R_DrawSpan16_PointUV_LinearZ(draw_span_vars_t * dsvars)5088 static void R_DrawSpan16_PointUV_LinearZ(draw_span_vars_t *dsvars)
5089 {
5090    unsigned count = dsvars->x2 - dsvars->x1 + 1;
5091    fixed_t xfrac = dsvars->xfrac;
5092    fixed_t yfrac = dsvars->yfrac;
5093    const fixed_t xstep = dsvars->xstep;
5094    const fixed_t ystep = dsvars->ystep;
5095    const uint8_t *source = dsvars->source;
5096 
5097 
5098 
5099 
5100    uint16_t *dest = drawvars.short_topleft + dsvars->y* SCREENWIDTH + dsvars->x1;
5101 
5102    const int y = dsvars->y;
5103    int x1 = dsvars->x1;
5104 
5105 
5106    const int fracz = (dsvars->z >> 12) & 255;
5107    const uint8_t *dither_colormaps[2] = { dsvars->colormap, dsvars->nextcolormap };
5108 
5109 
5110    while (count) {
5111       const fixed_t xtemp = (xfrac >> 16) & 63;
5112       const fixed_t ytemp = (yfrac >> 10) & 4032;
5113 
5114       const fixed_t spot = xtemp | ytemp;
5115       xfrac += xstep;
5116       yfrac += ystep;
5117       *dest++ = V_Palette16[ (dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x1)&(4 -1)] < (fracz)) ? 1 : 0)][(source[spot])])*64 + ((64 -1)) ];
5118       count--;
5119 
5120       x1--;
5121 
5122 
5123    }
5124 }
5125 
R_DrawSpan16_LinearUV_PointZ(draw_span_vars_t * dsvars)5126 static void R_DrawSpan16_LinearUV_PointZ(draw_span_vars_t *dsvars)
5127 {
5128    if ((D_abs(dsvars->xstep) > drawvars.mag_threshold)
5129          || (D_abs(dsvars->ystep) > drawvars.mag_threshold))
5130    {
5131       R_GetDrawSpanFunc(RDRAW_FILTER_POINT,
5132             drawvars.filterz)(dsvars);
5133       return;
5134    }
5135 
5136    {
5137       unsigned count = dsvars->x2 - dsvars->x1 + 1;
5138       fixed_t xfrac = dsvars->xfrac;
5139       fixed_t yfrac = dsvars->yfrac;
5140       const fixed_t xstep = dsvars->xstep;
5141       const fixed_t ystep = dsvars->ystep;
5142       const uint8_t *source = dsvars->source;
5143 
5144 
5145       const uint8_t *colormap = dsvars->colormap;
5146 
5147       uint16_t *dest = drawvars.short_topleft + dsvars->y* SCREENWIDTH + dsvars->x1;
5148 
5149       while (count) {
5150 
5151 
5152          *dest++ = ( V_Palette16[ (colormap[(source[ ((((xfrac)+(1<<16))>>16)&0x3f) | ((((yfrac)+(1<<16))>>10)&0xfc0)])])*64 + ((unsigned int)(((xfrac)&0xffff)*((yfrac)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[ (((xfrac)>>16)&0x3f) | ((((yfrac)+(1<<16))>>10)&0xfc0)])])*64 + ((unsigned int)((0xffff-((xfrac)&0xffff))*((yfrac)&0xffff))>>(32-6)) ] + V_Palette16[ (colormap[(source[ (((xfrac)>>16)&0x3f) | (((yfrac)>>10)&0xfc0)])])*64 + ((unsigned int)((0xffff-((xfrac)&0xffff))*(0xffff-((yfrac)&0xffff)))>>(32-6)) ] + V_Palette16[ (colormap[(source[ ((((xfrac)+(1<<16))>>16)&0x3f) | (((yfrac)>>10)&0xfc0)])])*64 + ((unsigned int)(((xfrac)&0xffff)*(0xffff-((yfrac)&0xffff)))>>(32-6)) ]);
5153          xfrac += xstep;
5154          yfrac += ystep;
5155          count--;
5156       }
5157    }
5158 }
5159 
R_DrawSpan16_LinearUV_LinearZ(draw_span_vars_t * dsvars)5160 static void R_DrawSpan16_LinearUV_LinearZ(draw_span_vars_t *dsvars)
5161 {
5162    if ((D_abs(dsvars->xstep) > drawvars.mag_threshold)
5163          || (D_abs(dsvars->ystep) > drawvars.mag_threshold))
5164    {
5165       R_GetDrawSpanFunc(RDRAW_FILTER_POINT,
5166             drawvars.filterz)(dsvars);
5167       return;
5168    }
5169 
5170    {
5171       unsigned count = dsvars->x2 - dsvars->x1 + 1;
5172       fixed_t xfrac = dsvars->xfrac;
5173       fixed_t yfrac = dsvars->yfrac;
5174       const fixed_t xstep = dsvars->xstep;
5175       const fixed_t ystep = dsvars->ystep;
5176       const uint8_t *source = dsvars->source;
5177 
5178 
5179 
5180 
5181       uint16_t *dest = drawvars.short_topleft + dsvars->y* SCREENWIDTH + dsvars->x1;
5182 
5183       const int y = dsvars->y;
5184       int x1 = dsvars->x1;
5185 
5186 
5187       const int fracz = (dsvars->z >> 12) & 255;
5188       const uint8_t *dither_colormaps[2] = { dsvars->colormap, dsvars->nextcolormap };
5189 
5190 
5191       while (count) {
5192 
5193 
5194          *dest++ = ( V_Palette16[ (dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x1)&(4 -1)] < (fracz)) ? 1 : 0)][(source[ ((((xfrac)+(1<<16))>>16)&0x3f) | ((((yfrac)+(1<<16))>>10)&0xfc0)])])*64 + ((unsigned int)(((xfrac)&0xffff)*((yfrac)&0xffff))>>(32-6)) ] + V_Palette16[ (dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x1)&(4 -1)] < (fracz)) ? 1 : 0)][(source[ (((xfrac)>>16)&0x3f) | ((((yfrac)+(1<<16))>>10)&0xfc0)])])*64 + ((unsigned int)((0xffff-((xfrac)&0xffff))*((yfrac)&0xffff))>>(32-6)) ] + V_Palette16[ (dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x1)&(4 -1)] < (fracz)) ? 1 : 0)][(source[ (((xfrac)>>16)&0x3f) | (((yfrac)>>10)&0xfc0)])])*64 + ((unsigned int)((0xffff-((xfrac)&0xffff))*(0xffff-((yfrac)&0xffff)))>>(32-6)) ] + V_Palette16[ (dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x1)&(4 -1)] < (fracz)) ? 1 : 0)][(source[ ((((xfrac)+(1<<16))>>16)&0x3f) | (((yfrac)>>10)&0xfc0)])])*64 + ((unsigned int)(((xfrac)&0xffff)*(0xffff-((yfrac)&0xffff)))>>(32-6)) ]);
5195          xfrac += xstep;
5196          yfrac += ystep;
5197          count--;
5198 
5199          x1--;
5200       }
5201    }
5202 }
5203 
R_DrawSpan16_RoundedUV_PointZ(draw_span_vars_t * dsvars)5204 static void R_DrawSpan16_RoundedUV_PointZ(draw_span_vars_t *dsvars)
5205 {
5206    if ((D_abs(dsvars->xstep) > drawvars.mag_threshold)
5207          || (D_abs(dsvars->ystep) > drawvars.mag_threshold))
5208    {
5209       R_GetDrawSpanFunc(RDRAW_FILTER_POINT,
5210             drawvars.filterz)(dsvars);
5211       return;
5212    }
5213 
5214    {
5215       unsigned count = dsvars->x2 - dsvars->x1 + 1;
5216       fixed_t xfrac = dsvars->xfrac;
5217       fixed_t yfrac = dsvars->yfrac;
5218       const fixed_t xstep = dsvars->xstep;
5219       const fixed_t ystep = dsvars->ystep;
5220       const uint8_t *source = dsvars->source;
5221 
5222 
5223       const uint8_t *colormap = dsvars->colormap;
5224 
5225       uint16_t *dest = drawvars.short_topleft + dsvars->y* SCREENWIDTH + dsvars->x1;
5226       while (count) {
5227          *dest++ = V_Palette16[ (colormap[(filter_getScale2xQuadColors( source[ (((xfrac)>>16)&0x3f) | (((yfrac)>>10)&0xfc0) ], source[ (((xfrac)>>16)&0x3f) | ((((yfrac)-(1<<16))>>10)&0xfc0) ], source[ ((((xfrac)+(1<<16))>>16)&0x3f) | (((yfrac)>>10)&0xfc0) ], source[ (((xfrac)>>16)&0x3f) | ((((yfrac)+(1<<16))>>10)&0xfc0) ], source[ ((((xfrac)-(1<<16))>>16)&0x3f) | (((yfrac)>>10)&0xfc0) ] ) [ filter_roundedUVMap[ (((((xfrac)>>8) & 0xff)>>(8-6))<<6) + ((((yfrac)>>8) & 0xff)>>(8-6)) ] ])])*64 + ((64 -1)) ];
5228          xfrac += xstep;
5229          yfrac += ystep;
5230          count--;
5231       }
5232    }
5233 }
5234 
R_DrawSpan16_RoundedUV_LinearZ(draw_span_vars_t * dsvars)5235 static void R_DrawSpan16_RoundedUV_LinearZ(draw_span_vars_t *dsvars)
5236 {
5237    if ((D_abs(dsvars->xstep) > drawvars.mag_threshold)
5238          || (D_abs(dsvars->ystep) > drawvars.mag_threshold))
5239    {
5240       R_GetDrawSpanFunc(RDRAW_FILTER_POINT,
5241             drawvars.filterz)(dsvars);
5242       return;
5243    }
5244 
5245    {
5246       unsigned count = dsvars->x2 - dsvars->x1 + 1;
5247       fixed_t xfrac = dsvars->xfrac;
5248       fixed_t yfrac = dsvars->yfrac;
5249       const fixed_t xstep = dsvars->xstep;
5250       const fixed_t ystep = dsvars->ystep;
5251       const uint8_t *source = dsvars->source;
5252 
5253 
5254 
5255 
5256       uint16_t *dest = drawvars.short_topleft + dsvars->y* SCREENWIDTH + dsvars->x1;
5257 
5258       const int y = dsvars->y;
5259       int x1 = dsvars->x1;
5260 
5261 
5262       const int fracz = (dsvars->z >> 12) & 255;
5263       const uint8_t *dither_colormaps[2] = { dsvars->colormap, dsvars->nextcolormap };
5264 
5265 
5266       while (count) {
5267          *dest++ = V_Palette16[ (dither_colormaps[((filter_ditherMatrix[(y)&(4 -1)][(x1)&(4 -1)] < (fracz)) ? 1 : 0)][(filter_getScale2xQuadColors( source[ (((xfrac)>>16)&0x3f) | (((yfrac)>>10)&0xfc0) ], source[ (((xfrac)>>16)&0x3f) | ((((yfrac)-(1<<16))>>10)&0xfc0) ], source[ ((((xfrac)+(1<<16))>>16)&0x3f) | (((yfrac)>>10)&0xfc0) ], source[ (((xfrac)>>16)&0x3f) | ((((yfrac)+(1<<16))>>10)&0xfc0) ], source[ ((((xfrac)-(1<<16))>>16)&0x3f) | (((yfrac)>>10)&0xfc0) ] ) [ filter_roundedUVMap[ (((((xfrac)>>8) & 0xff)>>(8-6))<<6) + ((((yfrac)>>8) & 0xff)>>(8-6)) ] ])])*64 + ((64 -1)) ];
5268          xfrac += xstep;
5269          yfrac += ystep;
5270          count--;
5271 
5272          x1--;
5273       }
5274    }
5275 }
5276 
5277 static R_DrawSpan_f drawspanfuncs[RDRAW_FILTER_MAXFILTERS][RDRAW_FILTER_MAXFILTERS] = {
5278     {
5279       NULL,
5280       NULL,
5281       NULL,
5282       NULL,
5283     },
5284     {
5285       NULL,
5286       R_DrawSpan16_PointUV_PointZ,
5287       R_DrawSpan16_LinearUV_PointZ,
5288       R_DrawSpan16_RoundedUV_PointZ,
5289     },
5290     {
5291       NULL,
5292       R_DrawSpan16_PointUV_LinearZ,
5293       R_DrawSpan16_LinearUV_LinearZ,
5294       R_DrawSpan16_RoundedUV_LinearZ,
5295     },
5296     {
5297       NULL,
5298       NULL,
5299       NULL,
5300       NULL,
5301     },
5302 };
5303 
R_GetDrawSpanFunc(enum draw_filter_type_e filter,enum draw_filter_type_e filterz)5304 R_DrawSpan_f R_GetDrawSpanFunc(enum draw_filter_type_e filter,
5305                                enum draw_filter_type_e filterz) {
5306   R_DrawSpan_f result = drawspanfuncs[filterz][filter];
5307   if (result == NULL)
5308     I_Error("R_GetDrawSpanFunc: undefined function (%d, %d)",
5309             filter, filterz);
5310   return result;
5311 }
5312 
R_DrawSpan(draw_span_vars_t * dsvars)5313 void R_DrawSpan(draw_span_vars_t *dsvars) {
5314   R_GetDrawSpanFunc(drawvars.filterfloor, drawvars.filterz)(dsvars);
5315 }
5316 
5317 //
5318 // R_InitBuffer
5319 // Creats lookup tables that avoid
5320 //  multiplies and other hazzles
5321 //  for getting the framebuffer address
5322 //  of a pixel to draw.
5323 //
5324 
R_InitBuffer(int width,int height)5325 void R_InitBuffer(int width, int height)
5326 {
5327   int i=0;
5328   // Handle resize,
5329   //  e.g. smaller view windows
5330   //  with border and/or status bar.
5331 
5332   // Same with base row offset.
5333 
5334   drawvars.short_topleft = (unsigned short *)(screens[0].data);
5335   drawvars.int_topleft = (unsigned int *)(screens[0].data);
5336 
5337   for (i=0; i<FUZZTABLE; i++)
5338 	  fuzzoffset[i] = fuzzoffset_org[i] * SURFACE_SHORT_PITCH;
5339 }
5340