2 * $Logfile: /Freespace2/code/Graphics/Tmapper.cpp $
7 * Routines to draw a texture map.
10 * Revision 1.1 2002/05/03 03:28:09 root
14 * 3 12/06/98 3:08p Dave
15 * Fixed grx_tmapper to handle pixel fog flag. First run fog support for
18 * 2 10/07/98 10:53a Dave
21 * 1 10/07/98 10:49a Dave
23 * 78 5/13/98 2:53p John
24 * Made subspace effect work under software. Had to add new inner loop to
25 * tmapper. Added glows to end of subspace effect. Made subspace effect
26 * levels use gamepalette-subspace palette.
28 * 77 4/10/98 5:20p John
29 * Changed RGB in lighting structure to be ubytes. Removed old
30 * not-necessary 24 bpp software stuff.
32 * 76 4/09/98 7:58p John
33 * Cleaned up tmapper code a bit. Put NDEBUG around some ndebug stuff.
34 * Took out XPARENT flag settings in all the alpha-blended texture stuff.
36 * 75 4/09/98 7:16p John
37 * Fixed bug causing software to not render
39 * 74 3/27/98 8:34p Mike
42 * 73 3/25/98 8:08p John
43 * Restructured software rendering into two modules; One for windowed
44 * debug mode and one for DirectX fullscreen.
46 * 72 3/23/98 5:00p John
47 * Improved missile trails. Made smooth alpha under hardware. Made end
48 * taper. Made trail touch weapon.
50 * 71 3/22/98 2:33p John
51 * Took out fx_v/v_right. Made fx_u etc get calculated in tmapper.
53 * 70 3/10/98 4:19p John
54 * Cleaned up graphics lib. Took out most unused gr functions. Made D3D
55 * & Glide have popups and print screen. Took out all >8bpp software
56 * support. Made Fred zbuffer. Made zbuffer allocate dynamically to
57 * support Fred. Made zbuffering key off of functions rather than one
60 * 69 2/10/98 5:34p John
62 * 68 2/05/98 9:21p John
63 * Some new Direct3D code. Added code to monitor a ton of stuff in the
66 * 67 1/29/98 8:18a John
67 * Put in some commented out hooks for RGB lighting
69 * 66 1/28/98 1:27p John
70 * Really fixed bug with exception on mov al, [esi]
72 * 65 1/28/98 1:22p John
73 * Fixed bug with unitialized dwdx_wide.
75 * 64 1/27/98 5:13p John
76 * Moved all float to int conversions out of inner loops and into outer.
77 * Made outer loop use FISTP instead of ftol, saved about 10%.
79 * 63 1/23/98 5:08p John
80 * Took L out of vertex structure used B (blue) instead. Took all small
81 * fireballs out of fireball types and used particles instead. Fixed some
82 * debris explosion things. Restructured fireball code. Restructured
83 * some lighting code. Made dynamic lighting on by default. Made groups
84 * of lasers only cast one light. Made fireballs not cast light.
86 * 62 1/19/98 6:15p John
87 * Fixed all my Optimized Build compiler warnings
89 * 61 12/15/97 11:32a John
92 * 60 12/02/97 4:00p John
93 * Added first rev of thruster glow, along with variable levels of
94 * translucency, which retquired some restructing of palman.
96 * 59 11/30/97 4:40p John
97 * made 32-bpp tiled tmapper call scanline
99 * 58 11/30/97 3:57p John
100 * Made fixed 32-bpp translucency. Made BmpMan always map translucent
101 * color into 255 even if you aren't supposed to remap and make it's
104 * 57 11/30/97 12:18p John
105 * added more 24 & 32-bpp primitives
107 * 56 11/29/97 2:06p John
108 * added mode 16-bpp support
110 * 55 11/21/97 11:32a John
111 * Added nebulas. Fixed some warpout bugs.
113 * 54 11/14/97 12:30p John
114 * Fixed some DirectX bugs. Moved the 8-16 xlat tables into Graphics
115 * libs. Made 16-bpp DirectX modes know what bitmap format they're in.
117 * 53 11/06/97 11:18a John
118 * added 16-bpp gouraud flat shader
120 * 52 10/19/97 12:55p John
121 * new code to lock / unlock surfaces for smooth directx integration.
123 * 51 10/16/97 10:55a John
124 * added tmapper to draw a monochrome alpha blended bitmap.
126 * 50 10/14/97 8:08a John
127 * added a bunch more 16 bit support
129 * 49 10/09/97 5:23p John
130 * Added support for more 16-bpp functions
132 * 48 9/30/97 2:30p John
133 * test code for texture fading
135 * 47 9/24/97 10:37a John
136 * made tmapper not trash uv values anymore.
138 * 46 9/09/97 11:01a Sandeep
139 * fixed warning level 4 bugs
141 * 45 7/11/97 11:54a John
142 * added rotated 3d bitmaps.
144 * 44 6/18/97 5:02p John
145 * fixed bug with 32x32 and 16x16 tmapper
147 * 43 6/12/97 5:04p John
148 * Initial rev of Glide support
150 * 42 6/12/97 2:50a Lawrance
151 * bm_unlock() now passed bitmap number, not pointer
153 * 41 6/02/97 11:45a John
154 * fixed bugs with 64x64 and 128x128 tmappers.
156 * 40 6/01/97 3:41p John
157 * made non-tilable textures on tilable models bash uvs to 0-1.
159 * 39 5/12/97 12:27p John
160 * Restructured Graphics Library to add support for multiple renderers.
162 * 38 5/07/97 4:14p John
163 * Reenabled calls to gr_start/end_frame.
165 * 37 4/21/97 10:06a John
166 * Got capital ships working again.
168 * 36 4/17/97 6:06p John
169 * New code/data for v19 of BSPGEN with smoothing and zbuffer
172 * 35 4/08/97 5:18p John
173 * First rev of decent (dynamic, correct) lighting in FreeSpace.
175 * 34 3/18/97 9:42a John
177 * 33 3/15/97 2:44p John
178 * got scanline sorting method working. Bummer it is slower than zbuffer!
180 * 32 3/14/97 3:55p John
181 * Made tiled tmapper not always be zbuffered.
183 * 31 3/13/97 10:32a John
184 * Added code for tiled 256x256 textures in certain models.
186 * 30 3/12/97 2:51p John
187 * Added some test code for tmapper.
189 * 29 3/12/97 9:25a John
190 * fixed a bug with zbuffering. Reenabled it by default.
192 * 28 3/11/97 4:36p John
193 * added zbuffering to textest. Made zbuffered tmapper a bit faster by
194 * rearranging some instructions.
196 * 27 3/10/97 5:20p John
197 * Differentiated between Gouraud and Flat shading. Since we only do flat
198 * shading as of now, we don't need to interpolate L in the outer loop.
199 * This should save a few percent.
201 * 26 3/10/97 2:24p John
202 * added some commets about precompiled inner loop
204 * 25 3/05/97 7:15p John
205 * took out the old z stop tmapper used for briefing.
207 * 24 1/20/97 4:17p John
209 * 23 1/06/97 2:44p John
210 * Added in slow (but correct) zbuffering
212 * 22 12/30/96 3:46p John
214 * 21 12/23/96 10:56a John
215 * Totally restructured the POF stuff to support multiple
216 * detail levels in one POF file.
219 * 20 12/10/96 10:37a John
220 * Restructured texture mapper to remove some overhead from each scanline
221 * setup. This gave about a 30% improvement drawing trans01.pof, which is
222 * a really complex model. In the process, I cleaned up the scanline
223 * functions and separated them into different modules for each pixel
226 * 19 11/26/96 6:50p John
227 * Added some more hicolor primitives. Made windowed mode run as current
228 * bpp, if bpp is 8,16,or 32.
230 * 18 11/07/96 6:19p John
231 * Added a bunch of 16bpp primitives so the game sort of runs in 16bpp
234 * 17 11/07/96 3:08p John
235 * Inlined more Tmapper functions in preparation for cleaning up the Tmap1
236 * interface to the assembly.
238 * 16 11/07/96 2:17p John
239 * Took out the OldTmapper stuff.
241 * 15 11/07/96 12:04p John
242 * Sped up outer loop by 35% by inlining the incrementing of the variables
243 * for each scanline step and inlined the calculation for deltas at the
244 * start of each scanline.
246 * 14 11/06/96 2:33p John
247 * Added more asserts for checking that non-tiled UV's are between 0 and
248 * 1.0. Put code in the model_init code that checks for polys that have
249 * a vertex duplicated and throws them out.
251 * 13 11/05/96 4:05p John
252 * Added roller. Added code to draw a distant planet. Made bm_load
253 * return -1 if invalid bitmap.
255 * 12 10/31/96 7:20p John
256 * Added per,tiled tmapper. Made models tile if they use 64x64 textures.
258 * 11 10/26/96 1:40p John
259 * Added some now primitives to the 2d library and
260 * cleaned up some old ones.
274 #include "grinternal.h"
278 #include "tmapscanline.h"
280 #include "floating.h"
283 typedef void (* pscanline)();
285 pscanline tmap_scanline;
287 int Tmap_screen_flags = -1;
290 int Tmap_nscanlines=0;
293 int Tmap_show_layers=0;
295 typedef struct tmap_scan_desc {
300 // Convert from a 0-255 byte to a 0-1.0 float.
301 float Light_table[256];
304 //====================== 8-BPP SCANLINES ========================
305 tmap_scan_desc tmap_scanlines8[] = {
306 { 0, tmapscan_flat8 },
307 { TMAP_FLAG_TEXTURED, tmapscan_lnn8 },
308 { TMAP_FLAG_TEXTURED|TMAP_FLAG_XPARENT, tmapscan_lnt8 },
309 { TMAP_FLAG_TEXTURED|TMAP_FLAG_RAMP, tmapscan_lln8 },
310 { TMAP_FLAG_TEXTURED|TMAP_FLAG_RAMP|TMAP_FLAG_CORRECT, tmapscan_pln8 },
312 { TMAP_FLAG_RAMP|TMAP_FLAG_GOURAUD, tmapscan_flat_gouraud },
314 { TMAP_FLAG_TEXTURED|TMAP_FLAG_RAMP|TMAP_FLAG_GOURAUD, tmapscan_lln8 },
315 { TMAP_FLAG_TEXTURED|TMAP_FLAG_RAMP|TMAP_FLAG_GOURAUD|TMAP_FLAG_CORRECT, tmapscan_pln8 },
317 { TMAP_FLAG_TEXTURED|TMAP_FLAG_RAMP|TMAP_FLAG_CORRECT|TMAP_FLAG_TILED, tmapscan_pln8_tiled },
318 { TMAP_FLAG_TEXTURED|TMAP_FLAG_RAMP|TMAP_FLAG_CORRECT|TMAP_FLAG_GOURAUD|TMAP_FLAG_TILED, tmapscan_pln8_tiled },
320 { TMAP_FLAG_RAMP|TMAP_FLAG_GOURAUD|TMAP_FLAG_NEBULA, tmapscan_nebula8 },
322 // { TMAP_FLAG_TEXTURED|TMAP_FLAG_TILED, tmapscan_lnn8_tiled_256x256 },
323 // Totally non-general specific inner loop for subspace effect
324 { TMAP_FLAG_TEXTURED|TMAP_FLAG_CORRECT|TMAP_FLAG_TILED, tmapscan_pnn8_tiled_256x256_subspace },
327 { 0, NULL }, // Dummy element to mark the end of fast scanlines.
331 pscanline tmap_scanline_table[TMAP_MAX_SCANLINES];
334 // -------------------------------------------------------------------------------------
335 // This sets up the tmapper at the start of a given frame, so everything
336 // can can be pre-calculated should be calculated in here.
337 // This just fills in the tmap_scanline_table for the
338 // appropriate scan lines.
343 tmap_scan_desc * func_table = NULL;
345 Tmap_screen_flags = gr_screen.mode;
347 // Some constants for the inner loop
348 Tmap.FixedScale = 65536.0f;
349 Tmap.FixedScale8 = 2048.0f; //8192.0f; // 2^16 / 8
352 // Set tmap_scanline to not call a function
353 for (i=0; i<TMAP_MAX_SCANLINES; i++ ) {
354 tmap_scanline_table[i] = NULL;
357 func_table = tmap_scanlines8;
359 while(func_table->scan_func != NULL) {
360 tmap_scanline_table[func_table->flags] = func_table->scan_func;
364 for (i=0; i<256; i++ ) {
365 Light_table[i] = i2fl(i)/255.0f;
371 // Sets up flat-shaded lighting
372 void tmapper_set_light(vertex *v, uint flags)
374 if ( flags & TMAP_FLAG_GOURAUD ) return;
376 if ( (flags & (TMAP_FLAG_RAMP|TMAP_FLAG_RGB))==(TMAP_FLAG_RAMP|TMAP_FLAG_RGB)) {
377 Int3(); // You're doing RGB and RAMP lighting!!!
380 if ( flags & TMAP_FLAG_RAMP ) {
381 Tmap.l.b = Tmap.r.b = i2fl(v->b)/255.0f;
382 Tmap.deltas.b = 0.0f;
386 void tmapper_show_layers()
389 ubyte * ptr = (ubyte *)Tmap.dest_row_data;
391 for (i=0; i<Tmap.loop_count; i++, ptr++ ) {
392 *ptr = (unsigned char)(*ptr + 1);
398 void tmap_scan_generic()
403 float u, v, w, du, dv, dw;
405 dptr = (ubyte *)Tmap.dest_row_data;
407 Tmap.fx_w = fl2i(Tmap.l.sw * GR_Z_RANGE)+gr_zoffset;
408 Tmap.fx_dwdx = fl2i(Tmap.deltas.sw * GR_Z_RANGE);
420 for (i=0; i<Tmap.loop_count; i++ ) {
421 int tmp = (uint)dptr-Tmap.pScreenBits;
422 if ( Tmap.fx_w > (int)gr_zbuffer[tmp] ) {
423 gr_zbuffer[tmp] = Tmap.fx_w;
425 ui = fl2i( u / w ) % Tmap.bp->w;
426 vi = fl2i( v / w ) % Tmap.bp->h;
428 c = Tmap.pixptr[vi*Tmap.bp->w+ui];
429 *dptr = gr_fade_table[fl2i(l*31)*256+c];
432 Tmap.fx_w += Tmap.fx_dwdx;
443 // Same as ftol except that it might round up or down,
444 // unlike C's ftol, which must always round down.
445 // But, in the tmapper, we don't care, since this is
447 inline int tmap_ftol(float f)
460 #define tmap_ftol(f) ((int)(f))
465 004569c3 add esp,fffffff4
467 004569c7 fnstcw [ebp-02]
469 004569cb mov ax,word ptr [ebp-02]
471 004569d2 mov word ptr [ebp-04],ax
472 004569d6 fldcw [ebp-04]
473 004569d9 fistp qword ptr [ebp-0c]
474 004569dc fldcw [ebp-02]
475 004569df mov eax,dword ptr [ebp-0c]
476 004569e2 mov edx,dword ptr [ebp-08]
483 extern ubyte gr_palette[768];
485 uint last_code = 0xf;
486 void change_fade_table(uint code)
490 if ( last_code == code ) return;
493 int r1=0, g1=0, b1=0;
495 for (i=0; i<256; i++ ) {
498 r = gr_palette[i*3+0];
499 g = gr_palette[i*3+1];
500 b = gr_palette[i*3+2];
502 if ( (r == 255) && (g == 255) && (b == 255) ) {
503 // Make pure white not fade
504 for (l=0; l<32; l++ ) {
505 gr_fade_table[((l+1)*256)+i] = (unsigned char)i;
508 for (l=24; l<32; l++ ) {
519 if ( code & 4 ) gr = gi*2; else gr = r;
520 if ( code & 2 ) gg = gi*2; else gg = g;
521 if ( code & 1 ) gb = gi*2; else gb = b;
527 x = l-24; // x goes from 0 to 7
528 y = 31-l; // y goes from 7 to 0
530 ur = ((gr*x)+(r*y))/7; if ( ur > 255 ) ur = 255;
531 ug = ((gg*x)+(g*y))/7; if ( ug > 255 ) ug = 255;
532 ub = ((gb*x)+(b*y))/7; if ( ub > 255 ) ub = 255;
534 gr_fade_table[((l+1)*256)+i] = (unsigned char)palette_find( ur, ug, ub );
538 gr_fade_table[ (0*256)+i ] = gr_fade_table[ (1*256)+i ];
539 gr_fade_table[ (33*256)+i ] = gr_fade_table[ (32*256)+i ];
542 // Mirror the fade table
543 for (i=0; i<34; i++ ) {
544 for ( l = 0; l < 256; l++ ) {
545 gr_fade_table[ ((67-i)*256)+l ] = gr_fade_table[ (i*256)+l ];
553 void grx_tmapper( int nverts, vertex **verts, uint flags )
555 int i, y, li, ri, ly, ry, top, rem;
558 float ulist[TMAP_MAX_VERTS], vlist[TMAP_MAX_VERTS], llist[TMAP_MAX_VERTS];
560 flags &= (~TMAP_FLAG_ALPHA);
561 flags &= (~TMAP_FLAG_NONDARKENING);
562 flags &= (~TMAP_FLAG_PIXEL_FOG);
564 // Check for invalid flags
566 if ( (flags & (TMAP_FLAG_RAMP|TMAP_FLAG_RGB))==(TMAP_FLAG_RAMP|TMAP_FLAG_RGB)) {
567 Int3(); // You're doing RGB and RAMP lighting!!!
570 if ( flags & TMAP_FLAG_RGB ) {
571 Int3(); // RGB not supported!
574 if ( (flags & TMAP_FLAG_GOURAUD) && (!(flags & TMAP_FLAG_RAMP)) ) {
575 Int3(); // Ramp mode required for gouraud!
578 if ( gr_screen.bits_per_pixel != 8 ) {
579 Int3(); // Only 8-bpp tmapper supported
583 Tmap_nverts += nverts;
585 Assert(nverts <= TMAP_MAX_VERTS );
589 if ( flags & (TMAP_FLAG_RAMP|TMAP_FLAG_GOURAUD) ) {
590 for (i=0; i<nverts; i++ ) {
591 llist[i] = Light_table[verts[i]->b];
595 if ( Tmap_screen_flags != gr_screen.mode ) {
599 tmap_scanline = tmap_scanline_table[flags];
600 // tmap_scanline = tmap_scan_generic;
603 Assert( tmap_scanline != NULL );
605 if (Tmap_show_layers)
606 tmap_scanline = tmapper_show_layers;
609 if ( tmap_scanline == NULL ) return;
611 Tmap.FadeLookup = (uint)palette_get_fade_table();
612 Tmap.BlendLookup = (uint)palette_get_blend_table(gr_screen.current_alpha);
614 if ( flags & TMAP_FLAG_TEXTURED ) {
616 Tmap.bp = bm_lock( gr_screen.current_bitmap, 8, 0 );
618 int was_tiled = 0, can_tile = 0;
619 if ( flags & TMAP_FLAG_TILED ) {
620 if ( (Tmap.bp->w==16) && (Tmap.bp->h==16) ) can_tile = 1;
621 if ( (Tmap.bp->w==32) && (Tmap.bp->h==32) ) can_tile = 1;
622 if ( (Tmap.bp->w==64) && (Tmap.bp->h==64) ) can_tile = 1;
623 if ( (Tmap.bp->w==128) && (Tmap.bp->h==128) ) can_tile = 1;
624 if ( (Tmap.bp->w==256) && (Tmap.bp->h==256) ) can_tile = 1;
628 flags &= (~TMAP_FLAG_TILED);
632 float max_u = i2fl(Tmap.bp->w) - 0.5f;
633 float max_v = i2fl(Tmap.bp->h) - 0.5f;
635 for (i=0; i<nverts; i++ ) {
636 ulist[i] = verts[i]->u * Tmap.bp->w;
637 vlist[i] = verts[i]->v * Tmap.bp->h;
639 if ( !(flags & TMAP_FLAG_TILED) ) {
640 if ( ulist[i] < 1.0f ) ulist[i] = 1.0f;
641 if ( vlist[i] < 1.0f ) vlist[i] = 1.0f;
642 if ( ulist[i] > max_u ) ulist[i] = max_u;
643 if ( vlist[i] > max_v ) vlist[i] = max_v;
646 // Multiply all u,v's by sw for perspective correction
647 if ( flags & TMAP_FLAG_CORRECT ) {
648 ulist[i] *= verts[i]->sw;
649 vlist[i] *= verts[i]->sw;
653 Tmap.pixptr = (unsigned char *)Tmap.bp->data;
654 Tmap.src_offset = Tmap.bp->rowsize;
657 // Find the topmost vertex
658 //top = -1; // Initialize to dummy value to avoid compiler warning
659 //ymin = 0.0f; // Initialize to dummy value to avoid compiler warning
660 // Instead of initializing to avoid compiler warnings, set to first value outside loop and remove (i==0)
661 // comparison, which otherwise happens nverts times. MK, 3/20/98 (was tracing code figuring out my shield effect bug...)
664 for (i=1; i<nverts; i++ ) {
665 if (verts[i]->sy < ymin) {
673 y = fl_round_2048(ymin); //(int)floor(ymin + 0.5);
677 Tmap.pScreenBits = (uint)gr_screen.offscreen_buffer_base;
680 while ( ly<=y && rem>0 ) { // Advance left edge?
681 float dy, frac, recip;
684 if ( i<0 ) i = nverts-1;
685 ly = fl_round_2048(verts[i]->sy); //(int)floor(verts[i]->sy+0.5);
687 dy = verts[i]->sy - verts[li]->sy;
688 if ( dy == 0.0f ) dy = 1.0f;
690 frac = y + 0.5f - verts[li]->sy;
693 Tmap.dl.sx = (verts[i]->sx - verts[li]->sx)*recip;
694 Tmap.l.sx = verts[li]->sx + Tmap.dl.sx*frac;
696 if ( flags & TMAP_FLAG_TEXTURED ) {
697 Tmap.dl.u = (ulist[i] - ulist[li])*recip;
698 Tmap.l.u = ulist[li] + Tmap.dl.u*frac;
699 Tmap.dl.v = (vlist[i] - vlist[li])*recip;
700 Tmap.l.v = vlist[li] + Tmap.dl.v*frac;
703 if ( (flags & TMAP_FLAG_CORRECT) || gr_zbuffering ) {
704 Tmap.dl.sw = (verts[i]->sw - verts[li]->sw)*recip;
705 Tmap.l.sw = verts[li]->sw + Tmap.dl.sw*frac;
708 if ( flags & TMAP_FLAG_GOURAUD ) {
709 if ( flags & TMAP_FLAG_RAMP ) {
710 Tmap.dl.b = (llist[i] - llist[li])*recip;
711 Tmap.l.b = llist[li] + Tmap.dl.b*frac;
717 while ( ry<=y && rem>0 ) { // Advance right edge?
718 float dy, frac, recip;
721 if ( i>=nverts ) i = 0;
722 ry = fl_round_2048(verts[i]->sy); //(int)floor(verts[i]->sy+0.5);
724 dy = verts[i]->sy - verts[ri]->sy;
725 if ( dy == 0.0f ) dy = 1.0f;
727 frac = y + 0.5f - verts[ri]->sy;
730 Tmap.dr.sx = (verts[i]->sx - verts[ri]->sx)*recip;
731 Tmap.r.sx = verts[ri]->sx + Tmap.dr.sx*frac;
733 if ( flags & TMAP_FLAG_TEXTURED ) {
734 Tmap.dr.u = (ulist[i] - ulist[ri])*recip;
735 Tmap.r.u = ulist[ri] + Tmap.dr.u*frac;
736 Tmap.dr.v = (vlist[i] - vlist[ri])*recip;
737 Tmap.r.v = vlist[ri] + Tmap.dr.v*frac;
740 if ( (flags & TMAP_FLAG_CORRECT) || gr_zbuffering ) {
741 Tmap.dr.sw = (verts[i]->sw - verts[ri]->sw)*recip;
742 Tmap.r.sw = verts[ri]->sw + Tmap.dr.sw*frac;
745 if ( flags & TMAP_FLAG_GOURAUD ) {
746 if ( flags & TMAP_FLAG_RAMP ) {
747 Tmap.dr.b = (llist[i] - llist[ri])*recip;
748 Tmap.r.b = llist[ri] + Tmap.dr.b*frac;
760 for ( ; y<next_break; y++ ) {
761 if ( (y >= gr_screen.clip_top) && ( y<=gr_screen.clip_bottom) ) {
765 lx = fl_round_2048(Tmap.l.sx);
766 if ( lx < gr_screen.clip_left ) {
767 Tmap.clipped_left = i2fl(gr_screen.clip_left) - Tmap.l.sx;
768 lx = gr_screen.clip_left;
770 Tmap.clipped_left = 0.0f;
772 rx = fl_round_2048(Tmap.r.sx-1.0f);
774 if ( rx > gr_screen.clip_right ) rx = gr_screen.clip_right;
776 float dx, recip; //frac;
778 dx = Tmap.r.sx - Tmap.l.sx;
779 if ( dx == 0.0f ) dx = 1.0f;
781 //frac = lx + 0.5f - Tmap.l.sx;
787 Tmap.loop_count = rx - lx + 1;
789 Tmap_npixels += Tmap.loop_count;
793 if ( (flags & TMAP_FLAG_CORRECT) || gr_zbuffering ) {
794 Tmap.deltas.sw = (Tmap.r.sw - Tmap.l.sw)*recip;
795 Tmap.fl_dwdx_wide = Tmap.deltas.sw*32.0f;
798 if ( flags & TMAP_FLAG_TEXTURED ) {
799 Tmap.deltas.u = (Tmap.r.u - Tmap.l.u)*recip;
800 Tmap.deltas.v = (Tmap.r.v - Tmap.l.v)*recip;
802 if ( flags & TMAP_FLAG_CORRECT ) {
803 Tmap.fl_dudx_wide = Tmap.deltas.u*32.0f;
804 Tmap.fl_dvdx_wide = Tmap.deltas.v*32.0f;
806 Tmap.fx_u = tmap_ftol((Tmap.l.u+Tmap.clipped_left*Tmap.deltas.u)*65536.0f);
807 Tmap.fx_v = tmap_ftol((Tmap.l.v+Tmap.clipped_left*Tmap.deltas.v)*65536.0f);
808 Tmap.fx_du_dx = tmap_ftol(Tmap.deltas.u*65536.0f);
809 Tmap.fx_dv_dx = tmap_ftol(Tmap.deltas.v*65536.0f);
813 if ( flags & TMAP_FLAG_GOURAUD ) {
814 if ( flags & TMAP_FLAG_RAMP ) {
815 Tmap.deltas.b = (Tmap.r.b - Tmap.l.b)*recip;
817 Tmap.fx_l = tmap_ftol(Tmap.l.b*32.0f*65536.0f);
818 Tmap.fx_l_right = tmap_ftol(Tmap.r.b*32.0f*65536.0f);
819 Tmap.fx_dl_dx = tmap_ftol(Tmap.deltas.b*32.0f*65536.0f);
821 if ( Tmap.fx_dl_dx < 0 ) {
822 Tmap.fx_dl_dx = -Tmap.fx_dl_dx;
823 Tmap.fx_l = (67*F1_0)-Tmap.fx_l;
824 Tmap.fx_l_right = (67*F1_0)-Tmap.fx_l_right;
825 // Assert( Tmap.fx_l > 31*F1_0 );
826 // Assert( Tmap.fx_l < 66*F1_0 );
827 // Assert( Tmap.fx_dl_dx >= 0 );
828 // Assert( Tmap.fx_dl_dx < 31*F1_0 );
833 if ( gr_zbuffering ) {
834 Tmap.fx_w = tmap_ftol(Tmap.l.sw * GR_Z_RANGE)+gr_zoffset;
835 Tmap.fx_dwdx = tmap_ftol(Tmap.deltas.sw * GR_Z_RANGE);
838 Tmap.dest_row_data = GR_SCREEN_PTR_SIZE(gr_screen.bytes_per_pixel,Tmap.lx,Tmap.y);
846 Tmap.l.sx += Tmap.dl.sx;
847 Tmap.r.sx += Tmap.dr.sx;
849 if ( flags & TMAP_FLAG_TEXTURED ) {
850 Tmap.l.u += Tmap.dl.u;
851 Tmap.l.v += Tmap.dl.v;
853 Tmap.r.u += Tmap.dr.u;
854 Tmap.r.v += Tmap.dr.v;
857 if ( (flags & TMAP_FLAG_CORRECT) || gr_zbuffering ) {
858 Tmap.l.sw += Tmap.dl.sw;
859 Tmap.r.sw += Tmap.dr.sw;
862 if ( flags & TMAP_FLAG_GOURAUD ) {
863 if ( flags & TMAP_FLAG_RAMP ) {
864 Tmap.l.b += Tmap.dl.b;
865 Tmap.r.b += Tmap.dr.b;
873 if ( flags & TMAP_FLAG_TEXTURED ) {
874 bm_unlock(gr_screen.current_bitmap);