From fa116ea81cad2c661c5c59b2f0b714a62760d065 Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Sat, 26 Oct 2013 21:02:52 -0400 Subject: [PATCH] more cleanup - remove old files --- include/2d.h | 5 +- include/grinternal.h | 5 +- include/grzbuffer.h | 59 - src/graphics/2d.cpp | 50 +- src/graphics/aaline.cpp | 709 --- src/graphics/bitblt.cpp | 511 -- src/graphics/circle.cpp | 107 - src/graphics/colors.cpp | 620 --- src/graphics/gradient.cpp | 207 - src/graphics/grd3d.cpp | 3060 ----------- src/graphics/grd3drender.cpp | 2269 -------- src/graphics/grd3dtexture.cpp | 1417 ----- src/graphics/grdirectdraw.cpp | 1301 ----- src/graphics/grglide.cpp | 3769 ------------- src/graphics/grglidetexture.cpp | 1063 ---- src/graphics/gropengl.cpp | 16 +- src/graphics/gropengl1.cpp | 12 +- src/graphics/gropengl1render.cpp | 4 +- src/graphics/grsoft.cpp | 1943 ------- src/graphics/grzbuffer.cpp | 125 - src/graphics/line.cpp | 199 - src/graphics/pixel.cpp | 110 - src/graphics/rect.cpp | 137 - src/graphics/scaler.cpp | 1175 ----- src/graphics/shade.cpp | 265 - src/graphics/tmapgenericscans.cpp | 6959 ------------------------- src/graphics/tmapper.cpp | 907 ---- src/graphics/tmapscanline.cpp | 4585 ---------------- src/graphics/tmapscantiled128x128.cpp | 1257 ----- src/graphics/tmapscantiled16x16.cpp | 1302 ----- src/graphics/tmapscantiled256x256.cpp | 2267 -------- src/graphics/tmapscantiled32x32.cpp | 1301 ----- src/graphics/tmapscantiled64x64.cpp | 1303 ----- src/model/modelinterp.cpp | 6 +- 34 files changed, 54 insertions(+), 38971 deletions(-) delete mode 100644 include/grzbuffer.h delete mode 100644 src/graphics/aaline.cpp delete mode 100644 src/graphics/bitblt.cpp delete mode 100644 src/graphics/circle.cpp delete mode 100644 src/graphics/colors.cpp delete mode 100644 src/graphics/gradient.cpp delete mode 100644 src/graphics/grd3d.cpp delete mode 100644 src/graphics/grd3drender.cpp delete mode 100644 src/graphics/grd3dtexture.cpp delete mode 100644 src/graphics/grdirectdraw.cpp delete mode 100644 src/graphics/grglide.cpp delete mode 100644 src/graphics/grglidetexture.cpp delete mode 100644 src/graphics/grsoft.cpp delete mode 100644 src/graphics/grzbuffer.cpp delete mode 100644 src/graphics/line.cpp delete mode 100644 src/graphics/pixel.cpp delete mode 100644 src/graphics/rect.cpp delete mode 100644 src/graphics/scaler.cpp delete mode 100644 src/graphics/shade.cpp delete mode 100644 src/graphics/tmapgenericscans.cpp delete mode 100644 src/graphics/tmapper.cpp delete mode 100644 src/graphics/tmapscanline.cpp delete mode 100644 src/graphics/tmapscantiled128x128.cpp delete mode 100644 src/graphics/tmapscantiled16x16.cpp delete mode 100644 src/graphics/tmapscantiled256x256.cpp delete mode 100644 src/graphics/tmapscantiled32x32.cpp delete mode 100644 src/graphics/tmapscantiled64x64.cpp diff --git a/include/2d.h b/include/2d.h index e673d6b..6c76ba3 100644 --- a/include/2d.h +++ b/include/2d.h @@ -716,8 +716,9 @@ __inline bool gr_is_32bit() #define gr_zbias GR_CALL(gr_screen.gf_zbias) #define gr_set_viewport GR_CALL(gr_screen.gf_set_viewport) -#define gr_force_fullscreen GR_CALL(gr_screen.gf_force_fullscreen) -#define gr_force_windowed GR_CALL(gr_screen.gf_force_windowed) + +void gr_force_fullscreen(); +void gr_force_windowed(); // new bitmap functions void gr_bitmap(int x, int y); diff --git a/include/grinternal.h b/include/grinternal.h index 58a02d8..2d8ea54 100644 --- a/include/grinternal.h +++ b/include/grinternal.h @@ -141,7 +141,6 @@ #include "font.h" #include "2d.h" -#include "grzbuffer.h" extern int Gr_cursor; @@ -199,6 +198,10 @@ extern color_gun Gr_ta_red, Gr_ta_green, Gr_ta_blue, Gr_ta_alpha; // of the above values extern color_gun *Gr_current_red, *Gr_current_green, *Gr_current_blue, *Gr_current_alpha; +// zbuffer stuff +extern int Gr_zbuffering; +extern int Gr_zbuffering_mode; +extern int Gr_global_zbuffering; // Translate the 768 byte 'src' palette into // the current screen format's palette. diff --git a/include/grzbuffer.h b/include/grzbuffer.h deleted file mode 100644 index 016e2dd..0000000 --- a/include/grzbuffer.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/GrZbuffer.h $ - * $Revision$ - * $Date$ - * $Author$ - * - * Include for software render zbuffering - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:13 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:12 root - * Initial import. - * - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 1 3/25/98 8:07p John - * Split software renderer into Win32 and DirectX - * - * $NoKeywords: $ - */ - -#ifndef _GRZBUFFER_H -#define _GRZBUFFER_H - -// Z-buffer stuff -extern uint *gr_zbuffer; -extern uint gr_zbuffer_offset; // Add this to pixel location to get zbuffer location -extern int gr_zoffset; // add this to w before interpolation - -extern int gr_zbuffering, gr_zbuffering_mode; -extern int gr_global_zbuffering; - -#define GR_Z_RANGE 0x400000 //(2^31)/GR_Z_COUNT -#define GR_Z_COUNT 500 // How many frames between zbuffer clear. - // The bigger, the less precise. - -// If mode is FALSE, turn zbuffer off the entire frame, -// no matter what people pass to gr_zbuffer_set. -void gr8_zbuffer_clear(int mode); -int gr8_zbuffer_get(); -int gr8_zbuffer_set(int mode); - - -#endif //_GRZBUFFER_H - diff --git a/src/graphics/2d.cpp b/src/graphics/2d.cpp index 2c74ec8..74dd8da 100644 --- a/src/graphics/2d.cpp +++ b/src/graphics/2d.cpp @@ -508,6 +508,10 @@ ubyte Gr_original_palette[768]; // The palette ubyte Gr_current_palette[768]; char Gr_current_palette_name[128] = NOX("none"); +int Gr_zbuffering = 0; +int Gr_zbuffering_mode = 0; +int Gr_global_zbuffering = 0; + // cursor stuff int Gr_cursor = -1; int Web_cursor_bitmap = -1; @@ -882,29 +886,14 @@ int gr_init(int res, int mode, int depth, int fred_x, int fred_y) atexit(gr_close); // If already inited, shutdown the previous graphics - if ( Gr_inited ) { - switch( gr_screen.mode ) { -#ifndef PLAT_UNIX - case GR_SOFTWARE: - gr_soft_cleanup(); - break; - case GR_DIRECTDRAW: - Int3(); - gr_directdraw_cleanup(); - break; - case GR_DIRECT3D: - gr_d3d_cleanup(); - break; - case GR_GLIDE: - gr_glide_cleanup(); - break; -#endif - case GR_OPENGL: - gr_opengl_cleanup(); - break; - default: - Int3(); // Invalid graphics mode - break; + if (Gr_inited) { + switch (gr_screen.mode) { + case GR_OPENGL: + gr_opengl_cleanup(); + break; + default: + Int3(); // Invalid graphics mode + break; } } @@ -1019,6 +1008,21 @@ void gr_force_windowed() } } +void gr_force_fullscreen() +{ + if ( !Gr_inited ) { + return; + } + + if (gr_screen.gf_force_fullscreen) { + (*gr_screen.gf_force_fullscreen)(); + } + + if (Os_debugger_running) { + Sleep(1000); + } +} + void gr_activate(int active) { if ( !Gr_inited ) { diff --git a/src/graphics/aaline.cpp b/src/graphics/aaline.cpp deleted file mode 100644 index 9e3adb5..0000000 --- a/src/graphics/aaline.cpp +++ /dev/null @@ -1,709 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/aaline.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Code to draw antialiased lines - * - * $Log$ - * Revision 1.5 2002/06/09 04:41:17 relnev - * added copyright header - * - * Revision 1.4 2002/06/09 03:16:04 relnev - * added _splitpath. - * - * removed unneeded asm, old sdl 2d setup. - * - * fixed crash caused by opengl_get_region. - * - * Revision 1.3 2002/05/28 08:52:03 relnev - * implemented two assembly stubs. - * - * cleaned up a few warnings. - * - * added a little demo hackery to make it progress a little farther. - * - * Revision 1.2 2002/05/07 03:16:45 theoddone33 - * The Great Newline Fix - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 3 12/02/98 5:47p Dave - * Put in interface xstr code. Converted barracks screen to new format. - * - * 2 10/07/98 10:52a Dave - * Initial checkin. - * - * 1 10/07/98 10:48a Dave - * - * 13 5/06/98 5:30p John - * Removed unused cfilearchiver. Removed/replaced some unused/little used - * graphics functions, namely gradient_h and _v and pixel_sp. Put in new - * DirectX header files and libs that fixed the Direct3D alpha blending - * problems. - * - * 12 3/24/98 4:03p Lawrance - * JOHN: Fix up outline drawing code to support different colors - * - * 11 3/10/98 4:18p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 10 1/19/98 6:15p John - * Fixed all my Optimized Build compiler warnings - * - * 9 11/30/97 4:26p John - * Added 32-bpp antialiased line. Took gamma out of alphacolor - * calculation. - * - * 8 11/29/97 2:06p John - * added mode 16-bpp support - * - * 7 10/20/97 8:47a John - * fixed gr_lock bug in aaline - * - * 6 10/19/97 12:55p John - * new code to lock / unlock surfaces for smooth directx integration. - * - * 5 10/14/97 8:08a John - * added a bunch more 16 bit support - * - * 4 10/04/97 11:27a John - * took out debug code - * - * 3 10/03/97 9:50a John - * enabled antialiasing lines in alphacolor set. - * - * 2 10/03/97 9:10a John - * added better antialiased line drawer - * - * 1 10/03/97 9:07a John - * - * $NoKeywords: $ - */ - -/* - - Code for drawing antialiased lines. Taken from some code - published in the Journal of Graphic Tools at www.acm.org/jgt - - Here is the README that came with the source code: - - Sample code to draw antialiased lines as described in the Journal of - Graphic Tools article High Quality Hardware Line Antialiasing by - Scott R. Nelson of Sun Microsystems. - - The code is written in C and designed to run on any machine with the - addition of a proper "display" module. Currently, display modules - exist for Macintosh, Unix, and Wintel machines. Thanks to Sanjay Gupta - (sanjay.gupta@eng.sun.com) for the Unix X11 display code and Chris - Babcock (babcock@rtp.idt.com) for the Windows code. - - This code is not 100% bug free and is definitely not optimized for - performance. It does, however, illustrate all of the points made in - the JGT article. -*/ - - -#include -#include - -#include "pstypes.h" -#include "2d.h" -#include "line.h" -#include "grinternal.h" -#include "palman.h" - -// Convert from floating-point to internal fixed-point formats -#define ONE_XY (long int) 0x00100000 -#define FIX_XY_SHIFT (long int) 20 -#define ONEHALF_XY (long int) 0x00080000 -#define ONE_Z (long int) 0x40000000 -#define ONE_RGB (long int) 0x40000000 -#define ONE_16 (long int) 0x4000 - -#define FLOAT_TO_FIX_XY(x) ((long int) ((x) * (float) ONE_XY)) - -#define FLOAT_TO_FIX_RGB(x) ((long int) ((x) * (float) ONE_RGB)) -#define FLOAT_TO_FIX_16(x) ((long int) ((x) * (float) ONE_16)) -#define FIX_TO_INT_XY(x) ((x) >> FIX_XY_SHIFT) -#define FIX_16_TO_FLOAT(x) ((float) (x) / (float) ONE_16) -#define FIX_TO_FLOAT_XY(x) ((float) (x) / (float) ONE_XY) -#define FIX_TO_FLOAT_RGB(x) ((float) (x) / (float) ONE_RGB) - -// Get fractional part, next lowest integer part -#define FRACT_XY(x) ((x) & (long int) 0x000fffff) -#define FLOOR_XY(x) ((x) & (long int) 0xfff00000) -#define FIX_XY_TO_INT(x) ((long int) (x) >> (long int) FIX_XY_SHIFT) - -// Sizes for tables in Draw -#define FILTER_WIDTH 0.75 // Line filter width adjustment // .75 // .5 works good with 5.0 gamma -#define F_TABLE_SIZE 64 // Filter table size -#define SC_TABLE_SIZE 32 // Slope correction table size -#define SRT_INT 5 // Sqrt table index integer bits -#define SRT_FRACT 4 // ...fraction bits -#define SR_INT 3 // Square root result integer bits -#define SR_FRACT 5 // ...fraction bits -#define SR_TABLE_SIZE (1 << (SRT_INT + SRT_FRACT)) -#define INV_FILTER 47 - -#define EP_MASK (long int) 0x000f0000u // AA line end-point filter mask -#define EP_SHIFT 13u // Number of bits to shift end-point - - -typedef long int fix_xy; // S11.20 - -// One vertex at any of the various stages of the pipeline - -typedef struct aa_vertex { - float x, y; -} aa_vertex; - -// All values needed to draw one line -typedef struct aa_setup_line { - int x_major; - int negative; - - fix_xy vs; // Starting point - fix_xy us; - fix_xy ue; // End (along major axis) - fix_xy dvdu; // Delta for minor axis step - -} aa_setup_line; - - -// Tables that need to be initialized -long int slope_corr_table[SC_TABLE_SIZE]; -long int filter_table[F_TABLE_SIZE]; -long int sqrt_table[SR_TABLE_SIZE]; - -ubyte new_table[F_TABLE_SIZE*512]; - -int aaline_inited = 0; - -// Initialize the tables normally found in ROM in the hardware. -void aaline_init_tables() -{ - int i,j; // Iterative counter - double m; // Slope - double d; // Distance from center of curve - double v; // Value to put in table - double sr; // The square root value - - aaline_inited = 1; - - // Build slope correction table. The index into this table - // is the truncated 5-bit fraction of the slope used to draw - // the line. Round the computed values here to get the closest - // fit for all slopes matching an entry. - - for (i = 0; i < SC_TABLE_SIZE; i++) { - // Round and make a fraction - m = ((double) i + 0.5) / (float) SC_TABLE_SIZE; - v = sqrt(m * m + 1) * 0.707106781; /* (m + 1)^2 / sqrt(2) */ - slope_corr_table[i] = (long int) (v * 256.0); - } - - // Build the Gaussian filter table, round to the middle of the sample region. - for (i = 0; i < F_TABLE_SIZE; i++) { - d = ((double) i + 0.5) / (float) (F_TABLE_SIZE / 2.0); - d = d / FILTER_WIDTH; - v = 1.0 / exp(d * d); // Gaussian function - filter_table[i] = (long int) (v * 256.0); - } - - for ( i=0; i<512; i++ ) { - long int corr_slope = i<<8; - for (j=0; j> (16+4)); - if (new_table[i*F_TABLE_SIZE+j]==15 ) { - // HACK!!! Account for "glass" pixel for hud bitmaps. - new_table[i*F_TABLE_SIZE+j] = 14; - } - } - } - - - // Build the square root table for big dots. - for (i = 0; i < SR_TABLE_SIZE; i++) { - v = (double) ((i << 1) + 1) / (double) (1 << (SRT_FRACT + 1)); - sr = sqrt(v); - sqrt_table[i] = (long int) (sr * (double) (1 << SR_FRACT)); - } - - -} - - - -// Multiply a fixed-point number by a s11.20 fixed-point -// number. The actual multiply uses less bits for the -// multiplier, since it always represents a fraction -// less than 1.0 and less total bits are sufficient. -// Some of the steps here are not needed. This was originally -// written to simulate exact hardware behavior. -long int fix_xy_mult(long int oa, fix_xy ob) -{ -#ifdef PLAT_UNIX - STUB_FUNCTION; - - return 0; -#else - int retval; - - _asm { - mov edx, oa - mov eax, ob - imul edx - shrd eax,edx,20 - mov retval, eax - } - - return retval; -#endif -} - - - -// Draw one span of an antialiased line (for horizontal lines). -void draw_aa_hspan8(fix_xy x, fix_xy y, long int ep_corr, long int slope) -{ -#ifndef HARDWARE_ONLY - long int sample_dist; // Distance from line to sample point - long int filter_index; // Index into filter table - long int i; // Count pixels across span - long int index; // Final filter table index - int a; // Alpha - - sample_dist = (FRACT_XY(y) >> (FIX_XY_SHIFT - 5)) - 16; - y = y - ONE_XY; - filter_index = sample_dist + 32; - - - int yi = FIX_XY_TO_INT( y ); - int xi = FIX_XY_TO_INT( x ); - - if ( xi < gr_screen.clip_left ) return; - if ( xi > gr_screen.clip_right ) return; - - int clipped = 0; - - if ( yi < gr_screen.clip_top ) clipped++; - if ( yi+3 > gr_screen.clip_bottom ) clipped++; - - long int corr_slope = (slope * ep_corr) & 0x1ff00; - - ubyte * lookup = (ubyte *)&Current_alphacolor->table.lookup[0][0]; - - ubyte * filter_lookup = (ubyte *)&new_table[(corr_slope>>8)*F_TABLE_SIZE]; - - - if ( clipped ) { - ubyte * dptr; - - for (i = 0; i < 4; i++) { - if (filter_index < 0) - index = ~filter_index; // Invert when negative - else - index = filter_index; - - if (index > INV_FILTER) { - SDL_assert( i == 3 ); - return; // Not a valid pixel - } - - //a = ((corr_slope * filter_table[index]) & 0xf00000) >> (16+4-8); - a = filter_lookup[index]<<8; - - // Should include the alpha value as well... - if ( (yi >= gr_screen.clip_top) && (yi <= gr_screen.clip_bottom) ) { - dptr = GR_SCREEN_PTR(ubyte,xi, yi); - - *dptr = lookup[*dptr+a]; - } - - filter_index -= 32; - //y += ONE_XY; - yi++; - } - } else { - ubyte * dptr; - - dptr = GR_SCREEN_PTR(ubyte,xi, yi); - - for (i = 0; i < 4; i++) { - if (filter_index < 0) - index = ~filter_index; // Invert when negative - else - index = filter_index; - - if (index > INV_FILTER) { - SDL_assert( i == 3 ); - return; // Not a valid pixel - } - - a = filter_lookup[index]<<8; - - // Should include the alpha value as well... - *dptr = lookup[*dptr+a]; - - dptr += gr_screen.rowsize; - - filter_index -= 32; - } - - - } -#else - Int3(); -#endif -} - -// draw_aa_vspan -// Draw one span of an antialiased line (for vertical lines). - -void draw_aa_vspan8(fix_xy x, fix_xy y, long int ep_corr, long int slope) -{ -#ifndef HARDWARE_ONLY - long int sample_dist; // Distance from line to sample point - long int filter_index; // Index into filter table - long int i; // Count pixels across span - long int index; // Final filter table index - int a; // Alpha - - sample_dist = (FRACT_XY(x) >> (FIX_XY_SHIFT - 5)) - 16; - x = x - ONE_XY; - filter_index = sample_dist + 32; - - int yi = FIX_XY_TO_INT( y ); - int xi = FIX_XY_TO_INT( x ); - - if ( yi < gr_screen.clip_top ) return; - if ( yi > gr_screen.clip_bottom ) return; - - int clipped = 0; - - if ( xi < gr_screen.clip_left ) clipped++; - if ( xi+3 > gr_screen.clip_right ) clipped++; - - long int corr_slope = (slope * ep_corr) & 0x1ff00; - - ubyte * lookup = (ubyte *)&Current_alphacolor->table.lookup[0][0]; - - ubyte * filter_lookup = (ubyte *)&new_table[(corr_slope>>8)*F_TABLE_SIZE]; - - - if ( clipped ) { - ubyte * dptr; - - for (i = 0; i < 4; i++) { - if (filter_index < 0) - index = ~filter_index; // Invert when negative - else - index = filter_index; - - if (index > INV_FILTER) { - SDL_assert( i == 3 ); - return; // Not a valid pixel - } - - //a = ((corr_slope * filter_table[index]) & 0xf00000) >> (16+4-8); - a = filter_lookup[index]<<8; - - // Draw the pixel - if ( (xi >= gr_screen.clip_left) && (xi <= gr_screen.clip_right) ) { - dptr = GR_SCREEN_PTR(ubyte,xi, yi); - - *dptr = lookup[*dptr+a]; - } - - filter_index -= 32; - xi++; - } - } else { - - ubyte *dptr = GR_SCREEN_PTR(ubyte,xi, yi); - - for (i = 0; i < 4; i++) { - if (filter_index < 0) - index = ~filter_index; // Invert when negative - else - index = filter_index; - - if (index > INV_FILTER) { - SDL_assert( i == 3 ); - return; // Not a valid pixel - } - - a = filter_lookup[index]<<8; - - // Should include the alpha value as well... - - // Draw the pixel - *dptr = lookup[*dptr+a]; - - filter_index -= 32; - dptr++; - } - } -#else - Int3(); -#endif -} - - -void draw_line(aa_setup_line *line) -{ - fix_xy x, y; // Start value - fix_xy dudu; // Constant 1 or -1 for step - fix_xy dx, dy; // Steps in X and Y - fix_xy u_off; // Offset to starting sample grid - fix_xy us, vs, ue; // Start and end for drawing - fix_xy count; // How many pixels to draw - long int slope_index; // Index into slope correction table - long int slope; // Slope correction value - long int ep_corr; // End-point correction value - long int scount, ecount; // Start/end count for endpoints - long int sf, ef; // Sand and end fractions - long int ep_code; // One of 9 endpoint codes - - // Get directions - if (line->negative) { - dudu = -ONE_XY; - } else { - dudu = ONE_XY; - } - - if (line->x_major) { - dx = dudu; - dy = line->dvdu; - } else { - dx = line->dvdu; - dy = dudu; - } - - // Get initial values and count - if (line->negative) { - u_off = FRACT_XY(line->us) - ONE_XY; - us = line->us + ONE_XY; - ue = line->ue; - count = FLOOR_XY(us) - FLOOR_XY(ue); - } else { - u_off = 0 - FRACT_XY(line->us); - us = line->us; - ue = line->ue + ONE_XY; - count = FLOOR_XY(ue) - FLOOR_XY(us); - } - - vs = line->vs + fix_xy_mult(line->dvdu, u_off) + ONEHALF_XY; - - if (line->x_major) { - x = us; - y = vs; - } else { - x = vs; - y = us; - } - - //a = line->as + fix_xy_mult(line->dadu, u_off); - - // Compute slope correction once per line - slope_index = (line->dvdu >> (FIX_XY_SHIFT - 5)) & 0x3fu; - - if (line->dvdu < 0) { - slope_index ^= 0x3fu; - } - - if ((slope_index & 0x20u) == 0) { - slope = slope_corr_table[slope_index]; - } else { - slope = 0x100; /* True 1.0 */ - } - - // Set up counters for determining endpoint regions - scount = 0; - ecount = FIX_TO_INT_XY(count); - - // Get 4-bit fractions for end-point adjustments - sf = (us & EP_MASK) >> EP_SHIFT; - ef = (ue & EP_MASK) >> EP_SHIFT; - - // Interpolate the edges - while (count >= 0) { - - /*- - * Compute end-point code (defined as follows): - * 0 = 0, 0: short, no boundary crossing - * 1 = 0, 1: short line overlap (< 1.0) - * 2 = 0, 2: 1st pixel of 1st endpoint - * 3 = 1, 0: short line overlap (< 1.0) - * 4 = 1, 1: short line overlap (> 1.0) - * 5 = 1, 2: 2nd pixel of 1st endpoint - * 6 = 2, 0: last of 2nd endpoint - * 7 = 2, 1: first of 2nd endpoint - * 8 = 2, 2: regular part of line - */ - - ep_code = ((scount < 2) ? scount : 2) * 3 + ((ecount < 2) ? ecount : 2); - - if (line->negative) { - - // Drawing in the negative direction - - // Compute endpoint information - switch (ep_code) { - case 0: ep_corr = 0; break; - case 1: ep_corr = ((sf - ef) & 0x78) | 4; break; - case 2: ep_corr = sf | 4; break; - case 3: ep_corr = ((sf - ef) & 0x78) | 4; break; - case 4: ep_corr = ((sf - ef) + 0x80) | 4; break; - case 5: ep_corr = (sf + 0x80) | 4; break; - case 6: ep_corr = (0x78 - ef) | 4; break; - case 7: ep_corr = ((0x78 - ef) + 0x80) | 4; break; - case 8: ep_corr = 0x100; break; - default: ep_corr = 0; break; - } - - } else { - // Drawing in the positive direction - - // Compute endpoint information - switch (ep_code) { - case 0: ep_corr = 0; break; - case 1: ep_corr = ((ef - sf) & 0x78) | 4; break; - case 2: ep_corr = (0x78 - sf) | 4; break; - case 3: ep_corr = ((ef - sf) & 0x78) | 4; break; - case 4: ep_corr = ((ef - sf) + 0x80) | 4; break; - case 5: ep_corr = ((0x78 - sf) + 0x80) | 4; break; - case 6: ep_corr = ef | 4; break; - case 7: ep_corr = (ef + 0x80) | 4; break; - case 8: ep_corr = 0x100; break; - default: ep_corr = 0; break; - } - } - - if (line->x_major) { - draw_aa_hspan8(x, y, ep_corr, slope); - } else { - draw_aa_vspan8(x, y, ep_corr, slope); - } - - x += dx; - y += dy; - //a += line->dadu; - - scount++; - ecount--; - count -= ONE_XY; - } - -} - - -// Perform the setup operation for a line, then draw it - -void aaline_setup(aa_vertex *v1, aa_vertex *v2) -{ - float dx, dy; // Deltas in X and Y - float udx, udy; // Positive version of deltas - float one_du; // 1.0 / udx or udy - aa_setup_line line; - - if ( !aaline_inited ) - aaline_init_tables(); - - - dx = v1->x - v2->x; - dy = v1->y - v2->y; - - if (dx < 0.0) { - udx = -dx; - } else { - udx = dx; - } - - if (dy < 0.0) { - udy = -dy; - } else { - udy = dy; - } - - if (udx > udy) { - // X major line - line.x_major = 1; - line.negative = (dx < 0.0); - line.us = FLOAT_TO_FIX_XY(v2->x); - line.vs = FLOAT_TO_FIX_XY(v2->y); - line.ue = FLOAT_TO_FIX_XY(v1->x); - one_du = 1.0f / udx; - line.dvdu = FLOAT_TO_FIX_XY(dy * one_du); - } else { - // Y major line - line.x_major = 0; - line.negative = (dy < 0.0); - line.us = FLOAT_TO_FIX_XY(v2->y); - line.vs = FLOAT_TO_FIX_XY(v2->x); - line.ue = FLOAT_TO_FIX_XY(v1->y); - one_du = 1.0f / udy; - line.dvdu = FLOAT_TO_FIX_XY(dx * one_du); - } - - // Convert colors to fixed-point - //line.as = FLOAT_TO_FIX_RGB(v2->a); - - // Compute delta values for colors - //line.dadu = FLOAT_TO_FIX_RGB((v1->a - v2->a) * one_du); - - // Now go draw it - - gr_lock(); - draw_line(&line); - gr_unlock(); -} - - -void gr8_aaline( vertex *v1, vertex *v2 ) -{ - aa_vertex aa1, aa2; - - if ( !Current_alphacolor ) { - gr_line(fl2i(v1->sx),fl2i(v1->sy),fl2i(v2->sx),fl2i(v2->sy)); - return; - } - -// return; - - aa1.x = v1->sx; - aa1.y = v1->sy; - - aa2.x = v2->sx; - aa2.y = v2->sy; - - { - int clipped = 0, swapped = 0; - float a1, b1, a2, b2; - a1 = (float)gr_screen.clip_left; - b1 = (float)gr_screen.clip_top; - a2 = (float)gr_screen.clip_right; - b2 = (float)gr_screen.clip_bottom; - - FL_CLIPLINE(aa1.x,aa1.y,aa2.x,aa2.y,a1,b1,a2,b2,return,clipped=1,swapped=1); - } - - aaline_setup( &aa1, &aa2 ); -} - diff --git a/src/graphics/bitblt.cpp b/src/graphics/bitblt.cpp deleted file mode 100644 index 407e465..0000000 --- a/src/graphics/bitblt.cpp +++ /dev/null @@ -1,511 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/Bitblt.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Code to do software bitblt type stuff - * - * $Log$ - * Revision 1.4 2002/06/09 04:41:17 relnev - * added copyright header - * - * Revision 1.3 2002/06/05 08:05:29 relnev - * stub/warning removal. - * - * reworked the sound code. - * - * Revision 1.2 2002/05/28 21:36:10 relnev - * some more timer junk. - * - * tried to fix software mode. - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 3 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 2 10/07/98 10:52a Dave - * Initial checkin. - * - * 1 10/07/98 10:48a Dave - * - * 2 4/14/98 12:15p John - * Made 16-bpp movies work. - * - * 1 3/25/98 8:07p John - * Split software renderer into Win32 and DirectX - * - * $NoKeywords: $ - */ - -#include "osapi.h" -#include "2d.h" -#include "bmpman.h" -#include "key.h" -#include "floating.h" -#include "palman.h" -#include "grsoft.h" -#include "grinternal.h" - -// Headers for 2d functions -#include "bitblt.h" - -MONITOR( Num2dBitmaps ); - -void gr8_aabitmap_ex(int x,int y,int w,int h,int sx,int sy) -{ -#if 0 - int hi; - bitmap * bmp; - - if ( w < 1 ) return; - if ( h < 1 ) return; - - MONITOR_INC( Num2dBitmaps, 1 ); - - if ( !Current_alphacolor ) return; - - // mprintf(( "x=%d, y=%d, w=%d, h=%d\n", x, y, w, h )); - // mprintf(( "sx=%d, sy=%d, bw=%d, bh=%d\n", sx, sy, bmp->w, bmp->h )); - - bmp = bm_lock( gr_screen.current_bitmap, 8, BMP_RLE|BMP_NO_PALETTE_MAP ); - - gr_lock(); - - if (bmp->flags & BMP_RLE) { - int * offsets = (int *)(bmp->data); - ubyte *lookup = &Current_alphacolor->table.lookup[0][0]; - - for (hi=0; hi < h; hi++ ) { - ubyte * dp = GR_SCREEN_PTR(ubyte,x,y+hi); - ubyte * sp = (ubyte *)bmp->data + offsets[sy+hi]; - - int x1 = sx; - int x2 = sx+w; - int i = 0; - - while(i x1 ) { - // This span crosses X1.. so skip some and draw some - if ( i+count >= x2 ) { - count = x2 - i; - } - - if ( run_span ) { - // RLE'd data - ubyte c = *sp++; - - if ( c > 0 ) { - // We have 'count' pixels of c - ubyte *tmp_lookup = &lookup[c<<8]; - while( count-- ) { - if ( i >= x1 ) { - *dp = tmp_lookup[*dp]; - dp++; - } - i++; - } - } else { - while( count-- ) { - if ( i >= x1 ) { - dp++; - } - i++; - } - } - } else { - // non RLE'd data - - // We have 'count' un-rle'd pixels - while( count-- ) { - if ( i >= x1 ) { - ubyte c = *sp; - *dp = lookup[(c<<8) | *dp]; - dp++; - } - sp++; - i++; - } - } - - } else { - i += count; - if ( run_span ) { - // RLE'd data - sp++; - } else { - sp += count; - } - } - } - - while(i= x2 ) { - count = x2 - i; - } - i += count; - - ubyte *end_ptr = dp + count; - - if ( count > 0 ) { - if ( run_span ) { - // RLE'd data - ubyte c = *sp++; - - if ( c > 0 ) { - // We have 'count' pixels of c - ubyte *tmp_lookup = &lookup[c<<8]; - - while( count >= 4 ) { - // We have to plot at least 4 pixels of constant color starting at 'dp' - dp[0] = tmp_lookup[dp[0]]; - dp[1] = tmp_lookup[dp[1]]; - dp[2] = tmp_lookup[dp[2]]; - dp[3] = tmp_lookup[dp[3]]; - - count -= 4; - dp += 4; - } - - while ( count > 0 ) { - *dp = tmp_lookup[*dp]; - dp++; - count--; - } - } - } else { - // non RLE'd data - - // We have 'count' un-rle'd pixels - do { - ubyte c = *sp++; - *dp = lookup[(c<<8) | *dp]; - dp++; - } while ( dp < end_ptr ); - } - } - - dp = end_ptr; - } - - } - } else { - ubyte * sptr = (ubyte *)( bmp->data + (sy*bmp->w+sx) ); - ubyte *lookup = (ubyte *)&Current_alphacolor->table.lookup[0][0]; - - for (hi=0; hi 0 ) { - *dp = lookup[(c<<8) | *dp]; - } - dp++; - } - sptr += bmp->w; - } - } - - gr_unlock(); - bm_unlock(gr_screen.current_bitmap); -#endif -} - -void grx_aabitmap_ex(int x,int y,int w,int h,int sx,int sy) -{ - int reclip; - #ifndef NDEBUG - int count = 0; - #endif - - int dx1=x, dx2=x+w-1; - int dy1=y, dy2=y+h-1; - - int bw, bh; - bm_get_info( gr_screen.current_bitmap, &bw, &bh, NULL ); - - do { - reclip = 0; - #ifndef NDEBUG - if ( count > 1 ) Int3(); - count++; - #endif - - if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return; - if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return; - if ( dx1 < gr_screen.clip_left ) { sx += gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; } - if ( dy1 < gr_screen.clip_top ) { sy += gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; } - if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; } - if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; } - - if ( sx < 0 ) { - dx1 -= sx; - sx = 0; - reclip = 1; - } - - if ( sy < 0 ) { - dy1 -= sy; - sy = 0; - reclip = 1; - } - - w = dx2-dx1+1; - h = dy2-dy1+1; - - if ( sx + w > bw ) { - w = bw - sx; - dx2 = dx1 + w - 1; - } - - if ( sy + h > bh ) { - h = bh - sy; - dy2 = dy1 + h - 1; - } - - if ( w < 1 ) return; // clipped away! - if ( h < 1 ) return; // clipped away! - - } while (reclip); - - // Make sure clipping algorithm works - #ifndef NDEBUG - SDL_assert( w > 0 ); - SDL_assert( h > 0 ); - SDL_assert( w == (dx2-dx1+1) ); - SDL_assert( h == (dy2-dy1+1) ); - SDL_assert( sx >= 0 ); - SDL_assert( sy >= 0 ); - SDL_assert( sx+w <= bw ); - SDL_assert( sy+h <= bh ); - SDL_assert( dx2 >= dx1 ); - SDL_assert( dy2 >= dy1 ); - SDL_assert( (dx1 >= gr_screen.clip_left ) && (dx1 <= gr_screen.clip_right) ); - SDL_assert( (dx2 >= gr_screen.clip_left ) && (dx2 <= gr_screen.clip_right) ); - SDL_assert( (dy1 >= gr_screen.clip_top ) && (dy1 <= gr_screen.clip_bottom) ); - SDL_assert( (dy2 >= gr_screen.clip_top ) && (dy2 <= gr_screen.clip_bottom) ); - #endif - - // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions. - - // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2) - - switch( gr_screen.bits_per_pixel ) { - case 8: - gr8_aabitmap_ex(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy); - break; - - default: - Error( LOCATION, "Unsupported BPP=%d in grx_aabitmap_ex!\n", gr_screen.bytes_per_pixel ); - } - - -} - - -void gr8_bitmap_ex(int x,int y,int w,int h,int sx,int sy) -{ -#if 0 - MONITOR_INC( Num2dBitmaps, 1 ); - - gr_lock(); - - // Normal bitblt - int i; - bitmap * bmp; - ubyte * sptr; - - bmp = bm_lock( gr_screen.current_bitmap, 8, 0 ); - sptr = (ubyte *)( bmp->data + (sy*bmp->w+sx) ); - - //mprintf(( "x=%d, y=%d, w=%d, h=%d\n", x, y, w, h )); - //mprintf(( "sx=%d, sy=%d, bw=%d, bh=%d\n", sx, sy, bmp->w, bmp->h )); - - if ( bmp->flags & BMP_XPARENT ) { - for (i=0; iw; - } - } else { - for (i=0; iw; - } - } - bm_unlock(gr_screen.current_bitmap); - - gr_unlock(); -#endif -} - - - -void grx_bitmap_ex(int x,int y,int w,int h,int sx,int sy) -{ - int reclip; - #ifndef NDEBUG - int count = 0; - #endif - - int dx1=x, dx2=x+w-1; - int dy1=y, dy2=y+h-1; - - int bw, bh; - bm_get_info( gr_screen.current_bitmap, &bw, &bh, NULL ); - - do { - reclip = 0; - #ifndef NDEBUG - if ( count > 1 ) Int3(); - count++; - #endif - - if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return; - if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return; - if ( dx1 < gr_screen.clip_left ) { sx += gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; } - if ( dy1 < gr_screen.clip_top ) { sy += gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; } - if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; } - if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; } - - if ( sx < 0 ) { - dx1 -= sx; - sx = 0; - reclip = 1; - } - - if ( sy < 0 ) { - dy1 -= sy; - sy = 0; - reclip = 1; - } - - w = dx2-dx1+1; - h = dy2-dy1+1; - - if ( sx + w > bw ) { - w = bw - sx; - dx2 = dx1 + w - 1; - } - - if ( sy + h > bh ) { - h = bh - sy; - dy2 = dy1 + h - 1; - } - - if ( w < 1 ) return; // clipped away! - if ( h < 1 ) return; // clipped away! - - } while (reclip); - - // Make sure clipping algorithm works - #ifndef NDEBUG - SDL_assert( w > 0 ); - SDL_assert( h > 0 ); - SDL_assert( w == (dx2-dx1+1) ); - SDL_assert( h == (dy2-dy1+1) ); - SDL_assert( sx >= 0 ); - SDL_assert( sy >= 0 ); - SDL_assert( sx+w <= bw ); - SDL_assert( sy+h <= bh ); - SDL_assert( dx2 >= dx1 ); - SDL_assert( dy2 >= dy1 ); - SDL_assert( (dx1 >= gr_screen.clip_left ) && (dx1 <= gr_screen.clip_right) ); - SDL_assert( (dx2 >= gr_screen.clip_left ) && (dx2 <= gr_screen.clip_right) ); - SDL_assert( (dy1 >= gr_screen.clip_top ) && (dy1 <= gr_screen.clip_bottom) ); - SDL_assert( (dy2 >= gr_screen.clip_top ) && (dy2 <= gr_screen.clip_bottom) ); - #endif - - // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions. - - // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2) - - gr8_bitmap_ex(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy); -} - - - -void grx_bitmap(int x,int y) -{ - int w, h; - - bm_get_info( gr_screen.current_bitmap, &w, &h, NULL ); - int dx1=x, dx2=x+w-1; - int dy1=y, dy2=y+h-1; - int sx=0, sy=0; - - if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return; - if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return; - if ( dx1 < gr_screen.clip_left ) { sx = gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; } - if ( dy1 < gr_screen.clip_top ) { sy = gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; } - if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; } - if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; } - - if ( sx < 0 ) return; - if ( sy < 0 ) return; - if ( sx >= w ) return; - if ( sy >= h ) return; - - // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2) - - gr8_bitmap_ex(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy); -} - -void grx_aabitmap(int x,int y) -{ - int w, h; - - bm_get_info( gr_screen.current_bitmap, &w, &h, NULL ); - int dx1=x, dx2=x+w-1; - int dy1=y, dy2=y+h-1; - int sx=0, sy=0; - - if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return; - if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return; - if ( dx1 < gr_screen.clip_left ) { sx = gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; } - if ( dy1 < gr_screen.clip_top ) { sy = gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; } - if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; } - if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; } - - if ( sx < 0 ) return; - if ( sy < 0 ) return; - if ( sx >= w ) return; - if ( sy >= h ) return; - - // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2) - - gr8_aabitmap_ex(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy); -} - diff --git a/src/graphics/circle.cpp b/src/graphics/circle.cpp deleted file mode 100644 index cea2e49..0000000 --- a/src/graphics/circle.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/Circle.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Code to draw circles. - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:17 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 2 10/07/98 10:52a Dave - * Initial checkin. - * - * 1 10/07/98 10:48a Dave - * - * 9 3/10/98 4:18p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 8 11/06/97 11:18a John - * fixed bug with some scanlines being drawn twice - * - * 7 11/26/96 6:50p John - * Added some more hicolor primitives. Made windowed mode run as current - * bpp, if bpp is 8,16,or 32. - * - * 6 11/26/96 4:30p John - * Put in some better quality circle_empty code. - * - * 5 11/07/96 6:19p John - * Added a bunch of 16bpp primitives so the game sort of runs in 16bpp - * mode. - * - * 4 10/26/96 1:40p John - * Added some now primitives to the 2d library and - * cleaned up some old ones. - * - * $NoKeywords: $ - */ - -#include "2d.h" -#include "pixel.h" -#include "circle.h" - -// THIS COULD BE OPTIMIZED BY MOVING THE GR_RECT CODE INTO HERE!!!!!!!! - -#define circle_fill(x,y,w) gr_rect((x),(y),(w),1) - -void gr8_circle( int xc, int yc, int d ) -{ - int p,x, y, r; - - r = d/2; - p=3-d; - x=0; - y=r; - - // Big clip - if ( (xc+r) < gr_screen.clip_left ) return; - if ( (xc-r) > gr_screen.clip_right ) return; - if ( (yc+r) < gr_screen.clip_top ) return; - if ( (yc-r) > gr_screen.clip_bottom ) return; - - while(x8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 24 2/07/98 7:50p John - * Added code so that we can use the old blending type of alphacolors if - * we want to. Made the stars use them. - * - * 23 1/13/98 10:20a John - * Added code to support "glass" in alphacolors - * - * 22 1/02/98 9:10p Lawrance - * Big changes to how colors get set on the HUD. - * - * 21 12/30/97 4:32p John - * - * 20 12/02/97 3:59p John - * Added first rev of thruster glow, along with variable levels of - * translucency, which retquired some restructing of palman. - * - * 19 11/30/97 4:26p John - * Added 32-bpp antialiased line. Took gamma out of alphacolor - * calculation. - * - * 18 11/29/97 2:06p John - * added mode 16-bpp support - * - * 17 11/21/97 11:32a John - * Added nebulas. Fixed some warpout bugs. - * - * 16 11/14/97 12:30p John - * Fixed some DirectX bugs. Moved the 8-16 xlat tables into Graphics - * libs. Made 16-bpp DirectX modes know what bitmap format they're in. - * - * 15 11/05/97 11:20p Lawrance - * increase number of alpha colors to 52 - * - * 14 11/04/97 6:32p Hoffoss - * Changes to hotkey screen. Needed to add new colors for - * Color_text_active*. - * - * 13 10/31/97 10:47a John - * upped clr version to force rebuild after changing palette code. - * - * 12 10/14/97 4:50p John - * more 16 bpp stuff. - * - * 11 10/14/97 8:08a John - * added a bunch more 16 bit support - * - * 10 10/09/97 5:23p John - * Added support for more 16-bpp functions - * - * 9 10/03/97 9:10a John - * added better antialiased line drawer - * - * 8 9/20/97 8:16a John - * Made .clr files go into the Cache directory. Replaced cfopen(name,NULL) - * to delete a file with cf_delete. - * - * 7 9/09/97 10:46a Sandeep - * fixed warning level 4 - * - * 6 7/18/97 12:40p John - * cached alphacolors to disk. Also made cfopen be able to delete a file - * by passing NULL for mode. - * - * 5 7/16/97 3:07p John - * - * 4 6/18/97 12:07p John - * fixed some color bugs - * - * 3 6/18/97 9:46a John - * added first rev of d3d shader. Made HUD target use medium detail - * models. Took out some color debug messages. - * - * 2 6/17/97 7:04p John - * added d3d support for gradients. - * fixed some color bugs by adding screen signatures instead of watching - * flags and palette changes. - * - * 1 6/17/97 12:01p John - * - * $NoKeywords: $ - */ - -#include "pstypes.h" -#include "2d.h" -#include "grinternal.h" -#include "colors.h" -#include "palman.h" -#include "cfile.h" -#include "systemvars.h" - -//#define MAX_ALPHACOLORS 36 -#define MAX_ALPHACOLORS 72 - -alphacolor Alphacolors[MAX_ALPHACOLORS]; -static int Alphacolors_intited = 0; - -alphacolor * Current_alphacolor = NULL; - - -void calc_alphacolor_hud_type( alphacolor * ac ) -{ -#ifndef HARDWARE_ONLY - int i,j; - int tr,tg,tb, Sr, Sg, Sb; - ubyte * pal; - int r, g, b, alpha; - float falpha; - - SDL_assert(Alphacolors_intited); - -// mprintf(( "Calculating alphacolor for %d,%d,%d,%d\n", ac->r, ac->g, ac->b, ac->alpha )); - - falpha = i2fl(ac->alpha)/255.0f; - if ( falpha<0.0f ) falpha = 0.0f; else if ( falpha > 1.0f ) falpha = 1.0f; - - alpha = ac->alpha >> 4; - if (alpha < 0 ) alpha = 0; else if (alpha > 15 ) alpha = 15; - r = ac->r; - if (r < 0 ) r = 0; else if (r > 255 ) r = 255; - g = ac->g; - if (g < 0 ) g = 0; else if (g > 255 ) g = 255; - b = ac->b; - if (b < 0 ) b = 0; else if (b > 255 ) b = 255; - - int ii[16]; - - for (j=1; j<15; j++ ) { - - // JAS: Use 1.5/Gamma instead of 1/Gamma because on Adam's - // PC a gamma of 1.2 makes text look good, but his gamma is - // really 1.8. 1.8/1.2 = 1.5 - float factor = falpha * (float)pow(i2fl(j)/14.0f, 1.5f/Gr_gamma); - //float factor = i2fl(j)/14.0f; - - tr = fl2i( i2fl(r) * factor ); - tg = fl2i( i2fl(g) * factor ); - tb = fl2i( i2fl(b) * factor ); - - ii[j] = tr; - if ( tg > ii[j] ) ii[j] = tg; - if ( tb > ii[j] ) ii[j] = tb; - } - - pal = gr_palette; - - int m = r; - if ( g > m ) m = g; - if ( b > m ) m = b; - - ubyte ri[256], gi[256], bi[256]; - - if ( m > 0 ) { - for (i=0; i<256; i++ ) { - ri[i] = ubyte((i*r)/m); - gi[i] = ubyte((i*g)/m); - bi[i] = ubyte((i*b)/m); - } - } else { - for (i=0; i<256; i++ ) { - ri[i] = 0; - gi[i] = 0; - bi[i] = 0; - } - } - - for (i=0; i<256; i++ ) { - Sr = pal[0]; - Sg = pal[1]; - Sb = pal[2]; - pal += 3; - - int dst_intensity = Sr; - if ( Sg > dst_intensity ) dst_intensity = Sg; - if ( Sb > dst_intensity ) dst_intensity = Sb; - - ac->table.lookup[0][i] = (unsigned char)i; - - for (j=1; j<15; j++ ) { - - int tmp_i = max( ii[j], dst_intensity ); - - ac->table.lookup[j][i] = (unsigned char)palette_find(ri[tmp_i],gi[tmp_i],bi[tmp_i]); - } - - float di = (i2fl(Sr)*.30f+i2fl(Sg)*0.60f+i2fl(Sb)*.10f)/255.0f; - float factor = 0.0f + di*0.75f; - - tr = fl2i( factor*i2fl(r)*falpha ); - tg = fl2i( factor*i2fl(g)*falpha ); - tb = fl2i( factor*i2fl(b)*falpha ); - - if ( tr > 255 ) tr = 255; else if ( tr < 0 ) tr = 0; - if ( tg > 255 ) tg = 255; else if ( tg < 0 ) tg = 0; - if ( tb > 255 ) tb = 255; else if ( tb < 0 ) tb = 0; - - ac->table.lookup[15][i] = (unsigned char)palette_find(tr,tg,tb); - //ac->table.lookup[15][i] = (unsigned char)palette_find(255,0,0); - - } -#endif -} - -// Old way to calculate alpha colors - -void calc_alphacolor_blend_type( alphacolor * ac ) -{ -#ifndef HARDWARE_ONLY - int i,j; - int tr,tg,tb, Sr, Sg, Sb; - int Dr, Dg, Db; - ubyte * pal; - int r, g, b, alpha; - - SDL_assert(Alphacolors_intited); - -// mprintf(( "Calculating alphacolor for %d,%d,%d,%d\n", ac->r, ac->g, ac->b, ac->alpha )); - - alpha = ac->alpha >> 4; - if (alpha < 0 ) alpha = 0; else if (alpha > 15 ) alpha = 15; - r = ac->r; - if (r < 0 ) r = 0; else if (r > 255 ) r = 255; - g = ac->g; - if (g < 0 ) g = 0; else if (g > 255 ) g = 255; - b = ac->b; - if (b < 0 ) b = 0; else if (b > 255 ) b = 255; - - int gamma_j1[16]; - - for (j=1; j<16; j++ ) { - // JAS: Use 1.5/Gamma instead of 1/Gamma because on Adam's - // PC a gamma of 1.2 makes text look good, but his gamma is - // really 1.8. 1.8/1.2 = 1.5 - gamma_j1[j] = (int)((pow(i2fl(j)/15.0f, 1.5f/Gr_gamma)*16.0f) + 0.5); - } - - pal = gr_palette; - - for (i=0; i<256; i++ ) { - Sr = pal[0]; - Sg = pal[1]; - Sb = pal[2]; - pal += 3; - - Dr = ( Sr*(16-alpha) + (r*alpha) ) >> 4; - Dg = ( Sg*(16-alpha) + (g*alpha) ) >> 4; - Db = ( Sb*(16-alpha) + (b*alpha) ) >> 4; - - ac->table.lookup[0][i] = (unsigned char)i; - - for (j=1; j<16; j++ ) { - - int j1 = gamma_j1[j]; - - tr = ( Sr*(16-j1) + (Dr*j1) ) >> 4; - tg = ( Sg*(16-j1) + (Dg*j1) ) >> 4; - tb = ( Sb*(16-j1) + (Db*j1) ) >> 4; - - if ( tr > 255 ) tr = 255; else if ( tr < 0 ) tr = 0; - if ( tg > 255 ) tg = 255; else if ( tg < 0 ) tg = 0; - if ( tb > 255 ) tb = 255; else if ( tb < 0 ) tb = 0; - - ac->table.lookup[j][i] = (unsigned char)palette_find(tr,tg,tb); - } - } -#endif -} - -void calc_alphacolor( alphacolor * ac ) -{ - switch(ac->type) { - case AC_TYPE_HUD: - calc_alphacolor_hud_type(ac); - break; - case AC_TYPE_BLEND: - calc_alphacolor_blend_type(ac); - break; - default: - Int3(); // Passing an invalid type of alphacolor! - } -} - -void grx_init_alphacolors() -{ - int i; - - Alphacolors_intited = 1; - - for (i=0; i 255 ) alpha = 255; - - n = -1; - if ( (clr->magic == 0xAC01) && (clr->is_alphacolor) ) { - if ( (clr->alphacolor >= 0) && (clr->alphacolor < MAX_ALPHACOLORS)) { - if ( Alphacolors[clr->alphacolor].used && (Alphacolors[clr->alphacolor].clr==clr) ) { - n = clr->alphacolor; - } - } - } - - int changed = 0; - - if ( n==-1 ) { - for (n=0; nr!=r || ac->g!=g || ac->b!=b || ac->alpha!=alpha || ac->type != type ) ) { - // we're changing the color, so delete the old cache file - //mprintf(( "Changing ac from %d,%d,%d,%d to %d,%d,%d,%d\n", ac->r, ac->g, ac->b, ac->alpha, r, g, b, alpha )); - //ac_delete_cached(ac); - } - - ac->used = 1; - ac->r = r; - ac->g = g; - ac->b = b; - ac->alpha = alpha; - ac->type = type; - ac->clr=clr; - - calc_alphacolor(ac); - - grx_init_color( clr, r, g, b ); - - // Link the alphacolor to the color - clr->alpha = (unsigned char)alpha; - clr->ac_type = (ubyte)type; - clr->alphacolor = n; - clr->is_alphacolor = 1; -} - - -void grx_get_color( int * r, int * g, int * b ) -{ - if (r) *r = gr_screen.current_color.red; - if (g) *g = gr_screen.current_color.green; - if (b) *b = gr_screen.current_color.blue; -} - -void grx_init_color( color * dst, int r, int g, int b ) -{ - dst->screen_sig = gr_screen.signature; - dst->red = (unsigned char)r; - dst->green = (unsigned char)g; - dst->blue = (unsigned char)b; - dst->alpha = 255; - dst->ac_type = AC_TYPE_NONE; - dst->is_alphacolor = 0; - dst->alphacolor = -1; - dst->magic = 0xAC01; - - dst->raw8 = (unsigned char)palette_find( r, g, b ); -} - -void grx_set_color_fast( color * dst ) -{ - if ( dst->magic != 0xAC01 ) return; - - if ( dst->screen_sig != gr_screen.signature ) { - if ( dst->is_alphacolor ) { - grx_init_alphacolor( dst, dst->red, dst->green, dst->blue, dst->alpha, dst->ac_type ); - } else { - grx_init_color( dst, dst->red, dst->green, dst->blue ); - } - } - - gr_screen.current_color = *dst; - - if ( dst->is_alphacolor ) { - SDL_assert( dst->alphacolor > -1 ); - SDL_assert( dst->alphacolor <= MAX_ALPHACOLORS ); - SDL_assert( Alphacolors[dst->alphacolor].used ); - - // Current_alphacolor = &Alphacolors[dst->alphacolor]; - Current_alphacolor = NULL; - } else { - Current_alphacolor = NULL; - } -} - - -void grx_set_color( int r, int g, int b ) -{ - SDL_assert((r >= 0) && (r < 256)); - SDL_assert((g >= 0) && (g < 256)); - SDL_assert((b >= 0) && (b < 256)); - -// if ( r!=0 || g!=0 || b!=0 ) { -// mprintf(( "Setcolor: %d,%d,%d\n", r,g,b )); -// } - grx_init_color( &gr_screen.current_color, r, g, b ); - Current_alphacolor = NULL; -} - -void calc_alphacolor_hud_type_old( alphacolor_old * ac ) -{ - int i,j; - int tr,tg,tb, Sr, Sg, Sb; - ubyte * pal; - int r, g, b, alpha; - float falpha; - - // SDL_assert(Alphacolors_intited); - -// mprintf(( "Calculating alphacolor for %d,%d,%d,%d\n", ac->r, ac->g, ac->b, ac->alpha )); - - falpha = i2fl(ac->alpha)/255.0f; - if ( falpha<0.0f ) falpha = 0.0f; else if ( falpha > 1.0f ) falpha = 1.0f; - - alpha = ac->alpha >> 4; - if (alpha < 0 ) alpha = 0; else if (alpha > 15 ) alpha = 15; - r = ac->r; - if (r < 0 ) r = 0; else if (r > 255 ) r = 255; - g = ac->g; - if (g < 0 ) g = 0; else if (g > 255 ) g = 255; - b = ac->b; - if (b < 0 ) b = 0; else if (b > 255 ) b = 255; - - int ii[16]; - - for (j=1; j<15; j++ ) { - - // JAS: Use 1.5/Gamma instead of 1/Gamma because on Adam's - // PC a gamma of 1.2 makes text look good, but his gamma is - // really 1.8. 1.8/1.2 = 1.5 - float factor = falpha * (float)pow(i2fl(j)/14.0f, 1.5f/Gr_gamma); - //float factor = i2fl(j)/14.0f; - - tr = fl2i( i2fl(r) * factor ); - tg = fl2i( i2fl(g) * factor ); - tb = fl2i( i2fl(b) * factor ); - - ii[j] = tr; - if ( tg > ii[j] ) ii[j] = tg; - if ( tb > ii[j] ) ii[j] = tb; - } - - pal = gr_palette; - - int m = r; - if ( g > m ) m = g; - if ( b > m ) m = b; - - ubyte ri[256], gi[256], bi[256]; - - if ( m > 0 ) { - for (i=0; i<256; i++ ) { - ri[i] = ubyte((i*r)/m); - gi[i] = ubyte((i*g)/m); - bi[i] = ubyte((i*b)/m); - } - } else { - for (i=0; i<256; i++ ) { - ri[i] = 0; - gi[i] = 0; - bi[i] = 0; - } - } - - for (i=0; i<256; i++ ) { - Sr = pal[0]; - Sg = pal[1]; - Sb = pal[2]; - pal += 3; - - int dst_intensity = Sr; - if ( Sg > dst_intensity ) dst_intensity = Sg; - if ( Sb > dst_intensity ) dst_intensity = Sb; - - ac->table.lookup[0][i] = (unsigned char)i; - - for (j=1; j<15; j++ ) { - - int tmp_i = max( ii[j], dst_intensity ); - - ac->table.lookup[j][i] = (unsigned char)palette_find(ri[tmp_i],gi[tmp_i],bi[tmp_i]); - } - - float di = (i2fl(Sr)*.30f+i2fl(Sg)*0.60f+i2fl(Sb)*.10f)/255.0f; - float factor = 0.0f + di*0.75f; - - tr = fl2i( factor*i2fl(r)*falpha ); - tg = fl2i( factor*i2fl(g)*falpha ); - tb = fl2i( factor*i2fl(b)*falpha ); - - if ( tr > 255 ) tr = 255; else if ( tr < 0 ) tr = 0; - if ( tg > 255 ) tg = 255; else if ( tg < 0 ) tg = 0; - if ( tb > 255 ) tb = 255; else if ( tb < 0 ) tb = 0; - - ac->table.lookup[15][i] = (unsigned char)palette_find(tr,tg,tb); - //ac->table.lookup[15][i] = (unsigned char)palette_find(255,0,0); - } -} - -void calc_alphacolor_old(alphacolor_old *ac) -{ - SDL_assert(Fred_running); - calc_alphacolor_hud_type_old(ac); -} diff --git a/src/graphics/gradient.cpp b/src/graphics/gradient.cpp deleted file mode 100644 index 6ecba9f..0000000 --- a/src/graphics/gradient.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/Gradient.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Routines to draw rectangular gradients. - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:17 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 3 12/02/98 5:47p Dave - * Put in interface xstr code. Converted barracks screen to new format. - * - * 2 10/07/98 10:52a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 17 5/06/98 5:30p John - * Removed unused cfilearchiver. Removed/replaced some unused/little used - * graphics functions, namely gradient_h and _v and pixel_sp. Put in new - * DirectX header files and libs that fixed the Direct3D alpha blending - * problems. - * - * 16 3/10/98 4:18p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 15 1/19/98 6:15p John - * Fixed all my Optimized Build compiler warnings - * - * 14 11/30/97 4:04p John - * - * 13 11/30/97 12:18p John - * added more 24 & 32-bpp primitives - * - * 12 10/19/97 12:55p John - * new code to lock / unlock surfaces for smooth directx integration. - * - * 11 10/14/97 4:50p John - * more 16 bpp stuff. - * - * 10 10/14/97 8:08a John - * added a bunch more 16 bit support - * - * 9 10/09/97 5:23p John - * Added support for more 16-bpp functions - * - * 8 6/11/97 1:12p John - * Started fixing all the text colors in the game. - * - * 7 5/12/97 12:27p John - * Restructured Graphics Library to add support for multiple renderers. - * - * 6 12/12/96 4:59p Lawrance - * made clipping for horizontal and vertical gradient lines right - * - * 5 11/19/96 2:46p Allender - * fix up gradient support for 15bpp - * - * 4 11/18/96 4:34p Allender - * new 16 bit gradient functions - * - * 3 10/27/96 1:21a Lawrance - * added check to avoid divide by zero when calculating gradients - * - * 2 10/26/96 2:56p John - * Got gradient code working. - * - * 1 10/26/96 1:45p John - * Initial skeletion code. - * - * $NoKeywords: $ - */ - -#ifndef PLAT_UNIX -#include -#include -#endif - -#include "2d.h" -#include "grinternal.h" -#include "gradient.h" -#include "floating.h" -#include "line.h" -#include "palman.h" - -void gr8_gradient(int x1,int y1,int x2,int y2) -{ -#ifndef HARDWARE_ONLY - int i; - int xstep,ystep; - int clipped = 0, swapped=0; - ubyte *xlat_table; - - int l=0, dl=0; - - if (!Current_alphacolor) { - gr_line( x1, y1, x2, y2 ); - return; - } - - INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,gr_screen.clip_right,gr_screen.clip_bottom,return,clipped=1,swapped=1); - - int dy=y2-y1; - int dx=x2-x1; - int error_term=0; - - if ( dx==0 && dy==0 ) { - return; - } - - gr_lock(); - - ubyte *dptr = GR_SCREEN_PTR(ubyte,x1,y1); - - xlat_table = (ubyte *)&Current_alphacolor->table.lookup[0][0]; - - - if(dy<0) { - dy=-dy; - ystep=-gr_screen.rowsize / gr_screen.bytes_per_pixel; - } else { - ystep=gr_screen.rowsize / gr_screen.bytes_per_pixel; - } - - if(dx<0) { - dx=-dx; - xstep=-1; - } else { - xstep=1; - } - - if(dx>dy) { - - if (!swapped) { - l = 14<<8; - dl = (-14<<8) / dx; - } else { - l = 0; - dl = (14<<8) / dx; - } - - for(i=0;idx) { - error_term-=dx; - dptr+=ystep; - } - } - *dptr = xlat_table[(l&0xF00)|*dptr]; - - } else { - - if (!swapped) { - l = 14<<8; - dl = (-14<<8) / dy; - } else { - l = 0; - dl = (14<<8) / dy; - } - - for(i=0;i0) { - error_term-=dy; - dptr+=xstep; - } - - } - *dptr = xlat_table[(l&0xF00)|*dptr]; - - } - gr_unlock(); -#else - Int3(); -#endif -} - - - - - diff --git a/src/graphics/grd3d.cpp b/src/graphics/grd3d.cpp deleted file mode 100644 index 1d88792..0000000 --- a/src/graphics/grd3d.cpp +++ /dev/null @@ -1,3060 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/GrD3D.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Code for our Direct3D renderer - * - * $Log$ - * Revision 1.3 2002/06/09 04:41:17 relnev - * added copyright header - * - * Revision 1.2 2002/05/07 03:16:45 theoddone33 - * The Great Newline Fix - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 42 10/13/99 3:49p Jefff - * fixed unnumbered XSTRs - * - * 41 9/13/99 11:25p Dave - * Fixed problem with mode-switching and D3D movies. - * - * 40 9/13/99 11:30a Dave - * Added checkboxes and functionality for disabling PXO banners as well as - * disabling d3d zbuffer biasing. - * - * 39 9/10/99 11:53a Dave - * Shutdown graphics before sound to eliminate apparent lockups when - * Directsound decides to be lame. Fix TOPMOST problem with D3D windows. - * - * 38 9/04/99 8:00p Dave - * Fixed up 1024 and 32 bit movie support. - * - * 37 8/30/99 5:01p Dave - * Made d3d do less state changing in the nebula. Use new chat server for - * PXO. - * - * 36 8/20/99 2:09p Dave - * PXO banner cycling. - * - * 35 8/18/99 9:35a Dave - * Made d3d shutdown more stable. - * - * 34 8/11/99 3:30p Dave - * Fixed window focus problems. - * - * 33 8/04/99 5:36p Dave - * Make glide and D3D switch out properly. - * - * 32 8/02/99 6:25p Dave - * Fixed d3d screen save/popup problem. - * - * 31 7/30/99 7:01p Dave - * Dogfight escort gauge. Fixed up laser rendering in Glide. - * - * 30 7/29/99 10:47p Dave - * Standardized D3D fogging using vertex fog. Shook out Savage 4 bugs. - * - * 29 7/27/99 3:09p Dave - * Made g400 work. Whee. - * - * 28 7/24/99 4:19p Dave - * Fixed dumb code with briefing bitmaps. Made d3d zbuffer work much - * better. Made model code use zbuffer more intelligently. - * - * 27 7/16/99 1:49p Dave - * 8 bit aabitmaps. yay. - * - * 26 7/14/99 9:42a Dave - * Put in clear_color debug function. Put in base for 3dnow stuff / P3 - * stuff - * - * 25 7/13/99 1:15p Dave - * 32 bit support. Whee! - * - * 24 6/29/99 10:35a Dave - * Interface polygon bitmaps! Whee! - * - * 23 6/03/99 6:37p Dave - * More TNT fun. Made perspective bitmaps more flexible. - * - * 22 5/05/99 9:02p Dave - * Fixed D3D aabitmap rendering. Spiffed up nebula effect a bit (added - * rotations, tweaked values, made bitmap selection more random). Fixed - * D3D beam weapon clipping problem. Added D3d frame dumping. - * - * 21 2/03/99 11:44a Dave - * Fixed d3d transparent textures. - * - * 20 1/24/99 11:36p Dave - * First full rev of beam weapons. Very customizable. Removed some bogus - * Int3()'s in low level net code. - * - * 19 1/15/99 11:29a Neilk - * Fixed D3D screen/texture pixel formatting problem. - * - * 18 1/11/99 6:21p Neilk - * Fixed broken D3D card fog-capability check. - * - * 17 1/06/99 2:24p Dave - * Stubs and release build fixes. - * - * 16 12/18/98 1:13a Dave - * Rough 1024x768 support for Direct3D. Proper detection and usage through - * the launcher. - * - * 15 12/09/98 7:34p Dave - * Cleanup up nebula effect. Tweaked many values. - * - * 14 12/08/98 7:30p Dave - * Fixed broken compile. - * - * 13 12/08/98 7:03p Dave - * Much improved D3D fogging. Also put in vertex fogging for the cheesiest - * of 3d cards. - * - * 12 12/08/98 2:47p Johnson - * Made D3D fogging use eye-relative depth instead of z-depth. Works like - * Glide w-buffer now. - * - * 11 12/08/98 9:36a Dave - * Almost done nebula effect for D3D. Looks 85% as good as Glide. - * - * 10 12/07/98 5:51p Dave - * Finally got d3d fog working! Now we just need to tweak values. - * - * 9 12/06/98 6:53p Dave - * - * 8 12/06/98 3:08p Dave - * Fixed grx_tmapper to handle pixel fog flag. First run fog support for - * D3D. - * - * 7 12/06/98 2:36p Dave - * Drastically improved nebula fogging. - * - * 6 12/01/98 10:25a Johnson - * Fixed direct3d texture coord/font problems. - * - * 5 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 4 11/11/98 5:37p Dave - * Checkin for multiplayer testing. - * - * 3 10/09/98 2:57p Dave - * Starting splitting up OS stuff. - * - * 2 10/07/98 10:52a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 110 6/13/98 6:01p Hoffoss - * Externalized all new (or forgot to be added) strings to all the code. - * - * 109 6/13/98 3:18p Hoffoss - * NOX()ed out a bunch of strings that shouldn't be translated. - * - * 108 5/24/98 9:41p John - * changed allender's previous fix to actually not draw the lines on - * NDEBUG. - * - * 107 5/24/98 9:16p Allender - * put in previously non-NDEBUG code to draw bogus cursor when Gr_cursor - * wasn't defined. Caused d3d to crash before playing movies - * - * 106 5/22/98 10:29p John - * fixed some mode switching and line offset detection bugs. - * - * 105 5/22/98 1:11p John - * Added code to actually detect which offset a line needs - * - * - * $NoKeywords: $ - */ - -#include - -#include "grd3dinternal.h" - -#include "osapi.h" -#include "2d.h" -#include "bmpman.h" -#include "key.h" -#include "floating.h" -#include "palman.h" -#include "osregistry.h" -#include "grd3d.h" -#include "line.h" -#include "font.h" -#include "grinternal.h" -#include "mouse.h" -#include "alphacolors.h" -#include "systemvars.h" -#include "cfile.h" -#include "cmdline.h" - - -LPDIRECTDRAW lpDD1 = NULL; -LPDIRECTDRAW2 lpDD = NULL; -LPDIRECT3D2 lpD3D = NULL; -LPDIRECT3DDEVICE2 lpD3DDevice = NULL; -// LPDIRECT3DDEVICE lpD3DDeviceEB = NULL; -LPDIRECTDRAWSURFACE lpBackBuffer = NULL; -LPDIRECTDRAWSURFACE lpFrontBuffer = NULL; -LPDIRECTDRAWSURFACE lpZBuffer = NULL; - -LPDIRECT3DVIEWPORT2 lpViewport; - -DDPIXELFORMAT AlphaTextureFormat; -int Largest_alpha = 0; -DDPIXELFORMAT NonAlphaTextureFormat; -DDPIXELFORMAT NonAlphaTextureFormat_1555; -DDPIXELFORMAT NonAlphaTextureFormat_565; -int Largest_rgb = 0; -DDPIXELFORMAT ScreenFormat; - -static RECT D3D_cursor_clip_rect; - -D3DDEVICEDESC D3DHWDevDesc, D3DHELDevDesc; -LPD3DDEVICEDESC lpDevDesc = NULL; - -DDCAPS DD_driver_caps; -DDCAPS DD_hel_caps; - -int D3D_texture_divider = 1; - -int D3D_window = 0; - -char Device_init_error[512] = ""; - -// -1 == no fog, bad bad bad -// 0 == vertex fog -// 1 == table fog -int D3D_fog_mode = -1; - -static int In_frame = 0; - -int D3D_inited = 0; - -int DrawPrim = 0; - -int D3d_rendition_uvs = 0; - -int D3D_32bit = 0; - -int D3D_zbias = 1; -DCF(zbias, "") -{ - D3D_zbias = !D3D_zbias; -} - -#define MAX_D2D_DEVICES 8 -#define MAX_D3D_DEVICES 16 - -typedef struct d3d_device { - GUID guid_2d; - LPGUID pguid_2d; - - GUID guid_3d; - LPGUID pguid_3d; - - char name[1024]; -} d3d_device; - -d3d_device D2D_devices[MAX_D2D_DEVICES]; -d3d_device D3D_devices[MAX_D3D_DEVICES]; - -int Num_d2d_devices = 0; -int Num_d3d_devices = 0; - -d3d_device *D3D_device; - -void mprint_guid( LPGUID lpGuid ) -{ - /* - if ( !lpGuid ) { - mprintf(( "None\n" )); - } else { - int i; - for (i=0; ibOpcode = op; \ - ((LPD3DINSTRUCTION) ptr)->bSize = sz; \ - ((LPD3DINSTRUCTION) ptr)->wCount = cnt; \ - ptr = (void *)(((LPD3DINSTRUCTION) ptr) + 1); } while (0) - -#define VERTEX_DATA(loc, cnt, ptr) do { \ - if ((ptr) != (loc)) memcpy((ptr), (loc), sizeof(D3DVERTEX) * (cnt)); \ - ptr = (void *)(((LPD3DVERTEX) (ptr)) + (cnt)); } while (0) - -// OP_MATRIX_MULTIPLY size: 4 (sizeof D3DINSTRUCTION) -#define OP_MATRIX_MULTIPLY(cnt, ptr) \ - PUTD3DINSTRUCTION(D3DOP_MATRIXMULTIPLY, sizeof(D3DMATRIXMULTIPLY), cnt, ptr) - -// MATRIX_MULTIPLY_DATA size: 12 (sizeof MATRIXMULTIPLY) -#define MATRIX_MULTIPLY_DATA(src1, src2, dest, ptr) do { \ - ((LPD3DMATRIXMULTIPLY) ptr)->hSrcMatrix1 = src1; \ - ((LPD3DMATRIXMULTIPLY) ptr)->hSrcMatrix2 = src2; \ - ((LPD3DMATRIXMULTIPLY) ptr)->hDestMatrix = dest; \ - ptr = (void *)(((LPD3DMATRIXMULTIPLY) ptr) + 1); } while (0) - -// OP_STATE_LIGHT size: 4 (sizeof D3DINSTRUCTION) -#define OP_STATE_LIGHT(cnt, ptr) \ - PUTD3DINSTRUCTION(D3DOP_STATELIGHT, sizeof(D3DSTATE), cnt, ptr) - -// OP_STATE_TRANSFORM size: 4 (sizeof D3DINSTRUCTION) -#define OP_STATE_TRANSFORM(cnt, ptr) \ - PUTD3DINSTRUCTION(D3DOP_STATETRANSFORM, sizeof(D3DSTATE), cnt, ptr) - -// OP_STATE_RENDER size: 4 (sizeof D3DINSTRUCTION) -#define OP_STATE_RENDER(cnt, ptr) \ - PUTD3DINSTRUCTION(D3DOP_STATERENDER, sizeof(D3DSTATE), cnt, ptr) - -// STATE_DATA size: 8 (sizeof D3DSTATE) -#define STATE_DATA(type, arg, ptr) do { \ - ((LPD3DSTATE) ptr)->drstRenderStateType = (D3DRENDERSTATETYPE)type; \ - ((LPD3DSTATE) ptr)->dwArg[0] = arg; \ - ptr = (void *)(((LPD3DSTATE) ptr) + 1); } while (0) - -// OP_PROCESS_VERTICES size: 4 (sizeof D3DINSTRUCTION) -#define OP_PROCESS_VERTICES(cnt, ptr) \ - PUTD3DINSTRUCTION(D3DOP_PROCESSVERTICES, sizeof(D3DPROCESSVERTICES), cnt, ptr) - -// PROCESSVERTICES_DATA size: 16 (sizeof D3DPROCESSVERTICES) -#define PROCESSVERTICES_DATA(flgs, strt, cnt, ptr) do { \ - ((LPD3DPROCESSVERTICES) ptr)->dwFlags = flgs; \ - ((LPD3DPROCESSVERTICES) ptr)->wStart = strt; \ - ((LPD3DPROCESSVERTICES) ptr)->wDest = strt; \ - ((LPD3DPROCESSVERTICES) ptr)->dwCount = cnt; \ - ((LPD3DPROCESSVERTICES) ptr)->dwReserved = 0; \ - ptr = (void *)(((LPD3DPROCESSVERTICES) ptr) + 1); } while (0) - -// OP_TRIANGLE_LIST size: 4 (sizeof D3DINSTRUCTION) -#define OP_TRIANGLE_LIST(cnt, ptr) \ - PUTD3DINSTRUCTION(D3DOP_TRIANGLE, sizeof(D3DTRIANGLE), cnt, ptr) - -#define TRIANGLE_LIST_DATA(loc, count, ptr) do { \ - if ((ptr) != (loc)) memcpy((ptr), (loc), sizeof(D3DTRIANGLE) * (count)); \ - ptr = (void *)(((LPD3DTRIANGLE) (ptr)) + (count)); } while (0) - -// OP_LINE_LIST size: 4 (sizeof D3DINSTRUCTION) -#define OP_LINE_LIST(cnt, ptr) \ - PUTD3DINSTRUCTION(D3DOP_LINE, sizeof(D3DLINE), cnt, ptr) - -#define LINE_LIST_DATA(loc, count, ptr) do { \ - if ((ptr) != (loc)) memcpy((ptr), (loc), sizeof(D3DLINE) * (count)); \ - ptr = (void *)(((LPD3DLINE) (ptr)) + (count)); } while (0) - -// OP_POINT_LIST size: 8 (sizeof D3DINSTRUCTION + sizeof D3DPOINT) -#define OP_POINT_LIST(first, cnt, ptr) do { \ - PUTD3DINSTRUCTION(D3DOP_POINT, sizeof(D3DPOINT), 1, ptr); \ - ((LPD3DPOINT)(ptr))->wCount = cnt; \ - ((LPD3DPOINT)(ptr))->wFirst = first; \ - ptr = (void*)(((LPD3DPOINT)(ptr)) + 1); } while(0) - -// OP_SPAN_LIST size: 8 (sizeof D3DINSTRUCTION + sizeof D3DSPAN) -#define OP_SPAN_LIST(first, cnt, ptr) \ - PUTD3DINSTRUCTION(D3DOP_SPAN, sizeof(D3DSPAN), 1, ptr); \ - ((LPD3DSPAN)(ptr))->wCount = cnt; \ - ((LPD3DSPAN)(ptr))->wFirst = first; \ - ptr = (void*)(((LPD3DSPAN)(ptr)) + 1); } while(0) - -// OP_BRANCH_FORWARD size: 18 (sizeof D3DINSTRUCTION + sizeof D3DBRANCH) -#define OP_BRANCH_FORWARD(tmask, tvalue, tnegate, toffset, ptr) \ - PUTD3DINSTRUCTION(D3DOP_BRANCHFORWARD, sizeof(D3DBRANCH), 1, ptr); \ - ((LPD3DBRANCH) ptr)->dwMask = tmask; \ - ((LPD3DBRANCH) ptr)->dwValue = tvalue; \ - ((LPD3DBRANCH) ptr)->bNegate = tnegate; \ - ((LPD3DBRANCH) ptr)->dwOffset = toffset; \ - ptr = (void *)(((LPD3DBRANCH) (ptr)) + 1); } while (0) - -// OP_SET_STATUS size: 20 (sizeof D3DINSTRUCTION + sizeof D3DSTATUS) -#define OP_SET_STATUS(flags, status, _x1, _y1, _x2, _y2, ptr) \ - PUTD3DINSTRUCTION(D3DOP_SETSTATUS, sizeof(D3DSTATUS), 1, ptr); \ - ((LPD3DSTATUS)(ptr))->dwFlags = flags; \ - ((LPD3DSTATUS)(ptr))->dwStatus = status; \ - ((LPD3DSTATUS)(ptr))->drExtent.x1 = _x1; \ - ((LPD3DSTATUS)(ptr))->drExtent.y1 = _y1; \ - ((LPD3DSTATUS)(ptr))->drExtent.x2 = _x2; \ - ((LPD3DSTATUS)(ptr))->drExtent.y2 = _y2; \ - ptr = (void *)(((LPD3DSTATUS) (ptr)) + 1); } while (0) - -// OP_NOP size: 4 -#define OP_NOP(ptr) \ - PUTD3DINSTRUCTION(D3DOP_TRIANGLE, sizeof(D3DTRIANGLE), 0, ptr) - -#define OP_EXIT(ptr) \ - PUTD3DINSTRUCTION(D3DOP_EXIT, 0, 0, ptr) - -#define QWORD_ALIGNED(ptr) \ - (!(0x00000007L & (ULONG)(ptr))) - -#define D3D_MAX_VERTS 512 -#define D3D_EXBUFFER_SIZE 65536 -static int D3D_num_verts; -//static D3DTLVERTEX D3D_vertices[D3D_MAX_VERTS]; -static D3DTLVERTEX *D3D_vertices; -//static ubyte D3D_exbuffer[D3D_EXBUFFER_SIZE]; -static void *D3D_ex_ptr, *D3D_ex_end; -LPDIRECT3DEXECUTEBUFFER lpExBuf = NULL; - -LPVOID lpBufStart, lpPointer, lpInsStart; -int Exb_size; - - -void gr_d3d_exb_init() -{ - /* - HRESULT ddrval; - D3DEXECUTEBUFFERDESC debDesc; - - if ( DrawPrim ) { - return; - } - - Exb_size = D3D_EXBUFFER_SIZE + sizeof(D3DTLVERTEX)*D3D_MAX_VERTS; - - // create a D3DEXECUTEBUFFERDESC - memset( &debDesc, 0, sizeof( debDesc ) ); - debDesc.dwSize = sizeof( debDesc ); - debDesc.dwFlags = D3DDEB_BUFSIZE; - debDesc.dwBufferSize = Exb_size; - - // create the buffer - ddrval = lpD3DDeviceEB->CreateExecuteBuffer( &debDesc, &lpExBuf, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_D3D_INIT: CreateExecuteBuffer failed. size=%d, '%s'\n", Exb_size, d3d_error_string(ddrval) )); - goto D3DError; - } - - memset( &debDesc, 0, sizeof( debDesc ) ); - debDesc.dwSize = sizeof( debDesc ); - ddrval = lpExBuf->Lock( &debDesc ); - if ( ddrval != DD_OK ) { - mprintf(( "Failed to lock the execute buffer!\n" )); - goto D3DError; - } - - lpPointer = lpBufStart = lpInsStart = debDesc.lpData; - - lpPointer = (void *)((uint)lpPointer+sizeof(D3DTLVERTEX)*D3D_MAX_VERTS); - lpInsStart = lpPointer; - - OP_PROCESS_VERTICES( 1, lpPointer ); - PROCESSVERTICES_DATA( D3DPROCESSVERTICES_COPY, 0, 1, lpPointer ); - - D3D_num_verts = 0; - D3D_ex_ptr = lpPointer; - D3D_ex_end = (void *)((uint)lpBufStart + Exb_size - 1024); - D3D_vertices = (D3DTLVERTEX *)lpBufStart; - return; - - -D3DError: - // Reset everything - if ( lpExBuf ) { - lpExBuf->Release(); - lpExBuf = NULL; - } - gr_d3d_cleanup(); - exit(1); - */ -} - -HRESULT set_wbuffer_planes(LPDIRECT3DDEVICE2 lpDev, float dvWNear, float dvWFar) -{ - HRESULT res; - D3DMATRIX matWorld; - D3DMATRIX matView; - D3DMATRIX matProj; - - memset(&matWorld, 0, sizeof(matWorld)); - memset(&matView, 0, sizeof(matWorld)); - memset(&matProj, 0, sizeof(matWorld)); - matWorld._11 = 1; matWorld._22 = 1; matWorld._33 = 1; matWorld._44 = 1; - matView._11 = 1; matView._22 = 1; matView._33 = 1; matView._44 = 1; - matProj._11 = 1; matProj._22 = 1; matProj._33 = 1; matProj._44 = 1; - - res = lpDev->SetTransform( D3DTRANSFORMSTATE_WORLD, &matWorld ); - if (res) return res; - res = lpDev->SetTransform( D3DTRANSFORMSTATE_VIEW, &matView ); - if (res) return res; - - matProj._43 = 0; - matProj._34 = 1; - matProj._44 = dvWNear; // not used - matProj._33 = dvWNear / (dvWFar - dvWNear) + 1; - - res = lpDev->SetTransform( D3DTRANSFORMSTATE_PROJECTION, &matProj ); - return res; -} - -DCF(wplanes, "") -{ - dc_get_arg(ARG_FLOAT); - float n = Dc_arg_float; - dc_get_arg(ARG_FLOAT); - float f = Dc_arg_float; - set_wbuffer_planes(lpD3DDevice, n, f); -} - -void gr_d3d_exb_flush(int end_of_frame) -{ - /* - HRESULT ddrval; - D3DEXECUTEBUFFERDESC debDesc; - D3DEXECUTEDATA d3dExData; - - if ( DrawPrim ) { - return; - } - - if (!lpExBuf) return; - - OP_EXIT( D3D_ex_ptr ); - - lpPointer = lpInsStart; - OP_PROCESS_VERTICES( 1, lpPointer ); - PROCESSVERTICES_DATA( D3DPROCESSVERTICES_COPY, 0, D3D_num_verts, lpPointer ); - - ddrval = lpExBuf->Unlock(); - if (ddrval != DD_OK ) { - mprintf(( "Failed to unlock the execute buffer!\n" )); - goto D3DError; - } - - memset(&d3dExData, 0, sizeof(D3DEXECUTEDATA)); - d3dExData.dwSize = sizeof(D3DEXECUTEDATA); - d3dExData.dwVertexCount = D3D_num_verts; - d3dExData.dwInstructionOffset = (ULONG)((char*)lpInsStart - (char*)lpBufStart); - d3dExData.dwInstructionLength = (ULONG)((char*)D3D_ex_ptr - (char*)lpInsStart); - -// if (end_of_frame==0) { -// mprintf(( "Flushing execute buffer in frame, %d verts, %d data size!\n", D3D_num_verts, d3dExData.dwInstructionLength )); -// } else if (end_of_frame==2) { -// mprintf(( "Flushing execute buffer in frame, because of VRAM flush!\n" )); -// } - - ddrval = lpExBuf->SetExecuteData(&d3dExData); - if (ddrval != DD_OK ) { - mprintf(( "Failed to SetExecuteData!\n" )); - goto D3DError; - } - - ddrval = lpD3DDeviceEB->Execute( lpExBuf, lpViewport, D3DEXECUTE_UNCLIPPED ); - if (ddrval != DD_OK ) { - mprintf(( "Failed to Execute! nverts=%d\n", D3D_num_verts)); - mprintf(( "(%s)\n", d3d_error_string(ddrval) )); - goto D3DError; - } - - - memset( &debDesc, 0, sizeof( debDesc ) ); - debDesc.dwSize = sizeof( debDesc ); - ddrval = lpExBuf->Lock( &debDesc ); - if ( ddrval != DD_OK ) { - mprintf(( "Failed to lock the execute buffer!\n" )); - goto D3DError; - } - - lpPointer = lpBufStart = lpInsStart = debDesc.lpData; - - lpPointer = (void *)((uint)lpPointer+sizeof(D3DTLVERTEX)*D3D_MAX_VERTS); - lpInsStart = lpPointer; - - OP_PROCESS_VERTICES( 1, lpPointer ); - PROCESSVERTICES_DATA( D3DPROCESSVERTICES_COPY, 0, 1, lpPointer ); - - D3D_num_verts = 0; - D3D_ex_ptr = lpPointer; - D3D_ex_end = (void *)((uint)lpBufStart + Exb_size - 1024); - D3D_vertices = (D3DTLVERTEX *)lpBufStart; - return; - - -D3DError: - // Reset everything - - if ( lpExBuf ) { - lpExBuf->Release(); - lpExBuf = NULL; - } -// gr_d3d_cleanup(); -// exit(1); -*/ -} - - - -HRESULT d3d_SetRenderState( D3DRENDERSTATETYPE dwRenderStateType, DWORD dwRenderState ) -{ - if ( DrawPrim ) { - return lpD3DDevice->SetRenderState(dwRenderStateType, dwRenderState ); - } else { - if ( (uint)D3D_ex_ptr > (uint)D3D_ex_end ) { - gr_d3d_exb_flush(0); - } - OP_STATE_RENDER(1, D3D_ex_ptr); - STATE_DATA(dwRenderStateType, dwRenderState, D3D_ex_ptr); - return DD_OK; - } - -} - -HRESULT d3d_DrawPrimitive( D3DPRIMITIVETYPE dptPrimitiveType, D3DVERTEXTYPE dvtVertexType, LPVOID lpvVertices, DWORD dwVertexCount, DWORD dwFlags ) -{ - if ( DrawPrim ) { - return lpD3DDevice->DrawPrimitive(dptPrimitiveType, dvtVertexType, lpvVertices, dwVertexCount, dwFlags ); - } else { - - switch( dptPrimitiveType ) { - - case D3DPT_TRIANGLEFAN: - if ( dvtVertexType == D3DVT_TLVERTEX ) { - - D3DTLVERTEX *Verts = (D3DTLVERTEX *)lpvVertices; - - if ( D3D_num_verts + dwVertexCount > D3D_MAX_VERTS ) gr_d3d_exb_flush(0); - if ( (uint)D3D_ex_ptr > (uint)D3D_ex_end ) gr_d3d_exb_flush(0); - - D3DTLVERTEX *src_v = &D3D_vertices[D3D_num_verts]; - - int i; - for (i=0; i<(int)dwVertexCount; i++ ) { - *src_v++ = Verts[i]; - } - - // triangle data must be QWORD aligned, so we need to make sure - // that the OP_TRIANGLE_LIST is unaligned! Note that you MUST have - // the braces {} around the OP_NOP since the macro in D3DMACS.H will - // fail if you remove them. - - if ( QWORD_ALIGNED( D3D_ex_ptr ) ) { - OP_NOP( D3D_ex_ptr ); - } - - OP_TRIANGLE_LIST( unsigned short(dwVertexCount-2), D3D_ex_ptr ); - - LPD3DTRIANGLE tri = ( LPD3DTRIANGLE )D3D_ex_ptr; - - for (i=0; i<(int)dwVertexCount-2; i++ ) { - tri->v1 = unsigned short(D3D_num_verts+0); - tri->v2 = unsigned short(D3D_num_verts+i+1); - tri->v3 = unsigned short(D3D_num_verts+i+2); - tri->wFlags = D3DTRIFLAG_EDGEENABLETRIANGLE; - tri++; - - } - D3D_ex_ptr = ( LPVOID )tri; - D3D_num_verts += (int)dwVertexCount; - } - break; - - case D3DPT_LINELIST: - if ( dvtVertexType == D3DVT_TLVERTEX ) { - - D3DTLVERTEX *Verts = (D3DTLVERTEX *)lpvVertices; - - if ( D3D_num_verts + dwVertexCount > D3D_MAX_VERTS ) gr_d3d_exb_flush(0); - if ( (uint)D3D_ex_ptr > (uint)D3D_ex_end ) gr_d3d_exb_flush(0); - - D3DTLVERTEX *src_v = &D3D_vertices[D3D_num_verts]; - - int i; - for (i=0; i<(int)dwVertexCount; i++ ) { - *src_v++ = Verts[i]; - } - - // triangle data must be QWORD aligned, so we need to make sure - // that the OP_TRIANGLE_LIST is unaligned! Note that you MUST have - // the braces {} around the OP_NOP since the macro in D3DMACS.H will - // fail if you remove them. - - if ( QWORD_ALIGNED( D3D_ex_ptr ) ) { - OP_NOP( D3D_ex_ptr ); - } - - ushort nlines = ushort(dwVertexCount/2); - - OP_LINE_LIST( nlines, D3D_ex_ptr ); - - for (i=0; i<(int)nlines; i++ ) { - LPD3DLINE line = (LPD3DLINE )D3D_ex_ptr; - line->v1 = unsigned short(D3D_num_verts); - line->v2 = unsigned short(D3D_num_verts+1); - D3D_ex_ptr = (void *)(((LPD3DLINE)D3D_ex_ptr) + 1); - } - - D3D_num_verts += (int)dwVertexCount; - } - break; - } - return DD_OK; - } -} - -volatile int D3D_running = 0; -volatile int D3D_activate = 0; -volatile int D3D_deactivate = 0; - -void gr_d3d_activate(int active) -{ - if ( !D3D_running ) { - return; - } - mprintf(( "Direct3D activate: %d\n", active )); - - HWND hwnd = (HWND)os_get_window(); - - if ( active ) { - D3D_activate++; - - if ( hwnd ) { - ClipCursor(&D3D_cursor_clip_rect); - ShowWindow(hwnd,SW_RESTORE); - } - } else { - D3D_deactivate++; - - if ( hwnd ) { - ClipCursor(NULL); - ShowWindow(hwnd,SW_MINIMIZE); - } - } -} - - -void d3d_start_frame() -{ - HRESULT ddrval; - - if (!D3D_inited) return; - - if ( In_frame < 0 || In_frame > 1 ) { - mprintf(( "Start frame error! (%d)\n", In_frame )); - return; - } - if ( In_frame == 1 ) return; - -// gr_d3d_clear_surface(lpBackBuffer, 0.0f, 0.0f, 0.0f); - - In_frame++; - - ddrval = lpD3DDevice->BeginScene(); - if (ddrval != D3D_OK ) { - //mprintf(( "Failed to begin scene!\n%s\n", d3d_error_string(ddrval) )); - return; - } - - -} - - -void d3d_stop_frame() -{ - HRESULT ddrval; - - if (!D3D_inited) return; - - if ( In_frame < 0 || In_frame > 1 ) { - mprintf(( "Stop frame error! (%d)\n", In_frame )); - return; - } - - if ( In_frame == 0 ) return; - - gr_d3d_exb_flush(1); - - In_frame--; - - ddrval = lpD3DDevice->EndScene(); - if (ddrval != D3D_OK ) { - //mprintf(( "Failed to end scene!\n%s\n", d3d_error_string(ddrval) )); - return; - } - -} - -void d3d_flush() -{ - d3d_stop_frame(); - d3d_start_frame(); -} - -static void d3d_dump_format(DDPIXELFORMAT *pf) -{ - unsigned long m; - int r, g, b, a; - for (r = 0, m = pf->dwRBitMask; !(m & 1); r++, m >>= 1); - for (r = 0; m & 1; r++, m >>= 1); - for (g = 0, m = pf->dwGBitMask; !(m & 1); g++, m >>= 1); - for (g = 0; m & 1; g++, m >>= 1); - for (b = 0, m = pf->dwBBitMask; !(m & 1); b++, m >>= 1); - for (b = 0; m & 1; b++, m >>= 1); - if ( pf->dwFlags & DDPF_ALPHAPIXELS ) { - for (a = 0, m = pf->dwRGBAlphaBitMask; !(m & 1); a++, m >>= 1); - for (a = 0; m & 1; a++, m >>= 1); - mprintf(( "ARGB, %d:%d:%d:%d\n", a, r, g, b )); - } else { - a = 0; - mprintf(( "RGB, %d:%d:%d\n", r, g, b )); - } -} - -int D3D_found_1555_tex = 0; -int D3D_found_565_tex = 0; -static HRESULT WINAPI EnumTextureFormatsCallback(LPDDSURFACEDESC lpDDSD, LPVOID lpContext) -{ - if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXEDTO8) { - mprintf(( "Palettized to an 8 bpp palette\n" )); - } - - if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) { - mprintf(( "Palettized 8 bpp\n" )); -// TextureFormat = *lpDDSD; -// mprintf(( " ^-- And I'm using this one!\n" )); - } else if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED4) { - mprintf(( "Palettized 4 bpp\n" )); - return DDENUMRET_OK; - } else if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED2) { - mprintf(( "Palettized 2 bpp\n" )); - return DDENUMRET_OK; - } else if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED1) { - mprintf(( "Palettized 1 bpp\n" )); - } else if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_ALPHA ) { - mprintf(( "Alpha something or other\n" )); - return DDENUMRET_OK; - } else if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_YUV ) { - mprintf(( "YUV?\n" )); - return DDENUMRET_OK; - } else if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_ZBUFFER ) { - mprintf(( "ZBUFFER?\n" )); - return DDENUMRET_OK; - } else if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_COMPRESSED ) { - mprintf(( "Compressed?\n" )); - return DDENUMRET_OK; - } else if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_FOURCC) { - mprintf(( "FourCC?\n" )); - return DDENUMRET_OK; - } else { - unsigned long m; - int r, g, b, a; - for (r = 0, m = lpDDSD->ddpfPixelFormat.dwRBitMask; !(m & 1) && (r < 32); r++, m >>= 1); - for (r = 0; m & 1; r++, m >>= 1); - for (g = 0, m = lpDDSD->ddpfPixelFormat.dwGBitMask; !(m & 1) && (g < 32); g++, m >>= 1); - for (g = 0; m & 1; g++, m >>= 1); - for (b = 0, m = lpDDSD->ddpfPixelFormat.dwBBitMask; !(m & 1) && (b < 32); b++, m >>= 1); - for (b = 0; m & 1; b++, m >>= 1); - if ( lpDDSD->ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS ) { - for (a = 0, m = lpDDSD->ddpfPixelFormat.dwRGBAlphaBitMask; !(m & 1) && (a < 32); a++, m >>= 1); - for (a = 0; m & 1; a++, m >>= 1); - mprintf(( "ARGB, %d:%d:%d:%d\n", a, r, g, b )); - } else { - a = 0; - mprintf(( "RGB, %d:%d:%d\n", r, g, b )); - } - - // if we found a nice 1555 texture format - if( (r == 5) && (g == 5) && (b == 5) && (a == 1)){ - Largest_rgb = 15; - NonAlphaTextureFormat_1555 = lpDDSD->ddpfPixelFormat; - NonAlphaTextureFormat = lpDDSD->ddpfPixelFormat; - D3D_found_1555_tex = 1; - } - // 565 textures - else if ( (r == 5) && (g == 6) && (b == 5) ){ - NonAlphaTextureFormat_565 = lpDDSD->ddpfPixelFormat; - D3D_found_565_tex = 1; - } - // otherwise keep looking - else if(!D3D_found_1555_tex) { - //if ( (r==4) && (g==4) && (b==4) && (a==4) && (lpDDSD->ddpfPixelFormat.dwRGBBitCount==16) ) { - if ( (r>0) && (g>0) && (b>0) && (lpDDSD->ddpfPixelFormat.dwRGBBitCount==16) ) { - if ( r+g+b > Largest_rgb ) { - Largest_rgb = r+g+b; - NonAlphaTextureFormat = lpDDSD->ddpfPixelFormat; - } - } - } - - // HACK!!! Some 3dfx cards (Allender, Whiteside, Johnson) choose - // ARGB=8:3:3:2 as a texture format but when you go to create a surface - // in system RAM with this format, it fails, saying invalid surface format... - // So I'll just force 4:4:4:4 which seems to work on all cards I've seen. - if ( (a>0) && (a<8) && (lpDDSD->ddpfPixelFormat.dwRGBBitCount<=16) ) { - if ( a > Largest_alpha ) { - Largest_alpha = a; - AlphaTextureFormat = lpDDSD->ddpfPixelFormat; - } - } - - } - return DDENUMRET_OK; -} - -HRESULT WINAPI gr_d3d_enum( LPGUID lpGUID, - LPSTR lpDeviceDescription, - LPSTR lpDeviceName, - LPD3DDEVICEDESC lpHWDesc, - LPD3DDEVICEDESC lpHELDesc, - LPVOID lpContext ) -{ - int use_it = 0; - -// mprintf(( "Found 3d device %s: %s\n", lpDeviceName, lpDeviceDescription )); - - if ( lpHWDesc && lpHWDesc->dwFlags != 0 ) { - use_it = 1; - } //else if ( lpHELDesc ) { - - - if ( use_it ) { - d3d_device *d2d = (d3d_device *)lpContext; - d3d_device *d3d = (d3d_device *)&D3D_devices[Num_d3d_devices++]; - - if ( lpGUID ) { - memmove( &d3d->guid_3d, lpGUID, sizeof(GUID) ); - d3d->pguid_3d = &d3d->guid_3d; - } else { - memset( &d3d->guid_3d, 0, sizeof(GUID) ); - d3d->pguid_3d = NULL; - } - - memmove( &d3d->guid_2d, &d2d->guid_2d, sizeof(GUID) ); - if ( d2d->pguid_2d ) { - d3d->pguid_2d = &d3d->guid_2d; - } else { - d3d->pguid_2d = NULL; - } - - //strcpy( d3d->name, lpDeviceName ); - //strcat( d3d->name, " - " ); - strcpy( d3d->name, NOX("Direct 3D - ") ); - strcat( d3d->name, d2d->name ); - //strcat( d3d->name, lpDeviceDescription ); - } - - return D3DENUMRET_OK; -} - -BOOL WINAPI gr_d2d_enum( LPGUID lpGUID, - LPSTR lpDeviceDescription, - LPSTR lpDeviceName, - LPVOID lpContext ) -{ - d3d_device *d2d = (d3d_device *)&D2D_devices[Num_d2d_devices++]; - -// mprintf(( "Found 2d device %s: %s\n", lpDeviceName, lpDeviceDescription )); - - if ( lpGUID ) { - memmove( &d2d->guid_2d, lpGUID, sizeof(GUID) ); - d2d->pguid_2d = &d2d->guid_2d; - } else { - memset( &d2d->guid_2d, 0, sizeof(GUID) ); - d2d->pguid_2d = NULL; - } - - strcpy( d2d->name, lpDeviceDescription ); -// strcat( d2d->name, lpDeviceName ); - - return D3DENUMRET_OK; -} - -d3d_device *d3d_poll_devices() -{ - int i; - HRESULT ddrval; - - Num_d2d_devices = 0; - Num_d3d_devices = 0; - - ddrval = DirectDrawEnumerate( gr_d2d_enum, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_D3D_INIT: DirectDrawEnumerate failed.\n" )); - goto D3DError; - } - - for ( i=0; ipguid_2d, &lpDD1, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_D3D_INIT: DirectDrawCreate failed.\n" )); - goto D3DError; - } - - ddrval = lpDD1->QueryInterface( IID_IDirect3D2, ( LPVOID *) &lpD3D ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_D3D_INIT: QueryInterface failed.\n" )); - goto D3DError; - } - - ddrval = lpD3D->EnumDevices(gr_d3d_enum, d2d ); - if ( ddrval != DD_OK ) { - mprintf(( "WIN_DD32: D3D enum devices failed. (0x%x)\n", ddrval )); - } - - lpD3D->Release(); - lpD3D = NULL; - - lpDD1->Release(); - lpDD1 = NULL; - } - - for ( i=0; i 0 ) { - //mprintf(( "More than one D3D device found!\n" )); - - char *name = os_config_read_string( NULL, "VideoCard", NULL ); - - if ( name && (strlen(name)>0) ) { - for ( i=0; iCreateSurface( &ddsd, &lpFrontBuffer, NULL ); - if ( ddrval != DD_OK ) { - // mprintf(( "GR_D3D_INIT: CreateSurface (Front) failed.\n" )); - strcpy(Device_init_error, "CreateSurface (Front) failed."); - return 0; - } - - // create a clipper and a backbuffer in windowed mode - if(D3D_window){ - // create a clipper for windowed mode - LPDIRECTDRAWCLIPPER pcClipper; - HRESULT hr = lpDD->CreateClipper(0, &pcClipper, NULL); - if(hr != DD_OK){ - return 0; - } - - // Associate the clipper with our window. - pcClipper->SetHWnd(0, (HWND)os_get_window()); - lpFrontBuffer->SetClipper(pcClipper); - pcClipper->Release(); - - // backbuffer - ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; - ddsd.dwWidth = gr_screen.max_w; - ddsd.dwHeight = gr_screen.max_h; - hr = lpDD->CreateSurface(&ddsd, &lpBackBuffer, NULL); - if(hr != DD_OK){ - strcpy(Device_init_error, "Windowed backbuffer create failed."); - return 0; - } - } - // backbuffer is already created for us in fullscreen mode - else { - ddscaps.dwCaps = DDSCAPS_BACKBUFFER; - ddrval = lpFrontBuffer->GetAttachedSurface( &ddscaps, &lpBackBuffer ); - if ( ddrval != DD_OK ) { - // mprintf(( "GR_D3D_INIT: GetAttachedSurface (Back) failed.\n" )); - strcpy(Device_init_error, "GetAttachedSurface (Back) failed."); - return 0; - } - } - } - - // Create a z-buffer and attach it to the backbuffer - { - DDSURFACEDESC ddsd; - - memset( &ddsd, 0, sizeof( ddsd ) ); - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_ZBUFFERBITDEPTH; - ddsd.dwWidth = gr_screen.max_w; - ddsd.dwHeight = gr_screen.max_h; - ddsd.dwZBufferBitDepth = 16; - - ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY; - if (lpDD->CreateSurface(&ddsd, &lpZBuffer, NULL) != DD_OK) { - // mprintf(( "GR_D3D_INIT: Create Zbuffer failed.\n" )); - strcpy(Device_init_error, "Create Zbuffer failed."); - return 0; - } - - if (lpBackBuffer->AddAttachedSurface(lpZBuffer) != DD_OK) { - // mprintf(( "GR_D3D_INIT: Attach Zbuffer failed.\n" )); - strcpy(Device_init_error, "Attach Zbuffer failed."); - return 0; - } - } - - // blit all the buffers clear - if(clear){ - // Clear the surface - DDBLTFX ddBltFx; - ddBltFx.dwSize = sizeof(DDBLTFX); - ddBltFx.dwFillColor = 0; - lpFrontBuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &ddBltFx); - lpBackBuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &ddBltFx); - } - - // Create the D3D device - lpD3DDevice = NULL; - ddrval = lpD3D->CreateDevice( D3D_device->guid_3d, lpBackBuffer, &lpD3DDevice ); - if ( ddrval != DD_OK ) { - // mprintf(( "GR_D3D_INIT: Create D3D Device2 failed. %s\n", d3d_error_string(ddrval) )); - sprintf(Device_init_error, "Create D3D Device2 failed. %s\n", d3d_error_string(ddrval)); - return 0; - } - - // Create and add viewport - ddrval = lpD3D->CreateViewport( &lpViewport, NULL ); - if ( ddrval != DD_OK ) { - // mprintf(( "GR_D3D_INIT: CreateViewport failed.\n" )); - strcpy(Device_init_error, "CreateViewport failed."); - return 0; - } - - ddrval = lpD3DDevice->AddViewport( lpViewport ); - if ( ddrval != DD_OK ) { - // mprintf(( "GR_D3D_INIT: AddViewport failed.\n" )); - strcpy(Device_init_error, "CreateViewport failed."); - return 0; - } - - - // Setup the viewport for a reasonable viewing area - D3DVIEWPORT viewdata; - DWORD largest_side; - - memset( &viewdata, 0, sizeof( viewdata ) ); - - // Compensate for aspect ratio - if ( gr_screen.max_w > gr_screen.max_h ){ - largest_side = gr_screen.max_w; - } else { - largest_side = gr_screen.max_h; - } - - // this sets up W data so the fogging can work - extern float z_mult; - set_wbuffer_planes(lpD3DDevice, 0.0f, z_mult); - - viewdata.dwSize = sizeof( viewdata ); - viewdata.dwX = viewdata.dwY = 0; - viewdata.dwWidth = gr_screen.max_w; - viewdata.dwHeight = gr_screen.max_h; - viewdata.dvScaleX = largest_side / 2.0F; - viewdata.dvScaleY = largest_side / 2.0F; - viewdata.dvMaxX = ( float ) ( viewdata.dwWidth / ( 2.0F * viewdata.dvScaleX ) ); - viewdata.dvMaxY = ( float ) ( viewdata.dwHeight / ( 2.0F * viewdata.dvScaleY ) ); - viewdata.dvMinZ = 0.0f; - viewdata.dvMaxZ = 1.0f; // choose something appropriate here! - - ddrval = lpViewport->SetViewport( &viewdata ); - if ( ddrval != DD_OK ) { - // mprintf(( "GR_D3D_INIT: SetViewport failed.\n" )); - strcpy(Device_init_error, "SetViewport failed."); - return 0; - } - - ddrval = lpD3DDevice->SetCurrentViewport(lpViewport ); - if ( ddrval != DD_OK ) { - // mprintf(( "GR_D3D_INIT: SetCurrentViewport failed.\n" )); - strcpy(Device_init_error, "SetCurrentViewport failed."); - return 0; - } - - return 1; -} - -void gr_d3d_release_rendering_objects() -{ - if ( lpViewport ) { - lpViewport->Release(); - lpViewport = NULL; - } - - if ( lpD3DDevice ) { - lpD3DDevice->Release(); - lpD3DDevice = NULL; - } - - if (lpZBuffer) { - lpZBuffer->Release(); - lpZBuffer = NULL; - } - - if (lpBackBuffer) { - lpBackBuffer->Release(); - lpBackBuffer = NULL; - } - - if (lpFrontBuffer) { - lpFrontBuffer->Release(); - lpFrontBuffer = NULL; - } -} - -void gr_d3d_set_initial_render_state() -{ - d3d_SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE ); - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREMIN, D3DFILTER_LINEAR ); - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREMAG, D3DFILTER_LINEAR ); - d3d_SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD ); - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE ); - d3d_SetRenderState(D3DRENDERSTATE_SPECULARENABLE, FALSE ); -} - -void gr_d3d_init_device(int screen_width, int screen_height) -{ - HRESULT ddrval; - HWND hwnd; - - if ( os_config_read_uint( NULL, NOX("D3DUseExecuteBuffers"), 0 )) { - DrawPrim = 0; - } else { - DrawPrim = 1; - } - - os_suspend(); - d3d_device *dd = d3d_poll_devices(); - os_resume(); - if (!dd ) { - // Error( LOCATION, "No Direct3D devices found!\n" ); - strcpy(Device_init_error, "No Direct3D devices found!"); - goto D3DError; - } - - // Let things catch up.... -// Sleep(1000); - - hwnd = (HWND)os_get_window(); - if ( !hwnd ) { - // mprintf(( "gr_d3d_init_device: No window handle.\n" )); - strcpy(Device_init_error, "Could not get application window handle"); - return; - } - - // windowed - if(D3D_window){ - SetWindowPos(hwnd, HWND_TOP, 0, 0, gr_screen.max_w, gr_screen.max_h, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_DRAWFRAME); - SetForegroundWindow(hwnd); - SetActiveWindow(hwnd); - - D3D_cursor_clip_rect.left = 0; - D3D_cursor_clip_rect.top = 0; - D3D_cursor_clip_rect.right = gr_screen.max_w-1; - D3D_cursor_clip_rect.bottom = gr_screen.max_h-1; - } else { - // Prepare the window to go full screen - #ifndef NDEBUG - mprintf(( "Window in debugging mode... mouse clicking may cause problems!\n" )); - SetWindowLong( hwnd, GWL_EXSTYLE, 0 ); - SetWindowLong( hwnd, GWL_STYLE, WS_POPUP ); - ShowWindow(hwnd, SW_SHOWNORMAL ); - RECT work_rect; - SystemParametersInfo( SPI_GETWORKAREA, 0, &work_rect, 0 ); - SetWindowPos( hwnd, HWND_TOPMOST, work_rect.left, work_rect.top, gr_screen.max_w, gr_screen.max_h, 0 ); - SetActiveWindow(hwnd); - SetForegroundWindow(hwnd); - D3D_cursor_clip_rect.left = work_rect.left; - D3D_cursor_clip_rect.top = work_rect.top; - D3D_cursor_clip_rect.right = work_rect.left + gr_screen.max_w - 1; - D3D_cursor_clip_rect.bottom = work_rect.top + gr_screen.max_h - 1; - #else - SetWindowLong( hwnd, GWL_EXSTYLE, 0 ); - SetWindowLong( hwnd, GWL_STYLE, WS_POPUP ); - ShowWindow(hwnd, SW_SHOWNORMAL ); - // SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, GetSystemMetrics( SM_CXSCREEN ), GetSystemMetrics( SM_CYSCREEN ), 0 ); - SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, gr_screen.max_w, gr_screen.max_h, 0 ); - SetActiveWindow(hwnd); - SetForegroundWindow(hwnd); - D3D_cursor_clip_rect.left = 0; - D3D_cursor_clip_rect.top = 0; - D3D_cursor_clip_rect.right = gr_screen.max_w-1; - D3D_cursor_clip_rect.bottom = gr_screen.max_h-1; - #endif - } - - // active d3d device - D3D_device = dd; - - os_suspend(); - ddrval = DirectDrawCreate( dd->pguid_2d, &lpDD1, NULL ); - os_resume(); - if ( ddrval != DD_OK ) { - // mprintf(( "GR_D3D_INIT: DirectDrawCreate failed.\n" )); - strcpy(Device_init_error, "DirectDrawCreate failed"); - goto D3DError; - } - - ddrval = lpDD1->QueryInterface(IID_IDirectDraw2, (LPVOID *)&lpDD); - if(ddrval != DD_OK) { - // mprintf(( "GR_D3D_INIT: DirectDrawCreate2 failed.\n" )); - strcpy(Device_init_error, "DirectDrawCreate2 failed"); - goto D3DError; - } - - if(D3D_window){ - ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_NORMAL ); - } else { - ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_NOWINDOWCHANGES ); - } - if ( ddrval != DD_OK ) { - // mprintf(( "GR_D3D_INIT: SetCooperativeLevel EXCLUSIVE failed.\n" )); - strcpy(Device_init_error, "SetCooperativeLevel EXCLUSIVE failed."); - goto D3DError; - } - - // Go to full screen! - if(!D3D_window){ - os_suspend(); - ddrval = lpDD->SetDisplayMode( screen_width, screen_height, gr_screen.bits_per_pixel, 0, 0 ); - os_resume(); - if ( ddrval != DD_OK ) { - // mprintf(( "GR_D3D_INIT: SetDisplayMode failed.\n" )); - strcpy(Device_init_error, "SetDisplayMode failed."); - goto D3DError; - } - } - - gr_d3d_clip_cursor(1); - - ddrval = lpDD->QueryInterface( IID_IDirect3D2, ( LPVOID *) &lpD3D ); - if ( ddrval != DD_OK ) { - // mprintf(( "GR_D3D_INIT: QueryInterface failed.\n" )); - strcpy(Device_init_error, "QueryInterface failed."); - goto D3DError; - } - - // create all surfaces here - if(!gr_d3d_create_rendering_objects(1)){ - goto D3DError; - } - - { - extern void dd_get_shift_masks( DDSURFACEDESC *ddsd ); - DDSURFACEDESC ddsd; - memset( &ddsd, 0, sizeof( ddsd ) ); - ddsd.dwSize = sizeof(ddsd); - lpBackBuffer->GetSurfaceDesc(&ddsd); - dd_get_shift_masks( &ddsd ); - ScreenFormat = ddsd.ddpfPixelFormat; - } - - // if we're in windowed mode, fill in bits per pixel and bytes per pixel here - if(D3D_window){ - gr_screen.bits_per_pixel = ScreenFormat.dwRGBBitCount; - gr_screen.bytes_per_pixel = gr_screen.bits_per_pixel / 8; - } - - // Init values so we can choose the largest of each format - Largest_alpha = 0; - Largest_rgb = 0; - D3D_found_1555_tex = 0; - D3D_found_565_tex = 0; - ddrval = lpD3DDevice->EnumTextureFormats(EnumTextureFormatsCallback, NULL ); - if ( ddrval != DD_OK ) { - // mprintf(( "GR_D3D_INIT: EnumTextureFormats failed.\n" )); - strcpy(Device_init_error, "EnumTextureFormats failed."); - goto D3DError; - } - - // if we found our ideal texture, set the global pixel format - if(D3D_found_1555_tex){ - Bm_pixel_format = BM_PIXEL_FORMAT_ARGB_D3D; - } - - if ( Largest_alpha == 0 ) { - gr_d3d_cleanup(); - MessageBox( NULL, XSTR("Alpha channel textures",620), XSTR("Missing Features",621), MB_OK|MB_TASKMODAL|MB_SETFOREGROUND ); - exit(1); - } - if ( Largest_rgb == 0 ) { - gr_d3d_cleanup(); - MessageBox( NULL, XSTR("16-bpp RGB textures",622), XSTR("Missing Features",621), MB_OK|MB_TASKMODAL|MB_SETFOREGROUND ); - exit(1); - } - - // setup texture pixel formats - { - DDPIXELFORMAT *surface_desc; - int s; - // RGB decoder - unsigned long m; - - // Determine the red, green and blue masks' shift and scale. - surface_desc = &NonAlphaTextureFormat; - for (s = 0, m = surface_desc->dwRBitMask; !(m & 1); s++, m >>= 1); - Gr_t_red.mask = surface_desc->dwRBitMask; - Gr_t_red.shift = s; - Gr_t_red.scale = 255 / (surface_desc->dwRBitMask >> s); - for (s = 0, m = surface_desc->dwGBitMask; !(m & 1); s++, m >>= 1); - Gr_t_green.mask = surface_desc->dwRBitMask; - Gr_t_green.shift = s; - Gr_t_green.scale = 255 / (surface_desc->dwGBitMask >> s); - for (s = 0, m = surface_desc->dwBBitMask; !(m & 1); s++, m >>= 1); - Gr_t_blue.mask = surface_desc->dwRBitMask; - Gr_t_blue.shift = s; - Gr_t_blue.scale = 255 / (surface_desc->dwBBitMask >> s); - Gr_t_alpha.mask = surface_desc->dwRGBAlphaBitMask; - if ( surface_desc->dwFlags & DDPF_ALPHAPIXELS ) { - for (s = 0, m = surface_desc->dwRGBAlphaBitMask; !(m & 1); s++, m >>= 1); - Gr_t_alpha.shift = s; - Gr_t_alpha.scale = 255 / (surface_desc->dwRGBAlphaBitMask >> s); - } else { - Gr_t_alpha.shift = 0; - Gr_t_alpha.scale = 256; - } - - // Determine the red, green and blue masks' shift and scale. - surface_desc = &AlphaTextureFormat; - for (s = 0, m = surface_desc->dwRBitMask; !(m & 1); s++, m >>= 1); - Gr_ta_red.mask = surface_desc->dwRBitMask; - Gr_ta_red.shift = s; - Gr_ta_red.scale = 255 / (surface_desc->dwRBitMask >> s); - for (s = 0, m = surface_desc->dwGBitMask; !(m & 1); s++, m >>= 1); - Gr_ta_green.mask = surface_desc->dwRBitMask; - Gr_ta_green.shift = s; - Gr_ta_green.scale = 255 / (surface_desc->dwGBitMask >> s); - for (s = 0, m = surface_desc->dwBBitMask; !(m & 1); s++, m >>= 1); - Gr_ta_blue.mask = surface_desc->dwRBitMask; - Gr_ta_blue.shift = s; - Gr_ta_blue.scale = 255 / (surface_desc->dwBBitMask >> s); - Gr_ta_alpha.mask = surface_desc->dwRGBAlphaBitMask; - if ( surface_desc->dwFlags & DDPF_ALPHAPIXELS ) { - for (s = 0, m = surface_desc->dwRGBAlphaBitMask; !(m & 1); s++, m >>= 1); - Gr_ta_alpha.shift = s; - Gr_ta_alpha.scale = 255 / (surface_desc->dwRGBAlphaBitMask >> s); - } else { - Gr_ta_alpha.shift = 0; - Gr_ta_alpha.scale = 256; - } - } - - mprintf(( "Alpha texture format = " )); - d3d_dump_format(&AlphaTextureFormat); - - mprintf(( "Non-alpha texture format = " )); - d3d_dump_format(&NonAlphaTextureFormat); - - mprintf(( "Screen format = " )); - d3d_dump_format(&ScreenFormat); - -// key_getch(); - - // gr_d3d_exb_init(); - - memset( &D3DHWDevDesc, 0, sizeof( D3DHWDevDesc ) ); - D3DHWDevDesc.dwSize = sizeof(D3DHELDevDesc); - - memset( &D3DHELDevDesc, 0, sizeof( D3DHELDevDesc ) ); - D3DHELDevDesc.dwSize = sizeof(D3DHELDevDesc); - - ddrval = lpD3DDevice->GetCaps( &D3DHWDevDesc, &D3DHELDevDesc ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_D3D_INIT: 3DDevice->GetCaps failed.\n" )); - goto D3DError; - } - lpDevDesc = &D3DHWDevDesc; - - lpDD->GetCaps(&DD_driver_caps,&DD_hel_caps); - - { - int not_good = 0; - - char missing_features[128*1024]; - - strcpy( missing_features, XSTR("Your video card is missing the following features required by FreeSpace:\r\n\r\n",623) ); - - // fog - if ( !(lpDevDesc->dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGVERTEX) && !(lpDevDesc->dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE)){ - strcat( missing_features, XSTR("Vertex fog or Table fog\r\n", 1499) ); - not_good++; - } - - // Texture blending values - if ( !(lpDevDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_MODULATE )) { - strcat( missing_features, XSTR("Texture blending mode = Modulate\r\n", 624) ); - not_good++; - } - - // Source blending values -// if ( !(lpDevDesc->dpcTriCaps.dwSrcBlendCaps & D3DPBLENDCAPS_ONE) ) { -// strcat( missing_features, "Source blending mode = ONE\r\n" ); -// not_good++; -// } - - if ( !(lpDevDesc->dpcTriCaps.dwSrcBlendCaps & (D3DPBLENDCAPS_SRCALPHA|D3DPBLENDCAPS_BOTHSRCALPHA)) ) { - strcat( missing_features, XSTR("Source blending mode = SRCALPHA or BOTHSRCALPHA\r\n", 625) ); - not_good++; - } - -// if ( !(lpDevDesc->dpcTriCaps.dwDestBlendCaps & D3DPBLENDCAPS_ZERO ) ) { -// strcat( missing_features, "Destination blending mode = ZERO\r\n" ); -// not_good++; -// } - -// if ( !(lpDevDesc->dpcTriCaps.dwDestBlendCaps & D3DPBLENDCAPS_ONE ) ) { -// strcat( missing_features, "Destination blending mode = ONE\r\n" ); -// not_good++; -// } - - // Dest blending values - if ( !(lpDevDesc->dpcTriCaps.dwDestBlendCaps & (D3DPBLENDCAPS_INVSRCALPHA|D3DPBLENDCAPS_BOTHINVSRCALPHA)) ) { - strcat( missing_features, XSTR("Destination blending mode = INVSRCALPHA or BOTHINVSRCALPHA\r\n",626) ); - not_good++; - } - - // If card is Mystique 220, turn off modulaalpha since it doesn't work... - if ( Largest_alpha < 4 ) { - lpDevDesc->dpcTriCaps.dwTextureBlendCaps &= (~D3DPTBLENDCAPS_MODULATEALPHA); - } - - if ( not_good ) { - gr_d3d_cleanup(); - MessageBox( NULL, missing_features, XSTR("Missing Features",621), MB_OK|MB_TASKMODAL|MB_SETFOREGROUND ); - exit(1); - } - } - - // fog info - for now we'll prefer table fog over vertex fog - D3D_fog_mode = 1; - // if the user wants to force w-fog, maybe do it - if(os_config_read_uint(NULL, "ForceWFOG", 0) && (lpDevDesc->dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE)){ - D3D_fog_mode = 2; - } - // if the card does not have vertex fog, but has table fog, let it go - if(!(lpDevDesc->dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGVERTEX) && (lpDevDesc->dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE)){ - D3D_fog_mode = 2; - } - - { - DDSCAPS ddsCaps; - DWORD dwFree, dwTotal; - - memset(&ddsCaps,0,sizeof(ddsCaps) ); - ddsCaps.dwCaps = DDSCAPS_TEXTURE; - HRESULT ddrval = lpDD->GetAvailableVidMem(&ddsCaps, &dwTotal, &dwFree); - if ( ddrval != DD_OK ) { - mprintf(( "GR_D3D_INIT: GetAvailableVidMem failed.\n" )); - dwFree = 0; - } - - if ( dwFree < (1024*1024) ) { - gr_d3d_cleanup(); - MessageBox( NULL, XSTR("At least 1 MB of available video memory required.",627), XSTR("Missing Features",621), MB_OK|MB_TASKMODAL|MB_SETFOREGROUND ); - exit(1); - } - } - - // setup proper render state - gr_d3d_set_initial_render_state(); - - mprintf(( "Direct3D Initialized OK!\n" )); - - D3D_inited = 1; - return; - -D3DError: - mprintf(( "Direct3D Initialization failed.\n" )); - - gr_d3d_cleanup(); -} - - -int Gr_d3d_mouse_saved = 0; -int Gr_d3d_mouse_saved_x1 = 0; -int Gr_d3d_mouse_saved_y1 = 0; -int Gr_d3d_mouse_saved_x2 = 0; -int Gr_d3d_mouse_saved_y2 = 0; -int Gr_d3d_mouse_saved_w = 0; -int Gr_d3d_mouse_saved_h = 0; -#define MAX_SAVE_SIZE (32*32) -ushort Gr_d3d_mouse_saved_data[MAX_SAVE_SIZE]; - -// Clamps X between R1 and R2 -#define CLAMP(x,r1,r2) do { if ( (x) < (r1) ) (x) = (r1); else if ((x) > (r2)) (x) = (r2); } while(0) - -void gr_d3d_save_mouse_area(int x, int y, int w, int h ) -{ - // bail in 32 bit - if(D3D_32bit){ - return; - } - - Gr_d3d_mouse_saved_x1 = x; - Gr_d3d_mouse_saved_y1 = y; - Gr_d3d_mouse_saved_x2 = x+w-1; - Gr_d3d_mouse_saved_y2 = y+h-1; - - CLAMP(Gr_d3d_mouse_saved_x1, gr_screen.clip_left, gr_screen.clip_right ); - CLAMP(Gr_d3d_mouse_saved_x2, gr_screen.clip_left, gr_screen.clip_right ); - CLAMP(Gr_d3d_mouse_saved_y1, gr_screen.clip_top, gr_screen.clip_bottom ); - CLAMP(Gr_d3d_mouse_saved_y2, gr_screen.clip_top, gr_screen.clip_bottom ); - - Gr_d3d_mouse_saved_w = Gr_d3d_mouse_saved_x2 - Gr_d3d_mouse_saved_x1 + 1; - Gr_d3d_mouse_saved_h = Gr_d3d_mouse_saved_y2 - Gr_d3d_mouse_saved_y1 + 1; - - if ( Gr_d3d_mouse_saved_w < 1 ) return; - if ( Gr_d3d_mouse_saved_h < 1 ) return; - - // Make sure we're not saving too much! - SDL_assert( (Gr_d3d_mouse_saved_w*Gr_d3d_mouse_saved_h) <= MAX_SAVE_SIZE ); - - HRESULT ddrval; - DDSURFACEDESC ddsd; - - memset( &ddsd, 0, sizeof( ddsd ) ); - ddsd.dwSize = sizeof( ddsd ); - - ddrval = lpBackBuffer->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ); - if ( ddrval == DD_OK ) { - - ushort *rptr; - int short_per_row=ddsd.lPitch/2; - - rptr = (ushort *)ddsd.lpSurface; - - ushort *sptr, *dptr; - - dptr = Gr_d3d_mouse_saved_data; - - for (int i=0; iUnlock( NULL ); - - Gr_d3d_mouse_saved = 1; - - } else { - mprintf(( "Couldn't get read-only lock to backbuffer for d3d mouse save\n" )); - } - -} - - -void gr_d3d_flip() -{ - int mx, my; - HRESULT ddrval; - - - gr_reset_clip(); - - mouse_eval_deltas(); - - Gr_d3d_mouse_saved = 0; // assume not saved - - if(!Gr_bitmap_poly){ - d3d_stop_frame(); - } - - if ( mouse_is_visible() ) { - gr_reset_clip(); - mouse_get_pos( &mx, &my ); - - gr_d3d_save_mouse_area(mx,my,32,32); - if ( Gr_cursor == -1 ) { - #ifndef NDEBUG - gr_set_color(255,255,255); - gr_line( mx, my, mx+7, my + 7 ); - gr_line( mx, my, mx+5, my ); - gr_line( mx, my, mx, my+5 ); - #endif - } else { - gr_set_bitmap(Gr_cursor); - gr_bitmap( mx, my ); - } - } - - // Move stop frame before drawing cursor so cursor always appears on PowerVR. - if(Gr_bitmap_poly){ - d3d_stop_frame(); - } - -// ddrval = lpFrontBuffer->Flip( NULL, 1 ); -// if (ddrval != DD_OK ) { -// mprintf(( "Fullscreen flip failed!\n" )); -// return; -// } - - if(D3D_window){ - // blt region - RECT rect, view_rect; - GetClientRect( (HWND)os_get_window(), &rect); - ClientToScreen( (HWND)os_get_window(), (POINT*)&rect.left ); - ClientToScreen( (HWND)os_get_window(), (POINT*)&rect.right ); - view_rect.left = 0; - view_rect.top = 0; - view_rect.right = gr_screen.max_w - 1; - view_rect.bottom = gr_screen.max_h - 1; - - // do the blit - lpFrontBuffer->Blt(&rect, lpBackBuffer, &view_rect, 0, NULL ); - while(lpFrontBuffer->GetBltStatus(DDGBS_ISBLTDONE) != DD_OK){} - } else { - TryFlipAgain: - if ( lpFrontBuffer->IsLost() == DDERR_SURFACELOST ) { - lpFrontBuffer->Restore(); - } - if ( lpBackBuffer->IsLost() == DDERR_SURFACELOST ) { - lpBackBuffer->Restore(); - } - if ( lpZBuffer->IsLost() == DDERR_SURFACELOST ) { - lpZBuffer->Restore(); - } - ddrval = lpFrontBuffer->Flip( NULL, DDFLIP_WAIT ); - if ( ddrval == DDERR_SURFACELOST ) { - mprintf(( "Front surface lost... attempting to restore...\n" )); - os_sleep(1000); // Wait a second - - // os poll? - #ifndef THREADED - os_poll(); - #endif - - goto TryFlipAgain; - } else if (ddrval != DD_OK ) { - mprintf(( "Fullscreen flip failed!\n" )); - } - } - - d3d_tcache_frame(); - - int cnt = D3D_activate; - if ( cnt ) { - D3D_activate-=cnt; - d3d_tcache_flush(); - gr_d3d_clip_cursor(1); - } - - cnt = D3D_deactivate; - if ( cnt ) { - D3D_deactivate-=cnt; - gr_d3d_clip_cursor(0); - } - - d3d_start_frame(); -} - -void gr_d3d_flip_cleanup() -{ - d3d_stop_frame(); - - if (lpFrontBuffer->Flip( NULL, 1 ) != DD_OK ) { - mprintf(( "Flip failed!\n" )); - return; - } -} - - -void gr_d3d_flip_window(uint _hdc, int x, int y, int w, int h ) -{ -} - -void gr_d3d_cleanup() -{ - if (!D3D_inited) return; - - d3d_tcache_cleanup(); - - // release surfaces - gr_d3d_release_rendering_objects(); - - if ( lpD3D ) { - lpD3D->Release(); - lpD3D = NULL; - } - - if ( lpDD1 ) { - - HRESULT ddrval; - HWND hwnd = (HWND)os_get_window(); - - ddrval = lpDD->RestoreDisplayMode(); - if( ddrval != DD_OK ) { - mprintf(( "WIN_DD32: RestoreDisplayMode failed (0x%x)\n", ddrval )); - } - - ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_NORMAL ); - if( ddrval != DD_OK ) { - mprintf(( "WIN_DD32: SetCooperativeLevel W Failed (0x%x)\n", ddrval )); - } - - // restore windows clipping rectangle - ClipCursor(NULL); - -// SetWindowLong( hwnd, GWL_STYLE, WS_CAPTION | WS_SYSMENU ); -// SetWindowLong( hwnd, GWL_EXSTYLE, 0 ); -// SetWindowPos( hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE ); - - // gr_d3d_clip_cursor(0); - - os_suspend(); - lpDD1->Release(); - os_resume(); - lpDD1 = NULL; - } - - D3D_inited = 0; -} - - -void gr_d3d_fade_in(int instantaneous) -{ -} - -void gr_d3d_fade_out(int instantaneous) -{ -} - - - -void gr_d3d_force_windowed() -{ - HWND hwnd = (HWND)os_get_window(); - - // Simulate Alt+Tab - PostMessage(hwnd,WM_SYSKEYUP, 0x9, 0xa00f0001 ); - PostMessage(hwnd,WM_SYSKEYUP, 0x12, 0xc0380001 ); - - gr_d3d_clip_cursor(0); - - // Wait a second to give things a change to settle down. - Sleep(1000); -} - -static char *Gr_saved_screen = NULL; - -int gr_d3d_save_screen() -{ - gr_reset_clip(); - - if ( Gr_saved_screen ) { - mprintf(( "Screen alread saved!\n" )); - return -1; - } - - Gr_saved_screen = (char*)malloc( gr_screen.max_w * gr_screen.max_h * gr_screen.bytes_per_pixel ); - if (!Gr_saved_screen) { - mprintf(( "Couldn't get memory for saved screen!\n" )); - return -1; - } - - HRESULT ddrval; - DDSURFACEDESC ddsd; - - memset( &ddsd, 0, sizeof( ddsd ) ); - ddsd.dwSize = sizeof( ddsd ); - - ddrval = lpFrontBuffer->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ); - if ( ddrval != DD_OK ) { - free(Gr_saved_screen); - Gr_saved_screen = NULL; - mprintf(( "Error locking surface for save_screen, %s\n", d3d_error_string(ddrval) )); - return -1; - } - - // 32 bit - if(D3D_32bit){ - uint *dptr = (uint*)ddsd.lpSurface; - int i; - for (i=0; iUnlock( NULL ); - - if ( Gr_d3d_mouse_saved && !D3D_32bit) { - ushort *sptr, *dptr; - - sptr = Gr_d3d_mouse_saved_data; - - for (int i=0; iLock( NULL, &ddsd, DDLOCK_WAIT, NULL ); - if ( ddrval != DD_OK ) { - free(Gr_saved_screen); - Gr_saved_screen = NULL; - mprintf(( "Error locking surface for restore_screen, %s\n", d3d_error_string(ddrval) )); - return; - } - - // restore - if(D3D_32bit){ - uint *dptr = (uint *)ddsd.lpSurface; - int i; - for (i=0; iUnlock( NULL ); -} - -void gr_d3d_free_screen(int id) -{ - if ( Gr_saved_screen ) { - free( Gr_saved_screen ); - Gr_saved_screen = NULL; - } -} - -static int D3d_dump_frames = 0; -static ubyte *D3d_dump_buffer = NULL; -static int D3d_dump_frame_number = 0; -static int D3d_dump_frame_count = 0; -static int D3d_dump_frame_count_max = 0; -static int D3d_dump_frame_size = 0; -void gr_d3d_dump_frame_start(int first_frame, int frames_between_dumps) -{ - if ( D3d_dump_frames ) { - Int3(); // We're already dumping frames. See John. - return; - } - D3d_dump_frames = 1; - D3d_dump_frame_number = first_frame; - D3d_dump_frame_count = 0; - D3d_dump_frame_count_max = frames_between_dumps; - D3d_dump_frame_size = gr_screen.max_w * gr_screen.max_h * 2; - - if ( !D3d_dump_buffer ) { - int size = D3d_dump_frame_count_max * D3d_dump_frame_size; - D3d_dump_buffer = (ubyte *)malloc(size); - if ( !D3d_dump_buffer ) { - Error(LOCATION, "Unable to malloc %d bytes for dump buffer", size ); - } - } -} - -extern int tga_compress(char *out, char *in, int bytecount); -void gr_d3d_flush_frame_dump() -{ - int i,j; - char filename[MAX_PATH_LEN], *movie_path = ".\\"; - ubyte outrow[1024*3*4]; - - if ( gr_screen.max_w > 1024) { - mprintf(( "Screen too wide for frame_dump\n" )); - return; - } - - for (i = 0; i < D3d_dump_frame_count; i++) { - - int w = gr_screen.max_w; - int h = gr_screen.max_h; - - sprintf(filename, NOX("%sfrm%04d.tga"), movie_path, D3d_dump_frame_number ); - D3d_dump_frame_number++; - - CFILE *f = cfopen(filename, "wb"); - - // Write the TGA header - cfwrite_ubyte( 0, f ); // IDLength; - cfwrite_ubyte( 0, f ); // ColorMapType; - cfwrite_ubyte( 10, f ); // ImageType; // 2 = 24bpp, uncompressed, 10=24bpp rle compressed - cfwrite_ushort( 0, f ); // CMapStart; - cfwrite_ushort( 0, f ); // CMapLength; - cfwrite_ubyte( 0, f ); // CMapDepth; - cfwrite_ushort( 0, f ); // XOffset; - cfwrite_ushort( 0, f ); // YOffset; - cfwrite_ushort( (ushort)w, f ); // Width; - cfwrite_ushort( (ushort)h, f ); // Height; - cfwrite_ubyte( 24, f ); //PixelDepth; - cfwrite_ubyte( 0, f ); //ImageDesc; - - // Go through and write our pixels - for (j=0;jLock( NULL, &ddsd, DDLOCK_WAIT | DDLOCK_READONLY, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "Error locking surface for get_region, %s\n", d3d_error_string(ddrval) )); - return; - } - - ushort *sptr; - ubyte *rptr = (ubyte*)ddsd.lpSurface; - - for (int i=0; i> 3) << 11); - pixel |= ((g >> 2) << 5); - pixel |= (b >> 3); - - *dst++ = pixel; - } - } - - // Unlock the buffer - surf->Unlock( NULL ); -} - -void gr_d3d_dump_frame() -{ - // A hacked function to dump the frame buffer contents - gr_d3d_dump_screen_hack( (ushort *)(D3d_dump_buffer+(D3d_dump_frame_count*D3d_dump_frame_size)) ); - - D3d_dump_frame_count++; - - if ( D3d_dump_frame_count == D3d_dump_frame_count_max ) { - gr_d3d_flush_frame_dump(); - } -} - -uint gr_d3d_lock() -{ - return 1; -} - -void gr_d3d_unlock() -{ -} - -void gr_d3d_fog_set(int fog_mode, int r, int g, int b, float fog_near, float fog_far) -{ - D3DCOLOR color = 0; - - SDL_assert((r >= 0) && (r < 256)); - SDL_assert((g >= 0) && (g < 256)); - SDL_assert((b >= 0) && (b < 256)); - - // turning fog off - if(fog_mode == GR_FOGMODE_NONE){ - // only change state if we need to - if(gr_screen.current_fog_mode != fog_mode){ - d3d_SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE ); - } - gr_screen.current_fog_mode = fog_mode; - - // to prevent further state changes - return; - } - - // maybe switch fogging on - if(gr_screen.current_fog_mode != fog_mode){ - d3d_SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE); - - // if we're using table fog, enable table fogging - if(D3D_fog_mode == 2){ - d3d_SetRenderState( D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_LINEAR ); - } - - gr_screen.current_fog_mode = fog_mode; - } - - // is color changing? - if( (gr_screen.current_fog_color.red != r) || (gr_screen.current_fog_color.green != g) || (gr_screen.current_fog_color.blue != b) ){ - // store the values - gr_d3d_init_color( &gr_screen.current_fog_color, r, g, b ); - - color = RGB_MAKE(r, g, b); - d3d_SetRenderState(D3DRENDERSTATE_FOGCOLOR, color); - } - - // planes changing? - if( (fog_near >= 0.0f) && (fog_far >= 0.0f) && ((fog_near != gr_screen.fog_near) || (fog_far != gr_screen.fog_far)) ){ - gr_screen.fog_near = fog_near; - gr_screen.fog_far = fog_far; - - // only generate a new fog table if we have to (wfog/table fog mode) - if(D3D_fog_mode == 2){ - d3d_SetRenderState( D3DRENDERSTATE_FOGTABLESTART, *((DWORD *)(&fog_near))); - d3d_SetRenderState( D3DRENDERSTATE_FOGTABLEEND, *((DWORD *)(&fog_far))); - } - } -} - -void gr_d3d_set_gamma(float gamma) -{ - Gr_gamma = gamma; - Gr_gamma_int = int(Gr_gamma*100); - - // Create the Gamma lookup table - int i; - for (i=0; i<256; i++ ) { - int v = fl2i(pow(i2fl(i)/255.0f, 1.0f/Gr_gamma)*255.0f); - if ( v > 255 ) { - v = 255; - } else if ( v < 0 ) { - v = 0; - } - Gr_gamma_lookup[i] = v; - } - - // Flush any existing textures - d3d_tcache_flush(); -} - -void d3d_get_pixel(int x, int y, ubyte *pixel) -{ - HRESULT ddrval; - DDSURFACEDESC ddsd; - - memset( &ddsd, 0, sizeof( ddsd ) ); - ddsd.dwSize = sizeof( ddsd ); - - ddrval = lpFrontBuffer->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "Error locking surface for uv test, %s\n", d3d_error_string(ddrval) )); - return; - } - - ubyte *dptr = (ubyte *)((uint)ddsd.lpSurface + y*ddsd.lPitch + (x * gr_screen.bytes_per_pixel)); - memcpy(pixel, dptr, gr_screen.bytes_per_pixel); - - // Unlock the buffer - lpFrontBuffer->Unlock( NULL ); -} - -void gr_d3d_get_pixel(int x, int y, int *r, int *g, int *b) -{ -} - -// resolution checking -int gr_d3d_supports_res_interface(int res) -{ - return 1; -} - -int gr_d3d_supports_res_ingame(int res) -{ - return 1; -} - -void gr_d3d_set_cull(int cull) -{ - // switch culling on or off - if(cull){ - d3d_SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_CCW ); - } else { - d3d_SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_NONE ); - } -} - -// cross fade -void gr_d3d_cross_fade(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct) -{ - if ( pct <= 50 ) { - gr_set_bitmap(bmap1); - gr_bitmap(x1, y1); - } else { - gr_set_bitmap(bmap2); - gr_bitmap(x2, y2); - } -} - -// filtering -void gr_d3d_filter_set(int filter) -{ -} - -// set clear color -void gr_d3d_set_clear_color(int r, int g, int b) -{ - gr_init_color(&gr_screen.current_clear_color, r, g, b); -} - -// JAS: Need to turn optimizations off or Alan's machine, with 3dfx direct3d hangs... -#pragma optimize("",off) - -void d3d_detect_texture_origin_32() -{ - int test_bmp = -1; - ubyte data[32*32]; - color ac; - uint pix1a, pix2a; - uint pix1b, pix2b; - - mprintf(( "Detecting uv type...\n" )); - - gr_set_gamma(1.0f); - gr_init_alphacolor(&ac,255,255,255,255); - - memset( data, 0, 32*32 ); - data[15*32+15] = 14; - - test_bmp = bm_create( 8, 32, 32, data, BMP_AABITMAP ); - - mprintf(( "Trial #1\n" )); - D3d_rendition_uvs = 0; - gr_reset_clip(); - gr_clear(); - gr_set_color_fast(&ac); - gr_set_bitmap( test_bmp ); - gr_aabitmap_ex(0, 0, 32, 32, 15, 15); - Mouse_hidden++; - gr_flip(); - d3d_get_pixel(0, 0, (ubyte*)&pix1a); - d3d_get_pixel(1, 1, (ubyte*)&pix1b); - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; - - mprintf(( "Trial #2\n" )); - D3d_rendition_uvs = 1; - gr_reset_clip(); - gr_clear(); - gr_set_color_fast(&ac); - gr_set_bitmap( test_bmp ); - gr_aabitmap_ex(0, 0, 32, 32, 15, 15); - Mouse_hidden++; - gr_flip(); - d3d_get_pixel(0, 0, (ubyte*)&pix2a); - d3d_get_pixel(1, 1, (ubyte*)&pix2b); - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; - - bm_release(test_bmp); - - mprintf(( "Pixel 1 = %x , %x\n", pix1a, pix1b )); - mprintf(( "Pixel 2 = %x , %x\n", pix2a, pix2b )); - - if ( (pix1b!=0) || (pix2b!=0) ) { - D3d_rendition_uvs = 1; - } else { - D3d_rendition_uvs = 0; - } - - mprintf(( "Rendition uvs: %d\n", D3d_rendition_uvs )); -} - -void d3d_detect_texture_origin_16() -{ - int test_bmp = -1; - ubyte data[32*32]; - color ac; - ushort pix1a, pix2a; - ushort pix1b, pix2b; - - mprintf(( "Detecting uv type...\n" )); - - gr_set_gamma(1.0f); - gr_init_alphacolor(&ac,255,255,255,255); - - memset( data, 0, 32*32 ); - data[15*32+15] = 14; - - test_bmp = bm_create( 8, 32, 32, data, BMP_AABITMAP ); - - mprintf(( "Trial #1\n" )); - D3d_rendition_uvs = 0; - gr_reset_clip(); - gr_clear(); - gr_set_color_fast(&ac); - gr_set_bitmap( test_bmp ); - gr_aabitmap_ex(0, 0, 32, 32, 15, 15); - Mouse_hidden++; - gr_flip(); - d3d_get_pixel(0, 0, (ubyte*)&pix1a); - d3d_get_pixel(1, 1, (ubyte*)&pix1b); - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; - - mprintf(( "Trial #2\n" )); - D3d_rendition_uvs = 1; - gr_reset_clip(); - gr_clear(); - gr_set_color_fast(&ac); - gr_set_bitmap( test_bmp ); - gr_aabitmap_ex(0, 0, 32, 32, 15, 15); - Mouse_hidden++; - gr_flip(); - d3d_get_pixel(0, 0, (ubyte*)&pix2a); - d3d_get_pixel(1, 1, (ubyte*)&pix2b); - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; - - bm_release(test_bmp); - - mprintf(( "Pixel 1 = %x , %x\n", pix1a, pix1b )); - mprintf(( "Pixel 2 = %x , %x\n", pix2a, pix2b )); - - if ( (pix1b!=0) || (pix2b!=0) ) { - D3d_rendition_uvs = 1; - } else { - D3d_rendition_uvs = 0; - } - - mprintf(( "Rendition uvs: %d\n", D3d_rendition_uvs )); -} - -void gr_d3d_get_region(int front, int w, int h, ubyte *data) -{ - HRESULT ddrval; - DDSURFACEDESC ddsd; - LPDIRECTDRAWSURFACE surf = front ? lpFrontBuffer : lpBackBuffer; - - memset( &ddsd, 0, sizeof( ddsd ) ); - ddsd.dwSize = sizeof( ddsd ); - - // try and lock the buffer - ddrval = surf->Lock( NULL, &ddsd, DDLOCK_WAIT | DDLOCK_READONLY, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "Error locking surface for get_region, %s\n", d3d_error_string(ddrval) )); - return; - } - - ubyte *sptr; - ubyte *dptr = data; - ubyte *rptr = (ubyte*)ddsd.lpSurface; - - for (int i=0; iUnlock( NULL ); -} - -extern float D3D_line_offset; - -void d3d_detect_line_offset_32() -{ - color ac; - uint pix1a, pix2a; - uint pix1b, pix2b; - - mprintf(( "Detecting line offset...\n" )); - - gr_set_gamma(1.0f); - gr_init_alphacolor(&ac, 255,255, 255, 255); - - mprintf(( "Trial #1\n" )); - D3D_line_offset = 0.0f; - gr_reset_clip(); - gr_clear(); - gr_set_color_fast(&ac); - gr_line( 0,0,0,0 ); - Mouse_hidden++; - gr_flip(); - d3d_get_pixel(0, 0, (ubyte*)&pix1a); - d3d_get_pixel(1, 1, (ubyte*)&pix1b); - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; - - mprintf(( "Trial #2\n" )); - D3D_line_offset = 0.5f; - gr_reset_clip(); - gr_clear(); - gr_set_color_fast(&ac); - gr_line( 0,0,0,0 ); - Mouse_hidden++; - gr_flip(); - d3d_get_pixel(0, 0, (ubyte*)&pix2a); - d3d_get_pixel(1, 1, (ubyte*)&pix2b); - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; - - mprintf(( "Pixel 1 = %x , %x\n", pix1a, pix1b )); - mprintf(( "Pixel 2 = %x , %x\n", pix2a, pix2b )); - - if ( (pix1a!=0) && (pix2a==0) ) { - D3D_line_offset = 0.0f; - } else if ( (pix1a==0) && (pix2a!=0) ) { - D3D_line_offset = 0.5f; - } else { - D3D_line_offset = 0.0f; - } - - mprintf(( "Line offset: %.1f\n", D3D_line_offset )); -} - -void d3d_detect_line_offset_16() -{ - color ac; - ushort pix1a, pix2a; - ushort pix1b, pix2b; - - mprintf(( "Detecting line offset...\n" )); - - gr_set_gamma(1.0f); - gr_init_alphacolor(&ac, 255,255, 255, 255); - - mprintf(( "Trial #1\n" )); - D3D_line_offset = 0.0f; - gr_reset_clip(); - gr_clear(); - gr_set_color_fast(&ac); - gr_line( 0,0,0,0 ); - Mouse_hidden++; - gr_flip(); - d3d_get_pixel(0, 0, (ubyte*)&pix1a); - d3d_get_pixel(1, 1, (ubyte*)&pix1b); - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; - - mprintf(( "Trial #2\n" )); - D3D_line_offset = 0.5f; - gr_reset_clip(); - gr_clear(); - gr_set_color_fast(&ac); - gr_line( 0,0,0,0 ); - Mouse_hidden++; - gr_flip(); - d3d_get_pixel(0, 0, (ubyte*)&pix2a); - d3d_get_pixel(1, 1, (ubyte*)&pix2b); - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; - - mprintf(( "Pixel 1 = %x , %x\n", pix1a, pix1b )); - mprintf(( "Pixel 2 = %x , %x\n", pix2a, pix2b )); - - if ( (pix1a!=0) && (pix2a==0) ) { - D3D_line_offset = 0.0f; - } else if ( (pix1a==0) && (pix2a!=0) ) { - D3D_line_offset = 0.5f; - } else { - D3D_line_offset = 0.0f; - } - - mprintf(( "Line offset: %.1f\n", D3D_line_offset )); -} - -#pragma optimize("",on) - -void gr_d3d_init() -{ - D3D_enabled = 1; // Tell Freespace code that we're using Direct3D. - D3D_running = 0; - - SDL_assert( !D3D_inited ); - - // pixel format - Bm_pixel_format = BM_PIXEL_FORMAT_D3D; - - D3D_32bit = 0; - D3D_window = Cmdline_window; - - // windowed? - if(D3D_window){ - gr_d3d_init_device(gr_screen.max_w, gr_screen.max_h); - } else { - // 32 bit mode - if(Cmdline_force_32bit){ - gr_screen.bits_per_pixel = 32; - gr_screen.bytes_per_pixel = 4; - gr_d3d_init_device(gr_screen.max_w, gr_screen.max_h); - } else { - // 16 bit mode - gr_screen.bits_per_pixel = 16; - gr_screen.bytes_per_pixel = 2; - gr_d3d_init_device(gr_screen.max_w, gr_screen.max_h); - } - } - - // determine 32 bit status - D3D_32bit = gr_screen.bits_per_pixel == 32 ? 1 : 0; - d3d_tcache_init(D3D_32bit ? 1 : 0); - Gr_bitmap_poly = D3D_32bit ? 1 : 0; - - // did we initialize properly? - if(!D3D_inited){ - return; - } - - // zbiasing? - if(os_config_read_uint(NULL, "DisableZbias", 0)){ - D3D_zbias = 0; - } - - d3d_start_frame(); - - Gr_current_red = &Gr_red; - Gr_current_blue = &Gr_blue; - Gr_current_green = &Gr_green; - Gr_current_alpha = &Gr_alpha; - - gr_screen.gf_flip = gr_d3d_flip; - gr_screen.gf_flip_window = gr_d3d_flip_window; - gr_screen.gf_set_clip = gr_d3d_set_clip; - gr_screen.gf_reset_clip = gr_d3d_reset_clip; - gr_screen.gf_set_font = grx_set_font; - - gr_screen.gf_get_color = gr_d3d_get_color; - gr_screen.gf_init_color = gr_d3d_init_color; - gr_screen.gf_set_color_fast = gr_d3d_set_color_fast; - gr_screen.gf_set_color = gr_d3d_set_color; - gr_screen.gf_init_color = gr_d3d_init_color; - gr_screen.gf_init_alphacolor = gr_d3d_init_alphacolor; - - gr_screen.gf_set_bitmap = gr_d3d_set_bitmap; - gr_screen.gf_create_shader = gr_d3d_create_shader; - gr_screen.gf_set_shader = gr_d3d_set_shader; - gr_screen.gf_clear = gr_d3d_clear; - // gr_screen.gf_bitmap = gr_d3d_bitmap; - // gr_screen.gf_bitmap_ex = gr_d3d_bitmap_ex; - gr_screen.gf_aabitmap = gr_d3d_aabitmap; - gr_screen.gf_aabitmap_ex = gr_d3d_aabitmap_ex; - - gr_screen.gf_rect = gr_d3d_rect; - gr_screen.gf_shade = gr_d3d_shade; - gr_screen.gf_string = gr_d3d_string; - gr_screen.gf_circle = gr_d3d_circle; - - gr_screen.gf_line = gr_d3d_line; - gr_screen.gf_aaline = gr_d3d_aaline; - gr_screen.gf_pixel = gr_d3d_pixel; - gr_screen.gf_scaler = gr_d3d_scaler; - gr_screen.gf_aascaler = gr_d3d_aascaler; - gr_screen.gf_tmapper = gr_d3d_tmapper; - - gr_screen.gf_gradient = gr_d3d_gradient; - - gr_screen.gf_set_palette = gr_d3d_set_palette; - gr_screen.gf_print_screen = gr_d3d_print_screen; - - gr_screen.gf_fade_in = gr_d3d_fade_in; - gr_screen.gf_fade_out = gr_d3d_fade_out; - gr_screen.gf_flash = gr_d3d_flash; - - gr_screen.gf_zbuffer_get = gr_d3d_zbuffer_get; - gr_screen.gf_zbuffer_set = gr_d3d_zbuffer_set; - gr_screen.gf_zbuffer_clear = gr_d3d_zbuffer_clear; - - gr_screen.gf_save_screen = gr_d3d_save_screen; - gr_screen.gf_restore_screen = gr_d3d_restore_screen; - gr_screen.gf_free_screen = gr_d3d_free_screen; - - // Screen dumping stuff - gr_screen.gf_dump_frame_start = gr_d3d_dump_frame_start; - gr_screen.gf_dump_frame_stop = gr_d3d_dump_frame_stop; - gr_screen.gf_dump_frame = gr_d3d_dump_frame; - - gr_screen.gf_set_gamma = gr_d3d_set_gamma; - - // Lock/unlock stuff - gr_screen.gf_lock = gr_d3d_lock; - gr_screen.gf_unlock = gr_d3d_unlock; - - // screen region - gr_screen.gf_get_region = gr_d3d_get_region; - - // fog stuff - gr_screen.gf_fog_set = gr_d3d_fog_set; - - // pixel get - gr_screen.gf_get_pixel = gr_d3d_get_pixel; - - // poly culling - gr_screen.gf_set_cull = gr_d3d_set_cull; - - // cross fade - gr_screen.gf_cross_fade = gr_d3d_cross_fade; - - // filtering - gr_screen.gf_filter_set = gr_d3d_filter_set; - - // texture cache - gr_screen.gf_tcache_set = d3d_tcache_set; - - // set clear color - gr_screen.gf_set_clear_color = gr_d3d_set_clear_color; - - uint tmp = os_config_read_uint( NULL, "D3DTextureOrigin", 0xFFFF ); - - if ( tmp != 0xFFFF ) { - if ( tmp ) { - D3d_rendition_uvs = 1; - } else { - D3d_rendition_uvs = 0; - } - } else { - if(D3D_32bit){ - d3d_detect_texture_origin_32(); - } else { - d3d_detect_texture_origin_16(); - } - } - - tmp = os_config_read_uint( NULL, "D3DLineOffset", 0xFFFF ); - - if ( tmp != 0xFFFF ) { - if ( tmp ) { - D3D_line_offset = 0.5f; - } else { - D3D_line_offset = 0.0f; - } - } else { - if(D3D_32bit){ - d3d_detect_line_offset_32(); - } else { - d3d_detect_line_offset_16(); - } - } - - D3D_running = 1; - - Mouse_hidden++; - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; -} - -char* d3d_error_string(HRESULT error) -{ -//XSTR:OFF - switch(error) { - case DD_OK: - return "No error.\0"; - case DDERR_ALREADYINITIALIZED: - return "This object is already initialized.\0"; - case DDERR_BLTFASTCANTCLIP: - return "Return if a clipper object is attached to the source surface passed into a BltFast call.\0"; - case DDERR_CANNOTATTACHSURFACE: - return "This surface can not be attached to the requested surface.\0"; - case DDERR_CANNOTDETACHSURFACE: - return "This surface can not be detached from the requested surface.\0"; - case DDERR_CANTCREATEDC: - return "Windows can not create any more DCs.\0"; - case DDERR_CANTDUPLICATE: - return "Can't duplicate primary & 3D surfaces, or surfaces that are implicitly created.\0"; - case DDERR_CLIPPERISUSINGHWND: - return "An attempt was made to set a cliplist for a clipper object that is already monitoring an hwnd.\0"; - case DDERR_COLORKEYNOTSET: - return "No src color key specified for this operation.\0"; - case DDERR_CURRENTLYNOTAVAIL: - return "Support is currently not available.\0"; - case DDERR_DIRECTDRAWALREADYCREATED: - return "A DirectDraw object representing this driver has already been created for this process.\0"; - case DDERR_EXCEPTION: - return "An exception was encountered while performing the requested operation.\0"; - case DDERR_EXCLUSIVEMODEALREADYSET: - return "An attempt was made to set the cooperative level when it was already set to exclusive.\0"; - case DDERR_GENERIC: - return "Generic failure.\0"; - case DDERR_HEIGHTALIGN: - return "Height of rectangle provided is not a multiple of reqd alignment.\0"; - case DDERR_HWNDALREADYSET: - return "The CooperativeLevel HWND has already been set. It can not be reset while the process has surfaces or palettes created.\0"; - case DDERR_HWNDSUBCLASSED: - return "HWND used by DirectDraw CooperativeLevel has been subclassed, this prevents DirectDraw from restoring state.\0"; - case DDERR_IMPLICITLYCREATED: - return "This surface can not be restored because it is an implicitly created surface.\0"; - case DDERR_INCOMPATIBLEPRIMARY: - return "Unable to match primary surface creation request with existing primary surface.\0"; - case DDERR_INVALIDCAPS: - return "One or more of the caps bits passed to the callback are incorrect.\0"; - case DDERR_INVALIDCLIPLIST: - return "DirectDraw does not support the provided cliplist.\0"; - case DDERR_INVALIDDIRECTDRAWGUID: - return "The GUID passed to DirectDrawCreate is not a valid DirectDraw driver identifier.\0"; - case DDERR_INVALIDMODE: - return "DirectDraw does not support the requested mode.\0"; - case DDERR_INVALIDOBJECT: - return "DirectDraw received a pointer that was an invalid DIRECTDRAW object.\0"; - case DDERR_INVALIDPARAMS: - return "One or more of the parameters passed to the function are incorrect.\0"; - case DDERR_INVALIDPIXELFORMAT: - return "The pixel format was invalid as specified.\0"; - case DDERR_INVALIDPOSITION: - return "Returned when the position of the overlay on the destination is no longer legal for that destination.\0"; - case DDERR_INVALIDRECT: - return "Rectangle provided was invalid.\0"; - case DDERR_LOCKEDSURFACES: - return "Operation could not be carried out because one or more surfaces are locked.\0"; - case DDERR_NO3D: - return "There is no 3D present.\0"; - case DDERR_NOALPHAHW: - return "Operation could not be carried out because there is no alpha accleration hardware present or available.\0"; - case DDERR_NOBLTHW: - return "No blitter hardware present.\0"; - case DDERR_NOCLIPLIST: - return "No cliplist available.\0"; - case DDERR_NOCLIPPERATTACHED: - return "No clipper object attached to surface object.\0"; - case DDERR_NOCOLORCONVHW: - return "Operation could not be carried out because there is no color conversion hardware present or available.\0"; - case DDERR_NOCOLORKEY: - return "Surface doesn't currently have a color key\0"; - case DDERR_NOCOLORKEYHW: - return "Operation could not be carried out because there is no hardware support of the destination color key.\0"; - case DDERR_NOCOOPERATIVELEVELSET: - return "Create function called without DirectDraw object method SetCooperativeLevel being called.\0"; - case DDERR_NODC: - return "No DC was ever created for this surface.\0"; - case DDERR_NODDROPSHW: - return "No DirectDraw ROP hardware.\0"; - case DDERR_NODIRECTDRAWHW: - return "A hardware-only DirectDraw object creation was attempted but the driver did not support any hardware.\0"; - case DDERR_NOEMULATION: - return "Software emulation not available.\0"; - case DDERR_NOEXCLUSIVEMODE: - return "Operation requires the application to have exclusive mode but the application does not have exclusive mode.\0"; - case DDERR_NOFLIPHW: - return "Flipping visible surfaces is not supported.\0"; - case DDERR_NOGDI: - return "There is no GDI present.\0"; - case DDERR_NOHWND: - return "Clipper notification requires an HWND or no HWND has previously been set as the CooperativeLevel HWND.\0"; - case DDERR_NOMIRRORHW: - return "Operation could not be carried out because there is no hardware present or available.\0"; - case DDERR_NOOVERLAYDEST: - return "Returned when GetOverlayPosition is called on an overlay that UpdateOverlay has never been called on to establish a destination.\0"; - case DDERR_NOOVERLAYHW: - return "Operation could not be carried out because there is no overlay hardware present or available.\0"; - case DDERR_NOPALETTEATTACHED: - return "No palette object attached to this surface.\0"; - case DDERR_NOPALETTEHW: - return "No hardware support for 16 or 256 color palettes.\0"; - case DDERR_NORASTEROPHW: - return "Operation could not be carried out because there is no appropriate raster op hardware present or available.\0"; - case DDERR_NOROTATIONHW: - return "Operation could not be carried out because there is no rotation hardware present or available.\0"; - case DDERR_NOSTRETCHHW: - return "Operation could not be carried out because there is no hardware support for stretching.\0"; - case DDERR_NOT4BITCOLOR: - return "DirectDrawSurface is not in 4 bit color palette and the requested operation requires 4 bit color palette.\0"; - case DDERR_NOT4BITCOLORINDEX: - return "DirectDrawSurface is not in 4 bit color index palette and the requested operation requires 4 bit color index palette.\0"; - case DDERR_NOT8BITCOLOR: - return "DirectDrawSurface is not in 8 bit color mode and the requested operation requires 8 bit color.\0"; - case DDERR_NOTAOVERLAYSURFACE: - return "Returned when an overlay member is called for a non-overlay surface.\0"; - case DDERR_NOTEXTUREHW: - return "Operation could not be carried out because there is no texture mapping hardware present or available.\0"; - case DDERR_NOTFLIPPABLE: - return "An attempt has been made to flip a surface that is not flippable.\0"; - case DDERR_NOTFOUND: - return "Requested item was not found.\0"; - case DDERR_NOTLOCKED: - return "Surface was not locked. An attempt to unlock a surface that was not locked at all, or by this process, has been attempted.\0"; - case DDERR_NOTPALETTIZED: - return "The surface being used is not a palette-based surface.\0"; - case DDERR_NOVSYNCHW: - return "Operation could not be carried out because there is no hardware support for vertical blank synchronized operations.\0"; - case DDERR_NOZBUFFERHW: - return "Operation could not be carried out because there is no hardware support for zbuffer blitting.\0"; - case DDERR_NOZOVERLAYHW: - return "Overlay surfaces could not be z layered based on their BltOrder because the hardware does not support z layering of overlays.\0"; - case DDERR_OUTOFCAPS: - return "The hardware needed for the requested operation has already been allocated.\0"; - case DDERR_OUTOFMEMORY: - return "DirectDraw does not have enough memory to perform the operation.\0"; - case DDERR_OUTOFVIDEOMEMORY: - return "DirectDraw does not have enough memory to perform the operation.\0"; - case DDERR_OVERLAYCANTCLIP: - return "The hardware does not support clipped overlays.\0"; - case DDERR_OVERLAYCOLORKEYONLYONEACTIVE: - return "Can only have ony color key active at one time for overlays.\0"; - case DDERR_OVERLAYNOTVISIBLE: - return "Returned when GetOverlayPosition is called on a hidden overlay.\0"; - case DDERR_PALETTEBUSY: - return "Access to this palette is being refused because the palette is already locked by another thread.\0"; - case DDERR_PRIMARYSURFACEALREADYEXISTS: - return "This process already has created a primary surface.\0"; - case DDERR_REGIONTOOSMALL: - return "Region passed to Clipper::GetClipList is too small.\0"; - case DDERR_SURFACEALREADYATTACHED: - return "This surface is already attached to the surface it is being attached to.\0"; - case DDERR_SURFACEALREADYDEPENDENT: - return "This surface is already a dependency of the surface it is being made a dependency of.\0"; - case DDERR_SURFACEBUSY: - return "Access to this surface is being refused because the surface is already locked by another thread.\0"; - case DDERR_SURFACEISOBSCURED: - return "Access to surface refused because the surface is obscured.\0"; - case DDERR_SURFACELOST: - return "Access to this surface is being refused because the surface memory is gone. The DirectDrawSurface object representing this surface should have Restore called on it.\0"; - case DDERR_SURFACENOTATTACHED: - return "The requested surface is not attached.\0"; - case DDERR_TOOBIGHEIGHT: - return "Height requested by DirectDraw is too large.\0"; - case DDERR_TOOBIGSIZE: - return "Size requested by DirectDraw is too large, but the individual height and width are OK.\0"; - case DDERR_TOOBIGWIDTH: - return "Width requested by DirectDraw is too large.\0"; - case DDERR_UNSUPPORTED: - return "Action not supported.\0"; - case DDERR_UNSUPPORTEDFORMAT: - return "FOURCC format requested is unsupported by DirectDraw.\0"; - case DDERR_UNSUPPORTEDMASK: - return "Bitmask in the pixel format requested is unsupported by DirectDraw.\0"; - case DDERR_VERTICALBLANKINPROGRESS: - return "Vertical blank is in progress.\0"; - case DDERR_WASSTILLDRAWING: - return "Informs DirectDraw that the previous Blt which is transfering information to or from this Surface is incomplete.\0"; - case DDERR_WRONGMODE: - return "This surface can not be restored because it was created in a different mode.\0"; - case DDERR_XALIGN: - return "Rectangle provided was not horizontally aligned on required boundary.\0"; - case D3DERR_BADMAJORVERSION: - return "D3DERR_BADMAJORVERSION\0"; - case D3DERR_BADMINORVERSION: - return "D3DERR_BADMINORVERSION\0"; - case D3DERR_EXECUTE_LOCKED: - return "D3DERR_EXECUTE_LOCKED\0"; - case D3DERR_EXECUTE_NOT_LOCKED: - return "D3DERR_EXECUTE_NOT_LOCKED\0"; - case D3DERR_EXECUTE_CREATE_FAILED: - return "D3DERR_EXECUTE_CREATE_FAILED\0"; - case D3DERR_EXECUTE_DESTROY_FAILED: - return "D3DERR_EXECUTE_DESTROY_FAILED\0"; - case D3DERR_EXECUTE_LOCK_FAILED: - return "D3DERR_EXECUTE_LOCK_FAILED\0"; - case D3DERR_EXECUTE_UNLOCK_FAILED: - return "D3DERR_EXECUTE_UNLOCK_FAILED\0"; - case D3DERR_EXECUTE_FAILED: - return "D3DERR_EXECUTE_FAILED\0"; - case D3DERR_EXECUTE_CLIPPED_FAILED: - return "D3DERR_EXECUTE_CLIPPED_FAILED\0"; - case D3DERR_TEXTURE_NO_SUPPORT: - return "D3DERR_TEXTURE_NO_SUPPORT\0"; - case D3DERR_TEXTURE_NOT_LOCKED: - return "D3DERR_TEXTURE_NOT_LOCKED\0"; - case D3DERR_TEXTURE_LOCKED: - return "D3DERR_TEXTURELOCKED\0"; - case D3DERR_TEXTURE_CREATE_FAILED: - return "D3DERR_TEXTURE_CREATE_FAILED\0"; - case D3DERR_TEXTURE_DESTROY_FAILED: - return "D3DERR_TEXTURE_DESTROY_FAILED\0"; - case D3DERR_TEXTURE_LOCK_FAILED: - return "D3DERR_TEXTURE_LOCK_FAILED\0"; - case D3DERR_TEXTURE_UNLOCK_FAILED: - return "D3DERR_TEXTURE_UNLOCK_FAILED\0"; - case D3DERR_TEXTURE_LOAD_FAILED: - return "D3DERR_TEXTURE_LOAD_FAILED\0"; - case D3DERR_MATRIX_CREATE_FAILED: - return "D3DERR_MATRIX_CREATE_FAILED\0"; - case D3DERR_MATRIX_DESTROY_FAILED: - return "D3DERR_MATRIX_DESTROY_FAILED\0"; - case D3DERR_MATRIX_SETDATA_FAILED: - return "D3DERR_MATRIX_SETDATA_FAILED\0"; - case D3DERR_SETVIEWPORTDATA_FAILED: - return "D3DERR_SETVIEWPORTDATA_FAILED\0"; - case D3DERR_MATERIAL_CREATE_FAILED: - return "D3DERR_MATERIAL_CREATE_FAILED\0"; - case D3DERR_MATERIAL_DESTROY_FAILED: - return "D3DERR_MATERIAL_DESTROY_FAILED\0"; - case D3DERR_MATERIAL_SETDATA_FAILED: - return "D3DERR_MATERIAL_SETDATA_FAILED\0"; - case D3DERR_LIGHT_SET_FAILED: - return "D3DERR_LIGHT_SET_FAILED\0"; - default: - return "Unrecognized error value.\0"; - } -//XSTR:ON -} - diff --git a/src/graphics/grd3drender.cpp b/src/graphics/grd3drender.cpp deleted file mode 100644 index 3250bd1..0000000 --- a/src/graphics/grd3drender.cpp +++ /dev/null @@ -1,2269 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/GrD3DRender.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Code to actually render stuff using Direct3D - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:17 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 27 9/13/99 11:30a Dave - * Added checkboxes and functionality for disabling PXO banners as well as - * disabling d3d zbuffer biasing. - * - * 26 9/08/99 12:03a Dave - * Make squad logos render properly in D3D all the time. Added intel anim - * directory. - * - * 25 8/30/99 5:01p Dave - * Made d3d do less state changing in the nebula. Use new chat server for - * PXO. - * - * 24 7/30/99 4:04p Anoop - * Fixed D3D shader. - * - * 23 7/29/99 10:47p Dave - * Standardized D3D fogging using vertex fog. Shook out Savage 4 bugs. - * - * 22 7/27/99 3:09p Dave - * Made g400 work. Whee. - * - * 21 7/24/99 4:19p Dave - * Fixed dumb code with briefing bitmaps. Made d3d zbuffer work much - * better. Made model code use zbuffer more intelligently. - * - * 20 7/24/99 1:54p Dave - * Hud text flash gauge. Reworked dead popup to use 4 buttons in red-alert - * missions. - * - * 19 7/19/99 3:29p Dave - * Fixed gamma bitmap in the options screen. - * - * 18 7/14/99 9:42a Dave - * Put in clear_color debug function. Put in base for 3dnow stuff / P3 - * stuff - * - * 17 7/13/99 1:15p Dave - * 32 bit support. Whee! - * - * 16 7/12/99 11:42a Jefff - * Made rectangle drawing smarter in D3D. Made plines draw properly on Ati - * Rage Pro. - * - * 15 6/29/99 10:35a Dave - * Interface polygon bitmaps! Whee! - * - * 14 5/05/99 9:02p Dave - * Fixed D3D aabitmap rendering. Spiffed up nebula effect a bit (added - * rotations, tweaked values, made bitmap selection more random). Fixed - * D3D beam weapon clipping problem. Added D3d frame dumping. - * - * 13 2/03/99 11:44a Dave - * Fixed d3d transparent textures. - * - * 12 1/30/99 5:08p Dave - * More new hi-res stuff.Support for nice D3D textures. - * - * 11 12/18/98 1:13a Dave - * Rough 1024x768 support for Direct3D. Proper detection and usage through - * the launcher. - * - * 10 12/08/98 7:03p Dave - * Much improved D3D fogging. Also put in vertex fogging for the cheesiest - * of 3d cards. - * - * 9 12/08/98 2:47p Johnson - * Made D3D fog use eye-relative fog instead of z depth fog. - * - * 8 12/08/98 9:36a Dave - * Almost done nebula effect for D3D. Looks 85% as good as Glide. - * - * 7 12/07/98 5:51p Dave - * Finally got d3d fog working! Now we just need to tweak values. - * - * 6 12/07/98 9:00a Dave - * Fixed d3d rendered. Still don't have fog working. - * - * 5 12/06/98 6:53p Dave - * - * 4 12/01/98 5:54p Dave - * Simplified the way pixel data is swizzled. Fixed tga bitmaps to work - * properly in D3D and Glide. - * - * 3 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 2 10/07/98 10:52a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 54 5/25/98 10:32a John - * Took out redundant code for font bitmap offsets that converted to a - * float, then later on converted back to an integer. Quite unnecessary. - * - * 53 5/24/98 6:45p John - * let direct3d do all clipping. - * - * 52 5/24/98 3:42p John - * Let Direct3D do clipping on any linear textures, like lasers. - * - * 51 5/23/98 7:18p John - * optimized the uv bashing a bit. - * - * 50 5/22/98 1:11p John - * Added code to actually detect which offset a line needs - * - * 49 5/22/98 12:54p John - * added .5 to each pixel of a line. This seemed to make single pixel - * lines draw on all cards. - * - * 48 5/22/98 9:00a John - * Fixed problem of no fading out of additive textures due to Permedia2 - * fix. Did this by dimming out the vertex RGB values. - * - * 47 5/21/98 9:56p John - * Made Direct3D work with classic alpha-blending only devices, like the - * Virge. Added a texture type XPARENT that fills the alpha in in the - * bitmap for Virge. Added support for Permedia by making making - * additive alphablending be one/one instead of alpha/one, which didn't - * work, and there is no way to tell this from caps. - * - * 46 5/20/98 9:45p John - * added code so the places in code that change half the palette don't - * have to clear the screen. - * - * 45 5/20/98 3:10p John - * Made lines work even if no alphagouraud capabilities on the card. - * - * 44 5/19/98 4:50p Lawrance - * JAS: Fixed some bugs on Alan's nVidia Riva128 PCI where some - * unitiallized fields, namely vertex->shw were causing glitches. - * - * 43 5/19/98 1:46p John - * Fixed Rendition/Riva128 uv problems. - * - * 42 5/19/98 12:34p John - * added code to fix uv's on rendition. added code to fix zbuffering - * problem on rendition. - * - * 41 5/18/98 8:26p John - * Made scanline be line. Made lines work if no line alpha blending - * supported. Made no alpha mode use alpha off. - * - * 40 5/17/98 4:13p John - * Made zbuffer clear only clear current clip region - * - * 39 5/17/98 3:23p John - * Took out capibility check for additive blending. Made gr_bitmap_ex - * clip properly in glide and direct3d. - * - * 38 5/15/98 8:48a John - * Fixed bug where one-pixel line was getting left on right and bottom. - * - * 37 5/12/98 8:43p John - * fixed particle zbuffering. - * - * 36 5/12/98 10:34a John - * Added d3d_shade functionality. Added d3d_flush function, since the - * shader seems to get reorganzed behind the overlay text stuff! - * - * 35 5/12/98 10:06a John - * Made all tmaps "clamp-clip". This fixed bug with offscreen hud - * indicators not rendering. - * - * 34 5/12/98 8:18a John - * Put in code to use a different texture format for alpha textures and - * normal textures. Turned off filtering for aabitmaps. Took out - * destblend=invsrccolor alpha mode that doesn't work on riva128. - * - * 33 5/11/98 10:58a John - * Fixed pilot name cursor bug. Started adding in code for alphachannel - * textures. - * - * 32 5/09/98 12:37p John - * More texture caching - * - * 31 5/09/98 12:16p John - * Even better texture caching. - * - * 30 5/08/98 10:12a John - * took out an mprintf - * - * 29 5/07/98 11:31a John - * Removed DEMO defines - * - * 28 5/07/98 10:28a John - * Made texture format use 4444. Made fonts use alpha to render. - * - * 27 5/07/98 10:09a John - * Fixed some bugs with short lines in D3D. - * - * 26 5/07/98 9:54a John - * Added in palette flash functionallity. - * - * 25 5/07/98 9:40a John - * Fixed some bitmap transparency issues with Direct3D. - * - * 24 5/06/98 11:21p John - * Fixed a bitmap bug with Direct3D. Started adding new caching code into - * D3D. - * - * 23 5/06/98 8:41p John - * Fixed some font clipping bugs. Moved texture handle set code for d3d - * into the texture module. - * - * 22 5/06/98 8:07p John - * made d3d clear work correctly. - * - * 21 5/06/98 8:00p John - * Got stars working under D3D. - * - * 20 5/06/98 5:30p John - * Removed unused cfilearchiver. Removed/replaced some unused/little used - * graphics functions, namely gradient_h and _v and pixel_sp. Put in new - * DirectX header files and libs that fixed the Direct3D alpha blending - * problems. - * - * 19 5/05/98 10:37p John - * Added code to optionally use execute buffers. - * - * 18 5/04/98 3:36p John - * Got zbuffering working with Direct3D. - * - * 17 5/03/98 10:52a John - * Made D3D sort of work on 3dfx. - * - * 16 5/03/98 10:43a John - * Working on Direct3D. - * - * 15 4/14/98 12:15p John - * Made 16-bpp movies work. - * - * 14 4/10/98 5:20p John - * Changed RGB in lighting structure to be ubytes. Removed old - * not-necessary 24 bpp software stuff. - * - * 13 4/09/98 11:05a John - * Removed all traces of Direct3D out of the demo version of Freespace and - * the launcher. - * - * 12 3/12/98 5:36p John - * Took out any unused shaders. Made shader code take rgbc instead of - * matrix and vector since noone used it like a matrix and it would have - * been impossible to do in hardware. Made Glide implement a basic - * shader for online help. - * - * 11 3/11/98 1:55p John - * Fixed warnings - * - * 10 3/10/98 4:18p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 9 3/08/98 12:33p John - * Added more lines, tris, and colored flat polys (lasers!) correctly. - * - * 8 3/08/98 10:25a John - * Added in lines - * - * 7 3/07/98 8:29p John - * Put in some Direct3D features. Transparency on bitmaps. Made fonts & - * aabitmaps render nice. - * - * 6 3/06/98 5:39p John - * Started adding in aabitmaps - * - * 5 3/02/98 5:42p John - * Removed WinAVI stuff from Freespace. Made all HUD gauges wriggle from - * afterburner. Made gr_set_clip work good with negative x &y. Made - * model_caching be on by default. Made each cached model have it's own - * bitmap id. Made asteroids not rotate when model_caching is on. - * - * 4 2/26/98 3:24p John - * fixed optimized warning - * - * 3 2/17/98 7:28p John - * Got fonts and texturing working in Direct3D - * - * 2 2/07/98 7:50p John - * Added code so that we can use the old blending type of alphacolors if - * we want to. Made the stars use them. - * - * 1 2/03/98 9:24p John - * - * $NoKeywords: $ - */ - -#include "grd3dinternal.h" -#include "2d.h" -#include "pstypes.h" -#include "bmpman.h" -#include "palman.h" -#include "line.h" -#include "cfile.h" -#include "neb.h" -#include "3d.h" - -typedef enum gr_texture_source { - TEXTURE_SOURCE_NONE, - TEXTURE_SOURCE_DECAL, - TEXTURE_SOURCE_NO_FILTERING, -} gr_texture_source; - -typedef enum gr_alpha_blend { - ALPHA_BLEND_NONE, // 1*SrcPixel + 0*DestPixel - ALPHA_BLEND_ALPHA_ADDITIVE, // Alpha*SrcPixel + 1*DestPixel - ALPHA_BLEND_ALPHA_BLEND_ALPHA, // Alpha*SrcPixel + (1-Alpha)*DestPixel - ALPHA_BLEND_ALPHA_BLEND_SRC_COLOR, // Alpha*SrcPixel + (1-SrcPixel)*DestPixel -} gr_alpha_blend; - -typedef enum gr_zbuffer_type { - ZBUFFER_TYPE_NONE, - ZBUFFER_TYPE_READ, - ZBUFFER_TYPE_WRITE, - ZBUFFER_TYPE_FULL, -} gr_zbuffer_type; - -int D3d_last_state = -1; - -// Hack! move to another file! -extern int D3d_rendition_uvs; - -// Hack! move to another file! -extern int D3D_fog_mode; - -void gr_d3d_set_state( gr_texture_source ts, gr_alpha_blend ab, gr_zbuffer_type zt ) -{ - int current_state = 0; - - current_state = current_state | (ts<<0); - current_state = current_state | (ab<<5); - current_state = current_state | (zt<<10); - - if ( current_state == D3d_last_state ) { - return; - } - D3d_last_state = current_state; - - switch( ts ) { - case TEXTURE_SOURCE_NONE: - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREHANDLE, NULL ); - // Let the texture cache system know whe set the handle to NULL - gr_tcache_set(-1, -1, NULL, NULL ); - - break; - case TEXTURE_SOURCE_DECAL: - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREMIN, D3DFILTER_LINEAR ); - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREMAG, D3DFILTER_LINEAR ); - - if ( lpDevDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_MODULATEALPHA ) { - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATEALPHA ); - } else { - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE ); - } - break; - - case TEXTURE_SOURCE_NO_FILTERING: - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREMIN, D3DFILTER_NEAREST ); - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREMAG, D3DFILTER_NEAREST ); - if ( lpDevDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_MODULATEALPHA ) { - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATEALPHA ); - } else { - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE ); - } - break; - - default: - Int3(); - } - - switch( ab ) { - case ALPHA_BLEND_NONE: // 1*SrcPixel + 0*DestPixel - d3d_SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE ); - break; - - case ALPHA_BLEND_ALPHA_ADDITIVE: // Alpha*SrcPixel + 1*DestPixel - case ALPHA_BLEND_ALPHA_BLEND_SRC_COLOR: // Alpha*SrcPixel + (1-SrcPixel)*DestPixel - if ( lpDevDesc->dpcTriCaps.dwDestBlendCaps & D3DPBLENDCAPS_ONE ) { - d3d_SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE ); - // Must use ONE:ONE as the Permedia2 can't do SRCALPHA:ONE. - // But I lower RGB values so we don't loose anything. - d3d_SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE ); - //d3d_SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA ); - d3d_SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE ); - break; - } - // Fall through to normal alpha blending mode... - - case ALPHA_BLEND_ALPHA_BLEND_ALPHA: // Alpha*SrcPixel + (1-Alpha)*DestPixel - if ( lpDevDesc->dpcTriCaps.dwSrcBlendCaps & D3DPBLENDCAPS_SRCALPHA ) { - d3d_SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE ); - d3d_SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA ); - d3d_SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA ); - } else { - d3d_SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE ); - d3d_SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_BOTHSRCALPHA ); - } - break; - - - default: - Int3(); - } - - switch( zt ) { - - case ZBUFFER_TYPE_NONE: - d3d_SetRenderState(D3DRENDERSTATE_ZENABLE,FALSE); - d3d_SetRenderState(D3DRENDERSTATE_ZWRITEENABLE,FALSE); - break; - - case ZBUFFER_TYPE_READ: - d3d_SetRenderState(D3DRENDERSTATE_ZENABLE,TRUE); - d3d_SetRenderState(D3DRENDERSTATE_ZWRITEENABLE,FALSE); - break; - - case ZBUFFER_TYPE_WRITE: - d3d_SetRenderState(D3DRENDERSTATE_ZENABLE,FALSE); - d3d_SetRenderState(D3DRENDERSTATE_ZWRITEENABLE,TRUE); - break; - - case ZBUFFER_TYPE_FULL: - d3d_SetRenderState(D3DRENDERSTATE_ZENABLE,TRUE); - d3d_SetRenderState(D3DRENDERSTATE_ZWRITEENABLE,TRUE); - break; - - default: - Int3(); - } - -} - -extern int D3D_zbias; -void d3d_zbias(int bias) -{ - if(D3D_zbias){ - d3d_SetRenderState(D3DRENDERSTATE_ZBIAS, bias); - } -} - -// If mode is FALSE, turn zbuffer off the entire frame, -// no matter what people pass to gr_zbuffer_set. -void gr_d3d_zbuffer_clear(int mode) -{ - if ( mode ) { - gr_zbuffering = 1; - gr_zbuffering_mode = GR_ZBUFF_FULL; - gr_global_zbuffering = 1; - - // Make sure zbuffering is on - gr_d3d_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_NONE, ZBUFFER_TYPE_FULL ); - - - // An application can clear z-buffers by using the IDirectDrawSurface2::Blt method. - // The DDBLT_DEPTHFILL flag indicates that the blit clears z-buffers. If this flag - // is specified, the DDBLTFX structure passed to the IDirectDrawSurface2::Blt method - // should have its dwFillDepth member set to the required z-depth. If the DirectDraw device - // driver for a 3D-accelerated display card is designed to provide support for z-buffer - // clearing in hardware, it should export the DDCAPS_BLTDEPTHFILL flag and should - // handle DDBLT_DEPTHFILL blits. The destination surface of a depth-fill blit must - // be a z-buffer. - // Note The actual interpretation of a depth value is specific to the 3D renderer. - - D3DRECT rect; - - rect.x1 = gr_screen.clip_left + gr_screen.offset_x; - rect.y1 = gr_screen.clip_top + gr_screen.offset_y; - rect.x2 = gr_screen.clip_right + gr_screen.offset_x; - rect.y2 = gr_screen.clip_bottom + gr_screen.offset_y; - - if (lpViewport->Clear( 1, &rect, D3DCLEAR_ZBUFFER ) != D3D_OK ) { - mprintf(( "Failed to clear zbuffer!\n" )); - return; - } - - - } else { - gr_zbuffering = 0; - gr_zbuffering_mode = GR_ZBUFF_NONE; - gr_global_zbuffering = 0; - } -} - -// internal d3d rect function -void gr_d3d_rect_internal(int x, int y, int w, int h, int r, int g, int b, int a) -{ - int saved_zbuf; - vertex v[4]; - vertex *verts[4] = {&v[0], &v[1], &v[2], &v[3]}; - - saved_zbuf = gr_zbuffer_get(); - - // start the frame, no zbuffering, no culling - g3_start_frame(1); - gr_zbuffer_set(GR_ZBUFF_NONE); - gr_set_cull(0); - - // stuff coords - v[0].sx = i2fl(x); - v[0].sy = i2fl(y); - v[0].sw = 0.0f; - v[0].u = 0.0f; - v[0].v = 0.0f; - v[0].flags = PF_PROJECTED; - v[0].codes = 0; - v[0].r = (ubyte)r; - v[0].g = (ubyte)g; - v[0].b = (ubyte)b; - v[0].a = (ubyte)a; - - v[1].sx = i2fl(x + w); - v[1].sy = i2fl(y); - v[1].sw = 0.0f; - v[1].u = 0.0f; - v[1].v = 0.0f; - v[1].flags = PF_PROJECTED; - v[1].codes = 0; - v[1].r = (ubyte)r; - v[1].g = (ubyte)g; - v[1].b = (ubyte)b; - v[1].a = (ubyte)a; - - v[2].sx = i2fl(x + w); - v[2].sy = i2fl(y + h); - v[2].sw = 0.0f; - v[2].u = 0.0f; - v[2].v = 0.0f; - v[2].flags = PF_PROJECTED; - v[2].codes = 0; - v[2].r = (ubyte)r; - v[2].g = (ubyte)g; - v[2].b = (ubyte)b; - v[2].a = (ubyte)a; - - v[3].sx = i2fl(x); - v[3].sy = i2fl(y + h); - v[3].sw = 0.0f; - v[3].u = 0.0f; - v[3].v = 0.0f; - v[3].flags = PF_PROJECTED; - v[3].codes = 0; - v[3].r = (ubyte)r; - v[3].g = (ubyte)g; - v[3].b = (ubyte)b; - v[3].a = (ubyte)a; - - // draw the polys - g3_draw_poly_constant_sw(4, verts, TMAP_FLAG_GOURAUD | TMAP_FLAG_RGB | TMAP_FLAG_ALPHA, 0.1f); - - g3_end_frame(); - - // restore zbuffer and culling - gr_zbuffer_set(saved_zbuf); - gr_set_cull(1); -} - -int gr_d3d_zbuffer_get() -{ - if ( !gr_global_zbuffering ) { - return GR_ZBUFF_NONE; - } - return gr_zbuffering_mode; -} - -int gr_d3d_zbuffer_set(int mode) -{ - /* - if ( !gr_global_zbuffering ) { - gr_zbuffering = 0; - return GR_ZBUFF_NONE; - } - */ - - int tmp = gr_zbuffering_mode; - - gr_zbuffering_mode = mode; - - if ( gr_zbuffering_mode == GR_ZBUFF_NONE ) { - gr_zbuffering = 0; - } else { - gr_zbuffering = 1; - } - return tmp; -} - -float D3D_line_offset = 0.0f; - -void d3d_make_rect( D3DTLVERTEX *a, D3DTLVERTEX *b, int x1, int y1, int x2, int y2 ) -{ - // Alan's nvidia riva128 PCI screws up targetting brackets if - // rhw are uninitialized. - a->rhw = 1.0f; - b->rhw = 1.0f; - - // just for completeness, initialize specular and sz. - a->specular = 0; - b->specular = 0; - - a->sz = 0.99f; - b->sz = 0.99f; - - a->sx = i2fl(x1 + gr_screen.offset_x)+D3D_line_offset; - a->sy = i2fl(y1 + gr_screen.offset_y)+D3D_line_offset; - - b->sx = i2fl(x2 + gr_screen.offset_x)+D3D_line_offset; - b->sy = i2fl(y2 + gr_screen.offset_y)+D3D_line_offset; - - if ( x1 == x2 ) { - // Verticle line - if ( a->sy < b->sy ) { - b->sy += 0.5f; - } else { - a->sy += 0.5f; - } - } else if ( y1 == y2 ) { - // Horizontal line - if ( a->sx < b->sx ) { - b->sx += 0.5f; - } else { - a->sx += 0.5f; - } - } - -} - -// basically just fills in the alpha component of the specular color. Hardware does the rest -// when rendering the poly -void gr_d3d_stuff_fog_value(float z, D3DCOLOR *spec) -{ - float f_float; - *spec = 0; - - // linear fog formula - f_float = (gr_screen.fog_far - z) / (gr_screen.fog_far - gr_screen.fog_near); - if(f_float < 0.0f){ - f_float = 0.0f; - } else if(f_float > 1.0f){ - f_float = 1.0f; - } - *spec = D3DRGBA(0.0f, 0.0f, 0.0f, f_float); -} - -float z_mult = 30000.0f; -DCF(zmult, "") -{ - dc_get_arg(ARG_FLOAT); - z_mult = Dc_arg_float; -} - -float flCAP( float x, float minx, float maxx) -{ - if ( x < minx ) { - return minx; - } else if ( x > maxx ) { - return maxx; - } - return x; -} - -#define NEBULA_COLORS 20 - -void gr_d3d_tmapper_internal( int nverts, vertex **verts, uint flags, int is_scaler ) -{ - int i; - float u_scale = 1.0f, v_scale = 1.0f; - int bw = 1, bh = 1; - - // Make nebula use the texture mapper... this blends the colors better. - if ( flags & TMAP_FLAG_NEBULA ){ - Int3(); - /* - flags |= TMAP_FLAG_TEXTURED | TMAP_FLAG_CORRECT; - - static int test_bmp = -1; - static ushort data[16]; - if ( test_bmp == -1 ){ - ushort pix; - ubyte a, r, g, b; - int idx; - - // stuff the fake bitmap - a = 1; r = 255; g = 255; b = 255; - pix = 0; - bm_set_components((ubyte*)&pix, &r, &g, &b, &a); - for(idx=0; idx<16; idx++){ - data[idx] = pix; - } - test_bmp = bm_create( 16, 4, 4, data ); - } - gr_set_bitmap( test_bmp ); - - for (i=0; iu = verts[i]->v = 0.5f; - } - */ - } - - gr_texture_source texture_source = (gr_texture_source)-1; - gr_alpha_blend alpha_blend = (gr_alpha_blend)-1; - gr_zbuffer_type zbuffer_type = (gr_zbuffer_type)-1; - - - if ( gr_zbuffering ) { - if ( is_scaler || (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) ) { - zbuffer_type = ZBUFFER_TYPE_READ; - } else { - zbuffer_type = ZBUFFER_TYPE_FULL; - } - } else { - zbuffer_type = ZBUFFER_TYPE_NONE; - } - - int alpha; - - int tmap_type = TCACHE_TYPE_NORMAL; - - int r, g, b; - - if ( flags & TMAP_FLAG_TEXTURED ) { - r = 255; - g = 255; - b = 255; - } else { - r = gr_screen.current_color.red; - g = gr_screen.current_color.green; - b = gr_screen.current_color.blue; - } - - if ( gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER ) { - - if ( lpDevDesc->dpcTriCaps.dwDestBlendCaps & D3DPBLENDCAPS_ONE ) { - tmap_type = TCACHE_TYPE_NORMAL; - alpha_blend = ALPHA_BLEND_ALPHA_ADDITIVE; - - // Blend with screen pixel using src*alpha+dst - float factor = gr_screen.current_alpha; - - alpha = 255; - - if ( factor <= 1.0f ) { - int tmp_alpha = fl2i(gr_screen.current_alpha*255.0f); - r = (r*tmp_alpha)/255; - g = (g*tmp_alpha)/255; - b = (b*tmp_alpha)/255; - } - } else { - - tmap_type = TCACHE_TYPE_XPARENT; - - alpha_blend = ALPHA_BLEND_ALPHA_BLEND_ALPHA; - - // Blend with screen pixel using src*alpha+dst - float factor = gr_screen.current_alpha; - - if ( factor > 1.0f ) { - alpha = 255; - } else { - alpha = fl2i(gr_screen.current_alpha*255.0f); - } - } - } else { - if(Bm_pixel_format == BM_PIXEL_FORMAT_ARGB_D3D){ - alpha_blend = ALPHA_BLEND_ALPHA_BLEND_ALPHA; - } else { - alpha_blend = ALPHA_BLEND_NONE; - } - alpha = 255; - } - - if(flags & TMAP_FLAG_BITMAP_SECTION){ - tmap_type = TCACHE_TYPE_BITMAP_SECTION; - } - - texture_source = TEXTURE_SOURCE_NONE; - - if ( flags & TMAP_FLAG_TEXTURED ) { - if ( !gr_tcache_set(gr_screen.current_bitmap, tmap_type, &u_scale, &v_scale, 0, gr_screen.current_bitmap_sx, gr_screen.current_bitmap_sy )) { - mprintf(( "Not rendering a texture because it didn't fit in VRAM!\n" )); - return; - } - - // use nonfiltered textures for bitmap sections - if(flags & TMAP_FLAG_BITMAP_SECTION){ - texture_source = TEXTURE_SOURCE_NO_FILTERING; - } else { - texture_source = TEXTURE_SOURCE_DECAL; - } - } - - gr_d3d_set_state( texture_source, alpha_blend, zbuffer_type ); - - D3DTLVERTEX d3d_verts[32]; - D3DTLVERTEX *src_v = d3d_verts; - - int x1, y1, x2, y2; - x1 = gr_screen.clip_left*16; - x2 = gr_screen.clip_right*16+15; - y1 = gr_screen.clip_top*16; - y2 = gr_screen.clip_bottom*16+15; - - float uoffset = 0.0f; - float voffset = 0.0f; - - float minu=0.0f, minv=0.0f, maxu=1.0f, maxv=1.0f; - - if ( flags & TMAP_FLAG_TEXTURED ) { - if ( D3d_rendition_uvs ) { - bm_get_info(gr_screen.current_bitmap, &bw, &bh); - - uoffset = 2.0f/i2fl(bw); - voffset = 2.0f/i2fl(bh); - - minu = uoffset; - minv = voffset; - - maxu = 1.0f - uoffset; - maxv = 1.0f - voffset; - } - } - - // turn on pixel fog if we're rendering against a fullneb background - // if(flags & TMAP_FLAG_PIXEL_FOG){ - // set fog - // gr_fog_set(GR_FOGMODE_FOG, gr_screen.current_fog_color.red, gr_screen.current_fog_color.green, gr_screen.current_fog_color.blue); - // } - - for (i=0; isz = va->z / z_mult; // For zbuffering and fogging - if ( src_v->sz > 0.98f ) { - src_v->sz = 0.98f; - } - } else { - src_v->sz = 0.99f; - } - - if ( flags & TMAP_FLAG_CORRECT ) { - src_v->rhw = va->sw; // For texture correction - } else { - src_v->rhw = 1.0f; // For texture correction - } - - int a; - - if ( flags & TMAP_FLAG_ALPHA ) { - a = verts[i]->a; - } else { - a = alpha; - } - - if ( flags & TMAP_FLAG_NEBULA ) { - int pal = (verts[i]->b*(NEBULA_COLORS-1))/255; - r = gr_palette[pal*3+0]; - g = gr_palette[pal*3+1]; - b = gr_palette[pal*3+2]; - } else if ( (flags & TMAP_FLAG_RAMP) && (flags & TMAP_FLAG_GOURAUD) ) { - r = Gr_gamma_lookup[verts[i]->b]; - g = Gr_gamma_lookup[verts[i]->b]; - b = Gr_gamma_lookup[verts[i]->b]; - } else if ( (flags & TMAP_FLAG_RGB) && (flags & TMAP_FLAG_GOURAUD) ) { - // Make 0.75 be 256.0f - r = Gr_gamma_lookup[verts[i]->r]; - g = Gr_gamma_lookup[verts[i]->g]; - b = Gr_gamma_lookup[verts[i]->b]; - } else { - // use constant RGB values... - } - - src_v->color = RGBA_MAKE(r, g, b, a); - - // if we're fogging and we're doing vertex fog - if((gr_screen.current_fog_mode != GR_FOGMODE_NONE) && (D3D_fog_mode == 1)){ - gr_d3d_stuff_fog_value(va->z, &src_v->specular); - } else { - src_v->specular = 0; - } - - int x, y; - x = fl2i(va->sx*16.0f); - y = fl2i(va->sy*16.0f); - - x += gr_screen.offset_x*16; - y += gr_screen.offset_y*16; - - src_v->sx = i2fl(x) / 16.0f; - src_v->sy = i2fl(y) / 16.0f; - - if ( flags & TMAP_FLAG_TEXTURED ) { - // argh. rendition - if ( D3d_rendition_uvs ){ - // tiled texture (ships, etc), bitmap sections - if(flags & TMAP_FLAG_TILED){ - src_v->tu = va->u*u_scale; - src_v->tv = va->v*v_scale; - } - // sectioned - else if(flags & TMAP_FLAG_BITMAP_SECTION){ - int sw, sh; - bm_get_section_size(gr_screen.current_bitmap, gr_screen.current_bitmap_sx, gr_screen.current_bitmap_sy, &sw, &sh); - - src_v->tu = (va->u + (0.5f / i2fl(sw))) * u_scale; - src_v->tv = (va->v + (0.5f / i2fl(sh))) * v_scale; - } - // all else. - else { - src_v->tu = flCAP(va->u, minu, maxu); - src_v->tv = flCAP(va->v, minv, maxv); - } - } - // yay. non-rendition - else { - src_v->tu = va->u*u_scale; - src_v->tv = va->v*v_scale; - } - } else { - src_v->tu = 0.0f; - src_v->tv = 0.0f; - } - src_v++; - } - - // if we're rendering against a fullneb background - if(flags & TMAP_FLAG_PIXEL_FOG){ - int r, g, b; - int ra, ga, ba; - ra = ga = ba = 0; - - // get the average pixel color behind the vertices - for(i=0; isx; y0 = va->sy; - x1 = vb->sx; y1 = vb->sy; - - xmin = i2fl(gr_screen.clip_left); ymin = i2fl(gr_screen.clip_top); - xmax = i2fl(gr_screen.clip_right); ymax = i2fl(gr_screen.clip_bottom); - - u0 = va->u; v0 = va->v; - u1 = vb->u; v1 = vb->v; - - // Check for obviously offscreen bitmaps... - if ( (y1<=y0) || (x1<=x0) ) return; - if ( (x1xmax) ) return; - if ( (y1ymax) ) return; - - clipped_u0 = u0; clipped_v0 = v0; - clipped_u1 = u1; clipped_v1 = v1; - - clipped_x0 = x0; clipped_y0 = y0; - clipped_x1 = x1; clipped_y1 = y1; - - // Clip the left, moving u0 right as necessary - if ( x0 < xmin ) { - clipped_u0 = FIND_SCALED_NUM(xmin,x0,x1,u0,u1); - clipped_x0 = xmin; - } - - // Clip the right, moving u1 left as necessary - if ( x1 > xmax ) { - clipped_u1 = FIND_SCALED_NUM(xmax,x0,x1,u0,u1); - clipped_x1 = xmax; - } - - // Clip the top, moving v0 down as necessary - if ( y0 < ymin ) { - clipped_v0 = FIND_SCALED_NUM(ymin,y0,y1,v0,v1); - clipped_y0 = ymin; - } - - // Clip the bottom, moving v1 up as necessary - if ( y1 > ymax ) { - clipped_v1 = FIND_SCALED_NUM(ymax,y0,y1,v0,v1); - clipped_y1 = ymax; - } - - dx0 = fl2i(clipped_x0); dx1 = fl2i(clipped_x1); - dy0 = fl2i(clipped_y0); dy1 = fl2i(clipped_y1); - - if (dx1<=dx0) return; - if (dy1<=dy0) return; - - //============= DRAW IT ===================== - - vertex v[4]; - vertex *vl[4]; - - vl[0] = &v[0]; - v->sx = clipped_x0; - v->sy = clipped_y0; - v->sw = va->sw; - v->z = va->z; - v->u = clipped_u0; - v->v = clipped_v0; - - vl[1] = &v[1]; - v[1].sx = clipped_x1; - v[1].sy = clipped_y0; - v[1].sw = va->sw; - v[1].z = va->z; - v[1].u = clipped_u1; - v[1].v = clipped_v0; - - vl[2] = &v[2]; - v[2].sx = clipped_x1; - v[2].sy = clipped_y1; - v[2].sw = va->sw; - v[2].z = va->z; - v[2].u = clipped_u1; - v[2].v = clipped_v1; - - vl[3] = &v[3]; - v[3].sx = clipped_x0; - v[3].sy = clipped_y1; - v[3].sw = va->sw; - v[3].z = va->z; - v[3].u = clipped_u0; - v[3].v = clipped_v1; - - gr_d3d_tmapper_internal( 4, vl, TMAP_FLAG_TEXTURED, 1 ); -} - -void gr_d3d_aascaler(vertex *va, vertex *vb ) -{ -} - - -void gr_d3d_pixel(int x, int y) -{ - gr_line(x,y,x,y); -} - - -void gr_d3d_clear() -{ - // Turn off zbuffering so this doesn't clear the zbuffer - gr_d3d_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_NONE, ZBUFFER_TYPE_NONE ); - - RECT dst; - DDBLTFX ddbltfx; - DDSURFACEDESC ddsd; - - // Get the surface desc - ddsd.dwSize = sizeof(ddsd); - lpBackBuffer->GetSurfaceDesc(&ddsd); - - memset(&ddbltfx, 0, sizeof(ddbltfx)); - ddbltfx.dwSize = sizeof(DDBLTFX); - - ddbltfx.dwFillColor = RGB_MAKE(gr_screen.current_clear_color.red, gr_screen.current_clear_color.green, gr_screen.current_clear_color.blue); - - dst.left = gr_screen.clip_left+gr_screen.offset_x; - dst.top = gr_screen.clip_top+gr_screen.offset_y; - dst.right = gr_screen.clip_right+1+gr_screen.offset_x; - dst.bottom = gr_screen.clip_bottom+1+gr_screen.offset_y; - - if ( lpBackBuffer->Blt( &dst, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx ) != DD_OK ) { - return; - } -} - - -// sets the clipping region & offset -void gr_d3d_set_clip(int x,int y,int w,int h) -{ - gr_screen.offset_x = x; - gr_screen.offset_y = y; - - gr_screen.clip_left = 0; - gr_screen.clip_right = w-1; - - gr_screen.clip_top = 0; - gr_screen.clip_bottom = h-1; - - // check for sanity of parameters - if ( gr_screen.clip_left+x < 0 ) { - gr_screen.clip_left = -x; - } else if ( gr_screen.clip_left+x > gr_screen.max_w-1 ) { - gr_screen.clip_left = gr_screen.max_w-1-x; - } - if ( gr_screen.clip_right+x < 0 ) { - gr_screen.clip_right = -x; - } else if ( gr_screen.clip_right+x >= gr_screen.max_w-1 ) { - gr_screen.clip_right = gr_screen.max_w-1-x; - } - - if ( gr_screen.clip_top+y < 0 ) { - gr_screen.clip_top = -y; - } else if ( gr_screen.clip_top+y > gr_screen.max_h-1 ) { - gr_screen.clip_top = gr_screen.max_h-1-y; - } - - if ( gr_screen.clip_bottom+y < 0 ) { - gr_screen.clip_bottom = -y; - } else if ( gr_screen.clip_bottom+y > gr_screen.max_h-1 ) { - gr_screen.clip_bottom = gr_screen.max_h-1-y; - } - - gr_screen.clip_width = gr_screen.clip_right - gr_screen.clip_left + 1; - gr_screen.clip_height = gr_screen.clip_bottom - gr_screen.clip_top + 1; - - // Setup the viewport for a reasonable viewing area - D3DVIEWPORT viewdata; - DWORD largest_side; - HRESULT ddrval; - - // Compensate for aspect ratio - if ( gr_screen.clip_width > gr_screen.clip_height ) - largest_side = gr_screen.clip_width; - else - largest_side = gr_screen.clip_height; - - viewdata.dwSize = sizeof( viewdata ); - viewdata.dwX = gr_screen.clip_left+x; - viewdata.dwY = gr_screen.clip_top+y; - viewdata.dwWidth = gr_screen.clip_width; - viewdata.dwHeight = gr_screen.clip_height; - viewdata.dvScaleX = largest_side / 2.0F; - viewdata.dvScaleY = largest_side / 2.0F; - viewdata.dvMaxX = ( float ) ( viewdata.dwWidth / ( 2.0F * viewdata.dvScaleX ) ); - viewdata.dvMaxY = ( float ) ( viewdata.dwHeight / ( 2.0F * viewdata.dvScaleY ) ); - viewdata.dvMinZ = 0.0F; - viewdata.dvMaxZ = 0.0F; // choose something appropriate here! - - ddrval = lpViewport->SetViewport( &viewdata ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_D3D_SET_CLIP: SetViewport failed.\n" )); - } - -} - - -void gr_d3d_reset_clip() -{ - gr_screen.offset_x = 0; - gr_screen.offset_y = 0; - gr_screen.clip_left = 0; - gr_screen.clip_top = 0; - gr_screen.clip_right = gr_screen.max_w - 1; - gr_screen.clip_bottom = gr_screen.max_h - 1; - gr_screen.clip_width = gr_screen.max_w; - gr_screen.clip_height = gr_screen.max_h; - - // Setup the viewport for a reasonable viewing area - D3DVIEWPORT viewdata; - DWORD largest_side; - HRESULT ddrval; - - // Compensate for aspect ratio - if ( gr_screen.clip_width > gr_screen.clip_height ) - largest_side = gr_screen.clip_width; - else - largest_side = gr_screen.clip_height; - - viewdata.dwSize = sizeof( viewdata ); - viewdata.dwX = gr_screen.clip_left; - viewdata.dwY = gr_screen.clip_top; - viewdata.dwWidth = gr_screen.clip_width; - viewdata.dwHeight = gr_screen.clip_height; - viewdata.dvScaleX = largest_side / 2.0F; - viewdata.dvScaleY = largest_side / 2.0F; - viewdata.dvMaxX = ( float ) ( viewdata.dwWidth / ( 2.0F * viewdata.dvScaleX ) ); - viewdata.dvMaxY = ( float ) ( viewdata.dwHeight / ( 2.0F * viewdata.dvScaleY ) ); - viewdata.dvMinZ = 0.0F; - viewdata.dvMaxZ = 0.0F; // choose something appropriate here! - - ddrval = lpViewport->SetViewport( &viewdata ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_D3D_SET_CLIP: SetViewport failed.\n" )); - } - -} - -void gr_d3d_init_color(color *c, int r, int g, int b) -{ - c->screen_sig = gr_screen.signature; - c->red = unsigned char(r); - c->green = unsigned char(g); - c->blue = unsigned char(b); - c->alpha = 255; - c->ac_type = AC_TYPE_NONE; - c->alphacolor = -1; - c->is_alphacolor = 0; - c->magic = 0xAC01; -} - -void gr_d3d_init_alphacolor( color *clr, int r, int g, int b, int alpha, int type ) -{ - if ( r < 0 ) r = 0; else if ( r > 255 ) r = 255; - if ( g < 0 ) g = 0; else if ( g > 255 ) g = 255; - if ( b < 0 ) b = 0; else if ( b > 255 ) b = 255; - if ( alpha < 0 ) alpha = 0; else if ( alpha > 255 ) alpha = 255; - - gr_d3d_init_color( clr, r, g, b ); - - clr->alpha = unsigned char(alpha); - clr->ac_type = (ubyte)type; - clr->alphacolor = -1; - clr->is_alphacolor = 1; -} - -void gr_d3d_set_color( int r, int g, int b ) -{ - SDL_assert((r >= 0) && (r < 256)); - SDL_assert((g >= 0) && (g < 256)); - SDL_assert((b >= 0) && (b < 256)); - - gr_d3d_init_color( &gr_screen.current_color, r, g, b ); -} - -void gr_d3d_get_color( int * r, int * g, int * b ) -{ - if (r) *r = gr_screen.current_color.red; - if (g) *g = gr_screen.current_color.green; - if (b) *b = gr_screen.current_color.blue; -} - -void gr_d3d_set_color_fast(color *dst) -{ - if ( dst->screen_sig != gr_screen.signature ) { - if ( dst->is_alphacolor ) { - gr_d3d_init_alphacolor( dst, dst->red, dst->green, dst->blue, dst->alpha, dst->ac_type ); - } else { - gr_d3d_init_color( dst, dst->red, dst->green, dst->blue ); - } - } - gr_screen.current_color = *dst; -} - -void gr_d3d_set_bitmap( int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha, int sx, int sy ) -{ - gr_screen.current_alpha = alpha; - gr_screen.current_alphablend_mode = alphablend_mode; - gr_screen.current_bitblt_mode = bitblt_mode; - gr_screen.current_bitmap = bitmap_num; - gr_screen.current_bitmap_sx = sx; - gr_screen.current_bitmap_sy = sy; -} - -void gr_d3d_bitmap_ex_internal(int x,int y,int w,int h,int sx,int sy) -{ - int i,j; - bitmap * bmp; - ushort * sptr; - ushort * dptr; - HRESULT ddrval; - DDSURFACEDESC ddsd; - - memset( &ddsd, 0, sizeof( ddsd ) ); - ddsd.dwSize = sizeof( ddsd ); - - ddrval = lpBackBuffer->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "Error locking surface for bitmap_ex, %s\n", d3d_error_string(ddrval) )); - return; - } - - dptr = (ushort *)((int)ddsd.lpSurface+ddsd.lPitch*(y+gr_screen.offset_y)+(x+gr_screen.offset_x)*2); - - bmp = bm_lock( gr_screen.current_bitmap, 16, 0 ); - sptr = (ushort *)( bmp->data + (sy*bmp->w + sx) ); - - // nice and speedy compared to the old way - for (i=0; iw; - } - - bm_unlock(gr_screen.current_bitmap); - - // Unlock the back buffer - lpBackBuffer->Unlock( NULL ); -} - -void gr_d3d_bitmap_ex(int x,int y,int w,int h,int sx,int sy) -{ - int reclip; - #ifndef NDEBUG - int count = 0; - #endif - - int dx1=x, dx2=x+w-1; - int dy1=y, dy2=y+h-1; - - int bw, bh; - bm_get_info( gr_screen.current_bitmap, &bw, &bh, NULL ); - - do { - reclip = 0; - #ifndef NDEBUG - if ( count > 1 ) Int3(); - count++; - #endif - - if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return; - if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return; - if ( dx1 < gr_screen.clip_left ) { sx += gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; } - if ( dy1 < gr_screen.clip_top ) { sy += gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; } - if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; } - if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; } - - if ( sx < 0 ) { - dx1 -= sx; - sx = 0; - reclip = 1; - } - - if ( sy < 0 ) { - dy1 -= sy; - sy = 0; - reclip = 1; - } - - w = dx2-dx1+1; - h = dy2-dy1+1; - - if ( sx + w > bw ) { - w = bw - sx; - dx2 = dx1 + w - 1; - } - - if ( sy + h > bh ) { - h = bh - sy; - dy2 = dy1 + h - 1; - } - - if ( w < 1 ) return; // clipped away! - if ( h < 1 ) return; // clipped away! - - } while (reclip); - - // Make sure clipping algorithm works - #ifndef NDEBUG - SDL_assert( w > 0 ); - SDL_assert( h > 0 ); - SDL_assert( w == (dx2-dx1+1) ); - SDL_assert( h == (dy2-dy1+1) ); - SDL_assert( sx >= 0 ); - SDL_assert( sy >= 0 ); - SDL_assert( sx+w <= bw ); - SDL_assert( sy+h <= bh ); - SDL_assert( dx2 >= dx1 ); - SDL_assert( dy2 >= dy1 ); - SDL_assert( (dx1 >= gr_screen.clip_left ) && (dx1 <= gr_screen.clip_right) ); - SDL_assert( (dx2 >= gr_screen.clip_left ) && (dx2 <= gr_screen.clip_right) ); - SDL_assert( (dy1 >= gr_screen.clip_top ) && (dy1 <= gr_screen.clip_bottom) ); - SDL_assert( (dy2 >= gr_screen.clip_top ) && (dy2 <= gr_screen.clip_bottom) ); - #endif - - // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions. - // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2) - - gr_d3d_bitmap_ex_internal(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy); -} - -void gr_d3d_bitmap(int x, int y) -{ - int w, h; - - - bm_get_info( gr_screen.current_bitmap, &w, &h, NULL ); - int dx1=x, dx2=x+w-1; - int dy1=y, dy2=y+h-1; - int sx=0, sy=0; - - if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return; - if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return; - if ( dx1 < gr_screen.clip_left ) { sx = gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; } - if ( dy1 < gr_screen.clip_top ) { sy = gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; } - if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; } - if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; } - - if ( sx < 0 ) return; - if ( sy < 0 ) return; - if ( sx >= w ) return; - if ( sy >= h ) return; - - // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2) - - gr_d3d_bitmap_ex_internal(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy); -} - - - -void gr_d3d_aabitmap_ex_internal(int x,int y,int w,int h,int sx,int sy) -{ - if ( w < 1 ) return; - if ( h < 1 ) return; - - if ( !gr_screen.current_color.is_alphacolor ) return; - - float u_scale, v_scale; - - gr_d3d_set_state( TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE ); - - if ( !gr_tcache_set( gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP, &u_scale, &v_scale ) ) { - // Couldn't set texture - //mprintf(( "GLIDE: Error setting aabitmap texture!\n" )); - return; - } - - LPD3DTLVERTEX src_v; - D3DTLVERTEX d3d_verts[4]; - - float u0, u1, v0, v1; - float x1, x2, y1, y2; - int bw, bh; - - bm_get_info( gr_screen.current_bitmap, &bw, &bh ); - - // Rendition - if ( D3d_rendition_uvs ) { - u0 = u_scale*(i2fl(sx)+0.5f)/i2fl(bw); - v0 = v_scale*(i2fl(sy)+0.5f)/i2fl(bh); - - u1 = u_scale*(i2fl(sx+w)+0.5f)/i2fl(bw); - v1 = v_scale*(i2fl(sy+h)+0.5f)/i2fl(bh); - } else { - u0 = u_scale*i2fl(sx)/i2fl(bw); - v0 = v_scale*i2fl(sy)/i2fl(bh); - - u1 = u_scale*i2fl(sx+w)/i2fl(bw); - v1 = v_scale*i2fl(sy+h)/i2fl(bh); - } - - x1 = i2fl(x+gr_screen.offset_x); - y1 = i2fl(y+gr_screen.offset_y); - x2 = i2fl(x+w+gr_screen.offset_x); - y2 = i2fl(y+h+gr_screen.offset_y); - - src_v = d3d_verts; - - uint color; - - if ( gr_screen.current_color.is_alphacolor ) { - if ( lpDevDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_MODULATEALPHA ) { - color = RGBA_MAKE(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue,gr_screen.current_color.alpha); - } else { - int r = (gr_screen.current_color.red*gr_screen.current_color.alpha)/255; - int g = (gr_screen.current_color.green*gr_screen.current_color.alpha)/255; - int b = (gr_screen.current_color.blue*gr_screen.current_color.alpha)/255; - - color = RGBA_MAKE(r,g,b, 255 ); - } - } else { - color = RGB_MAKE(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue); - } - - src_v->sz = 0.99f; - src_v->rhw = 1.0f; - src_v->color = color; - src_v->specular = 0; - src_v->sx = x1; - src_v->sy = y1; - src_v->tu = u0; - src_v->tv = v0; - src_v++; - - src_v->sz = 0.99f; - src_v->rhw = 1.0f; - src_v->color = color; - src_v->specular = 0; - src_v->sx = x2; - src_v->sy = y1; - src_v->tu = u1; - src_v->tv = v0; - src_v++; - - src_v->sz = 0.99f; - src_v->rhw = 1.0f; - src_v->color = color; - src_v->specular = 0; - src_v->sx = x2; - src_v->sy = y2; - src_v->tu = u1; - src_v->tv = v1; - src_v++; - - src_v->sz = 0.99f; - src_v->rhw = 1.0f; - src_v->color = color; - src_v->specular = 0; - src_v->sx = x1; - src_v->sy = y2; - src_v->tu = u0; - src_v->tv = v1; - - d3d_DrawPrimitive(D3DPT_TRIANGLEFAN,D3DVT_TLVERTEX,(LPVOID)d3d_verts,4,NULL); -} - -void gr_d3d_aabitmap_ex(int x,int y,int w,int h,int sx,int sy) -{ - int reclip; - #ifndef NDEBUG - int count = 0; - #endif - - int dx1=x, dx2=x+w-1; - int dy1=y, dy2=y+h-1; - - int bw, bh; - bm_get_info( gr_screen.current_bitmap, &bw, &bh, NULL ); - - do { - reclip = 0; - #ifndef NDEBUG - if ( count > 1 ) Int3(); - count++; - #endif - - if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return; - if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return; - if ( dx1 < gr_screen.clip_left ) { sx += gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; } - if ( dy1 < gr_screen.clip_top ) { sy += gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; } - if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; } - if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; } - - if ( sx < 0 ) { - dx1 -= sx; - sx = 0; - reclip = 1; - } - - if ( sy < 0 ) { - dy1 -= sy; - sy = 0; - reclip = 1; - } - - w = dx2-dx1+1; - h = dy2-dy1+1; - - if ( sx + w > bw ) { - w = bw - sx; - dx2 = dx1 + w - 1; - } - - if ( sy + h > bh ) { - h = bh - sy; - dy2 = dy1 + h - 1; - } - - if ( w < 1 ) return; // clipped away! - if ( h < 1 ) return; // clipped away! - - } while (reclip); - - // Make sure clipping algorithm works - #ifndef NDEBUG - SDL_assert( w > 0 ); - SDL_assert( h > 0 ); - SDL_assert( w == (dx2-dx1+1) ); - SDL_assert( h == (dy2-dy1+1) ); - SDL_assert( sx >= 0 ); - SDL_assert( sy >= 0 ); - SDL_assert( sx+w <= bw ); - SDL_assert( sy+h <= bh ); - SDL_assert( dx2 >= dx1 ); - SDL_assert( dy2 >= dy1 ); - SDL_assert( (dx1 >= gr_screen.clip_left ) && (dx1 <= gr_screen.clip_right) ); - SDL_assert( (dx2 >= gr_screen.clip_left ) && (dx2 <= gr_screen.clip_right) ); - SDL_assert( (dy1 >= gr_screen.clip_top ) && (dy1 <= gr_screen.clip_bottom) ); - SDL_assert( (dy2 >= gr_screen.clip_top ) && (dy2 <= gr_screen.clip_bottom) ); - #endif - - // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions. - gr_d3d_aabitmap_ex_internal(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy); -} - -void gr_d3d_aabitmap(int x, int y) -{ - int w, h; - - bm_get_info( gr_screen.current_bitmap, &w, &h, NULL ); - int dx1=x, dx2=x+w-1; - int dy1=y, dy2=y+h-1; - int sx=0, sy=0; - - if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return; - if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return; - if ( dx1 < gr_screen.clip_left ) { sx = gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; } - if ( dy1 < gr_screen.clip_top ) { sy = gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; } - if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; } - if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; } - - if ( sx < 0 ) return; - if ( sy < 0 ) return; - if ( sx >= w ) return; - if ( sy >= h ) return; - - // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2) - gr_aabitmap_ex(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy); -} - - -void gr_d3d_string( int sx, int sy, char *s ) -{ - int width, spacing, letter; - int x, y; - - if ( !Current_font ) { - return; - } - - gr_set_bitmap(Current_font->bitmap_id); - - x = sx; - y = sy; - - if (sx==0x8000) { //centered - x = get_centered_x(s); - } else { - x = sx; - } - - spacing = 0; - - while (*s) { - x += spacing; - - while (*s== '\n' ) { - s++; - y += Current_font->h; - if (sx==0x8000) { //centered - x = get_centered_x(s); - } else { - x = sx; - } - } - if (*s == 0 ) break; - - letter = get_char_width(s[0],s[1],&width,&spacing); - s++; - - //not in font, draw as space - if (letter<0) { - continue; - } - - int xd, yd, xc, yc; - int wc, hc; - - // Check if this character is totally clipped - if ( x + width < gr_screen.clip_left ) continue; - if ( y + Current_font->h < gr_screen.clip_top ) continue; - if ( x > gr_screen.clip_right ) continue; - if ( y > gr_screen.clip_bottom ) continue; - - xd = yd = 0; - if ( x < gr_screen.clip_left ) xd = gr_screen.clip_left - x; - if ( y < gr_screen.clip_top ) yd = gr_screen.clip_top - y; - xc = x+xd; - yc = y+yd; - - wc = width - xd; hc = Current_font->h - yd; - if ( xc + wc > gr_screen.clip_right ) wc = gr_screen.clip_right - xc; - if ( yc + hc > gr_screen.clip_bottom ) hc = gr_screen.clip_bottom - yc; - - if ( wc < 1 ) continue; - if ( hc < 1 ) continue; - - font_char *ch; - - ch = &Current_font->char_data[letter]; - - int u = Current_font->bm_u[letter]; - int v = Current_font->bm_v[letter]; - - gr_d3d_aabitmap_ex_internal( xc, yc, wc, hc, u+xd, v+yd ); - } -} - -void gr_d3d_rect(int x,int y,int w,int h) -{ - gr_d3d_rect_internal(x, y, w, h, gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha); -} - -void gr_d3d_flash(int r, int g, int b) -{ - CAP(r,0,255); - CAP(g,0,255); - CAP(b,0,255); - - if ( r || g || b ) { - uint color; - if ( lpDevDesc->dpcTriCaps.dwDestBlendCaps & D3DPBLENDCAPS_ONE ) { - gr_d3d_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_ADDITIVE, ZBUFFER_TYPE_NONE ); - color = RGBA_MAKE(r, g, b, 255); - } else { - gr_d3d_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE ); - - int a = (r+g+b)/3; - color = RGBA_MAKE(r,g,b,a); - } - - float x1, x2, y1, y2; - x1 = i2fl(gr_screen.clip_left+gr_screen.offset_x); - y1 = i2fl(gr_screen.clip_top+gr_screen.offset_y); - x2 = i2fl(gr_screen.clip_right+gr_screen.offset_x); - y2 = i2fl(gr_screen.clip_bottom+gr_screen.offset_y); - - LPD3DTLVERTEX src_v; - D3DTLVERTEX d3d_verts[4]; - - src_v = d3d_verts; - - src_v->sz = 0.99f; - src_v->rhw = 1.0f; - src_v->color = color; - src_v->specular = 0; - src_v->sx = x1; - src_v->sy = y1; - src_v++; - - src_v->sz = 0.99f; - src_v->rhw = 1.0f; - src_v->color = color; - src_v->specular = 0; - src_v->sx = x2; - src_v->sy = y1; - src_v++; - - src_v->sz = 0.99f; - src_v->rhw = 1.0f; - src_v->color = color; - src_v->specular = 0; - src_v->sx = x2; - src_v->sy = y2; - src_v++; - - src_v->sz = 0.99f; - src_v->rhw = 1.0f; - src_v->color = color; - src_v->specular = 0; - src_v->sx = x1; - src_v->sy = y2; - - d3d_DrawPrimitive(D3DPT_TRIANGLEFAN,D3DVT_TLVERTEX,(LPVOID)d3d_verts,4,NULL); - } -} - - - -void gr_d3d_create_shader(shader * shade, float r, float g, float b, float c ) -{ - shade->screen_sig = gr_screen.signature; - shade->r = r; - shade->g = g; - shade->b = b; - shade->c = c; -} - -void gr_d3d_set_shader( shader * shade ) -{ - if ( shade ) { - if (shade->screen_sig != gr_screen.signature) { - gr_create_shader( shade, shade->r, shade->g, shade->b, shade->c ); - } - gr_screen.current_shader = *shade; - } else { - gr_create_shader( &gr_screen.current_shader, 0.0f, 0.0f, 0.0f, 0.0f ); - } -} - -void gr_d3d_shade(int x,int y,int w,int h) -{ - int r,g,b,a; - - float shade1 = 1.0f; - float shade2 = 6.0f; - - r = fl2i(gr_screen.current_shader.r*255.0f*shade1); - if ( r < 0 ) r = 0; else if ( r > 255 ) r = 255; - g = fl2i(gr_screen.current_shader.g*255.0f*shade1); - if ( g < 0 ) g = 0; else if ( g > 255 ) g = 255; - b = fl2i(gr_screen.current_shader.b*255.0f*shade1); - if ( b < 0 ) b = 0; else if ( b > 255 ) b = 255; - a = fl2i(gr_screen.current_shader.c*255.0f*shade2); - if ( a < 0 ) a = 0; else if ( a > 255 ) a = 255; - - gr_d3d_rect_internal(x, y, w, h, r, g, b, a); -} - -void gr_d3d_circle( int xc, int yc, int d ) -{ - - int p,x, y, r; - - r = d/2; - p=3-d; - x=0; - y=r; - - // Big clip - if ( (xc+r) < gr_screen.clip_left ) return; - if ( (xc-r) > gr_screen.clip_right ) return; - if ( (yc+r) < gr_screen.clip_top ) return; - if ( (yc-r) > gr_screen.clip_bottom ) return; - - while(xdpcLineCaps.dwSrcBlendCaps & D3DPBLENDCAPS_SRCALPHA) && (lpDevDesc->dpcLineCaps.dwDestBlendCaps & D3DPBLENDCAPS_INVSRCALPHA) ) { - gr_d3d_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE ); - color = RGBA_MAKE(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha ); - } else { - // Matrox MGA-G200 doesn't support alpha-blended lines. - gr_d3d_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_NONE, ZBUFFER_TYPE_NONE ); - - int r = (gr_screen.current_color.red*gr_screen.current_color.alpha)/255; - int g = (gr_screen.current_color.green*gr_screen.current_color.alpha)/255; - int b = (gr_screen.current_color.blue*gr_screen.current_color.alpha)/255; - - color = RGBA_MAKE(r,g,b, 255 ); - } - - INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,gr_screen.clip_right,gr_screen.clip_bottom,return,clipped=1,swapped=1); - - D3DTLVERTEX d3d_verts[2]; - D3DTLVERTEX *a = d3d_verts; - D3DTLVERTEX *b = d3d_verts+1; - - d3d_make_rect(a,b,x1,y1,x2,y2); - - a->color = color; - b->color = color; - - d3d_DrawPrimitive(D3DPT_LINELIST,D3DVT_TLVERTEX,(LPVOID)d3d_verts,2,NULL); -} - -void gr_d3d_aaline(vertex *v1, vertex *v2) -{ - gr_d3d_line( fl2i(v1->sx), fl2i(v1->sy), fl2i(v2->sx), fl2i(v2->sy) ); -} - - -void gr_d3d_gradient(int x1,int y1,int x2,int y2) -{ - int clipped = 0, swapped=0; - - if ( !gr_screen.current_color.is_alphacolor ) { - gr_line( x1, y1, x2, y2 ); - return; - } - - INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,gr_screen.clip_right,gr_screen.clip_bottom,return,clipped=1,swapped=1); - - uint color1, color2; - - // Set up Render State - flat shading - alpha blending - if ( (lpDevDesc->dpcLineCaps.dwSrcBlendCaps & D3DPBLENDCAPS_SRCALPHA) && (lpDevDesc->dpcLineCaps.dwDestBlendCaps & D3DPBLENDCAPS_INVSRCALPHA) ) { - gr_d3d_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE ); - - if (lpDevDesc->dpcLineCaps.dwShadeCaps & D3DPSHADECAPS_ALPHAGOURAUDBLEND ) { - color1 = RGBA_MAKE(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha ); - color2 = RGBA_MAKE(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, 0 ); - } else if (lpDevDesc->dpcLineCaps.dwShadeCaps & D3DPSHADECAPS_COLORGOURAUDRGB ) { - color1 = RGBA_MAKE(gr_screen.current_color.red,gr_screen.current_color.green,gr_screen.current_color.blue,gr_screen.current_color.alpha); - color2 = RGBA_MAKE(0,0,0,gr_screen.current_color.alpha); - } else { - color1 = RGBA_MAKE(gr_screen.current_color.red,gr_screen.current_color.green,gr_screen.current_color.blue,gr_screen.current_color.alpha); - color2 = RGBA_MAKE(gr_screen.current_color.red,gr_screen.current_color.green,gr_screen.current_color.blue,gr_screen.current_color.alpha); - } - } else { - // Matrox MGA-G200 doesn't support alpha-blended lines. - gr_d3d_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_NONE, ZBUFFER_TYPE_NONE ); - - int r = (gr_screen.current_color.red*gr_screen.current_color.alpha)/255; - int g = (gr_screen.current_color.green*gr_screen.current_color.alpha)/255; - int b = (gr_screen.current_color.blue*gr_screen.current_color.alpha)/255; - - if (lpDevDesc->dpcLineCaps.dwShadeCaps & D3DPSHADECAPS_COLORGOURAUDRGB ) { - color1 = RGBA_MAKE(r,g,b, 255 ); - color2 = RGBA_MAKE(0,0,0, 255 ); - } else { - color1 = RGBA_MAKE(r,g,b, 255 ); - color2 = RGBA_MAKE(r,g,b, 255 ); - } - } - -// gr_d3d_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_NONE, ZBUFFER_TYPE_NONE ); -// color1 = RGBA_MAKE(gr_screen.current_color.red,gr_screen.current_color.green,gr_screen.current_color.blue,255); -// color2 = RGBA_MAKE(gr_screen.current_color.red,gr_screen.current_color.green,gr_screen.current_color.blue,255); - - D3DTLVERTEX d3d_verts[2]; - D3DTLVERTEX *a = d3d_verts; - D3DTLVERTEX *b = d3d_verts+1; - - d3d_make_rect( a, b, x1, y1, x2, y2 ); - - if ( swapped ) { - b->color = color1; - a->color = color2; - } else { - a->color = color1; - b->color = color2; - } - d3d_DrawPrimitive(D3DPT_LINELIST,D3DVT_TLVERTEX,(LPVOID)d3d_verts,2,NULL); -} - - -void gr_d3d_set_palette(ubyte *new_palette, int restrict_alphacolor) -{ -} - - -// copy from one pixel buffer to another -// -// from pointer to source buffer -// to pointer to dest. buffet -// pixels number of pixels to copy -// fromsize source pixel size -// tosize dest. pixel size - -static int tga_copy_data(char *to, char *from, int pixels, int fromsize, int tosize) -{ - if ( (fromsize == 2) && (tosize == 3) ) { - ushort *src = (ushort *)from; - ubyte *dst = (ubyte *)to; - - int i; - for (i=0; i>Gr_blue.shift)*Gr_blue.scale); - *dst++ = ubyte(((pixel & Gr_green.mask)>>Gr_green.shift)*Gr_green.scale); - *dst++ = ubyte(((pixel & Gr_red.mask)>>Gr_red.shift)*Gr_red.scale); - } - return tosize*pixels; - } else if( (fromsize == 4) && (tosize == 3) ){ - uint *src = (uint *)from; - ubyte *dst = (ubyte *)to; - - int i; - for (i=0; i>Gr_blue.shift)*Gr_blue.scale); - *dst++ = ubyte(((pixel & Gr_green.mask)>>Gr_green.shift)*Gr_green.scale); - *dst++ = ubyte(((pixel & Gr_red.mask)>>Gr_red.shift)*Gr_red.scale); - } - return tosize*pixels; - } else { - Int3(); - return tosize*pixels; - } -} - -// -// tga_pixels_equal -- Test if two pixels are identical -// -// Returns: -// 0 if No Match -// 1 if Match - -static int tga_pixels_equal(char *pix1, char *pix2, int pixbytes) -{ - do { - if ( *pix1++ != *pix2++ ) { - return 0; - } - } while ( --pixbytes > 0 ); - - return 1; -} - - -// tga_compress - Do the Run Length Compression -// -// Usage: -// out Buffer to write it out to -// in Buffer to compress -// bytecount Number of bytes input -// pixsize Number of bytes in input pixel -// outsize Number of bytes in output buffer - -static int tga_compress(char *out, char *in, int bytecount, int pixsize ) -{ - #define outsize 3 - - int pixcount; // number of pixels in the current packet - char *inputpixel=NULL; // current input pixel position - char *matchpixel=NULL; // pixel value to match for a run - char *flagbyte=NULL; // location of last flag byte to set - int rlcount; // current count in r.l. string - int rlthresh; // minimum valid run length - char *copyloc; // location to begin copying at - - // set the threshold -- the minimum valid run length - - #if outsize == 1 - rlthresh = 2; // for 8bpp, require a 2 pixel span before rle'ing - #else - rlthresh = 1; - #endif - - // set the first pixel up - - flagbyte = out; // place to put next flag if run - inputpixel = in; - pixcount = 1; - rlcount = 0; - copyloc = (char *)0; - - // loop till data processing complete - do { - - // if we have accumulated a 128-byte packet, process it - if ( pixcount == 129 ) { - *flagbyte = 127; - - // set the run flag if this is a run - - if ( rlcount >= rlthresh ) { - *flagbyte |= 0x80; - pixcount = 2; - } - - // copy the data into place - ++flagbyte; - flagbyte += tga_copy_data(flagbyte, copyloc, pixcount-1, pixsize, outsize); - pixcount = 1; - - // set up for next packet - continue; - } - - // if zeroth byte, handle as special case - if ( pixcount == 1 ) { - rlcount = 0; - copyloc = inputpixel; /* point to 1st guy in packet */ - matchpixel = inputpixel; /* set pointer to pix to match */ - pixcount = 2; - inputpixel += pixsize; - continue; - } - - // assembling a packet -- look at next pixel - - // current pixel == match pixel? - if ( tga_pixels_equal(inputpixel, matchpixel, outsize) ) { - - // establishing a run of enough length to - // save space by doing it - // -- write the non-run length packet - // -- start run-length packet - - if ( ++rlcount == rlthresh ) { - - // close a non-run packet - - if ( pixcount > (rlcount+1) ) { - // write out length and do not set run flag - - *flagbyte++ = (char)(pixcount - 2 - rlthresh); - - flagbyte += tga_copy_data(flagbyte, copyloc, (pixcount-1-rlcount), pixsize, outsize); - - copyloc = inputpixel; - pixcount = rlcount + 1; - } - } - } else { - - // no match -- either break a run or continue without one - // if a run exists break it: - // write the bytes in the string (outsize+1) - // start the next string - - if ( rlcount >= rlthresh ) { - - *flagbyte++ = (char)(0x80 | rlcount); - flagbyte += tga_copy_data(flagbyte, copyloc, 1, pixsize, outsize); - pixcount = 1; - continue; - } else { - - // not a match and currently not a run - // - save the current pixel - // - reset the run-length flag - rlcount = 0; - matchpixel = inputpixel; - } - } - pixcount++; - inputpixel += pixsize; - } while ( inputpixel < (in + bytecount)); - - // quit this buffer without loosing any data - - if ( --pixcount >= 1 ) { - *flagbyte = (char)(pixcount - 1); - if ( rlcount >= rlthresh ) { - *flagbyte |= 0x80; - pixcount = 1; - } - - // copy the data into place - ++flagbyte; - flagbyte += tga_copy_data(flagbyte, copyloc, pixcount, pixsize, outsize); - } - return(flagbyte-out); -} - -void gr_d3d_print_screen(char *filename) -{ - HRESULT ddrval; - DDSURFACEDESC ddsd; - ubyte outrow[1024*3*4]; - - if ( gr_screen.max_w > 1024 ) { - mprintf(( "Screen too wide for print_screen\n" )); - return; - } - - memset( &ddsd, 0, sizeof( ddsd ) ); - ddsd.dwSize = sizeof( ddsd ); - - ddrval = lpBackBuffer->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "Error locking surface for print_screen, %s\n", d3d_error_string(ddrval) )); - } - - ubyte *dptr = (ubyte *)ddsd.lpSurface; - - char tmp[1024]; - - strcpy( tmp, NOX(".\\")); // specify a path mean files goes in root - strcat( tmp, filename ); - strcat( tmp, NOX(".tga")); - - CFILE *f = cfopen(tmp, "wb"); - - // Write the TGA header - cfwrite_ubyte( 0, f ); // IDLength; - cfwrite_ubyte( 0, f ); // ColorMapType; - cfwrite_ubyte( 10, f ); // ImageType; // 2 = 24bpp, uncompressed, 10=24bpp rle compressed - cfwrite_ushort( 0, f ); // CMapStart; - cfwrite_ushort( 0, f ); // CMapLength; - cfwrite_ubyte( 0, f ); // CMapDepth; - cfwrite_ushort( 0, f ); // XOffset; - cfwrite_ushort( 0, f ); // YOffset; - cfwrite_ushort( (ushort)gr_screen.max_w, f ); // Width; - cfwrite_ushort( (ushort)gr_screen.max_h, f ); // Height; - cfwrite_ubyte( 24, f ); //PixelDepth; - cfwrite_ubyte( 0, f ); //ImageDesc; - - // Go through and read our pixels - int i; - for (i=0;iUnlock( NULL ); - -} - - - diff --git a/src/graphics/grd3dtexture.cpp b/src/graphics/grd3dtexture.cpp deleted file mode 100644 index 585ec88..0000000 --- a/src/graphics/grd3dtexture.cpp +++ /dev/null @@ -1,1417 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/GrD3DTexture.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Code to manage loading textures into VRAM for Direct3D - * - * $Log$ - * Revision 1.3 2002/06/09 04:41:17 relnev - * added copyright header - * - * Revision 1.2 2002/05/07 03:16:45 theoddone33 - * The Great Newline Fix - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 22 9/09/99 8:53p Dave - * Fixed multiplayer degenerate orientation case problem. Make sure warp - * effect never goes lower than LOD 1. - * - * 21 9/05/99 11:19p Dave - * Made d3d texture cache much more safe. Fixed training scoring bug where - * it would backout scores without ever having applied them in the first - * place. - * - * 20 8/16/99 4:04p Dave - * Big honking checkin. - * - * 19 7/29/99 10:47p Dave - * Standardized D3D fogging using vertex fog. Shook out Savage 4 bugs. - * - * 18 7/16/99 1:49p Dave - * 8 bit aabitmaps. yay. - * - * 17 7/13/99 1:15p Dave - * 32 bit support. Whee! - * - * 16 7/09/99 9:51a Dave - * Added thick polyline code. - * - * 15 6/29/99 10:35a Dave - * Interface polygon bitmaps! Whee! - * - * 14 6/16/99 4:06p Dave - * New pilot info popup. Added new draw-bitmap-as-poly function. - * - * 13 5/05/99 9:02p Dave - * Fixed D3D aabitmap rendering. Spiffed up nebula effect a bit (added - * rotations, tweaked values, made bitmap selection more random). Fixed - * D3D beam weapon clipping problem. Added D3d frame dumping. - * - * 12 2/11/99 3:08p Dave - * PXO refresh button. Very preliminary squad war support. - * - * 11 2/05/99 12:52p Dave - * Fixed Glide nondarkening textures. - * - * 10 2/03/99 11:44a Dave - * Fixed d3d transparent textures. - * - * 9 1/30/99 5:08p Dave - * More new hi-res stuff.Support for nice D3D textures. - * - * 8 1/15/99 11:29a Neilk - * Fixed D3D screen/texture pixel formatting problem. - * - * 7 1/12/99 12:53a Dave - * More work on beam weapons - made collision detection very efficient - - * collide against all object types properly - made 3 movement types - * smooth. Put in test code to check for possible non-darkening pixels on - * object textures. - * - * 6 12/01/98 6:12p Johnson - * Make sure to page in weapon impact animations as xparent textures. - * - * 5 12/01/98 10:32a Johnson - * Fixed direct3d font problems. Fixed sun bitmap problem. Fixed direct3d - * starfield problem. - * - * 4 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 3 10/09/98 2:57p Dave - * Starting splitting up OS stuff. - * - * 2 10/07/98 10:52a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 37 6/13/98 3:18p Hoffoss - * NOX()ed out a bunch of strings that shouldn't be translated. - * - * 36 5/23/98 6:12p John - * added code to use registry to force preloading of textures or not. - * - * 35 5/23/98 5:17p John - * added reg key to set texture divider - * - * 34 5/23/98 5:01p John - * made agp preloading happen if >= 6 MB of VRAM. - * - * 33 5/23/98 4:14p John - * Added code to preload textures to video card for AGP. Added in code - * to page in some bitmaps that weren't getting paged in at level start. - * - * 32 5/22/98 10:29p John - * made direct3d textures scale as little as glide. - * - * 31 5/22/98 12:54p John - * forced all cards to use a max of 256 pixel wide textures, but added a - * registry setting to disable it. - * - * 30 5/21/98 9:56p John - * Made Direct3D work with classic alpha-blending only devices, like the - * Virge. Added a texture type XPARENT that fills the alpha in in the - * bitmap for Virge. Added support for Permedia by making making - * additive alphablending be one/one instead of alpha/one, which didn't - * work, and there is no way to tell this from caps. - * - * 29 5/20/98 10:23a John - * put in code to fix an optimized build problem. - * - * 28 5/18/98 8:26p John - * Made cards with only 1bpp alpha fonts work. - * - * 27 5/12/98 7:53p John - * Fixed some 3dfx d3d bugs on allenders, jasen and johnson's computers - * caused by 8:3:3:2 format being used, but not liked by the card. - * - * 26 5/12/98 8:18a John - * Put in code to use a different texture format for alpha textures and - * normal textures. Turned off filtering for aabitmaps. Took out - * destblend=invsrccolor alpha mode that doesn't work on riva128. - * - * 25 5/11/98 10:58a John - * Fixed pilot name cursor bug. Started adding in code for alphachannel - * textures. - * - * 24 5/09/98 12:37p John - * More texture caching - * - * 23 5/09/98 12:16p John - * Even better texture caching. - * - * 22 5/09/98 11:07a John - * Better Direct3D texture caching - * - * 21 5/08/98 5:41p John - * - * 20 5/08/98 5:36p John - * MAde texturing blink white but not crash - * - * 19 5/07/98 3:02p John - * Mpre texture cleanup. You can now reinit d3d without a crash. - * - * 18 5/07/98 11:31a John - * Removed DEMO defines - * - * 17 5/07/98 10:28a John - * Made texture format use 4444. Made fonts use alpha to render. - * - * 16 5/07/98 9:40a John - * Fixed some bitmap transparency issues with Direct3D. - * - * 15 5/06/98 11:21p John - * Fixed a bitmap bug with Direct3D. Started adding new caching code into - * D3D. - * - * 14 5/06/98 8:41p John - * Fixed some font clipping bugs. Moved texture handle set code for d3d - * into the texture module. - * - * 13 5/03/98 10:52a John - * Made D3D sort of work on 3dfx. - * - * 12 5/03/98 10:43a John - * Working on Direct3D. - * - * 11 4/09/98 11:05a John - * Removed all traces of Direct3D out of the demo version of Freespace and - * the launcher. - * - * 10 3/12/98 5:36p John - * Took out any unused shaders. Made shader code take rgbc instead of - * matrix and vector since noone used it like a matrix and it would have - * been impossible to do in hardware. Made Glide implement a basic - * shader for online help. - * - * 9 3/08/98 10:25a John - * Made textures in VRAM reload if they changed - * - * 8 3/07/98 8:29p John - * Put in some Direct3D features. Transparency on bitmaps. Made fonts & - * aabitmaps render nice. - * - * 7 3/06/98 5:39p John - * Started adding in aabitmaps - * - * 6 3/02/98 6:00p John - * Moved MAX_BITMAPS into BmpMan.h so the stuff in the graphics code that - * is dependent on it won't break if it changes. Made ModelCache slots - * be equal to MAX_OBJECTS which is what it is. - * - * 5 2/17/98 7:46p John - * Took out debug code - * - * 4 2/17/98 7:28p John - * Got fonts and texturing working in Direct3D - * - * 3 2/06/98 4:56p John - * Turned off texturing - * - * 2 2/05/98 9:21p John - * Some new Direct3D code. Added code to monitor a ton of stuff in the - * game. - * - * 1 2/03/98 9:24p John - * - * $NoKeywords: $ - */ - -#include "grd3d.h" -#include "grd3dinternal.h" -#include "2d.h" -#include "pstypes.h" -#include "bmpman.h" -#include "key.h" -#include "systemvars.h" -#include "osregistry.h" - -#include "multi_log.h" - -typedef struct tcache_slot_d3d { - LPDIRECTDRAWSURFACE vram_texture_surface; - LPDIRECT3DTEXTURE2 vram_texture; - D3DTEXTUREHANDLE texture_handle; - float u_scale, v_scale; - int bitmap_id; - int size; - char used_this_frame; - int time_created; - ushort w, h; - - // sections - tcache_slot_d3d *data_sections[MAX_BMAP_SECTIONS_X][MAX_BMAP_SECTIONS_Y]; - tcache_slot_d3d *parent; -} tcache_slot_d3d; - -static void *Texture_sections = NULL; -tcache_slot_d3d *Textures = NULL; - - -int D3D_texture_sections = 0; -int D3D_texture_ram = 0; -int D3D_frame_count = 0; -int D3D_min_texture_width = 0; -int D3D_max_texture_width = 0; -int D3D_min_texture_height = 0; -int D3D_max_texture_height = 0; -int D3D_square_textures = 0; -int D3D_pow2_textures = 0; -int D3D_textures_in = 0; -int D3D_textures_in_frame = 0; -int D3D_last_bitmap_id = -1; -int D3D_last_detail = -1; -int D3D_last_bitmap_type = -1; -int D3D_last_section_x = -1; -int D3D_last_section_y = -1; - - -int vram_full = 0; - -int d3d_free_texture( tcache_slot_d3d *t ) -{ - int idx, s_idx; - - // Bitmap changed!! - if ( t->bitmap_id > -1 ) { - // if I, or any of my children have been used this frame, bail - if(t->used_this_frame){ - return 0; - } - for(idx=0; idxdata_sections[idx][s_idx] != NULL) && (t->data_sections[idx][s_idx]->used_this_frame)){ - return 0; - } - } - } - - // ok, now we know its legal to free everything safely - if ( t->vram_texture ) { - t->vram_texture->Release(); - t->vram_texture = NULL; - } - - if ( t->vram_texture_surface ) { - t->vram_texture_surface->Release(); - t->vram_texture_surface = NULL; - } - - t->texture_handle = NULL; - - if ( D3D_last_bitmap_id == t->bitmap_id ) { - D3D_last_bitmap_id = -1; - } - - // if this guy has children, free them too, since the children - // actually make up his size - for(idx=0; idxdata_sections[idx][s_idx] != NULL){ - d3d_free_texture(t->data_sections[idx][s_idx]); - } - } - } - - t->bitmap_id = -1; - t->used_this_frame = 0; - D3D_textures_in -= t->size; - } - - return 1; -} - -// we must make sure we never free my parent or any of my siblings!!!!! -int d3d_older_test(tcache_slot_d3d *new_slot, tcache_slot_d3d *test, tcache_slot_d3d *oldest) -{ - if ( (test != new_slot) && (test != new_slot->parent) && (test->bitmap_id > -1) && (!test->used_this_frame)) { - if ( (oldest == NULL) || (test->time_created < oldest->time_created)) { - return 1; - } - } - - // not older - return 0; -} - -int d3d_free_some_texture_ram(tcache_slot_d3d *t, int size) -{ - tcache_slot_d3d *oldest = NULL; - - // Go through all the textures... find the oldest one - // that was not used this frame yet. - int i; - - int goal_size = D3D_textures_in - size*2; - if ( goal_size < 0 ) { - goal_size = 0; - } else if ( goal_size > D3D_texture_ram*3/4 ) { - goal_size = D3D_texture_ram*3/4; - } - - while( D3D_textures_in > goal_size ) { - oldest = NULL; - for( i=0; inum_x; idx++){ - for(s_idx=0; s_idxnum_y; s_idx++){ - // bogus - if(t->data_sections[idx][s_idx] == NULL){ - return 0; - } - - // given a bitmap and a section, return the size (w, h) - bm_get_section_size(bitmap_id, idx, s_idx, &w, &h); - - // same ? - if((t->data_sections[idx][s_idx]->w != w) || (t->data_sections[idx][s_idx]->h != h)){ - return 0; - } - } - } - } - // non-sectioned bitmap - else { - if((t->w != w) || (t->h != h)){ - return 0; - } - } - - // all good - return 1; -} - -// get the final texture size (the one which will get allocated as a surface) -void d3d_tcache_get_adjusted_texture_size(int w_in, int h_in, int *w_out, int *h_out) -{ - int tex_w, tex_h; - - // bogus - if((w_out == NULL) || (h_out == NULL)){ - return; - } - - // starting size - tex_w = w_in; - tex_h = h_in; - - if ( D3D_pow2_textures ) { - int i; - for (i=0; i<16; i++ ) { - if ( (tex_w > (1< (1< D3D_max_texture_width ) { - tex_w = D3D_max_texture_width; - } - - if ( tex_h < D3D_min_texture_height ) { - tex_h = D3D_min_texture_height; - } else if ( tex_h > D3D_max_texture_height ) { - tex_h = D3D_max_texture_height; - } - - if ( D3D_square_textures ) { - int new_size; - // Make the both be equal to larger of the two - new_size = max(tex_w, tex_h); - tex_w = new_size; - tex_h = new_size; - } - - // store the outgoing size - *w_out = tex_w; - *h_out = tex_h; -} - -// data == start of bitmap data -// sx == x offset into bitmap -// sy == y offset into bitmap -// src_w == absolute width of section on source bitmap -// src_h == absolute height of section on source bitmap -// bmap_w == width of source bitmap -// bmap_h == height of source bitmap -// tex_w == width of final texture -// tex_h == height of final texture -int d3d_create_texture_sub(int bitmap_type, int texture_handle, ushort *data, int sx, int sy, int src_w, int src_h, int bmap_w, int bmap_h, int tex_w, int tex_h, tcache_slot_d3d *t, int reload, int fail_on_full) -{ - LPDIRECTDRAWSURFACE sys_texture_surface = NULL; - LPDIRECT3DTEXTURE2 sys_texture = NULL; - int ret_val = 1; - - #ifndef NDEBUG - if ( Show_uploads ) { - if ( reload ) { - mprintf(( "Reloading '%s'\n", bm_get_filename(texture_handle) )); - } else { - mprintf(( "Uploading '%s'\n", bm_get_filename(texture_handle) )); - } - } - #endif - - // bogus - if(t == NULL){ - return 0; - } - - if ( t->used_this_frame ) { - mprintf(( "ARGHH!!! Texture already used this frame! Cannot free it!\n" )); - return 0; - } - if ( !reload ) { - // gah - if(!d3d_free_texture(t)){ - return 0; - } - } - - DDSURFACEDESC ddsd; - HRESULT ddrval; - DWORD dwHeight, dwWidth; - int i,j; - ushort *bmp_data; - - DDPIXELFORMAT *surface_desc; - - switch( bitmap_type ) { - case TCACHE_TYPE_AABITMAP: - surface_desc = &AlphaTextureFormat; - break; - - case TCACHE_TYPE_XPARENT: - Int3(); - - default: - surface_desc = &NonAlphaTextureFormat; - } - - // get final texture size - d3d_tcache_get_adjusted_texture_size(tex_w, tex_h, &tex_w, &tex_h); - - if ( (tex_w < 1) || (tex_h < 1) ) { - mprintf(("Bitmap is to small at %dx%d.\n", tex_w, tex_h )); - return 0; - } - - if ( bitmap_type == TCACHE_TYPE_AABITMAP ) { - t->u_scale = (float)bmap_w / (float)tex_w; - t->v_scale = (float)bmap_h / (float)tex_h; - } else if(bitmap_type == TCACHE_TYPE_BITMAP_SECTION){ - t->u_scale = (float)src_w / (float)tex_w; - t->v_scale = (float)src_h / (float)tex_h; - } else { - t->u_scale = 1.0f; - t->v_scale = 1.0f; - } - - dwHeight = tex_h; - dwWidth = tex_w; - bmp_data = (ushort *)data; - ubyte *bmp_data_byte = (ubyte*)data; - - // Create a surface in system memory and load texture into it. - - // Create a surface of the given format using the dimensions of the bitmap - memset(&ddsd, 0, sizeof(DDSURFACEDESC)); - - ddsd.dwSize = sizeof(DDSURFACEDESC); - ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; - ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY; - ddsd.dwHeight = dwHeight; - ddsd.dwWidth = dwWidth; - ddsd.ddpfPixelFormat = *surface_desc; - - sys_texture_surface = NULL; - ddrval = lpDD->CreateSurface(&ddsd, &sys_texture_surface, NULL); - if ( (ddrval != DD_OK) || (sys_texture_surface == NULL) ) { - mprintf(("CreateSurface for texture failed (loadtex), w=%d, h=%d, %s\n", tex_w, tex_h, d3d_error_string(ddrval) )); - mprintf(( "Texture RAM = %d KB\n", D3D_textures_in / 1024 )); - // bm_unlock(bitmap_handle); - return 0; - } - - // Lock the surface so it can be filled with the bitmap data - memset(&ddsd, 0, sizeof(DDSURFACEDESC)); - ddsd.dwSize = sizeof(DDSURFACEDESC); - ddrval = sys_texture_surface->Lock(NULL, &ddsd, 0, NULL); - if (ddrval != DD_OK) { - sys_texture_surface->Release(); - mprintf(("Lock failed while loading surface (loadtex).\n" )); - return 0; - } - - SDL_assert( surface_desc->dwRGBBitCount == 16 ); - - // Each RGB bit count requires different pointers - ushort *lpSP; - ushort xlat[256]; - int r, g, b, a; - - switch( bitmap_type ) { - case TCACHE_TYPE_AABITMAP: - // setup convenient translation table - for (i=0; i<16; i++ ) { - r = 255; - g = 255; - b = 255; - a = Gr_gamma_lookup[(i*255)/15]; - r /= Gr_ta_red.scale; - g /= Gr_ta_green.scale; - b /= Gr_ta_blue.scale; - a /= Gr_ta_alpha.scale; - xlat[i] = unsigned short(((a<Unlock(NULL); - - sys_texture = NULL; - ddrval = sys_texture_surface->QueryInterface(IID_IDirect3DTexture2, (LPVOID *)&sys_texture); - if ( (ddrval != DD_OK) || (sys_texture == NULL) ) { - mprintf(( "Getting sys surface's texture failed!\n" )); - - // bad return value - ret_val = 0; - - goto FreeSurfacesAndExit; - } - -RetryLoad: - - if ( !reload ) { - // Create a surface of the given format using the dimensions of the bitmap - memset(&ddsd, 0, sizeof(DDSURFACEDESC)); - - ddsd.dwSize = sizeof(DDSURFACEDESC); - ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; - ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD | DDSCAPS_VIDEOMEMORY; - //| DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_ALLOCONLOAD; - ddsd.dwHeight = dwHeight; - ddsd.dwWidth = dwWidth; - ddsd.ddpfPixelFormat = *surface_desc; - - t->vram_texture_surface = NULL; - ddrval = lpDD->CreateSurface(&ddsd, &t->vram_texture_surface, NULL); - if ( (ddrval != DD_OK) || (t->vram_texture_surface == NULL) ) { - t->vram_texture = NULL; - t->vram_texture_surface = NULL; - t->texture_handle = NULL; - - if ( ddrval==DDERR_OUTOFVIDEOMEMORY ) { - mprintf(("Out of VRAM (w=%d, h=%d, used=%d KB)\n", tex_w, tex_h, D3D_textures_in / 1024 )); - if ( fail_on_full ) { - // bad return value - ret_val = 0; - - goto FreeSurfacesAndExit; - } - if ( d3d_free_some_texture_ram(t,dwHeight*dwWidth*2)) { - goto RetryLoad; - } - } else { - mprintf(("CreateSurface for VRAM texture failed, w=%d, h=%d\n%s\n", tex_w, tex_h, d3d_error_string(ddrval) )); - mprintf(( "Texture RAM = %d KB\n", D3D_textures_in / 1024 )); - } - vram_full = 1; - - // bad return value - ret_val = 0; - - goto FreeSurfacesAndExit; - //goto RetryLoad; - } - - t->vram_texture = NULL; - ddrval = t->vram_texture_surface->QueryInterface(IID_IDirect3DTexture2, (LPVOID *)&t->vram_texture); - if ( (ddrval != DD_OK) || (t->vram_texture == NULL) ) { - mprintf(( "GR_D3D_INIT: TextureSurface->QueryInterface failed.\n" )); - vram_full = 1; - - // bad return value - ret_val = 0; - - goto FreeSurfacesAndExit; - } - - // char *name = bm_get_filename(bitmap_handle); - // mprintf(( "Uploading '%s'\n", name )); - t->texture_handle = NULL; - ddrval = t->vram_texture->GetHandle(lpD3DDevice, &t->texture_handle ); - if ( (ddrval != DD_OK) || (t->texture_handle == NULL) ) { - mprintf(( "GR_D3D_INIT: Texture->GetHandle failed.\n" )); - t->texture_handle = NULL; - vram_full = 1; - - // bad return value - ret_val = 0; - - goto FreeSurfacesAndExit; - } - } - - // argh. this texture appears to be bogus. lets free it - if(t->vram_texture == NULL){ - d3d_free_texture(t); - - // bad - ret_val = 0; - - goto FreeSurfacesAndExit; - } - - ddrval = t->vram_texture->Load( sys_texture ); - if ( ddrval != DD_OK ) { - mprintf(("VRAM Load failed, w=%d, h=%d, %s\n", tex_w, tex_h, d3d_error_string(ddrval) )); - mprintf(( "Texture RAM = %d KB\n", D3D_textures_in / 1024 )); - vram_full = 1; - - // bad return value - ret_val = 0; - - goto FreeSurfacesAndExit; - } - - t->bitmap_id = texture_handle; - t->time_created = D3D_frame_count; - t->used_this_frame = 0; - t->size = tex_w * tex_h * 2; - t->w = (ushort)tex_w; - t->h = (ushort)tex_h; - D3D_textures_in_frame += t->size; - if ( !reload ) { - D3D_textures_in += t->size; - } - -FreeSurfacesAndExit: - if ( sys_texture ) { - sys_texture->Release(); - sys_texture = NULL; - } - - if ( sys_texture_surface ) { - sys_texture_surface->Release(); - sys_texture_surface = NULL; - } - - // hopefully this is 1 :) - return ret_val; -} - -int d3d_create_texture(int bitmap_handle, int bitmap_type, tcache_slot_d3d *tslot, int fail_on_full) -{ - ubyte flags; - bitmap *bmp; - int final_w, final_h; - ubyte bpp = 16; - int reload = 0; - - // setup texture/bitmap flags - flags = 0; - switch(bitmap_type){ - case TCACHE_TYPE_AABITMAP: - flags |= BMP_AABITMAP; - bpp = 8; - break; - case TCACHE_TYPE_NORMAL: - flags |= BMP_TEX_OTHER; - case TCACHE_TYPE_XPARENT: - flags |= BMP_TEX_XPARENT; - break; - case TCACHE_TYPE_NONDARKENING: - Int3(); - flags |= BMP_TEX_NONDARK; - break; - } - - // lock the bitmap into the proper format - bmp = bm_lock(bitmap_handle, bpp, flags); - if ( bmp == NULL ) { - mprintf(("Couldn't lock bitmap %d.\n", bitmap_handle )); - return 0; - } - - int max_w = bmp->w; - int max_h = bmp->h; - - if ( bitmap_type != TCACHE_TYPE_AABITMAP ) { - max_w /= D3D_texture_divider; - max_h /= D3D_texture_divider; - - // Detail.debris_culling goes from 0 to 4. - max_w /= 16 >> Detail.hardware_textures; - max_h /= 16 >> Detail.hardware_textures; - } - - // get final texture size as it will be allocated as a DD surface - d3d_tcache_get_adjusted_texture_size(max_w, max_h, &final_w, &final_h); - - // if this tcache slot has no bitmap - if ( tslot->bitmap_id < 0) { - reload = 0; - } - // different bitmap altogether - determine if the new one can use the old one's slot - else if (tslot->bitmap_id != bitmap_handle) { - if((final_w == tslot->w) && (final_h == tslot->h)){ - reload = 1; - - ml_printf("Reloading texture %d\n", bitmap_handle); - } else { - reload = 0; - } - } - - // call the helper - int ret_val = d3d_create_texture_sub(bitmap_type, bitmap_handle, (ushort*)bmp->data, 0, 0, bmp->w, bmp->h, bmp->w, bmp->h, max_w, max_h, tslot, reload, fail_on_full); - - // unlock the bitmap - bm_unlock(bitmap_handle); - - return ret_val; -} - -int d3d_create_texture_sectioned(int bitmap_handle, int bitmap_type, tcache_slot_d3d *tslot, int sx, int sy, int fail_on_full) -{ - ubyte flags; - bitmap *bmp; - int final_w, final_h; - int section_x, section_y; - int reload = 0; - - // setup texture/bitmap flags - SDL_assert(bitmap_type == TCACHE_TYPE_BITMAP_SECTION); - if(bitmap_type != TCACHE_TYPE_BITMAP_SECTION){ - bitmap_type = TCACHE_TYPE_BITMAP_SECTION; - } - flags = BMP_TEX_XPARENT; - - // lock the bitmap in the proper format - bmp = bm_lock(bitmap_handle, 16, flags); - if ( bmp == NULL ) { - mprintf(("Couldn't lock bitmap %d.\n", bitmap_handle )); - return 0; - } - - // determine the width and height of this section - bm_get_section_size(bitmap_handle, sx, sy, §ion_x, §ion_y); - - // get final texture size as it will be allocated as a DD surface - d3d_tcache_get_adjusted_texture_size(section_x, section_y, &final_w, &final_h); - - // if this tcache slot has no bitmap - if ( tslot->bitmap_id < 0) { - reload = 0; - } - // different bitmap altogether - determine if the new one can use the old one's slot - else if (tslot->bitmap_id != bitmap_handle) { - if((final_w == tslot->w) && (final_h == tslot->h)){ - reload = 1; - } else { - reload = 0; - } - } - - // call the helper - int ret_val = d3d_create_texture_sub(bitmap_type, bitmap_handle, (ushort*)bmp->data, bmp->sections.sx[sx], bmp->sections.sy[sy], section_x, section_y, bmp->w, bmp->h, section_x, section_y, tslot, reload, fail_on_full); - - // unlock the bitmap - bm_unlock(bitmap_handle); - - return ret_val; -} - -extern int bm_get_cache_slot( int bitmap_id, int separate_ani_frames ); -int d3d_tcache_set(int bitmap_id, int bitmap_type, float *u_scale, float *v_scale, int fail_on_full, int sx, int sy, int force ) -{ - bitmap *bmp = NULL; - int idx, s_idx; - int ret_val = 1; - - if ( bitmap_id < 0 ) { - D3D_last_bitmap_id = -1; - return 0; - } - - if ( D3D_last_detail != Detail.hardware_textures ) { - D3D_last_detail = Detail.hardware_textures; - d3d_tcache_flush(); - } - - //mprintf(( "Setting texture %d\n", bitmap_handle )); - if ( vram_full ) { - return 0; - } - - int n = bm_get_cache_slot( bitmap_id, 1 ); - tcache_slot_d3d * t = &Textures[n]; - - if ( (D3D_last_bitmap_id == bitmap_id) && (D3D_last_bitmap_type==bitmap_type) && (t->bitmap_id == bitmap_id) && (D3D_last_section_x == sx) && (D3D_last_section_y == sy)) { - t->used_this_frame++; - - // mark all children as used - if(D3D_texture_sections){ - for(idx=0; idxdata_sections[idx][s_idx] != NULL){ - t->data_sections[idx][s_idx]->used_this_frame++; - } - } - } - } - - *u_scale = t->u_scale; - *v_scale = t->v_scale; - return 1; - } - - // if this is a sectioned bitmap - if(bitmap_type == TCACHE_TYPE_BITMAP_SECTION){ - SDL_assert((sx >= 0) && (sy >= 0) && (sx < MAX_BMAP_SECTIONS_X) && (sy < MAX_BMAP_SECTIONS_Y)); - if(!((sx >= 0) && (sy >= 0) && (sx < MAX_BMAP_SECTIONS_X) && (sy < MAX_BMAP_SECTIONS_Y))){ - return 0; - } - - ret_val = 1; - - // if the texture sections haven't been created yet - if((t->bitmap_id < 0) || (t->bitmap_id != bitmap_id)){ - // lock the bitmap in the proper format - bmp = bm_lock(bitmap_id, 16, BMP_TEX_XPARENT); - bm_unlock(bitmap_id); - - // now lets do something for each texture - for(idx=0; idxsections.num_x; idx++){ - for(s_idx=0; s_idxsections.num_y; s_idx++){ - // hmm. i'd rather we didn't have to do it this way... - if(!d3d_create_texture_sectioned(bitmap_id, bitmap_type, t->data_sections[idx][s_idx], idx, s_idx, fail_on_full)){ - ret_val = 0; - } - - // not used this frame - t->data_sections[idx][s_idx]->used_this_frame = 0; - } - } - - // zero out pretty much everything in the parent struct since he's just the root - t->bitmap_id = bitmap_id; - t->texture_handle = NULL; - t->time_created = t->data_sections[sx][sy]->time_created; - t->used_this_frame = 0; - t->vram_texture = NULL; - t->vram_texture_surface = NULL; - } - - // argh. we failed to upload. free anything we can - if(!ret_val){ - d3d_free_texture(t); - } - // swap in the texture we want - else { - t = t->data_sections[sx][sy]; - } - } - // all other "normal" textures - else if((bitmap_id < 0) || (bitmap_id != t->bitmap_id)){ - ret_val = d3d_create_texture( bitmap_id, bitmap_type, t, fail_on_full ); - } - - // everything went ok - if(ret_val && (t->texture_handle != NULL) && !vram_full){ - *u_scale = t->u_scale; - *v_scale = t->v_scale; - - d3d_SetRenderState(D3DRENDERSTATE_TEXTUREHANDLE, t->texture_handle ); - - D3D_last_bitmap_id = t->bitmap_id; - D3D_last_bitmap_type = bitmap_type; - D3D_last_section_x = sx; - D3D_last_section_y = sy; - - t->used_this_frame++; - } - // gah - else { - return 0; - } - - return 1; -} - -int D3D_should_preload = 0; - -void d3d_tcache_init(int use_sections) -{ - int i, idx, s_idx; - - D3D_should_preload = 0; - - { - DDSCAPS ddsCaps; - DWORD dwFree, dwTotal; - - memset(&ddsCaps,0,sizeof(ddsCaps) ); - ddsCaps.dwCaps = DDSCAPS_TEXTURE; - HRESULT ddrval = lpDD->GetAvailableVidMem(&ddsCaps, &dwTotal, &dwFree); - if ( ddrval != DD_OK ) { - mprintf(( "GR_D3D_INIT: GetAvailableVidMem failed.\n" )); - dwFree = 0; -// goto D3DError; - } - - D3D_texture_ram = dwFree; - - uint tmp_pl = os_config_read_uint( NULL, NOX("D3DPreloadTextures"), 255 ); - - if ( tmp_pl == 0 ) { - D3D_should_preload = 0; - } else if ( tmp_pl == 1 ) { - D3D_should_preload = 1; - } else { - if ( D3D_texture_ram >= 6*1024*1024 ) { - D3D_should_preload = 1; - } else { - D3D_should_preload = 0; - } - } - - /* - int megs = dwFree / (1024*1024); - uint tmp_val = os_config_read_uint( NULL, NOX("D3DTextureDivider"), 255 ); - - if ( tmp_val == 0 ) { - // auto set - if ( megs <= 4 ) { - D3D_texture_divider = 4; - } else if ( megs <=8 ) { - D3D_texture_divider = 3; - } else if ( megs <=16 ) { - D3D_texture_divider = 2; - } else { - D3D_texture_divider = 1; - } - } else if ( tmp_val < 5 ) { - D3D_texture_divider = tmp_val; - } else { - // force to 4 - D3D_texture_divider = 4; - } - */ - - // setup texture divider - uint tmp_val = os_config_read_uint( NULL, NOX("D3DFast"), 1 ); - D3D_texture_divider = 1; - if(tmp_val){ - D3D_texture_divider = 4; - } - -#ifndef NDEBUG - int megs = dwFree / (1024*1024); - mprintf(( "TEXTURE RAM: %d bytes (%d MB) available, size divisor = %d\n", dwFree, megs, D3D_texture_divider )); -#endif - } - - - D3D_min_texture_width = (int)lpDevDesc->dwMinTextureWidth; - D3D_max_texture_width = (int)lpDevDesc->dwMaxTextureWidth; - D3D_min_texture_height = (int)lpDevDesc->dwMinTextureHeight; - D3D_max_texture_height = (int)lpDevDesc->dwMaxTextureHeight; - - // The following checks are needed because the PowerVR reports - // it's texture caps as 0,0 up to 0,0. - if ( D3D_min_texture_width < 16 ) { - D3D_min_texture_width = 16; - } - if ( D3D_min_texture_height < 16 ) { - D3D_min_texture_height = 16; - } - if ( D3D_max_texture_width < 16 ) { - mprintf(( "Driver claims to have a max texture width of %d. Bashing to 256.\n(Is this a PowerVR?)\n", D3D_max_texture_width )); - D3D_max_texture_width = 256; // Can we assume 256? - } - - if ( D3D_max_texture_height < 16 ) { - mprintf(( "Driver claims to have a max texture height of %d. Bashing to 256.\n(Is this a PowerVR?)\n", D3D_max_texture_height )); - D3D_max_texture_height = 256; // Can we assume 256? - } - - if (lpDevDesc->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY) { - mprintf(( "Darn. Driver needs square textures.\n" )); - D3D_square_textures = 1; - } else { - mprintf(( "Woohoo! Driver doesn't need square textures!\n" )); - D3D_square_textures = 0; - } - - if ( lpDevDesc->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2 ) { - mprintf(( "Textures must be power of 2.\n" )); - D3D_pow2_textures = 1; - } else { - mprintf(( "Textures can be any size.\n" )); - D3D_pow2_textures = 0; - } - - - if ( !(DD_driver_caps.dwCaps2 & DDCAPS2_WIDESURFACES) ) { - if ( D3D_max_texture_width > gr_screen.max_w ) { - D3D_max_texture_width = gr_screen.max_w; - - if ( D3D_pow2_textures ) { - for (i=0; i<16; i++ ) { - if ( (D3D_max_texture_width>= (1< D3D_max_texture_width ) { - D3D_max_texture_height = D3D_max_texture_width; - } - - mprintf(( "Doesn't support wide surfaces. Bashing max down to %d\n", D3D_max_texture_width )); - } - } - - if ( !os_config_read_uint( NULL, NOX("D3DUseLargeTextures"), 0 )) { - mprintf(( "No large texture flag specified, so using max of 256\n" )); - if ( D3D_max_texture_width > 256 ) { - D3D_max_texture_width = 256; - } - - if ( D3D_max_texture_height > 256 ) { - D3D_max_texture_height = 256; - } - } else { - mprintf(( "Large textures enabled!\n" )); - } - - Textures = (tcache_slot_d3d *)malloc(MAX_BITMAPS*sizeof(tcache_slot_d3d)); - if ( !Textures ) { - exit(1); - } - - if(use_sections){ - Texture_sections = (tcache_slot_d3d*)malloc(MAX_BITMAPS * MAX_BMAP_SECTIONS_X * MAX_BMAP_SECTIONS_Y * sizeof(tcache_slot_d3d)); - if(!Texture_sections){ - exit(1); - } - memset(Texture_sections, 0, MAX_BITMAPS * MAX_BMAP_SECTIONS_X * MAX_BMAP_SECTIONS_Y * sizeof(tcache_slot_d3d)); - } - - // Init the texture structures - int section_count = 0; - for( i=0; iparent = &Textures[i]; - - Textures[i].data_sections[idx][s_idx]->vram_texture = NULL; - Textures[i].data_sections[idx][s_idx]->vram_texture_surface = NULL; - Textures[i].data_sections[idx][s_idx]->texture_handle = NULL; - - Textures[i].data_sections[idx][s_idx]->bitmap_id = -1; - Textures[i].data_sections[idx][s_idx]->size = 0; - Textures[i].data_sections[idx][s_idx]->used_this_frame = 0; - } - } - } else { - for(idx=0; idxused_this_frame = 0; - } - } - } - } - } - } - - if ( vram_full ) { - d3d_tcache_flush(); - vram_full = 0; - } -} - - -void gr_d3d_preload_init() -{ - if ( gr_screen.mode != GR_DIRECT3D ) { - return; - } - d3d_tcache_flush(); -} - -int gr_d3d_preload(int bitmap_num, int is_aabitmap) -{ - if ( gr_screen.mode != GR_DIRECT3D ) { - return 0; - } - - if ( !D3D_should_preload ) { - return 0; - } - - float u_scale, v_scale; - - int retval; - - if ( is_aabitmap ) { - retval = gr_tcache_set(bitmap_num, TCACHE_TYPE_AABITMAP, &u_scale, &v_scale, 1 ); - } else { - retval = gr_tcache_set(bitmap_num, TCACHE_TYPE_NORMAL, &u_scale, &v_scale, 1 ); - } - - if ( !retval ) { - mprintf(("Texture upload failed!\n" )); - } - - return retval; -} - -// call this to safely fill in the texture shift and scale values for the specified texture type (Gr_t_*) -void gr_d3d_get_tex_format(int alpha) -{ - /* - DDPIXELFORMAT *surface_desc; - int s; - // RGB decoder - unsigned long m; - - // get the proper texture format - if(alpha){ - surface_desc = &AlphaTextureFormat; - } else { - surface_desc = &NonAlphaTextureFormat; - } - - // Determine the red, green and blue masks' shift and scale. - for (s = 0, m = surface_desc->dwRBitMask; !(m & 1); s++, m >>= 1); - Gr_t_red_shift = s; - Gr_t_red_scale = 255 / (surface_desc->dwRBitMask >> s); - for (s = 0, m = surface_desc->dwGBitMask; !(m & 1); s++, m >>= 1); - Gr_t_green_shift = s; - Gr_t_green_scale = 255 / (surface_desc->dwGBitMask >> s); - for (s = 0, m = surface_desc->dwBBitMask; !(m & 1); s++, m >>= 1); - Gr_t_blue_shift = s; - Gr_t_blue_scale = 255 / (surface_desc->dwBBitMask >> s); - - if ( surface_desc->dwFlags & DDPF_ALPHAPIXELS ) { - for (s = 0, m = surface_desc->dwRGBAlphaBitMask; !(m & 1); s++, m >>= 1); - Gr_t_alpha_shift = s; - Gr_t_alpha_scale = 255 / (surface_desc->dwRGBAlphaBitMask >> s); - } else { - Gr_t_alpha_shift = 0; - Gr_t_alpha_scale = 256; - } - */ -} diff --git a/src/graphics/grdirectdraw.cpp b/src/graphics/grdirectdraw.cpp deleted file mode 100644 index ed5e5ea..0000000 --- a/src/graphics/grdirectdraw.cpp +++ /dev/null @@ -1,1301 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/GrDirectDraw.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Code for software 8-bpp rendering using DirectDraw - * - * $Log$ - * Revision 1.3 2002/06/09 04:41:17 relnev - * added copyright header - * - * Revision 1.2 2002/05/07 03:16:45 theoddone33 - * The Great Newline Fix - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 9 7/14/99 9:42a Dave - * Put in clear_color debug function. Put in base for 3dnow stuff / P3 - * stuff - * - * 8 6/29/99 10:35a Dave - * Interface polygon bitmaps! Whee! - * - * 7 2/03/99 11:44a Dave - * Fixed d3d transparent textures. - * - * 6 1/24/99 11:37p Dave - * First full rev of beam weapons. Very customizable. Removed some bogus - * Int3()'s in low level net code. - * - * 5 12/18/98 1:13a Dave - * Rough 1024x768 support for Direct3D. Proper detection and usage through - * the launcher. - * - * 4 12/06/98 2:36p Dave - * Drastically improved nebula fogging. - * - * 3 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 2 10/07/98 10:52a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 17 5/22/98 10:28p John - * Made software movies not click your monitor when switching to 16-bpp. - * Total hack around my restrictive code, but at this point... - * - * 16 5/20/98 9:45p John - * added code so the places in code that change half the palette don't - * have to clear the screen. - * - * 15 5/17/98 5:03p John - * Fixed some bugs that make the taskbar interfere with the DEBUG-only - * mouse cursor. - * - * 14 5/16/98 1:18p John - * Made softtware DirectDraw reset palette after Alt+TAB. - * - * 13 5/15/98 9:34p John - * Removed the initial ugly little cursor part that drew right at program - * start. - * - * 12 5/14/98 5:42p John - * Revamped the whole window position/mouse code for the graphics windows. - * - * 11 5/12/98 8:15a John - * Made dd code not print out rgb surface info. - * - * 10 5/07/98 6:58p Hoffoss - * Made changes to mouse code to fix a number of problems. - * - * 9 5/06/98 5:30p John - * Removed unused cfilearchiver. Removed/replaced some unused/little used - * graphics functions, namely gradient_h and _v and pixel_sp. Put in new - * DirectX header files and libs that fixed the Direct3D alpha blending - * problems. - * - * 8 4/23/98 8:24a John - * Changed the way palette effect works so that: - * 1. If gr_flash isn't called this frame, screen shows no flash. - * 2. With hardware, only 3d portion of screen gets flashed. - * - * 7 4/21/98 5:22p John - * Fixed all the &^#@$ cursor bugs with popups. For Glide, had problem - * with mouse restoring assuming back buffer was same buffer last frame, - * for software, problems with half drawn new frames, then mouse got - * restored on top of that with old data. - * - * 6 4/17/98 3:56p Mike - * Fix palette trashing on MK's computer when he Alt-Tabs out of FreeSpace - * in software. At John's suggestion. - * - * 5 4/14/98 12:15p John - * Made 16-bpp movies work. - * - * 4 4/13/98 8:08p John - * Made surface restoration also restore the palette. - * - * 3 4/09/98 6:56p John - * Put in better code to restore surfaces when restoring them. Worth a - * try for an Interplay QA bug I can't find. - * - * 2 4/09/98 11:05a John - * Removed all traces of Direct3D out of the demo version of Freespace and - * the launcher. - * - * 1 3/25/98 8:07p John - * Split software renderer into Win32 and DirectX - * - * $NoKeywords: $ - */ - -#include -#include -#include - -#include "vddraw.h" - -#include "osapi.h" -#include "2d.h" -#include "bmpman.h" -#include "key.h" -#include "floating.h" -#include "palman.h" -#include "grsoft.h" -#include "grinternal.h" - -// Headers for 2d functions -#include "pixel.h" -#include "line.h" -#include "scaler.h" -#include "tmapper.h" -#include "circle.h" -#include "shade.h" -#include "rect.h" -#include "gradient.h" -#include "pcxutils.h" -#include "osapi.h" -#include "mouse.h" -#include "font.h" -#include "timer.h" -#include "colors.h" -#include "bitblt.h" -#include "grzbuffer.h" - -static LPDIRECTDRAW lpDD = NULL; -static LPDIRECTDRAWSURFACE lpBackBuffer = NULL; -static LPDIRECTDRAWSURFACE lpFrontBuffer = NULL; -static LPDIRECTDRAWCLIPPER lpClipper = NULL; -static LPDIRECTDRAWPALETTE lpPalette = NULL; - -void gr_directdraw_unlock(); -void gr_directdraw_set_palette_internal( ubyte * new_pal ); - -void directdraw_clear_all_vram() -{ -#ifndef HARDWARE_ONLY - DDSURFACEDESC ddsd; - HRESULT ddrval; - LPDIRECTDRAWSURFACE buffer[16]; - - int i; - int num_buffers = 0; - for (i=0; i<16; i++ ) { - memset( &ddsd, 0, sizeof( ddsd ) ); - - ddsd.dwSize = sizeof( ddsd ); - ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; - ddsd.dwWidth = gr_screen.max_w; - ddsd.dwHeight = gr_screen.max_h; - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY; - - // create the back buffer - ddrval = lpDD->CreateSurface( &ddsd, &buffer[i], NULL ); - if ( ddrval == DD_OK ) { - // Clear the surface - DDBLTFX ddBltFx; - - memset(&ddBltFx, 0, sizeof(DDBLTFX)); - ddBltFx.dwSize = sizeof(DDBLTFX); - ddBltFx.dwFillColor = 0; - - buffer[i]->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &ddBltFx); - - } else { - num_buffers = i; - buffer[i] = NULL; - break; - } - } - - for (i=0; iRelease(); - } -#else - Int3(); -#endif -} - -LPDIRECTDRAW gr_directdraw_start_mve() -{ -#ifndef HARDWARE_ONLY - ubyte tmp_pal[768]; - memset( tmp_pal, 0, 768 ); - - gr_directdraw_set_palette_internal(tmp_pal); - - // clear both buffers - gr_reset_clip(); - gr_clear(); - gr_flip(); - - gr_reset_clip(); - gr_clear(); - gr_flip(); - - gr_directdraw_unlock(); - - // Clear all of VRAM... - directdraw_clear_all_vram(); - - if ( lpPalette ) { - lpPalette->Release(); - lpPalette = NULL; - } - - if (lpFrontBuffer) { - lpFrontBuffer->Release(); - lpFrontBuffer = NULL; - } - - - return lpDD; -#else - Int3(); - return 0; -#endif -} - - -void gr_directdraw_stop_mve() -{ -#ifndef HARDWARE_ONLY - DDSURFACEDESC ddsd; - HRESULT ddrval; - - memset( &ddsd, 0, sizeof( ddsd ) ); - - ddsd.dwSize = sizeof( ddsd ); - ddsd.dwFlags = DDSD_CAPS; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - - ddrval = lpDD->CreateSurface( &ddsd, &lpFrontBuffer, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_SOFT_INIT: CreateSurface (Front) failed.\n" )); - lpDD->Release(); - exit(1); - } - - int i; - PALETTEENTRY pe[256]; - for (i=0; i<256; i++ ) { - pe[i].peFlags = PC_NOCOLLAPSE|PC_RESERVED; - pe[i].peRed = gr_palette[i*3+0]; - pe[i].peGreen = gr_palette[i*3+1]; - pe[i].peBlue = gr_palette[i*3+2]; - } - - ddrval = lpDD->CreatePalette( DDPCAPS_8BIT | DDPCAPS_ALLOW256, pe, &lpPalette, NULL); - if (ddrval != DD_OK) { - mprintf(( "Error creating palette\n" )); - } - - ddrval = lpFrontBuffer->SetPalette( lpPalette ); - if (ddrval != DD_OK) { - mprintf(( "Error setting palette in gr_directdraw_set_palette\n" )); - } - - gr_reset_clip(); - gr_clear(); - gr_flip(); -#else - Int3(); -#endif -} - -//#define DD_FLIP 1 - -static int Locked = 0; - -uint gr_directdraw_lock() -{ -#ifndef HARDWARE_ONLY - if ( !Locked ) { - - HRESULT ddrval; - DDSURFACEDESC ddsd; - - memset( &ddsd, 0, sizeof( ddsd ) ); - ddsd.dwSize = sizeof( ddsd ); - - ddrval = lpBackBuffer->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "Error locking surface in gr_d3d_lock\n" )); - gr_screen.offscreen_buffer_base = NULL; //(void *)fake_vram; - gr_screen.rowsize = 0; - gr_screen.offscreen_buffer = gr_screen.offscreen_buffer_base; - } else { - gr_screen.offscreen_buffer_base = (void *)ddsd.lpSurface; - gr_screen.rowsize = ddsd.lPitch; - gr_screen.offscreen_buffer = gr_screen.offscreen_buffer_base; - Locked = 1; - } - - } - return 1; -#else - Int3(); - return 0; -#endif -} - -void gr_directdraw_unlock() -{ -#ifndef HARDWARE_ONLY - if ( Locked ) { - // Unlock the back buffer - lpBackBuffer->Unlock( NULL ); - Locked = 0; - } -#else - Int3(); -#endif -} - -void gr_directdraw_unlock_fake() -{ -} - - -static int Palette_flashed = 0; -static int Palette_flashed_last_frame = 0; - - -static volatile int Gr_dd_activated = 0; - -void gr_dd_activate(int active) -{ -#ifndef HARDWARE_ONLY - if ( active ) { - Gr_dd_activated++; - } -#else - Int3(); -#endif -} - - -void gr_directdraw_flip() -{ -#ifndef HARDWARE_ONLY - if ( Gr_dd_activated || ((!Palette_flashed) && (Palette_flashed_last_frame)) ) { - // Reset flash - gr_directdraw_set_palette_internal( gr_palette ); - Gr_dd_activated = 0; - } - - Palette_flashed_last_frame = Palette_flashed; - Palette_flashed = 0; - - gr_reset_clip(); - - int mx, my; - - Grx_mouse_saved = 0; // assume not saved - - mouse_eval_deltas(); - if ( mouse_is_visible() ) { - gr_reset_clip(); - mouse_get_pos( &mx, &my ); - grx_save_mouse_area(mx,my,32,32); - if ( Gr_cursor == -1 ) { - gr_set_color(255,255,255); - gr_line( mx, my, mx+7, my + 7 ); - gr_line( mx, my, mx+5, my ); - gr_line( mx, my, mx, my+5 ); - } else { - gr_set_bitmap(Gr_cursor); - gr_bitmap( mx, my ); - } - } - - gr_directdraw_unlock(); - -#ifdef DD_FLIP -TryFlipAgain: - - if ( lpFrontBuffer->IsLost() == DDERR_SURFACELOST ) { - lpFrontBuffer->Restore(); - ddrval = lpFrontBuffer->SetPalette( lpPalette ); - if (ddrval != DD_OK) { - mprintf(( "Error setting palette after restore\n" )); - } - } - if ( lpBackBuffer->IsLost() == DDERR_SURFACELOST ) { - lpBackBuffer->Restore(); - } - - HRESULT ddrval = lpFrontBuffer->Flip( NULL, DDFLIP_WAIT ); - if ( ddrval == DDERR_SURFACELOST ) { - mprintf(( "Front surface lost... attempting to restore...\n" )); - os_sleep(1000); // Wait a second - goto TryFlipAgain; - } else if (ddrval != DD_OK ) { - mprintf(( "Fullscreen flip failed!\n" )); - } - -#else - RECT src_rect, dst_rect; - POINT pt; - HRESULT ddrval; - - HWND hWnd = (HWND)os_get_window(); - - if ( hWnd ) { - // src_rect is relative to offscreen buffer - GetClientRect( hWnd, &src_rect ); - - // dst_rect is relative to screen space so needs translation - pt.x = pt.y = 0; - ClientToScreen( hWnd, &pt ); - dst_rect = src_rect; - dst_rect.left += pt.x; - dst_rect.right += pt.x; - dst_rect.top += pt.y; - dst_rect.bottom += pt.y; - - // perform the blit from backbuffer to primary, using - // src_rect and dst_rect - -TryFlipAgain: - if ( lpFrontBuffer->IsLost() == DDERR_SURFACELOST ) { - lpFrontBuffer->Restore(); - -/* ddrval = lpFrontBuffer->SetPalette( lpPalette ); - if (ddrval != DD_OK) { - mprintf(( "Error setting palette after restore\n" )); - } -*/ } - if ( lpBackBuffer->IsLost() == DDERR_SURFACELOST ) { - lpBackBuffer->Restore(); - } - ddrval = lpFrontBuffer->Blt( &dst_rect, lpBackBuffer, &src_rect, DDBLT_WAIT, 0 ); - if ( ddrval == DDERR_SURFACELOST ) { - mprintf(( "Front surface lost... attempting to restore...\n" )); - os_sleep(1000); // Wait a second - goto TryFlipAgain; - } else if (ddrval != DD_OK ) { - mprintf(( "Flip failed! $%x\n", ddrval )); - } - } -#endif - - if ( Grx_mouse_saved ) { - grx_restore_mouse_area(); - } -#else - Int3(); -#endif -} - -void gr_directdraw_flip_window(uint _hdc, int x, int y, int w, int h ) -{ -} - -void gr_directdraw_start_frame() -{ - -} - -void gr_directdraw_stop_frame() -{ - -} - -void gr_directdraw_set_palette_internal( ubyte * new_pal ) -{ -#ifndef HARDWARE_ONLY - PALETTEENTRY pe[256]; - - gr_directdraw_unlock(); - - int i; - for (i=0; i<256; i++ ) { - pe[i].peFlags = PC_NOCOLLAPSE|PC_RESERVED; - pe[i].peRed = new_pal[i*3+0]; - pe[i].peGreen = new_pal[i*3+1]; - pe[i].peBlue = new_pal[i*3+2]; - } - - HRESULT ddrval; - ddrval = lpPalette->SetEntries( 0, 0, 256, pe ); - if ( ddrval != DD_OK ) { - mprintf(( "Error setting palette\n" )); - } - - gr_lock(); -#else - Int3(); -#endif -} - -void gr_directdraw_set_palette( ubyte * new_pal, int restrict_alphacolor ) -{ -#ifndef HARDWARE_ONLY - if ( !restrict_alphacolor ) { - Mouse_hidden++; - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; - } - - // Make sure color 0 is black - if ( (new_pal[0]!=0) || (new_pal[1]!=0) || (new_pal[2]!=0) ) { - // color 0 isn't black!! switch it! - int i; - int black_index = -1; - - for (i=1; i<256; i++ ) { - if ( (new_pal[i*3+0]==0) && (new_pal[i*3+1]==0) && (new_pal[i*3+2]==0) ) { - black_index = i; - break; - } - } - if ( black_index > -1 ) { - // swap black and color 0, so color 0 is black - ubyte tmp[3]; - tmp[0] = new_pal[black_index*3+0]; - tmp[1] = new_pal[black_index*3+1]; - tmp[2] = new_pal[black_index*3+2]; - - new_pal[black_index*3+0] = new_pal[0]; - new_pal[black_index*3+1] = new_pal[1]; - new_pal[black_index*3+2] = new_pal[2]; - - new_pal[0] = tmp[0]; - new_pal[1] = tmp[1]; - new_pal[2] = tmp[2]; - } else { - // no black in palette, force color 0 to be black. - new_pal[0] = 0; - new_pal[1] = 0; - new_pal[2] = 0; - } - } - - gr_directdraw_set_palette_internal( new_pal ); -#else - Int3(); -#endif -} - -void gr_directdraw_flash( int r, int g, int b ) -{ -#ifndef HARDWARE_ONLY - int t,i; - ubyte new_pal[768]; - - if ( (r==0) && (b==0) && (g==0) ) { - return; - } - - Palette_flashed++; - - for (i=0; i<256; i++ ) { - t = gr_palette[i*3+0] + r; - if ( t < 0 ) t = 0; else if (t>255) t = 255; - new_pal[i*3+0] = (ubyte)t; - - t = gr_palette[i*3+1] + g; - if ( t < 0 ) t = 0; else if (t>255) t = 255; - new_pal[i*3+1] = (ubyte)t; - - t = gr_palette[i*3+2] + b; - if ( t < 0 ) t = 0; else if (t>255) t = 255; - new_pal[i*3+2] = (ubyte)t; - } - - gr_directdraw_set_palette_internal( new_pal ); -#else - Int3(); -#endif -} - - -static int gr_palette_faded_out = 0; - -#define FADE_TIME (F1_0/4) // How long to fade out - -void gr_directdraw_fade_out(int instantaneous) -{ -#ifndef HARDWARE_ONLY - int i; - ubyte new_pal[768]; - - if (!gr_palette_faded_out) { - - if ( !instantaneous ) { - - int count = 0; - fix start_time, stop_time, t1; - - start_time = timer_get_fixed_seconds(); - t1 = 0; - - do { - for (i=0; i<768; i++ ) { - int c = (gr_palette[i]*(FADE_TIME-t1))/FADE_TIME; - if (c < 0 ) - c = 0; - else if ( c > 255 ) - c = 255; - - new_pal[i] = (ubyte)c; - } - gr_directdraw_set_palette_internal( new_pal ); - count++; - - t1 = timer_get_fixed_seconds() - start_time; - - } while ( (t1 < FADE_TIME) && (t1>=0) ); // Loop as long as time not up and timer hasn't rolled - - stop_time = timer_get_fixed_seconds(); - - mprintf(( "Took %d frames (and %.1f secs) to fade out\n", count, f2fl(stop_time-start_time) )); - - } - gr_palette_faded_out = 1; - } - - memset( new_pal, 0, 768 ); - gr_directdraw_set_palette_internal( new_pal ); -#else - Int3(); -#endif -} - - -void gr_directdraw_fade_in(int instantaneous) -{ -#ifndef HARDWARE_ONLY - int i; - ubyte new_pal[768]; - - if (gr_palette_faded_out) { - - if ( !instantaneous ) { - int count = 0; - fix start_time, stop_time, t1; - - start_time = timer_get_fixed_seconds(); - t1 = 0; - - do { - for (i=0; i<768; i++ ) { - int c = (gr_palette[i]*t1)/FADE_TIME; - if (c < 0 ) - c = 0; - else if ( c > 255 ) - c = 255; - - new_pal[i] = (ubyte)c; - } - gr_directdraw_set_palette_internal( new_pal ); - count++; - - t1 = timer_get_fixed_seconds() - start_time; - - } while ( (t1 < FADE_TIME) && (t1>=0) ); // Loop as long as time not up and timer hasn't rolled - - stop_time = timer_get_fixed_seconds(); - - mprintf(( "Took %d frames (and %.1f secs) to fade in\n", count, f2fl(stop_time-start_time) )); - } - gr_palette_faded_out = 0; - } - - memcpy( new_pal, gr_palette, 768 ); - gr_directdraw_set_palette_internal( new_pal ); -#else - Int3(); -#endif -} - -void gr_directdraw_get_region(int front, int w, int h, ubyte *data) -{ -} - -// sets the clipping region & offset -void gr_directdraw_set_clip(int x,int y,int w,int h) -{ -#ifndef HARDWARE_ONLY - gr_screen.offset_x = x; - gr_screen.offset_y = y; - - gr_screen.clip_left = 0; - gr_screen.clip_right = w-1; - - gr_screen.clip_top = 0; - gr_screen.clip_bottom = h-1; - - // check for sanity of parameters - if ( gr_screen.clip_left+x < 0 ) { - gr_screen.clip_left = -x; - } else if ( gr_screen.clip_left+x > gr_screen.max_w-1 ) { - gr_screen.clip_left = gr_screen.max_w-1-x; - } - if ( gr_screen.clip_right+x < 0 ) { - gr_screen.clip_right = -x; - } else if ( gr_screen.clip_right+x >= gr_screen.max_w-1 ) { - gr_screen.clip_right = gr_screen.max_w-1-x; - } - - if ( gr_screen.clip_top+y < 0 ) { - gr_screen.clip_top = -y; - } else if ( gr_screen.clip_top+y > gr_screen.max_h-1 ) { - gr_screen.clip_top = gr_screen.max_h-1-y; - } - - if ( gr_screen.clip_bottom+y < 0 ) { - gr_screen.clip_bottom = -y; - } else if ( gr_screen.clip_bottom+y > gr_screen.max_h-1 ) { - gr_screen.clip_bottom = gr_screen.max_h-1-y; - } - - gr_screen.clip_width = gr_screen.clip_right - gr_screen.clip_left + 1; - gr_screen.clip_height = gr_screen.clip_bottom - gr_screen.clip_top + 1; -#else - Int3(); -#endif -} - -// resolution checking -int gr_directdraw_supports_res_ingame(int res) -{ - return 1; -} - -int gr_directdraw_supports_res_interface(int res) -{ - return 1; -} - -void gr_directdraw_set_cull(int cull) -{ -} - -// resets the clipping region to entire screen -// -// should call this before gr_surface_flip() if you clipped some portion of the screen but still -// want a full-screen display -void gr_directdraw_reset_clip() -{ -#ifndef HARDWARE_ONLY - gr_screen.offset_x = 0; - gr_screen.offset_y = 0; - gr_screen.clip_left = 0; - gr_screen.clip_top = 0; - gr_screen.clip_right = gr_screen.max_w - 1; - gr_screen.clip_bottom = gr_screen.max_h - 1; - gr_screen.clip_width = gr_screen.max_w; - gr_screen.clip_height = gr_screen.max_h; -#else - Int3(); -#endif -} - - -// Sets the current bitmap -void gr_directdraw_set_bitmap( int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha, int sx, int sy ) -{ -#ifndef HARDWARE_ONLY - gr_screen.current_alpha = alpha; - gr_screen.current_alphablend_mode = alphablend_mode; - gr_screen.current_bitblt_mode = bitblt_mode; - gr_screen.current_bitmap = bitmap_num; - gr_screen.current_bitmap_sx = sx; - gr_screen.current_bitmap_sy = sy; -#else - Int3(); -#endif -} - -// clears entire clipping region to black. -void gr_directdraw_clear() -{ -#ifndef HARDWARE_ONLY - -#ifdef DD_FLIP - gr_directdraw_unlock(); - - DDBLTFX ddBltFx; - - ddBltFx.dwSize = sizeof(DDBLTFX); - ddBltFx.dwFillColor = 0; - - //DDBLT_WAIT | - lpBackBuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &ddBltFx); -// ddBltFx.dwROP = BLACKNESS; -// lpBackBuffer->Blt(NULL, NULL, NULL, DDBLT_ROP, &ddBltFx); - - gr_lock(); - -#else - gr_lock(); - - int i,w; - ubyte *pDestBits; - - w = gr_screen.clip_right-gr_screen.clip_left+1; - for (i=gr_screen.clip_top; i<=gr_screen.clip_bottom; i++) { - pDestBits = GR_SCREEN_PTR(ubyte,gr_screen.clip_left,i); - memset( pDestBits, 0, w ); - } - - gr_directdraw_unlock(); -#endif -#else - Int3(); -#endif -} - -void gr_directdraw_force_windowed() -{ -#ifndef HARDWARE_ONLY - gr_directdraw_unlock(); - - HWND hwnd = (HWND)os_get_window(); - - // Simulate Alt+Tab - PostMessage(hwnd,WM_SYSKEYUP, 0x9, 0xa00f0001 ); - PostMessage(hwnd,WM_SYSKEYUP, 0x12, 0xc0380001 ); - - // Wait a second to give things a change to settle down. - Sleep(1000); -#else - Int3(); -#endif -} - -void gr_directdraw_cleanup() -{ -#ifndef HARDWARE_ONLY - HWND hwnd = (HWND)os_get_window(); - - gr_directdraw_unlock(); - - if ( lpPalette ) { - lpPalette->Release(); - lpPalette = NULL; - } - - if (lpClipper) { - lpClipper->Release(); - lpClipper = NULL; - } - - if (lpBackBuffer) { - lpBackBuffer->Release(); - lpBackBuffer = NULL; - } - - if (lpFrontBuffer) { - lpFrontBuffer->Release(); - lpFrontBuffer = NULL; - } - - -// JAS: I took this out because my taskbar seems to get screwed up -// if I leave this in. Doesn't make sense, hence this comment. - HRESULT ddrval = lpDD->RestoreDisplayMode(); - if( ddrval != DD_OK ) { - mprintf(( "WIN_DD32: RestoreDisplayMode failed (0x%x)\n", ddrval )); - } - ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_NORMAL ); - if( ddrval != DD_OK ) { - mprintf(( "WIN_DD32: SetCooperativeLevel W Failed (0x%x)\n", ddrval )); - } - - os_suspend(); - if ( lpDD ) { - lpDD->Release(); - lpDD = NULL; - } - os_resume(); -#else - Int3(); -#endif -} - -void dd_get_shift_masks( DDSURFACEDESC *ddsd ) -{ - unsigned long m; - int s; - int r, red_shift, red_scale, red_mask; - int g, green_shift, green_scale, green_mask; - int b, blue_shift, blue_scale, blue_mask; - int a, alpha_shift, alpha_scale, alpha_mask; - - if (gr_screen.bits_per_pixel == 8 ) { - Gr_red.bits = 8; - Gr_red.shift = 16; - Gr_red.scale = 1; - Gr_red.mask = 0xff0000; - - Gr_green.bits = 8; - Gr_green.shift = 8; - Gr_green.scale = 1; - Gr_green.mask = 0xff00; - - Gr_blue.bits = 8; - Gr_blue.shift = 0; - Gr_blue.scale = 1; - Gr_blue.mask = 0xff; - return; - } - - // Determine the red, green and blue masks' shift and scale. - for (s = 0, m = ddsd->ddpfPixelFormat.dwRBitMask; !(m & 1); s++, m >>= 1); - for (r = 0; m & 1; r++, m >>= 1); - red_shift = s; - red_scale = 255 / (ddsd->ddpfPixelFormat.dwRBitMask >> s); - red_mask = ddsd->ddpfPixelFormat.dwRBitMask; - - for (s = 0, m = ddsd->ddpfPixelFormat.dwGBitMask; !(m & 1); s++, m >>= 1); - for (g = 0; m & 1; g++, m >>= 1); - green_shift = s; - green_scale = 255 / (ddsd->ddpfPixelFormat.dwGBitMask >> s); - green_mask = ddsd->ddpfPixelFormat.dwGBitMask; - - for (s = 0, m = ddsd->ddpfPixelFormat.dwBBitMask; !(m & 1); s++, m >>= 1); - for (b = 0; m & 1; b++, m >>= 1); - blue_shift = s; - blue_scale = 255 / (ddsd->ddpfPixelFormat.dwBBitMask >> s); - blue_mask = ddsd->ddpfPixelFormat.dwBBitMask; - - if ( ddsd->ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS ) { - for (s = 0, m = ddsd->ddpfPixelFormat.dwRGBAlphaBitMask; !(m & 1); s++, m >>= 1); - for (a = 0; m & 1; a++, m >>= 1); - alpha_shift = s; - alpha_scale = 255 / (ddsd->ddpfPixelFormat.dwRGBAlphaBitMask >> s); - alpha_mask = ddsd->ddpfPixelFormat.dwRGBAlphaBitMask; - } else { - alpha_shift = a = alpha_scale = alpha_mask = 0; - } - -// mprintf(( "Red Bits:%2d, Shift:%2d, Scale:%3d, Mask:$%08x\n", r, red_shift, red_scale, red_mask )); -// mprintf(( "Green Bits:%2d, Shift:%2d, Scale:%3d, Mask:$%08x\n", g, green_shift, green_scale, green_mask )); -// mprintf(( "Blue Bits:%2d, Shift:%2d, Scale:%3d, Mask:$%08x\n", b, blue_shift, blue_scale, blue_mask )); -// mprintf(( "Alpha Bits:%2d, Shift:%2d, Scale:%3d, Mask:$%08x\n", a, alpha_shift, alpha_scale, alpha_mask )); - - // we need to set stuff up so that the high bit is always an alpha bit. - - Gr_red.bits = r; - Gr_red.shift = red_shift; - Gr_red.scale = red_scale; - Gr_red.mask = red_mask; - - Gr_green.bits = g; - Gr_green.shift = green_shift; - Gr_green.scale = green_scale; - Gr_green.mask = green_mask; - - Gr_blue.bits = b; - Gr_blue.shift = blue_shift; - Gr_blue.scale = blue_scale; - Gr_blue.mask = blue_mask; -} - -// cross fade -void gr_directdraw_cross_fade(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct) -{ - if ( pct <= 50 ) { - gr_set_bitmap(bmap1); - gr_bitmap(x1, y1); - } else { - gr_set_bitmap(bmap2); - gr_bitmap(x2, y2); - } -} - -// filter -void gr_directdraw_filter_set(int filter) -{ -} - -// set clear color -void gr_directdraw_set_clear_color(int r, int g, int b) -{ -} - -void gr_directdraw_init() -{ -#ifndef HARDWARE_ONLY -// int i; - HRESULT ddrval; - - Palette_flashed = 0; - Palette_flashed_last_frame = 0; - - gr_screen.bits_per_pixel = 8; - gr_screen.bytes_per_pixel = 1; - - Gr_dd_activated = 0; - - HWND hwnd = (HWND)os_get_window(); - - if ( !hwnd ) { - mprintf(( "GR_SOFT_INIT: No window handle.\n" )); - exit(1); - } - - // Prepare the window to go full screen -#ifndef NDEBUG - mprintf(( "Window in debugging mode... mouse clicking may cause problems!\n" )); - SetWindowLong( hwnd, GWL_EXSTYLE, 0 ); - SetWindowLong( hwnd, GWL_STYLE, WS_POPUP ); - ShowWindow(hwnd, SW_SHOWNORMAL ); - RECT work_rect; - SystemParametersInfo( SPI_GETWORKAREA, 0, &work_rect, 0 ); - SetWindowPos( hwnd, HWND_NOTOPMOST, work_rect.left, work_rect.top, gr_screen.max_w, gr_screen.max_h, 0 ); - SetActiveWindow(hwnd); - SetForegroundWindow(hwnd); -#else - SetWindowLong( hwnd, GWL_EXSTYLE, 0 ); - SetWindowLong( hwnd, GWL_STYLE, WS_POPUP ); - ShowWindow(hwnd, SW_SHOWNORMAL ); - SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, GetSystemMetrics( SM_CXSCREEN ), GetSystemMetrics( SM_CYSCREEN ), 0 ); - SetActiveWindow(hwnd); - SetForegroundWindow(hwnd); -#endif - - os_suspend(); - ddrval = DirectDrawCreate( NULL, &lpDD, NULL ); - os_resume(); - if ( ddrval != DD_OK ) { - mprintf(( "GR_SOFT_INIT: DirectDrawCreate failed.\n" )); - exit(1); - } - - SDL_assert( lpDD ); - - ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_SOFT_INIT: SetCooperativeLevel EXCLUSIVE failed.\n" )); - lpDD->Release(); - exit(1); - } - - // Go to full screen! - os_suspend(); - ddrval = lpDD->SetDisplayMode( gr_screen.max_w, gr_screen.max_h, gr_screen.bits_per_pixel ); - os_resume(); - if ( ddrval != DD_OK ) { - mprintf(( "GR_SOFT_INIT: SetDisplayMode failed.\n" )); - lpDD->Release(); - exit(1); - } - - - DDSURFACEDESC ddsd; - -#ifdef DD_FLIP - DDSCAPS ddscaps; - - memset( &ddsd, 0, sizeof( ddsd )); - - ddsd.dwSize = sizeof( ddsd ); - ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; - ddsd.dwBackBufferCount = 2; - - ddrval = lpDD->CreateSurface( &ddsd, &lpFrontBuffer, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_SOFT_INIT: CreateSurface (Front) failed.\n" )); - lpDD->Release(); - exit(1); - } - - ddscaps.dwCaps = DDSCAPS_BACKBUFFER; - - ddrval = lpFrontBuffer->GetAttachedSurface( &ddscaps, &lpBackBuffer ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_SOFT_INIT: GetAttachedSurface (Back) failed.\n" )); - lpDD->Release(); - exit(1); - } - - lpClipper = NULL; -#else - - memset( &ddsd, 0, sizeof( ddsd ) ); - - ddsd.dwSize = sizeof( ddsd ); - ddsd.dwFlags = DDSD_CAPS; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - - ddrval = lpDD->CreateSurface( &ddsd, &lpFrontBuffer, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_SOFT_INIT: CreateSurface (Front) failed.\n" )); - lpDD->Release(); - exit(1); - } - - ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; - ddsd.dwWidth = gr_screen.max_w; - ddsd.dwHeight = gr_screen.max_h; - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - - // If debugging we have to create our surfaces in system memory - // so that our debugger isn't hosed when locking surfaces. - - //ddsd.ddsCaps.dwCaps |= DDSCAPS_NONLOCALVIDMEM; - ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; - - // create the back buffer - ddrval = lpDD->CreateSurface( &ddsd, &lpBackBuffer , NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_SOFT_INIT: CreateSurface (Back) failed.\n" )); - goto DDError; - } - - // create a clipper and attach it to our window - ddrval = lpDD->CreateClipper( 0, &lpClipper, NULL ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_SOFT_INIT: CreateClipper failed.\n" )); - goto DDError; - } - - - ddrval = lpClipper->SetHWnd( 0, hwnd ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_SOFT_INIT: SetHWnd failed.\n" )); - goto DDError; - } - - - ddrval = lpFrontBuffer->SetClipper( lpClipper ); - if ( ddrval != DD_OK ) { - mprintf(( "GR_SOFT_INIT: SetClipper failed.\n" )); - goto DDError; - } -#endif - - int i; - PALETTEENTRY pe[256]; - for (i=0; i<256; i++ ) { - pe[i].peFlags = PC_NOCOLLAPSE|PC_RESERVED; - pe[i].peRed = 0; - pe[i].peGreen = 0; - pe[i].peBlue = 0; - } - ddrval = lpDD->CreatePalette( DDPCAPS_8BIT | DDPCAPS_ALLOW256, pe, &lpPalette, NULL); - if (ddrval != DD_OK) { - mprintf(( "Error creating palette\n" )); - goto DDError; - } - - ddrval = lpFrontBuffer->SetPalette( lpPalette ); - if (ddrval != DD_OK) { - mprintf(( "Error setting palette in gr_directdraw_set_palette\n" )); - } - - - memset( &ddsd, 0, sizeof( ddsd ) ); - ddsd.dwSize = sizeof(ddsd); - lpFrontBuffer->GetSurfaceDesc(&ddsd); - dd_get_shift_masks( &ddsd ); - - mprintf(( "Surfaces created...\n" )); - - goto NoDDError; - -DDError: - lpDD->Release(); - exit(1); - - -NoDDError: - ; - - grx_init_alphacolors(); - - gr_screen.gf_flip = gr_directdraw_flip; - gr_screen.gf_flip_window = gr_directdraw_flip_window; - gr_screen.gf_set_clip = gr_directdraw_set_clip; - gr_screen.gf_reset_clip = gr_directdraw_reset_clip; - gr_screen.gf_set_font = grx_set_font; - gr_screen.gf_set_color = grx_set_color; - gr_screen.gf_set_bitmap = gr_directdraw_set_bitmap; - gr_screen.gf_create_shader = grx_create_shader; - gr_screen.gf_set_shader = grx_set_shader; - gr_screen.gf_clear = gr_directdraw_clear; - // gr_screen.gf_bitmap = grx_bitmap; - // gr_screen.gf_bitmap_ex = grx_bitmap_ex; - - gr_screen.gf_aabitmap = grx_aabitmap; - gr_screen.gf_aabitmap_ex = grx_aabitmap_ex; - - gr_screen.gf_rect = grx_rect; - gr_screen.gf_shade = gr8_shade; - gr_screen.gf_string = gr8_string; - gr_screen.gf_circle = gr8_circle; - - gr_screen.gf_line = gr8_line; - gr_screen.gf_aaline = gr8_aaline; - gr_screen.gf_pixel = gr8_pixel; - gr_screen.gf_scaler = gr8_scaler; - gr_screen.gf_aascaler = gr8_aascaler; - gr_screen.gf_tmapper = grx_tmapper; - - gr_screen.gf_gradient = gr8_gradient; - - gr_screen.gf_set_palette = gr_directdraw_set_palette; - gr_screen.gf_get_color = grx_get_color; - gr_screen.gf_init_color = grx_init_color; - gr_screen.gf_init_alphacolor = grx_init_alphacolor; - gr_screen.gf_set_color_fast = grx_set_color_fast; - gr_screen.gf_print_screen = grx_print_screen; - - gr_screen.gf_start_frame = gr_directdraw_start_frame; - gr_screen.gf_stop_frame = gr_directdraw_stop_frame; - - gr_screen.gf_fade_in = gr_directdraw_fade_in; - gr_screen.gf_fade_out = gr_directdraw_fade_out; - gr_screen.gf_flash = gr_directdraw_flash; - - // Retrieves the zbuffer mode. - gr_screen.gf_zbuffer_get = gr8_zbuffer_get; - gr_screen.gf_zbuffer_set = gr8_zbuffer_set; - gr_screen.gf_zbuffer_clear = gr8_zbuffer_clear; - - gr_screen.gf_save_screen = gr8_save_screen; - gr_screen.gf_restore_screen = gr8_restore_screen; - gr_screen.gf_free_screen = gr8_free_screen; - - // Screen dumping stuff - gr_screen.gf_dump_frame_start = gr8_dump_frame_start; - gr_screen.gf_dump_frame_stop = gr8_dump_frame_stop; - gr_screen.gf_dump_frame = gr8_dump_frame; - - // Gamma stuff - gr_screen.gf_set_gamma = gr8_set_gamma; - - // Lock/unlock stuff - gr_screen.gf_lock = gr_directdraw_lock; - gr_screen.gf_unlock = gr_directdraw_unlock_fake; - - // region - gr_screen.gf_get_region = gr_directdraw_get_region; - - // poly culling - gr_screen.gf_set_cull = gr_directdraw_set_cull; - - // cross fade - gr_screen.gf_cross_fade = gr_directdraw_cross_fade; - - // filter - gr_screen.gf_filter_set = gr_directdraw_filter_set; - - // set clear color - gr_screen.gf_set_clear_color = gr_directdraw_set_clear_color; - - gr_lock(); - - mprintf(( "Surfaces locked...\n" )); - - Mouse_hidden++; - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; -#else - Int3(); -#endif -} - diff --git a/src/graphics/grglide.cpp b/src/graphics/grglide.cpp deleted file mode 100644 index 0f88827..0000000 --- a/src/graphics/grglide.cpp +++ /dev/null @@ -1,3769 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/GrGlide.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Code that uses 3DFX's Glide graphics library - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:17 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 39 9/14/99 5:14a Dave - * Fixed credits drawing in Glide. - * - * 38 9/08/99 11:38p Dave - * Make V2 minimize/maximize the old way. - * - * 37 9/04/99 8:00p Dave - * Fixed up 1024 and 32 bit movie support. - * - * 36 9/01/99 10:49p Dave - * Added nice SquadWar checkbox to the client join wait screen. - * - * 35 8/30/99 5:01p Dave - * Made d3d do less state changing in the nebula. Use new chat server for - * PXO. - * - * 34 8/06/99 12:29a Dave - * Multiple bug fixes. - * - * 33 8/04/99 5:36p Dave - * Make glide and D3D switch out properly. - * - * 32 7/19/99 3:29p Dave - * Fixed gamma bitmap in the options screen. - * - * 31 7/14/99 9:42a Dave - * Put in clear_color debug function. Put in base for 3dnow stuff / P3 - * stuff - * - * 30 7/13/99 1:15p Dave - * 32 bit support. Whee! - * - * 29 6/29/99 10:35a Dave - * Interface polygon bitmaps! Whee! - * - * 28 5/05/99 9:02p Dave - * Fixed D3D aabitmap rendering. Spiffed up nebula effect a bit (added - * rotations, tweaked values, made bitmap selection more random). Fixed - * D3D beam weapon clipping problem. Added D3d frame dumping. - * - * 27 2/21/99 1:48p Dave - * Some code for monitoring datarate for multiplayer in detail. - * - * 26 2/11/99 3:08p Dave - * PXO refresh button. Very preliminary squad war support. - * - * 25 2/05/99 12:52p Dave - * Fixed Glide nondarkening textures. - * - * 24 2/04/99 6:29p Dave - * First full working rev of FS2 PXO support. Fixed Glide lighting - * problems. - * - * 23 2/03/99 11:44a Dave - * Fixed d3d transparent textures. - * - * 22 1/30/99 1:29a Dave - * Fixed nebula thumbnail problem. Full support for 1024x768 choose pilot - * screen. Fixed beam weapon death messages. - * - * 21 1/24/99 11:37p Dave - * First full rev of beam weapons. Very customizable. Removed some bogus - * Int3()'s in low level net code. - * - * 20 1/23/99 5:33p Dave - * Put in support for 1024x768 Glide. - * - * 19 1/15/99 11:29a Neilk - * Fixed D3D screen/texture pixel formatting problem. - * - * 18 12/18/98 1:13a Dave - * Rough 1024x768 support for Direct3D. Proper detection and usage through - * the launcher. - * - * 17 12/14/98 12:13p Dave - * Spiffed up xfer system a bit. Put in support for squad logo file xfer. - * Need to test now. - * - * 16 12/09/98 7:34p Dave - * Cleanup up nebula effect. Tweaked many values. - * - * 15 12/06/98 2:36p Dave - * Drastically improved nebula fogging. - * - * 14 12/04/98 10:20a Dave - * Fixed up gr_glide_get_pixel(...) - * - * 13 12/02/98 9:58a Dave - * Got fonttool working under Glide/Direct3d. - * - * 12 12/01/98 5:54p Dave - * Simplified the way pixel data is swizzled. Fixed tga bitmaps to work - * properly in D3D and Glide. - * - * 11 12/01/98 10:32a Johnson - * Fixed direct3d font problems. Fixed sun bitmap problem. Fixed direct3d - * starfield problem. - * - * 10 12/01/98 8:06a Dave - * Temporary checkin to fix some texture transparency problems in d3d. - * - * 9 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 8 11/24/98 4:43p Dave - * Make sure glide starts up in 640x480 - * - * 7 11/20/98 11:16a Dave - * Fixed up IPX support a bit. Making sure that switching modes and - * loading/saving pilot files maintains proper state. - * - * 6 11/14/98 5:32p Dave - * Lots of nebula work. Put in ship contrails. - * - * 5 11/12/98 12:19a Dave - * Removed compiler warning. - * - * 4 11/11/98 5:37p Dave - * Checkin for multiplayer testing. - * - * 3 11/09/98 2:11p Dave - * Nebula optimizations. - * - * 2 10/07/98 10:52a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 116 9/14/98 1:59p Allender - * allow for interlaced movies - * - * 115 5/25/98 10:32a John - * Took out redundant code for font bitmap offsets that converted to a - * float, then later on converted back to an integer. Quite unnecessary. - * - * 114 5/22/98 9:09a John - * fixed type in previous - * - * 113 5/22/98 9:07a John - * added in code that fixed Rush Glide startup problemmo. - * - * 112 5/20/98 9:46p John - * added code so the places in code that change half the palette don't - * have to clear the screen. - * - * 111 5/17/98 5:03p John - * Fixed some bugs that make the taskbar interfere with the DEBUG-only - * mouse cursor. - * - * 110 5/17/98 3:23p John - * Took out capibility check for additive blending. Made gr_bitmap_ex - * clip properly in glide and direct3d. - * - * 109 5/15/98 9:34p John - * Removed the initial ugly little cursor part that drew right at program - * start. - * - * 108 5/15/98 8:48a John - * Fixed bug where one-pixel line was getting left on right and bottom. - * - * 107 5/14/98 5:42p John - * Revamped the whole window position/mouse code for the graphics windows. - * - * 106 5/08/98 5:38p John - * Made Glide wait for retrace. - * - * 105 5/08/98 5:37p John - * - * 104 5/07/98 6:58p Hoffoss - * Made changes to mouse code to fix a number of problems. - * - * 103 5/07/98 8:43a John - * Turned off 3dfx gamma correction. - * - * 102 5/07/98 8:36a John - * Fixed Glide gradients - * - * 101 5/06/98 8:41p John - * Fixed some font clipping bugs. Moved texture handle set code for d3d - * into the texture module. - * - * 100 5/06/98 5:30p John - * Removed unused cfilearchiver. Removed/replaced some unused/little used - * graphics functions, namely gradient_h and _v and pixel_sp. Put in new - * DirectX header files and libs that fixed the Direct3D alpha blending - * problems. - * - */ - -//#define USE_8BPP_TEXTURES - -#include -#include -#include "glide.h" -#include "glideutl.h" - -#include "osapi.h" -#include "2d.h" -#include "bmpman.h" -#include "floating.h" -#include "palman.h" -#include "grinternal.h" -#include "grglide.h" -#include "line.h" -#include "font.h" -#include "mouse.h" -#include "key.h" -#include "systemvars.h" -#include "grglideinternal.h" -#include "cfile.h" -#include "timer.h" -// #include "movie.h" -#include "neb.h" - -#define NEBULA_COLORS 20 - -GrFog_t Glide_linear_fogtable[GR_FOG_TABLE_SIZE]; - -int Glide_textures_in = 0; - -int Glide_voodoo3 = 0; - -static int Inited = 0; - -// voodoo3 is a little sensitive to getting deactivated -#define VOODOO3_DEACTIVATED -1 -#define VOODOO3_INACTIVE() ( (Glide_voodoo3 == 1) && (Glide_deactivate == VOODOO3_DEACTIVATED) ) - -float Gr_gamma_lookup_float[256]; - -volatile int Glide_running = 0; -volatile int Glide_activate = 0; -volatile int Glide_deactivate = 0; - -typedef enum gr_texture_source { - TEXTURE_SOURCE_NONE, - TEXTURE_SOURCE_DECAL, -} gr_texture_source; - -typedef enum gr_color_source { - COLOR_SOURCE_VERTEX, - COLOR_SOURCE_TEXTURE, - COLOR_SOURCE_VERTEX_TIMES_TEXTURE, -} gr_color_source; - -typedef enum gr_alpha_source { - ALPHA_SOURCE_VERTEX, - ALPHA_SOURCE_VERTEX_NONDARKENING, - ALPHA_SOURCE_TEXTURE, - ALPHA_SOURCE_VERTEX_TIMES_TEXTURE, -} gr_alpha_source; - -typedef enum gr_alpha_blend { - ALPHA_BLEND_NONE, // 1*SrcPixel + 0*DestPixel - ALPHA_BLEND_ADDITIVE, // 1*SrcPixel + 1*DestPixel - ALPHA_BLEND_ALPHA_ADDITIVE, // Alpha*SrcPixel + 1*DestPixel - ALPHA_BLEND_ALPHA_BLEND_ALPHA, // Alpha*SrcPixel + (1-Alpha)*DestPixel - ALPHA_BLEND_ALPHA_BLEND_SRC_COLOR, // Alpha*SrcPixel + (1-SrcPixel)*DestPixel -} gr_alpha_blend; - -typedef enum gr_zbuffer_type { - ZBUFFER_TYPE_NONE, - ZBUFFER_TYPE_READ, - ZBUFFER_TYPE_WRITE, - ZBUFFER_TYPE_FULL, -} gr_zbuffer_type; - -int Glide_last_state = -1; - -void gr_glide_set_state( gr_texture_source ts, gr_color_source cs, gr_alpha_source as, gr_alpha_blend ab, gr_zbuffer_type zt ) -{ - int current_state = 0; - - if(VOODOO3_INACTIVE()){ - return; - } - - current_state = current_state | (ts<<0); - current_state = current_state | (cs<<5); - current_state = current_state | (as<<10); - current_state = current_state | (ab<<15); - current_state = current_state | (zt<<20); - - if ( current_state == Glide_last_state ) { - return; - } - Glide_last_state = current_state; - - switch( ts ) { - case TEXTURE_SOURCE_NONE: - grTexCombineFunction( GR_TMU0, GR_TEXTURECOMBINE_ONE ); - break; - case TEXTURE_SOURCE_DECAL: - grTexCombineFunction( GR_TMU0, GR_TEXTURECOMBINE_DECAL ); - break; - default: - Int3(); - } - - switch( cs ) { - case COLOR_SOURCE_VERTEX: - grColorCombine( GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_NONE, FXFALSE ); - break; - - case COLOR_SOURCE_TEXTURE: - grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_ONE, GR_COMBINE_LOCAL_NONE, GR_COMBINE_OTHER_TEXTURE, FXFALSE); - break; - - case COLOR_SOURCE_VERTEX_TIMES_TEXTURE: - grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_LOCAL, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_TEXTURE, FXFALSE); - break; - - default: - Int3(); - } - - switch( as ) { - case ALPHA_SOURCE_VERTEX: - grAlphaCombine( GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_NONE, FXFALSE ); - grAlphaControlsITRGBLighting(FXFALSE); - break; - - case ALPHA_SOURCE_VERTEX_NONDARKENING: - grAlphaCombine( GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_NONE, FXFALSE ); - grAlphaControlsITRGBLighting(FXTRUE); - grConstantColorValue(0xFFFFFFFF); // Non-darkening colors will use this - break; - - case ALPHA_SOURCE_TEXTURE: - grAlphaCombine( GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_ONE, GR_COMBINE_LOCAL_NONE, GR_COMBINE_OTHER_TEXTURE, FXFALSE); - grAlphaControlsITRGBLighting(FXFALSE); - break; - - case ALPHA_SOURCE_VERTEX_TIMES_TEXTURE: - grAlphaCombine( GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_LOCAL, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_TEXTURE, FXFALSE ); - grAlphaControlsITRGBLighting(FXFALSE); - break; - - default: - Int3(); - } - - - switch( ab ) { - case ALPHA_BLEND_NONE: // 1*SrcPixel + 0*DestPixel - grAlphaBlendFunction( GR_BLEND_ONE, GR_BLEND_ZERO, GR_BLEND_ZERO, GR_BLEND_ZERO ); - break; - - case ALPHA_BLEND_ADDITIVE: // 1*SrcPixel + 1*DestPixel - grAlphaBlendFunction( GR_BLEND_ONE, GR_BLEND_ONE, GR_BLEND_ZERO, GR_BLEND_ZERO ); - break; - - case ALPHA_BLEND_ALPHA_ADDITIVE: // Alpha*SrcPixel + 1*DestPixel - grAlphaBlendFunction( GR_BLEND_SRC_ALPHA, GR_BLEND_ONE, GR_BLEND_ZERO, GR_BLEND_ZERO); - break; - - case ALPHA_BLEND_ALPHA_BLEND_ALPHA: // Alpha*SrcPixel + (1-Alpha)*DestPixel - grAlphaBlendFunction( GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA, GR_BLEND_ZERO, GR_BLEND_ZERO ); - break; - - case ALPHA_BLEND_ALPHA_BLEND_SRC_COLOR: // Alpha*SrcPixel + (1-SrcPixel)*DestPixel - grAlphaBlendFunction( GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_COLOR, GR_BLEND_ZERO, GR_BLEND_ZERO ); - break; - - default: - Int3(); - } - - switch( zt ) { - - case ZBUFFER_TYPE_NONE: - grDepthBufferMode(GR_DEPTHBUFFER_DISABLE); - grDepthMask( FXFALSE ); - break; - - case ZBUFFER_TYPE_READ: - grDepthBufferMode(GR_DEPTHBUFFER_WBUFFER); - grDepthBufferFunction(GR_CMP_LEQUAL); - grDepthMask( FXFALSE ); - break; - - case ZBUFFER_TYPE_WRITE: - grDepthBufferMode(GR_DEPTHBUFFER_WBUFFER); - grDepthBufferFunction(GR_CMP_ALWAYS); - grDepthMask( FXTRUE ); - break; - - case ZBUFFER_TYPE_FULL: - grDepthBufferMode(GR_DEPTHBUFFER_WBUFFER); - grDepthBufferFunction(GR_CMP_LEQUAL); - grDepthMask( FXTRUE ); - break; - - default: - Int3(); - } - -} - -/* - gr_glide_set_state( - TEXTURE_SOURCE_NONE, TEXTURE_SOURCE_DECAL, - - COLOR_SOURCE_VERTEX, COLOR_SOURCE_TEXTURE, COLOR_SOURCE_VERTEX_TIMES_TEXTURE, - - ALPHA_SOURCE_VERTEX, ALPHA_SOURCE_TEXTURE, ALPHA_SOURCE_VERTEX_TIMES_TEXTURE, - - ALPHA_BLEND_NONE, ALPHA_BLEND_ADDITIVE, ALPHA_BLEND_ALPHA_ADDITIVE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ALPHA_BLEND_ALPHA_BLEND_SRC_COLOR, - - ZBUFFER_TYPE_NONE, ZBUFFER_TYPE_READ, ZBUFFER_TYPE_WRITE, ZBUFFER_TYPE_FULL, - - ); - -*/ - - -// If mode is FALSE, turn zbuffer off the entire frame, -// no matter what people pass to gr_zbuffer_set. -void gr_glide_zbuffer_clear(int mode) -{ - if(VOODOO3_INACTIVE()){ - return; - } - - if ( mode ) { - gr_zbuffering = 1; - gr_zbuffering_mode = GR_ZBUFF_FULL; - gr_global_zbuffering = 1; - - // Make sure zbuffering is on - gr_glide_set_state( TEXTURE_SOURCE_NONE, COLOR_SOURCE_VERTEX, ALPHA_SOURCE_VERTEX, ALPHA_BLEND_NONE, ZBUFFER_TYPE_FULL ); - - // Disable writes to color and alpha buffers - grColorMask( FXFALSE, FXFALSE ); - // Clear the zbuffer - grBufferClear( 0x0, 0, GR_WDEPTHVALUE_FARTHEST ); - // Re-enable writes to the color buffer - grColorMask( FXTRUE, FXFALSE ); - } else { - gr_zbuffering = 0; - gr_zbuffering_mode = GR_ZBUFF_NONE; - gr_global_zbuffering = 0; - } -} - -int gr_glide_zbuffer_get() -{ - if ( !gr_global_zbuffering ) { - return GR_ZBUFF_NONE; - } - return gr_zbuffering_mode; -} - -int gr_glide_zbuffer_set(int mode) -{ - if ( !gr_global_zbuffering ) { - gr_zbuffering = 0; - return GR_ZBUFF_NONE; - } - - int tmp = gr_zbuffering_mode; - - gr_zbuffering_mode = mode; - - if ( gr_zbuffering_mode == GR_ZBUFF_NONE ) { - gr_zbuffering = 0; - } else { - gr_zbuffering = 1; - } - return tmp; -} - - -void gr_glide_pixel(int x, int y) -{ - if(VOODOO3_INACTIVE()){ - return; - } - - gr_line(x,y,x,y); -/* - if ( x < gr_screen.clip_left ) return; - if ( x > gr_screen.clip_right ) return; - if ( y < gr_screen.clip_top ) return; - if ( y > gr_screen.clip_bottom ) return; - - // Set up Render State - flat shading - alpha blending - gr_glide_set_state( TEXTURE_SOURCE_NONE, COLOR_SOURCE_VERTEX, ALPHA_SOURCE_VERTEX, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE ); - - GrVertex p; - p.x = 0.5f + i2fl(x + gr_screen.offset_x); - p.y = 0.5f + i2fl(y + gr_screen.offset_y); - p.a = 255.0f; - p.r = i2fl(gr_screen.current_color.red); - p.g = i2fl(gr_screen.current_color.green); - p.b = i2fl(gr_screen.current_color.blue); - - grDrawPoint(&p); -*/ -} - -float snap(float x) -{ - int xi = fl2i(x*16.0f); - return i2fl(xi)/16.0f; -} - -void gr_glide_clear() -{ - GrColor_t clear_color; - - if(VOODOO3_INACTIVE()){ - return; - } - - // Turn off zbuffering so this doesn't clear the zbuffer - gr_glide_set_state( TEXTURE_SOURCE_NONE, COLOR_SOURCE_VERTEX, ALPHA_SOURCE_VERTEX, ALPHA_BLEND_NONE, ZBUFFER_TYPE_NONE ); - - // Clear the screen - clear_color = 0; - clear_color |= ((ubyte)gr_screen.current_clear_color.red); - clear_color |= ((ubyte)gr_screen.current_clear_color.green << 8); - clear_color |= ((ubyte)gr_screen.current_clear_color.blue << 16); - grBufferClear( clear_color, 0, GR_WDEPTHVALUE_FARTHEST ); -} - -static RECT Glide_cursor_clip_rect; - -void gr_glide_clip_cursor(int active) -{ - if ( active ) { - ClipCursor(&Glide_cursor_clip_rect); - } else { - ClipCursor(NULL); - } -} - - -int Gr_glide_mouse_saved = 0; -int Gr_glide_mouse_saved_x1 = 0; -int Gr_glide_mouse_saved_y1 = 0; -int Gr_glide_mouse_saved_x2 = 0; -int Gr_glide_mouse_saved_y2 = 0; -int Gr_glide_mouse_saved_w = 0; -int Gr_glide_mouse_saved_h = 0; -#define MAX_SAVE_SIZE (32*32) -ushort Gr_glide_mouse_saved_data[MAX_SAVE_SIZE]; - -// Clamps X between R1 and R2 -#define CLAMP(x,r1,r2) do { if ( (x) < (r1) ) (x) = (r1); else if ((x) > (r2)) (x) = (r2); } while(0) - -void gr_glide_save_mouse_area(int x, int y, int w, int h ) -{ - if(VOODOO3_INACTIVE()){ - return; - } - - Gr_glide_mouse_saved_x1 = x; - Gr_glide_mouse_saved_y1 = y; - Gr_glide_mouse_saved_x2 = x+w-1; - Gr_glide_mouse_saved_y2 = y+h-1; - - CLAMP(Gr_glide_mouse_saved_x1, gr_screen.clip_left, gr_screen.clip_right ); - CLAMP(Gr_glide_mouse_saved_x2, gr_screen.clip_left, gr_screen.clip_right ); - CLAMP(Gr_glide_mouse_saved_y1, gr_screen.clip_top, gr_screen.clip_bottom ); - CLAMP(Gr_glide_mouse_saved_y2, gr_screen.clip_top, gr_screen.clip_bottom ); - - Gr_glide_mouse_saved_w = Gr_glide_mouse_saved_x2 - Gr_glide_mouse_saved_x1 + 1; - Gr_glide_mouse_saved_h = Gr_glide_mouse_saved_y2 - Gr_glide_mouse_saved_y1 + 1; - - if ( Gr_glide_mouse_saved_w < 1 ) return; - if ( Gr_glide_mouse_saved_h < 1 ) return; - - // Make sure we're not saving too much! - SDL_assert( (Gr_glide_mouse_saved_w*Gr_glide_mouse_saved_h) <= MAX_SAVE_SIZE ); - - GrLfbInfo_t info; - - info.size=sizeof(GrLfbInfo_t); - - // get a read pointer - if ( grLfbLock( GR_LFB_READ_ONLY, GR_BUFFER_BACKBUFFER, GR_LFBWRITEMODE_565, - GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { - - ushort *rptr; - int short_per_row=info.strideInBytes/2; - - rptr = (ushort *)info.lfbPtr; - - ushort *sptr, *dptr; - - dptr = Gr_glide_mouse_saved_data; - - for (int i=0; i 0){ - int diff = timer_get_milliseconds() - Interface_last_tick; - gr_printf(10, 10, "%f", 1000.0f / (float)diff); - } - Interface_last_tick = timer_get_milliseconds(); - } -#endif - -#ifndef NDEBUG - grBufferSwap( 0 ); -#else - grBufferSwap( 1 ); -#endif - grSstIdle(); - - glide_tcache_frame(); -} - -void gr_glide_flip_window(uint _hdc, int x, int y, int w, int h ) -{ -} - -void gr_glide_set_clip(int x,int y,int w,int h) -{ - gr_screen.offset_x = x; - gr_screen.offset_y = y; - - gr_screen.clip_left = 0; - gr_screen.clip_right = w-1; - - gr_screen.clip_top = 0; - gr_screen.clip_bottom = h-1; - - if(VOODOO3_INACTIVE()){ - return; - } - - // check for sanity of parameters - if ( gr_screen.clip_left+x < 0 ) { - gr_screen.clip_left = -x; - } else if ( gr_screen.clip_left+x > gr_screen.max_w-1 ) { - gr_screen.clip_left = gr_screen.max_w-1-x; - } - if ( gr_screen.clip_right+x < 0 ) { - gr_screen.clip_right = -x; - } else if ( gr_screen.clip_right+x >= gr_screen.max_w-1 ) { - gr_screen.clip_right = gr_screen.max_w-1-x; - } - - if ( gr_screen.clip_top+y < 0 ) { - gr_screen.clip_top = -y; - } else if ( gr_screen.clip_top+y > gr_screen.max_h-1 ) { - gr_screen.clip_top = gr_screen.max_h-1-y; - } - - if ( gr_screen.clip_bottom+y < 0 ) { - gr_screen.clip_bottom = -y; - } else if ( gr_screen.clip_bottom+y > gr_screen.max_h-1 ) { - gr_screen.clip_bottom = gr_screen.max_h-1-y; - } - - gr_screen.clip_width = gr_screen.clip_right - gr_screen.clip_left + 1; - gr_screen.clip_height = gr_screen.clip_bottom - gr_screen.clip_top + 1; - - grClipWindow( gr_screen.clip_left+x, gr_screen.clip_top+y, gr_screen.clip_right+1+x, gr_screen.clip_bottom+1+y ); -} - -void gr_glide_reset_clip() -{ - if(VOODOO3_INACTIVE()){ - return; - } - - gr_screen.offset_x = 0; - gr_screen.offset_y = 0; - gr_screen.clip_left = 0; - gr_screen.clip_top = 0; - gr_screen.clip_right = gr_screen.max_w - 1; - gr_screen.clip_bottom = gr_screen.max_h - 1; - gr_screen.clip_width = gr_screen.max_w; - gr_screen.clip_height = gr_screen.max_h; - - grClipWindow( gr_screen.clip_left, gr_screen.clip_top, gr_screen.clip_right+1, gr_screen.clip_bottom+1 ); -} - - -void gr_glide_set_bitmap( int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha, int sx, int sy ) -{ - if(VOODOO3_INACTIVE()){ - return; - } - - gr_screen.current_alpha = alpha; - gr_screen.current_alphablend_mode = alphablend_mode; - gr_screen.current_bitblt_mode = bitblt_mode; - gr_screen.current_bitmap = bitmap_num; - - gr_screen.current_bitmap_sx = sx; - gr_screen.current_bitmap_sy = sy; -} - -void gr_glide_create_shader(shader * shade, float r, float g, float b, float c ) -{ - shade->screen_sig = gr_screen.signature; - - shade->r = r; - shade->g = g; - shade->b = b; - shade->c = c; -} - -void gr_glide_set_shader( shader * shade ) -{ - if ( shade ) { - if (shade->screen_sig != gr_screen.signature) { - gr_create_shader( shade, shade->r, shade->g, shade->b, shade->c ); - } - gr_screen.current_shader = *shade; - } else { - gr_create_shader( &gr_screen.current_shader, 0.0f, 0.0f, 0.0f, 0.0f ); - } -} - -void gr_glide_bitmap_ex_internal(int x,int y,int w,int h,int sx,int sy) -{ - int i,j; - bitmap * bmp; - ushort * sptr; - - if(VOODOO3_INACTIVE()){ - return; - } - - bmp = bm_lock( gr_screen.current_bitmap, 16, 0 ); - sptr = (ushort *)( bmp->data + (sy*bmp->w*2) + (sx*2) ); - - if ( x < gr_screen.clip_left ) return; - if ( x > gr_screen.clip_right ) return; - if ( y < gr_screen.clip_top ) return; - if ( y > gr_screen.clip_bottom ) return; - - gr_glide_set_state( TEXTURE_SOURCE_NONE, COLOR_SOURCE_VERTEX, ALPHA_SOURCE_VERTEX, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE ); - - GrLfbInfo_t info; - - if ( grLfbLock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER, GR_LFBWRITEMODE_1555, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info) ) { - - ushort *vram = (ushort *)info.lfbPtr; - int stride = info.strideInBytes / sizeof(ushort); - - for (i=0; iw; - } - - grLfbUnlock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER); - } - - bm_unlock(gr_screen.current_bitmap); -} - - -void gr_glide_bitmap_ex(int x,int y,int w,int h,int sx,int sy) -{ - int reclip; - #ifndef NDEBUG - int count = 0; - #endif - - int dx1=x, dx2=x+w-1; - int dy1=y, dy2=y+h-1; - - int bw, bh; - bm_get_info( gr_screen.current_bitmap, &bw, &bh, NULL ); - - do { - reclip = 0; - #ifndef NDEBUG - if ( count > 1 ) Int3(); - count++; - #endif - - if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return; - if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return; - if ( dx1 < gr_screen.clip_left ) { sx += gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; } - if ( dy1 < gr_screen.clip_top ) { sy += gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; } - if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; } - if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; } - - if ( sx < 0 ) { - dx1 -= sx; - sx = 0; - reclip = 1; - } - - if ( sy < 0 ) { - dy1 -= sy; - sy = 0; - reclip = 1; - } - - w = dx2-dx1+1; - h = dy2-dy1+1; - - if ( sx + w > bw ) { - w = bw - sx; - dx2 = dx1 + w - 1; - } - - if ( sy + h > bh ) { - h = bh - sy; - dy2 = dy1 + h - 1; - } - - if ( w < 1 ) return; // clipped away! - if ( h < 1 ) return; // clipped away! - - } while (reclip); - - // Make sure clipping algorithm works - #ifndef NDEBUG - SDL_assert( w > 0 ); - SDL_assert( h > 0 ); - SDL_assert( w == (dx2-dx1+1) ); - SDL_assert( h == (dy2-dy1+1) ); - SDL_assert( sx >= 0 ); - SDL_assert( sy >= 0 ); - SDL_assert( sx+w <= bw ); - SDL_assert( sy+h <= bh ); - SDL_assert( dx2 >= dx1 ); - SDL_assert( dy2 >= dy1 ); - SDL_assert( (dx1 >= gr_screen.clip_left ) && (dx1 <= gr_screen.clip_right) ); - SDL_assert( (dx2 >= gr_screen.clip_left ) && (dx2 <= gr_screen.clip_right) ); - SDL_assert( (dy1 >= gr_screen.clip_top ) && (dy1 <= gr_screen.clip_bottom) ); - SDL_assert( (dy2 >= gr_screen.clip_top ) && (dy2 <= gr_screen.clip_bottom) ); - #endif - - // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions. - // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2) - - gr_glide_bitmap_ex_internal(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy); -} - - -void gr_glide_bitmap(int x, int y) -{ - int w, h; - - bm_get_info( gr_screen.current_bitmap, &w, &h, NULL ); - int dx1=x, dx2=x+w-1; - int dy1=y, dy2=y+h-1; - int sx=0, sy=0; - - if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return; - if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return; - if ( dx1 < gr_screen.clip_left ) { sx = gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; } - if ( dy1 < gr_screen.clip_top ) { sy = gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; } - if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; } - if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; } - - if ( sx < 0 ) return; - if ( sy < 0 ) return; - if ( sx >= w ) return; - if ( sy >= h ) return; - - // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2) - - gr_glide_bitmap_ex_internal(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy); -} - - -static void glide_scanline( int x1, int x2, int y ) -{ - int w; - - if(VOODOO3_INACTIVE()){ - return; - } - - if ( x1 > x2 ) { - int tmp = x1; - x1 = x2; - x2 = tmp; - } - - if ( y < gr_screen.clip_top ) return; - if ( y > gr_screen.clip_bottom ) return; - - if ( x1 < gr_screen.clip_left ) x1 = gr_screen.clip_left; - if ( x2 > gr_screen.clip_right ) x2 = gr_screen.clip_right; - - w = x2 - x1 + 1; - - if ( w < 1 ) return; - -// for (i=0; i 0 ) - x2 = x + w - 1; - else - x2 = x + w + 1; - - if ( h > 0 ) - y2 = y + h - 1; - else - y2 = y + h + 1; - - if ( x2 < x1 ) { - int tmp; - tmp = x1; - x1 = x2; - x2 = tmp; - w = -w; - swapped = 1; - } - - if ( y2 < y1 ) { - int tmp; - tmp = y1; - y1 = y2; - y2 = tmp; - h = -h; - swapped = 1; - } - - for (int i=0; i x2 ) { - int tmp = x1; - x1 = x2; - x2 = tmp; - } - - if ( y < gr_screen.clip_top ) return; - if ( y > gr_screen.clip_bottom ) return; - - if ( x1 < gr_screen.clip_left ) x1 = gr_screen.clip_left; - if ( x2 > gr_screen.clip_right ) x2 = gr_screen.clip_right; - - w = x2 - x1 + 1; - - if ( w < 1 ) return; - - - // Set up Render State - flat shading - alpha blending - gr_glide_set_state( TEXTURE_SOURCE_NONE, COLOR_SOURCE_VERTEX, ALPHA_SOURCE_VERTEX, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE ); - - GrVertex v1,v2; - - v1.x = i2fl(x1 + gr_screen.offset_x); - v1.y = i2fl(y + gr_screen.offset_y); - v1.r = i2fl(r); - v1.g = i2fl(g); - v1.b = i2fl(b); - v1.a = i2fl(a); - - v2.x = i2fl(x2 + gr_screen.offset_x); - v2.y = i2fl(y + gr_screen.offset_y); - v2.r = i2fl(r); - v2.g = i2fl(g); - v2.b = i2fl(b); - v2.a = i2fl(a); - - if (v1.x 0 ) - x2 = x + w - 1; - else - x2 = x + w + 1; - - if ( h > 0 ) - y2 = y + h - 1; - else - y2 = y + h + 1; - - if ( x2 < x1 ) { - int tmp; - tmp = x1; - x1 = x2; - x2 = tmp; - w = -w; - swapped = 1; - } - - if ( y2 < y1 ) { - int tmp; - tmp = y1; - y1 = y2; - y2 = tmp; - h = -h; - swapped = 1; - } - - int r,g,b,a; - r = fl2i(gr_screen.current_shader.r*255.0f*shade1); - if ( r < 0 ) r = 0; else if ( r > 255 ) r = 255; - g = fl2i(gr_screen.current_shader.g*255.0f*shade1); - if ( g < 0 ) g = 0; else if ( g > 255 ) g = 255; - b = fl2i(gr_screen.current_shader.b*255.0f*shade1); - if ( b < 0 ) b = 0; else if ( b > 255 ) b = 255; - a = fl2i(gr_screen.current_shader.c*255.0f*shade2); - if ( a < 0 ) a = 0; else if ( a > 255 ) a = 255; - - for (int i=0; ichar_data[letter]; - - int sx = Current_font->bm_u[letter]; - int sy = Current_font->bm_v[letter]; - - gr_glide_aabitmap_ex_new( x, y, ch->byte_width, Current_font->h, sx, sy ); - -// mprintf(( "String = %s\n", text )); -} - - -void gr_glide_string( int sx, int sy, char *s ) -{ - int width, spacing, letter; - int x, y; - - if ( !Current_font ) { - return; - } - - gr_set_bitmap(Current_font->bitmap_id); - - x = sx; - y = sy; - - if (sx==0x8000) { //centered - x = get_centered_x(s); - } else { - x = sx; - } - - spacing = 0; - - while (*s) { - - x += spacing; - - while (*s== '\n' ) { - s++; - y += Current_font->h; - if (sx==0x8000) { //centered - x = get_centered_x(s); - } else { - x = sx; - } - } - if (*s == 0 ) break; - - letter = get_char_width(s[0],s[1],&width,&spacing); - s++; - - if (letter<0) { //not in font, draw as space - continue; - } - - gr_glide_char( x, y, letter ); - } -} - -void gr_glide_circle( int xc, int yc, int d ) -{ - - int p,x, y, r; - - r = d/2; - p=3-d; - x=0; - y=r; - - // Big clip - if ( (xc+r) < gr_screen.clip_left ) return; - if ( (xc-r) > gr_screen.clip_right ) return; - if ( (yc+r) < gr_screen.clip_top ) return; - if ( (yc-r) > gr_screen.clip_bottom ) return; - - while(xsx; - y1 = v1->sy; - - x2 = v2->sx; - y2 = v2->sy; - - a1 = (float)gr_screen.clip_left; - b1 = (float)gr_screen.clip_top; - a2 = (float)gr_screen.clip_right; - b2 = (float)gr_screen.clip_bottom; - - FL_CLIPLINE(x1,y1,x2,y2,a1,b1,a2,b2,return,clipped=1,swapped=1); - - gr_glide_set_state( TEXTURE_SOURCE_NONE, COLOR_SOURCE_VERTEX, ALPHA_SOURCE_VERTEX, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE ); - - GrVertex a,b; - - a.x = i2fl(fl2i(x1)) + gr_screen.offset_x; - a.y = i2fl(fl2i(y1)) + gr_screen.offset_y; - a.r = i2fl(gr_screen.current_color.red); - a.g = i2fl(gr_screen.current_color.green); - a.b = i2fl(gr_screen.current_color.blue); - a.a = i2fl(gr_screen.current_color.alpha); - - b.x = i2fl(fl2i(x2)) + gr_screen.offset_x; - b.y = i2fl(fl2i(y2)) + gr_screen.offset_y; - b.r = i2fl(gr_screen.current_color.red); - b.g = i2fl(gr_screen.current_color.green); - b.b = i2fl(gr_screen.current_color.blue); - b.a = i2fl(gr_screen.current_color.alpha); - - if (a.xu = verts[i]->v = 0.5f; - } - */ - } - - gr_texture_source texture_source = (gr_texture_source)-1; - gr_color_source color_source = (gr_color_source)-1; - gr_alpha_source alpha_source = (gr_alpha_source)-1; - gr_alpha_blend alpha_blend = (gr_alpha_blend)-1; - gr_zbuffer_type zbuffer_type = (gr_zbuffer_type)-1; - - if ( gr_zbuffering ) { - if ( is_scaler || (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) ) { - zbuffer_type = ZBUFFER_TYPE_READ; - } else { - zbuffer_type = ZBUFFER_TYPE_FULL; - } - } else { - zbuffer_type = ZBUFFER_TYPE_NONE; - } - - float alpha; - - alpha_source = ALPHA_SOURCE_VERTEX; - - switch(gr_screen.current_alphablend_mode){ - case GR_ALPHABLEND_FILTER: - // Blend with screen pixel using src*alpha+dst - if ( gr_screen.current_alpha > 1.0f ) { - alpha_blend = ALPHA_BLEND_ALPHA_BLEND_SRC_COLOR; - alpha = 255.0f; - } else { - alpha_blend = ALPHA_BLEND_ALPHA_ADDITIVE; - alpha = gr_screen.current_alpha*255.0f; - } - break; - - default : - alpha_blend = ALPHA_BLEND_ALPHA_BLEND_ALPHA; - alpha = 255.0f; - break; - } - - if ( flags & TMAP_FLAG_TEXTURED ) { - int texture_type = TCACHE_TYPE_NORMAL; - - if ( flags & TMAP_FLAG_NONDARKENING ) { - alpha_source = ALPHA_SOURCE_VERTEX_NONDARKENING; - //alpha_source = ALPHA_SOURCE_VERTEX_TIMES_TEXTURE; - texture_type = TCACHE_TYPE_NONDARKENING; - } else { - alpha_source = ALPHA_SOURCE_VERTEX_TIMES_TEXTURE; - texture_type = TCACHE_TYPE_XPARENT; - } - - // common settings - color_source = COLOR_SOURCE_VERTEX_TIMES_TEXTURE; - texture_source = TEXTURE_SOURCE_DECAL; - - // force texture type - if(flags & TMAP_FLAG_BITMAP_SECTION){ - texture_type = TCACHE_TYPE_BITMAP_SECTION; - } - - if ( !gr_tcache_set( gr_screen.current_bitmap, texture_type, &Glide_u_ratio, &Glide_v_ratio, 0, gr_screen.current_bitmap_sx, gr_screen.current_bitmap_sy )) { - // Error setting texture! - mprintf(( "GLIDE: Error setting texture!\n" )); - // Mark as no texturing - color_source = COLOR_SOURCE_VERTEX; - texture_source = TEXTURE_SOURCE_NONE; - } - } else { - color_source = COLOR_SOURCE_VERTEX; - texture_source = TEXTURE_SOURCE_NONE; - if(flags & TMAP_FLAG_ALPHA){ - alpha_source = ALPHA_SOURCE_VERTEX; - } - } - -// zbuffer_type = ZBUFFER_TYPE_NONE; -// alpha_source = ALPHA_SOURCE_VERTEX; -// alpha_blend = ALPHA_BLEND_NONE; -// alpha = 255.0f; -// color_source = COLOR_SOURCE_VERTEX; -// texture_source = TEXTURE_SOURCE_NONE; - gr_glide_set_state( texture_source, color_source, alpha_source, alpha_blend, zbuffer_type ); - - int x1, y1, x2, y2; - x1 = gr_screen.clip_left*16; - x2 = gr_screen.clip_right*16+15; - y1 = gr_screen.clip_top*16; - y2 = gr_screen.clip_bottom*16+15; - -// memset( GrVerts, 0, sizeof(GrVertex) * 25 ); - - for (i=0; ia); - } else { - GrVerts[i].a = alpha; - } - - if ( flags & TMAP_FLAG_NEBULA ) { - int pal = (verts[i]->b*(NEBULA_COLORS-1))/255; - GrVerts[i].r = i2fl(gr_palette[pal*3+0]); - GrVerts[i].g = i2fl(gr_palette[pal*3+1]); - GrVerts[i].b = i2fl(gr_palette[pal*3+2]); - } else if ( (flags & TMAP_FLAG_RAMP) && (flags & TMAP_FLAG_GOURAUD) ) { - GrVerts[i].r = Gr_gamma_lookup_float[verts[i]->b]; - GrVerts[i].g = Gr_gamma_lookup_float[verts[i]->b]; - GrVerts[i].b = Gr_gamma_lookup_float[verts[i]->b]; - } else if ( (flags & TMAP_FLAG_RGB) && (flags & TMAP_FLAG_GOURAUD) ) { - // Make 0.75 be 256.0f - GrVerts[i].r = Gr_gamma_lookup_float[verts[i]->r]; - GrVerts[i].g = Gr_gamma_lookup_float[verts[i]->g]; - GrVerts[i].b = Gr_gamma_lookup_float[verts[i]->b]; - } else { - if ( flags & TMAP_FLAG_TEXTURED ) { - GrVerts[i].r = 255.0f; - GrVerts[i].g = 255.0f; - GrVerts[i].b = 255.0f; - } else { - GrVerts[i].r = i2fl(gr_screen.current_color.red); - GrVerts[i].g = i2fl(gr_screen.current_color.green); - GrVerts[i].b = i2fl(gr_screen.current_color.blue); - } - } - - int x, y; - x = fl2i(verts[i]->sx*16.0f); - y = fl2i(verts[i]->sy*16.0f); - - if ( flags & TMAP_FLAG_CORRECT ) { - // "clip" it - if ( x < x1 ) { - x = x1; - } else if ( x > x2 ) { - x = x2; - } - if ( y < y1 ) { - y = y1; - } else if ( y > y2 ) { - y = y2; - } - } - - x += gr_screen.offset_x*16; - y += gr_screen.offset_y*16; - - GrVerts[i].x = i2fl(x) / 16.0f; - GrVerts[i].y = i2fl(y) / 16.0f; - - //verts[i]->sw = 1.0f; - - GrVerts[i].oow=verts[i]->sw; - - if ( flags & TMAP_FLAG_TEXTURED ) { - GrVerts[i].tmuvtx[GR_TMU0].oow=verts[i]->sw; - GrVerts[i].tmuvtx[GR_TMU0].sow=verts[i]->u * verts[i]->sw * Glide_u_ratio; - GrVerts[i].tmuvtx[GR_TMU0].tow=verts[i]->v * verts[i]->sw * Glide_v_ratio; - } - } - - // if we're rendering against a fullneb background - if(flags & TMAP_FLAG_PIXEL_FOG){ - int r, g, b; - int ra, ga, ba; - ra = ga = ba = 0; - - // get the average pixel color behind the vertices - for(i=0; isx; y0 = va->sy; - x1 = vb->sx; y1 = vb->sy; - - xmin = i2fl(gr_screen.clip_left); ymin = i2fl(gr_screen.clip_top); - xmax = i2fl(gr_screen.clip_right); ymax = i2fl(gr_screen.clip_bottom); - - u0 = va->u; v0 = va->v; - u1 = vb->u; v1 = vb->v; - - // Check for obviously offscreen bitmaps... - if ( (y1<=y0) || (x1<=x0) ) return; - if ( (x1xmax) ) return; - if ( (y1ymax) ) return; - - clipped_u0 = u0; clipped_v0 = v0; - clipped_u1 = u1; clipped_v1 = v1; - - clipped_x0 = x0; clipped_y0 = y0; - clipped_x1 = x1; clipped_y1 = y1; - - // Clip the left, moving u0 right as necessary - if ( x0 < xmin ) { - clipped_u0 = FIND_SCALED_NUM(xmin,x0,x1,u0,u1); - clipped_x0 = xmin; - } - - // Clip the right, moving u1 left as necessary - if ( x1 > xmax ) { - clipped_u1 = FIND_SCALED_NUM(xmax,x0,x1,u0,u1); - clipped_x1 = xmax; - } - - // Clip the top, moving v0 down as necessary - if ( y0 < ymin ) { - clipped_v0 = FIND_SCALED_NUM(ymin,y0,y1,v0,v1); - clipped_y0 = ymin; - } - - // Clip the bottom, moving v1 up as necessary - if ( y1 > ymax ) { - clipped_v1 = FIND_SCALED_NUM(ymax,y0,y1,v0,v1); - clipped_y1 = ymax; - } - - dx0 = fl2i(clipped_x0); dx1 = fl2i(clipped_x1); - dy0 = fl2i(clipped_y0); dy1 = fl2i(clipped_y1); - - if (dx1<=dx0) return; - if (dy1<=dy0) return; - - //============= DRAW IT ===================== - - vertex v[4]; - vertex *vl[4]; - - vl[0] = &v[0]; - v->sx = clipped_x0; - v->sy = clipped_y0; - v->sw = va->sw; - v->z = va->z; - v->u = clipped_u0; - v->v = clipped_v0; - - vl[1] = &v[1]; - v[1].sx = clipped_x1; - v[1].sy = clipped_y0; - v[1].sw = va->sw; - v[1].z = va->z; - v[1].u = clipped_u1; - v[1].v = clipped_v0; - - vl[2] = &v[2]; - v[2].sx = clipped_x1; - v[2].sy = clipped_y1; - v[2].sw = va->sw; - v[2].z = va->z; - v[2].u = clipped_u1; - v[2].v = clipped_v1; - - vl[3] = &v[3]; - v[3].sx = clipped_x0; - v[3].sy = clipped_y1; - v[3].sw = va->sw; - v[3].z = va->z; - v[3].u = clipped_u0; - v[3].v = clipped_v1; - - //glide_zbuffering(0); - gr_glide_tmapper_internal( 4, vl, TMAP_FLAG_TEXTURED, 1 ); -} - - -void gr_glide_aabitmap_ex_new(int x,int y,int w,int h,int sx,int sy) -{ - if ( w < 1 ) return; - if ( h < 1 ) return; - - if ( !gr_screen.current_color.is_alphacolor ) return; - - if(VOODOO3_INACTIVE()){ - return; - } - -// mprintf(( "x=%d, y=%d, w=%d, h=%d\n", x, y, w, h )); -// mprintf(( "sx=%d, sy=%d, bw=%d, bh=%d\n", sx, sy, bmp->w, bmp->h )); - - float Glide_u_ratio; - float Glide_v_ratio; - - // Set up Render State - flat shading - alpha blending - gr_glide_set_state( TEXTURE_SOURCE_DECAL, COLOR_SOURCE_VERTEX, ALPHA_SOURCE_VERTEX_TIMES_TEXTURE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE ); - - if ( !gr_tcache_set( gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP, &Glide_u_ratio, &Glide_v_ratio ) ) { - // Couldn't set texture - mprintf(( "GLIDE: Error setting aabitmap texture!\n" )); - return; - } - - GrVertex GrVerts[4]; - - float u0, u1, v0, v1; - float r,g,b,a; - - r = i2fl(gr_screen.current_color.red); - g = i2fl(gr_screen.current_color.green); - b = i2fl(gr_screen.current_color.blue); - a = i2fl(gr_screen.current_color.alpha); - - int bw, bh; - - bm_get_info( gr_screen.current_bitmap, &bw, &bh ); - - u0 = Glide_u_ratio*i2fl(sx)/i2fl(bw); - v0 = Glide_v_ratio*i2fl(sy)/i2fl(bh); - - u1 = Glide_u_ratio*i2fl(sx+w)/i2fl(bw); - v1 = Glide_v_ratio*i2fl(sy+h)/i2fl(bh); - - float x1, x2, y1, y2; - x1 = i2fl(x+gr_screen.offset_x); - y1 = i2fl(y+gr_screen.offset_y); - x2 = i2fl(x+w+gr_screen.offset_x); - y2 = i2fl(y+h+gr_screen.offset_y); - - int i; - - i = 0; - GrVerts[i].x = x1; - GrVerts[i].y = y1; - GrVerts[i].oow = 1.0f; - GrVerts[i].r = r; - GrVerts[i].g = g; - GrVerts[i].b = b; - GrVerts[i].a = a; - GrVerts[i].tmuvtx[GR_TMU0].sow=u0; - GrVerts[i].tmuvtx[GR_TMU0].tow=v0; - - i = 1; - GrVerts[i].x = x2; - GrVerts[i].y = y1; - GrVerts[i].oow = 1.0f; - GrVerts[i].r = r; - GrVerts[i].g = g; - GrVerts[i].b = b; - GrVerts[i].a = a; - GrVerts[i].tmuvtx[GR_TMU0].sow=u1; - GrVerts[i].tmuvtx[GR_TMU0].tow=v0; - - i = 2; - GrVerts[i].x = x2; - GrVerts[i].y = y2; - GrVerts[i].oow = 1.0f; - GrVerts[i].r = r; - GrVerts[i].g = g; - GrVerts[i].b = b; - GrVerts[i].a = a; - GrVerts[i].tmuvtx[GR_TMU0].sow=u1; - GrVerts[i].tmuvtx[GR_TMU0].tow=v1; - - i = 3; - GrVerts[i].x = x1; - GrVerts[i].y = y2; - GrVerts[i].oow = 1.0f; - GrVerts[i].r = r; - GrVerts[i].g = g; - GrVerts[i].b = b; - GrVerts[i].a = a; - GrVerts[i].tmuvtx[GR_TMU0].sow=u0; - GrVerts[i].tmuvtx[GR_TMU0].tow=v1; - - grDrawPolygonVertexList( 4, GrVerts ); -} - - - -void gr_glide_aabitmap_ex(int x,int y,int w,int h,int sx,int sy) -{ - int reclip; - #ifndef NDEBUG - int count = 0; - #endif - - int dx1=x, dx2=x+w-1; - int dy1=y, dy2=y+h-1; - - int bw, bh; - bm_get_info( gr_screen.current_bitmap, &bw, &bh, NULL ); - - do { - reclip = 0; - #ifndef NDEBUG - if ( count > 1 ) Int3(); - count++; - #endif - - if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return; - if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return; - if ( dx1 < gr_screen.clip_left ) { sx += gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; } - if ( dy1 < gr_screen.clip_top ) { sy += gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; } - if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; } - if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; } - - if ( sx < 0 ) { - dx1 -= sx; - sx = 0; - reclip = 1; - } - - if ( sy < 0 ) { - dy1 -= sy; - sy = 0; - reclip = 1; - } - - w = dx2-dx1+1; - h = dy2-dy1+1; - - if ( sx + w > bw ) { - w = bw - sx; - dx2 = dx1 + w - 1; - } - - if ( sy + h > bh ) { - h = bh - sy; - dy2 = dy1 + h - 1; - } - - if ( w < 1 ) return; // clipped away! - if ( h < 1 ) return; // clipped away! - - } while (reclip); - - // Make sure clipping algorithm works - #ifndef NDEBUG - SDL_assert( w > 0 ); - SDL_assert( h > 0 ); - SDL_assert( w == (dx2-dx1+1) ); - SDL_assert( h == (dy2-dy1+1) ); - SDL_assert( sx >= 0 ); - SDL_assert( sy >= 0 ); - SDL_assert( sx+w <= bw ); - SDL_assert( sy+h <= bh ); - SDL_assert( dx2 >= dx1 ); - SDL_assert( dy2 >= dy1 ); - SDL_assert( (dx1 >= gr_screen.clip_left ) && (dx1 <= gr_screen.clip_right) ); - SDL_assert( (dx2 >= gr_screen.clip_left ) && (dx2 <= gr_screen.clip_right) ); - SDL_assert( (dy1 >= gr_screen.clip_top ) && (dy1 <= gr_screen.clip_bottom) ); - SDL_assert( (dy2 >= gr_screen.clip_top ) && (dy2 <= gr_screen.clip_bottom) ); - #endif - - // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions. - - // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2) - gr_glide_aabitmap_ex_new(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy); -} - -void gr_glide_string_hack( int sx, int sy, char *s ) -{ - int width, spacing, letter; - int x, y; - - if ( !Current_font ) { - return; - } - - gr_set_bitmap(Current_font->bitmap_id); - - x = sx; - y = sy; - - if (sx==0x8000) { //centered - x = get_centered_x(s); - } else { - x = sx; - } - - spacing = 0; - - while (*s) { - - x += spacing; - - while (*s== '\n' ) { - s++; - y += Current_font->h; - if (sx==0x8000) { //centered - x = get_centered_x(s); - } else { - x = sx; - } - } - if (*s == 0 ) break; - - letter = get_char_width(s[0],s[1],&width,&spacing); - s++; - - if (letter<0) { //not in font, draw as space - continue; - } - - // formerly a call to gr_glide_char(...) - { - font_char *ch; - - ch = &Current_font->char_data[letter]; - - int _sx = Current_font->bm_u[letter]; - int _sy = Current_font->bm_v[letter]; - - gr_glide_aabitmap_ex( x, y, ch->byte_width, Current_font->h, _sx, _sy ); - } - } -} - -void gr_glide_aabitmap(int x, int y) -{ - int w, h; - - bm_get_info( gr_screen.current_bitmap, &w, &h, NULL ); - int dx1=x, dx2=x+w-1; - int dy1=y, dy2=y+h-1; - int sx=0, sy=0; - - if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return; - if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return; - if ( dx1 < gr_screen.clip_left ) { sx = gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; } - if ( dy1 < gr_screen.clip_top ) { sy = gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; } - if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; } - if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; } - - if ( sx < 0 ) return; - if ( sy < 0 ) return; - if ( sx >= w ) return; - if ( sy >= h ) return; - - // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2) - gr_aabitmap_ex(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy); -} - - -void gr_glide_gradient(int x1,int y1,int x2,int y2) -{ - int clipped = 0, swapped=0; - - if(VOODOO3_INACTIVE()){ - return; - } - - if ( !gr_screen.current_color.is_alphacolor ) { - gr_line( x1, y1, x2, y2 ); - return; - } - - INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,gr_screen.clip_right,gr_screen.clip_bottom,return,clipped=1,swapped=1); - - // Set up Render State - flat shading - alpha blending - gr_glide_set_state( TEXTURE_SOURCE_NONE, COLOR_SOURCE_VERTEX, ALPHA_SOURCE_VERTEX, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE ); - - GrVertex a,b; - - a.x = i2fl(x1 + gr_screen.offset_x); - a.y = i2fl(y1 + gr_screen.offset_y); - a.r = i2fl(gr_screen.current_color.red); - a.g = i2fl(gr_screen.current_color.green); - a.b = i2fl(gr_screen.current_color.blue); - - b.x = i2fl(x2 + gr_screen.offset_x); - b.y = i2fl(y2 + gr_screen.offset_y); - b.r = i2fl(gr_screen.current_color.red); - b.g = i2fl(gr_screen.current_color.green); - b.b = i2fl(gr_screen.current_color.blue); - - if ( swapped ) { - a.a = 0.0f; - b.a = i2fl(gr_screen.current_color.alpha); - } else { - b.a = 0.0f; - a.a = i2fl(gr_screen.current_color.alpha); - } - - if (a.xscreen_sig = gr_screen.signature; - c->red = unsigned char(r); - c->green = unsigned char(g); - c->blue = unsigned char(b); - c->alpha = 255; - c->ac_type = AC_TYPE_NONE; - c->alphacolor = -1; - c->is_alphacolor = 0; - c->magic = 0xAC01; -} - -void gr_glide_init_alphacolor( color *clr, int r, int g, int b, int alpha, int type ) -{ - if ( r < 0 ) r = 0; else if ( r > 255 ) r = 255; - if ( g < 0 ) g = 0; else if ( g > 255 ) g = 255; - if ( b < 0 ) b = 0; else if ( b > 255 ) b = 255; - if ( alpha < 0 ) alpha = 0; else if ( alpha > 255 ) alpha = 255; - - gr_glide_init_color( clr, r, g, b ); - - clr->alpha = unsigned char(alpha); - clr->ac_type = (ubyte)type; - clr->alphacolor = -1; - clr->is_alphacolor = 1; -} - -void gr_glide_set_color( int r, int g, int b ) -{ - SDL_assert((r >= 0) && (r < 256)); - SDL_assert((g >= 0) && (g < 256)); - SDL_assert((b >= 0) && (b < 256)); - - gr_glide_init_color( &gr_screen.current_color, r, g, b ); -} - -void gr_glide_get_color( int * r, int * g, int * b ) -{ - if (r) *r = gr_screen.current_color.red; - if (g) *g = gr_screen.current_color.green; - if (b) *b = gr_screen.current_color.blue; -} - -void gr_glide_set_color_fast(color *dst) -{ - if ( dst->screen_sig != gr_screen.signature ) { - if ( dst->is_alphacolor ) { - gr_glide_init_alphacolor( dst, dst->red, dst->green, dst->blue, dst->alpha, dst->ac_type ); - } else { - gr_glide_init_color( dst, dst->red, dst->green, dst->blue ); - } - } - gr_screen.current_color = *dst; -} - - - -void gr_glide_flash(int r, int g, int b) -{ - int Flash_r = r; - int Flash_g = g; - int Flash_b = b; - - if(VOODOO3_INACTIVE()){ - return; - } - - CAP(Flash_r,0,255); - CAP(Flash_g,0,255); - CAP(Flash_b,0,255); - - if ( Flash_r || Flash_g || Flash_b ) { - gr_glide_set_state( TEXTURE_SOURCE_NONE, COLOR_SOURCE_VERTEX, ALPHA_SOURCE_VERTEX, ALPHA_BLEND_ALPHA_ADDITIVE, ZBUFFER_TYPE_NONE ); - - GrVertex GrVerts[4]; - - float r,g,b,a; - - r = i2fl(Flash_r); - g = i2fl(Flash_g); - b = i2fl(Flash_b); - a = i2fl(255); - - float x1, x2, y1, y2; - x1 = i2fl(gr_screen.clip_left+gr_screen.offset_x); - y1 = i2fl(gr_screen.clip_top+gr_screen.offset_y); - x2 = i2fl(gr_screen.clip_right+gr_screen.offset_x); - y2 = i2fl(gr_screen.clip_bottom+gr_screen.offset_y); - - int i; - - i = 0; - GrVerts[i].x = x1; - GrVerts[i].y = y1; - GrVerts[i].r = r; - GrVerts[i].g = g; - GrVerts[i].b = b; - GrVerts[i].a = a; - - i = 1; - GrVerts[i].x = x2; - GrVerts[i].y = y1; - GrVerts[i].r = r; - GrVerts[i].g = g; - GrVerts[i].b = b; - GrVerts[i].a = a; - - i = 2; - GrVerts[i].x = x2; - GrVerts[i].y = y2; - GrVerts[i].r = r; - GrVerts[i].g = g; - GrVerts[i].b = b; - GrVerts[i].a = a; - - i = 3; - GrVerts[i].x = x1; - GrVerts[i].y = y2; - GrVerts[i].r = r; - GrVerts[i].g = g; - GrVerts[i].b = b; - GrVerts[i].a = a; - - grDrawPolygonVertexList( 4, GrVerts ); - } - -} - - - -void gr_glide_activate(int active) -{ - if (!Glide_running) { - return; - } - - mprintf(( "Glide activate: %d\n", active )); - - // voodoo3 - if(Glide_voodoo3){ - // choose resolution - GrScreenResolution_t res_mode; - if((gr_screen.max_w == 1024) && (gr_screen.max_h == 768)){ - res_mode = GR_RESOLUTION_1024x768; - } else { - res_mode = GR_RESOLUTION_640x480; - } - - HWND hwnd = (HWND)os_get_window(); - - if ( active ) { - // already active - if(Glide_deactivate == 0){ - return; - } - - Glide_deactivate = 0; - - if ( hwnd ) { - SetActiveWindow(hwnd); - SetForegroundWindow(hwnd); - grSstWinOpen( (DWORD)hwnd, res_mode, GR_REFRESH_60Hz, GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1 ); - ShowWindow(hwnd,SW_MAXIMIZE); - gr_glide_clip_cursor(1); - glide_tcache_init(); - grGammaCorrectionValue(1.0f); - } - } else { - // already deactivated - if(Glide_deactivate == VOODOO3_DEACTIVATED){ - return; - } - - Glide_deactivate = VOODOO3_DEACTIVATED; - - if ( hwnd ) { - gr_glide_clip_cursor(0); - ShowWindow(hwnd,SW_MINIMIZE); - grSstWinClose(); - } - } - } else { - HWND hwnd = (HWND)os_get_window(); - - if ( active ) { - Glide_activate++; - - if ( hwnd ) { - // SetActiveWindow(hwnd); - // SetForegroundWindow(hwnd); - ShowWindow(hwnd,SW_RESTORE); - // gr_glide_clip_cursor(1); - // grSstControl(GR_CONTROL_ACTIVATE); - } - } else { - Glide_deactivate++; - - if ( hwnd ) { - // grSstControl(GR_CONTROL_DEACTIVATE); - ClipCursor(NULL); - ShowWindow(hwnd,SW_MINIMIZE); - } - } - } -} - - -// copy from one pixel buffer to another -// -// from pointer to source buffer -// to pointer to dest. buffet -// pixels number of pixels to copy -// fromsize source pixel size -// tosize dest. pixel size - -static int tga_copy_data(char *to, char *from, int pixels, int fromsize, int tosize) -{ - int rmask = 0xf800; - int rshift = 11; - int rscale = 8;; - int gmask = 0x7e0; - int gshift = 5; - int gscale = 4; - int bmask = 0x1f; - int bshift = 0; - int bscale = 8;; - - if ( (fromsize == 2) && (tosize == 3) ) { - ushort *src = (ushort *)from; - ubyte *dst = (ubyte *)to; - - int i; - for (i=0; i>bshift)*bscale; - g = ((pixel & gmask)>>gshift)*gscale; - r = ((pixel & rmask)>>rshift)*rscale; - - // Adjust for gamma and output it - *dst++ = ubyte(b); - *dst++ = ubyte(g); - *dst++ = ubyte(r); - } - return tosize*pixels; - } else { - Int3(); - return tosize*pixels; - } -} - - - -// -// tga_pixels_equal -- Test if two pixels are identical -// -// Returns: -// 0 if No Match -// 1 if Match - -static int tga_pixels_equal(char *pix1, char *pix2, int pixbytes) -{ - do { - if ( *pix1++ != *pix2++ ) { - return 0; - } - } while ( --pixbytes > 0 ); - - return 1; -} - - -// tga_compress - Do the Run Length Compression -// -// Usage: -// out Buffer to write it out to -// in Buffer to compress -// bytecount Number of bytes input -// pixsize Number of bytes in input pixel -// outsize Number of bytes in output buffer - -int tga_compress(char *out, char *in, int bytecount ) -{ -#define pixsize 2 -#define outsize 3 - int pixcount; // number of pixels in the current packet - char *inputpixel=NULL; // current input pixel position - char *matchpixel=NULL; // pixel value to match for a run - char *flagbyte=NULL; // location of last flag byte to set - int rlcount; // current count in r.l. string - int rlthresh; // minimum valid run length - char *copyloc; // location to begin copying at - - // set the threshold -- the minimum valid run length - - #if outsize == 1 - rlthresh = 2; // for 8bpp, require a 2 pixel span before rle'ing - #else - rlthresh = 1; - #endif - - // set the first pixel up - - flagbyte = out; // place to put next flag if run - inputpixel = in; - pixcount = 1; - rlcount = 0; - copyloc = (char *)0; - - // loop till data processing complete - do { - - // if we have accumulated a 128-byte packet, process it - if ( pixcount == 129 ) { - *flagbyte = 127; - - // set the run flag if this is a run - - if ( rlcount >= rlthresh ) { - *flagbyte |= 0x80; - pixcount = 2; - } - - // copy the data into place - ++flagbyte; - flagbyte += tga_copy_data(flagbyte, copyloc, pixcount-1, pixsize, outsize); - pixcount = 1; - - // set up for next packet - continue; - } - - // if zeroth byte, handle as special case - if ( pixcount == 1 ) { - rlcount = 0; - copyloc = inputpixel; /* point to 1st guy in packet */ - matchpixel = inputpixel; /* set pointer to pix to match */ - pixcount = 2; - inputpixel += pixsize; - continue; - } - - // assembling a packet -- look at next pixel - - // current pixel == match pixel? - if ( tga_pixels_equal(inputpixel, matchpixel, outsize) ) { - - // establishing a run of enough length to - // save space by doing it - // -- write the non-run length packet - // -- start run-length packet - - if ( ++rlcount == rlthresh ) { - - // close a non-run packet - - if ( pixcount > (rlcount+1) ) { - // write out length and do not set run flag - - *flagbyte++ = (char)(pixcount - 2 - rlthresh); - - flagbyte += tga_copy_data(flagbyte, copyloc, (pixcount-1-rlcount), pixsize, outsize); - - copyloc = inputpixel; - pixcount = rlcount + 1; - } - } - } else { - - // no match -- either break a run or continue without one - // if a run exists break it: - // write the bytes in the string (outsize+1) - // start the next string - - if ( rlcount >= rlthresh ) { - - *flagbyte++ = (char)(0x80 | rlcount); - flagbyte += tga_copy_data(flagbyte, copyloc, 1, pixsize, outsize); - pixcount = 1; - continue; - } else { - - // not a match and currently not a run - // - save the current pixel - // - reset the run-length flag - rlcount = 0; - matchpixel = inputpixel; - } - } - pixcount++; - inputpixel += pixsize; - } while ( inputpixel < (in + bytecount)); - - // quit this buffer without loosing any data - - if ( --pixcount >= 1 ) { - *flagbyte = (char)(pixcount - 1); - if ( rlcount >= rlthresh ) { - *flagbyte |= 0x80; - pixcount = 1; - } - - // copy the data into place - ++flagbyte; - flagbyte += tga_copy_data(flagbyte, copyloc, pixcount, pixsize, outsize); - } - return(flagbyte-out); -} - - - -void gr_glide_print_screen(char *filename) -{ - GrLfbInfo_t info; - int i; - ubyte outrow[1024*3*4]; - - if(VOODOO3_INACTIVE()){ - return; - } - - if ( gr_screen.max_w > 1024 ) { - mprintf(( "Screen too wide for print_screen\n" )); - return; - } - - info.size=sizeof(GrLfbInfo_t); - - // get a read pointer - if ( grLfbLock( GR_LFB_READ_ONLY, GR_BUFFER_BACKBUFFER, GR_LFBWRITEMODE_565, - GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { - int w=gr_screen.max_w,h=gr_screen.max_h; - ushort *rptr; - int short_per_row=info.strideInBytes/2; - - rptr = (ushort *)info.lfbPtr; - - - char tmp[1024]; - - strcpy( tmp, NOX(".\\")); // specify a path mean files goes in root - strcat( tmp, filename ); - strcat( tmp, NOX(".tga")); - - CFILE *f = cfopen(tmp, "wb"); - - // Write the TGA header - cfwrite_ubyte( 0, f ); // IDLength; - cfwrite_ubyte( 0, f ); // ColorMapType; - cfwrite_ubyte( 10, f ); // ImageType; // 2 = 24bpp, uncompressed, 10=24bpp rle compressed - cfwrite_ushort( 0, f ); // CMapStart; - cfwrite_ushort( 0, f ); // CMapLength; - cfwrite_ubyte( 0, f ); // CMapDepth; - cfwrite_ushort( 0, f ); // XOffset; - cfwrite_ushort( 0, f ); // YOffset; - cfwrite_ushort( (ushort)w, f ); // Width; - cfwrite_ushort( (ushort)h, f ); // Height; - cfwrite_ubyte( 24, f ); //PixelDepth; - cfwrite_ubyte( 0, f ); //ImageDesc; - - // Go through and read our pixels - for (i=0;i> 8); - g = (ubyte)((bit_16 & 0x07e0) >> 3); - b = (ubyte)((bit_16 & 0x001f) << 3); - - // swizzle the data to 1555 (BM_PIXEL_FORMAT_ARGB) - *dptr = 0; - bm_set_components((ubyte*)dptr++, &r, &g, &b, &a); - } - } - - // Release the lock - grLfbUnlock(GR_LFB_READ_ONLY, front ? GR_BUFFER_FRONTBUFFER : GR_BUFFER_BACKBUFFER); - } -} - -void gr_glide_flush_frame_dump() -{ - int i,j; - char filename[MAX_PATH_LEN], *movie_path = ".\\"; - ubyte outrow[1024*3*4]; - - if(VOODOO3_INACTIVE()){ - return; - } - - if ( gr_screen.max_w > 1024) { - mprintf(( "Screen too wide for frame_dump\n" )); - return; - } - - for (i = 0; i < Glide_dump_frame_count; i++) { - - int w = gr_screen.max_w; - int h = gr_screen.max_h; - - sprintf(filename, NOX("%sfrm%04d.tga"), movie_path, Glide_dump_frame_number ); - Glide_dump_frame_number++; - - CFILE *f = cfopen(filename, "wb"); - - // Write the TGA header - cfwrite_ubyte( 0, f ); // IDLength; - cfwrite_ubyte( 0, f ); // ColorMapType; - cfwrite_ubyte( 10, f ); // ImageType; // 2 = 24bpp, uncompressed, 10=24bpp rle compressed - cfwrite_ushort( 0, f ); // CMapStart; - cfwrite_ushort( 0, f ); // CMapLength; - cfwrite_ubyte( 0, f ); // CMapDepth; - cfwrite_ushort( 0, f ); // XOffset; - cfwrite_ushort( 0, f ); // YOffset; - cfwrite_ushort( (ushort)w, f ); // Width; - cfwrite_ushort( (ushort)h, f ); // Height; - cfwrite_ubyte( 24, f ); //PixelDepth; - cfwrite_ubyte( 0, f ); //ImageDesc; - - // Go through and write our pixels - for (j=0;j 255 ) { - c = 255; - } - - gr_glide_restore_screen_internal(tmp_data); - - for (int i=0; i=0) ); // Loop as long as time not up and timer hasn't rolled - - stop_time = timer_get_fixed_seconds(); - - mprintf(( "Took %d frames (and %.1f secs) to fade out\n", count, f2fl(stop_time-start_time) )); - - } - } - } - - gr_clear(); - gr_flip(); - gr_palette_faded_out = 1; - Mouse_hidden--; - - if ( tmp_data ) { - free(tmp_data); - } -} - -void gr_glide_fade_in(int instantaneous) -{ - ushort *tmp_data; - - if(VOODOO3_INACTIVE()){ - return; - } - - Mouse_hidden++; - gr_reset_clip(); - - tmp_data = (ushort *)malloc( gr_screen.max_w*gr_screen.max_h*sizeof(ushort) ); - - if ( tmp_data ) { - gr_glide_save_screen_internal(tmp_data); - } - - if (gr_palette_faded_out) { - - gr_palette_faded_out = 0; - - if ( !instantaneous ) { - - if ( tmp_data ) { - int count = 0; - fix start_time, stop_time, t1; - - - start_time = timer_get_fixed_seconds(); - t1 = 0; - - do { - int c = (255*(FADE_TIME-t1))/FADE_TIME; - if (c < 0 ) { - c = 0; - } else if ( c > 255 ) { - c = 255; - } - - gr_glide_restore_screen_internal(tmp_data); - - for (int i=0; i=0) ); // Loop as long as time not up and timer hasn't rolled - - stop_time = timer_get_fixed_seconds(); - - mprintf(( "Took %d frames (and %.1f secs) to fade out\n", count, f2fl(stop_time-start_time) )); - - } - } - } - - - if ( tmp_data ) { - gr_glide_restore_screen_internal(tmp_data); - } - gr_flip(); - Mouse_hidden--; - - if ( tmp_data ) { - free(tmp_data); - } -} - -void gr_glide_cleanup() -{ - if ( !Inited ) return; - - - grGlideShutdown(); - - vglide_close(); - - gr_glide_clip_cursor(0); - - glide_tcache_cleanup(); - - Inited = 0; -} - -void gr_glide_set_gamma(float gamma) -{ - Gr_gamma = gamma; - Gr_gamma_int = int(Gr_gamma*100); - - // Create the Gamma lookup table - int i; - for (i=0; i<256; i++ ) { - int v = fl2i(pow(i2fl(i)/255.0f, 1.0f/Gr_gamma)*255.0f); - if ( v > 255 ) { - v = 255; - } else if ( v < 0 ) { - v = 0; - } - Gr_gamma_lookup[i] = v; - } - - for (i=0; i<256; i++ ) { - float v = (float)pow(i2fl(i)/255.0f, 1.0f/Gr_gamma)*255.0f; - if ( v > 255.0f ) { - v = 255.0f; - } else if ( v < 0.0f ) { - v = 0.0f; - } - Gr_gamma_lookup_float[i] = v; - } - - // Flush any existing textures - glide_tcache_flush(); - -} - -void gr_glide_fog_set(int fog_mode, int r, int g, int b, float fog_near, float fog_far) -{ - GrColor_t color = 0; - - if(VOODOO3_INACTIVE()){ - return; - } - - SDL_assert((r >= 0) && (r < 256)); - SDL_assert((g >= 0) && (g < 256)); - SDL_assert((b >= 0) && (b < 256)); - - // store the values - gr_glide_init_color( &gr_screen.current_fog_color, r, g, b ); - if(fog_near >= 0.0f){ - gr_screen.fog_near = fog_near; - } - if(fog_far >= 0.0f){ - gr_screen.fog_far = fog_far; - } - gr_screen.current_fog_mode = fog_mode; - - // enable/disable fog - if(fog_mode == GR_FOGMODE_NONE){ - grFogMode(GR_FOG_DISABLE); - - // always unset the global for value if we're disabling fog - gr_screen.fog_near = -1.0f; - gr_screen.fog_far = -1.0f; - - return; - } - grFogMode(GR_FOG_WITH_TABLE); - - // set the fog color - color |= ((ubyte)r); - color |= ((ubyte)g << 8); - color |= ((ubyte)b << 16); - grFogColorValue(color); - - // only generate a new fog table if we have to - if((fog_near >= 0.0f) && (fog_far > fog_near)){ - guFogGenerateLinear(Glide_linear_fogtable, fog_near, fog_far); - } - - // set the fog table - grFogTable(Glide_linear_fogtable); -} - -void gr_glide_get_pixel(int x, int y, int *r, int *g, int *b) -{ - ushort pixel; - *r = 0; - *g = 0; - *b = 0; - - if(VOODOO3_INACTIVE()){ - return; - } - - // returns data in 565 format - grLfbReadRegion(GR_BUFFER_BACKBUFFER, (FxU32)x, (FxU32)y, 1, 1, 2, &pixel); - - // unpack pixel color - *r = (0xf800 & pixel) >> 8; - *g = (0x07e0 & pixel) >> 3; - *b = (0x001f & pixel) << 3; -} - -// resolution checking -int gr_glide_supports_res_ingame(int res) -{ - return 1; -} - -int gr_glide_supports_res_interface(int res) -{ - return 1; -} - -void gr_glide_set_cull(int cull) -{ -} - -void gr_glide_filter_set(int filter) -{ - if(VOODOO3_INACTIVE()){ - return; - } - - if(filter){ - grTexFilterMode(GR_TMU0, GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR); - } else { - grTexFilterMode(GR_TMU0, GR_TEXTUREFILTER_POINT_SAMPLED, GR_TEXTUREFILTER_POINT_SAMPLED); - } -} - -// set clear color -void gr_glide_set_clear_color(int r, int g, int b) -{ - gr_init_color(&gr_screen.current_clear_color, r, g, b); -} - -extern int movie_rendered_flag; -extern int movie_frame_count; - -void __cdecl grglide_MovieShowFrame(void *buf,uint bufw,uint bufh, uint sx,uint sy,uint w,uint h,uint dstx,uint dsty, uint hi_color) -{ - // no soup for you! - - /* - RECT srect, drect; - - if(VOODOO3_INACTIVE()){ - return; - } - - gr_reset_clip(); - gr_clear(); - - ushort *src_data = (ushort *)buf; - - movie_rendered_flag = 1; - - if ( hi_color ) { - bufw >>= 1; - sx >>= 1; - w >>= 1; - dstx >>= 1; - } - - SetRect(&srect, sx, sy, sx+w-1, sy+h-1); - //SetRect(&drect, dstx, dsty, dstx+w-1, dsty+h-1); - dstx = (gr_screen.max_w - w)/2; - dsty = (gr_screen.max_h - h)/2; - SetRect(&drect, dstx, dsty, dstx+w-1, dsty+h-1); - - GrLfbInfo_t info; - int i; - - info.size=sizeof(GrLfbInfo_t); - - // get a read pointer - if ( grLfbLock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER, GR_LFBWRITEMODE_1555, - GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { - ushort *rptr; - int short_per_row=info.strideInBytes/2; - - rptr = (ushort *)info.lfbPtr; - - // if doing interlaced mode, then go through every other scanline - if ( Interlace_movies ) { - static int start_at = 0; - - for ( i = start_at; i < (int)h; i += 2 ) { - memcpy( &rptr[(dsty+i)*short_per_row+dstx], &src_data[bufw*i], w*sizeof(short) ); - } - //start_at = (start_at + 1) % 2; - } else { - // Go through and read our pixels - for (i=0;i<(int)h;i++) { - memcpy( &rptr[(dsty+i)*short_per_row+dstx], &src_data[bufw*i], w*sizeof(short) ); - } - } - - // Release the lock - grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER ); - } else { - mprintf(( "Couldn't get a write lock to glide's back buffer!\n" )); - } - - Mouse_hidden++; - gr_flip(); - Mouse_hidden--; - */ -} - -// cross fade -#define FETCH_A(i, j) { \ - ubyte code = 0; \ - code |= ((i+min_xw) << 2); \ - code |= ((j+min_yh) << 3); \ - if(code && (code < 4)){ \ - pixel_a = sptr1[i - (x1 - min_x)]; \ - } else { \ - pixel_a = pixel_black; \ - } \ -} -#define FETCH_B(i, j) { \ - ubyte code = 0; \ - code |= ((i+min_xw) << 2); \ - code |= ((j+min_yh) << 3); \ - if(code && (code < 4)){ \ - pixel_b = sptr2[i - (x2 - min_x)]; \ - } else { \ - pixel_b = pixel_black; \ - } \ -} -#define MIX(pout, p1, p2) { pout = p1; } -void gr_glide_cross_fade(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct) -{ - if ( pct <= 50 ) { - gr_set_bitmap(bmap1); - gr_bitmap(x1, y1); - } else { - gr_set_bitmap(bmap2); - gr_bitmap(x2, y2); - } - /* - int min_x = x1 < x2 ? x1 : x2; - int min_y = y1 < y2 ? y1 : y2; - int max_x = x2 > x1 ? x2 : x1; - int max_y = y2 > y1 ? y2 : y1; - int max_w, max_h; - int i, j; - ushort *sptr1; - ushort *sptr2; - bitmap *bmp1, *bmp2; - ushort pixel_a, pixel_b; - ushort pixel_black; - ushort pixel_out; - ubyte r, g, b, a; - - // stuff the black pixel - r = 0; g = 0; b = 0; a = 255; - pixel_black = 0; - bm_set_components(&pixel_black, &r, &g, &b, &a); - - // lock the first bitmap - bmp1 = bm_lock( bmap1, 16, 0 ); - sptr1 = (ushort *)( bmp1->data ); - - // lock the second bitmap - bmp2 = bm_lock( bmap2, 16, 0 ); - sptr2 = (ushort *)( bmp2->data ); - - if(x1 > x2){ - max_x = x1; - min_x = x2; - } else { - min_x = x1; - max_x = x2; - } - if(y1 > y2){ - max_y = y1; - min_y = y2; - } else { - min_y = y1; - max_y = y2; - } - if(bmp1->w > bmp2->w){ - max_w = bmp1->w; - } else { - max_w = bmp2->w; - } - if(bmp1->h > bmp2->h){ - max_h = bmp1->h; - } else { - max_h = bmp2->h; - } - - GrLfbInfo_t info; - - // lock the framebuffer - if ( grLfbLock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER, GR_LFBWRITEMODE_1555, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info) ) { - - // pointer into vram - ushort *vram = (ushort *)info.lfbPtr; - int stride = info.strideInBytes / sizeof(ushort); - - // for all scanlines - for (i=0; i=x1) << 0); - code |= ((j+min_y>=y1) << 1); - code |= ((i+min_x>x1+bmp1->w) << 2); - code |= ((j+min_y>y1+bmp1->h) << 3); - if(code && (code < 4)){ - pixel_a = sptr1[i - (x1 - min_x)]; - } else { - pixel_a = pixel_black; - } - } - { - ubyte code = 0; - code |= ((i+min_x>=x2) << 0); - code |= ((j+min_y>=y2) << 1); - code |= ((i+min_x>x2+bmp2->w) << 2); - code |= ((j+min_y>y2+bmp2->h) << 3); - if(code && (code < 4)){ - pixel_b = sptr2[i - (x2 - min_x)]; - } else { - pixel_b = pixel_black; - } - } - - - // mix them - for now just always pick pixel A - MIX(pixel_out, pixel_a, pixel_b); - - // write to vram - *dptr = pixel_out; - - // next pixel in vram - dptr++; - } - - // increment if we need to - if((j+min_y >= y1) && (j+min_y < y1+bmp1->h)){ - sptr1 += bmp1->w; - } - // increment if we need to - if((j+min_y >= y2) && (j+min_y < y2+bmp2->h)){ - sptr2 += bmp2->w; - } - } - - grLfbUnlock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER); - } - - bm_unlock(bmap1); - bm_unlock(bmap2); - */ -} - -GrHwConfiguration hwconfig; - -void gr_glide_init() -{ - D3D_enabled = 1; - Glide_running = 0; - int res_mode; - - if ( Inited ) { - gr_glide_cleanup(); - Inited = 0; - } - - // Turn off the 3Dfx splash screen - SetEnvironmentVariable("FX_GLIDE_NO_SPLASH","1"); - - // Turn off the 3Dfx gamma correction - SetEnvironmentVariable("SST_RGAMMA","1.0"); - SetEnvironmentVariable("SST_GGAMMA","1.0"); - SetEnvironmentVariable("SST_BGAMMA","1.0"); - - mprintf(( "Initializing glide graphics device...\n" )); - Inited = 1; - - if ( !vglide_init() ) { - mprintf(( "Glide DLL not found!\n" )); - exit(1); - } - -// os_suspend(); - - // Find the extents of the window - HWND hwnd = (HWND)os_get_window(); - - // Prepare the window to go full screen -#ifndef NDEBUG - mprintf(( "Window in debugging mode... mouse clicking may cause problems!\n" )); - SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT ); - SetWindowLong( hwnd, GWL_STYLE, WS_POPUP ); - ShowWindow(hwnd, SW_SHOWNORMAL ); - RECT work_rect; - SystemParametersInfo( SPI_GETWORKAREA, 0, &work_rect, 0 ); - SetWindowPos( hwnd, HWND_NOTOPMOST, work_rect.left, work_rect.top, gr_screen.max_w, gr_screen.max_h, 0 ); - SetActiveWindow(hwnd); - SetForegroundWindow(hwnd); - Glide_cursor_clip_rect.left = work_rect.left; - Glide_cursor_clip_rect.top = work_rect.top; - Glide_cursor_clip_rect.right = work_rect.left + gr_screen.max_w - 1; - Glide_cursor_clip_rect.bottom = work_rect.top + gr_screen.max_h - 1; -#else - SetWindowLong( hwnd, GWL_EXSTYLE, 0 ); - SetWindowLong( hwnd, GWL_STYLE, WS_POPUP ); - ShowWindow(hwnd, SW_SHOWNORMAL ); - SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, GetSystemMetrics( SM_CXSCREEN ), GetSystemMetrics( SM_CYSCREEN ), 0 ); - SetActiveWindow(hwnd); - SetForegroundWindow(hwnd); - Glide_cursor_clip_rect.left = 0; - Glide_cursor_clip_rect.top = 0; - Glide_cursor_clip_rect.right = gr_screen.max_w; - Glide_cursor_clip_rect.bottom = gr_screen.max_h; -#endif - - // Let things catch up.... - Sleep(2000); - - grGlideInit(); - - gr_screen.bytes_per_pixel = 2; - gr_screen.bits_per_pixel = 16; - - char version[80]; - grGlideGetVersion(version); - mprintf(( "Glide version: %s\n", version )); - - if ( !grSstQueryHardware( &hwconfig )) { - mprintf(( "Glide: Query hardaware failed!\n" )); - os_resume(); - exit(1); - } - - grSstSelect(0); - - // voodoo 3 - Glide_voodoo3 = 0; - if(hwconfig.SSTs[0].sstBoard.Voodoo2Config.fbRam >= 12){ - Glide_voodoo3 = 1; - } - - // choose resolution - if((gr_screen.max_w == 1024) && (gr_screen.max_h == 768)){ - res_mode = GR_RESOLUTION_1024x768; - } else { - res_mode = GR_RESOLUTION_640x480; - } - - int retval = grSstWinOpen( (DWORD)hwnd, res_mode, GR_REFRESH_60Hz, GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1 ); - if ( !retval ) { - mprintf(( "Glide: grSstOpen failed!\n" )); - os_resume(); - exit(1); - } - - // pixel format - Bm_pixel_format = BM_PIXEL_FORMAT_ARGB; - -// grChromakeyMode( GR_CHROMAKEY_ENABLE ); -// grChromakeyValue( 0x00FF00 ); - -// os_resume(); - - // Setup the surface format - Gr_red.bits = 5; - Gr_red.shift = 10; - Gr_red.scale = 256/32; - Gr_red.mask = 0x7C00; - Gr_t_red = Gr_red; - Gr_current_red = &Gr_red; - - Gr_green.bits = 5; - Gr_green.shift = 5; - Gr_green.scale = 256/32; - Gr_green.mask = 0x03e0; - Gr_t_green = Gr_green; - Gr_current_green = &Gr_green; - - Gr_blue.bits = 5; - Gr_blue.shift = 0; - Gr_blue.scale = 256/32; - Gr_blue.mask = 0x1F; - Gr_t_blue = Gr_blue; - Gr_current_blue = &Gr_blue; - - Gr_current_alpha = &Gr_alpha; - - glide_tcache_init(); - - gr_glide_clip_cursor(1); - - grGammaCorrectionValue(1.0f); - - gr_screen.gf_flip = gr_glide_flip; - gr_screen.gf_flip_window = gr_glide_flip_window; - gr_screen.gf_set_clip = gr_glide_set_clip; - gr_screen.gf_reset_clip = gr_glide_reset_clip; - gr_screen.gf_set_font = grx_set_font; - gr_screen.gf_set_color = gr_glide_set_color; - gr_screen.gf_set_bitmap = gr_glide_set_bitmap; - gr_screen.gf_create_shader = gr_glide_create_shader; - gr_screen.gf_set_shader = gr_glide_set_shader; - gr_screen.gf_clear = gr_glide_clear; - - // gr_screen.gf_bitmap = gr_glide_bitmap; - // gr_screen.gf_bitmap_ex = gr_glide_bitmap_ex; - - gr_screen.gf_rect = gr_glide_rect; - gr_screen.gf_shade = gr_glide_shade; - gr_screen.gf_string = gr_glide_string; - gr_screen.gf_circle = gr_glide_circle; - - gr_screen.gf_line = gr_glide_line; - gr_screen.gf_aaline = gr_glide_aaline; - gr_screen.gf_pixel = gr_glide_pixel; - gr_screen.gf_scaler = gr_glide_scaler; - gr_screen.gf_aascaler = gr_glide_aascaler; - gr_screen.gf_tmapper = gr_glide_tmapper; - - gr_screen.gf_gradient = gr_glide_gradient; - - gr_screen.gf_set_palette = gr_glide_set_palette; - gr_screen.gf_get_color = gr_glide_get_color; - gr_screen.gf_init_color = gr_glide_init_color; - gr_screen.gf_init_alphacolor = gr_glide_init_alphacolor; - gr_screen.gf_set_color_fast = gr_glide_set_color_fast; - gr_screen.gf_print_screen = gr_glide_print_screen; - - gr_screen.gf_aabitmap = gr_glide_aabitmap; - gr_screen.gf_aabitmap_ex = gr_glide_aabitmap_ex; - - gr_screen.gf_fade_in = gr_glide_fade_in; - gr_screen.gf_fade_out = gr_glide_fade_out; - gr_screen.gf_flash = gr_glide_flash; - - gr_screen.gf_zbuffer_get = gr_glide_zbuffer_get; - gr_screen.gf_zbuffer_set = gr_glide_zbuffer_set; - gr_screen.gf_zbuffer_clear = gr_glide_zbuffer_clear; - - gr_screen.gf_save_screen = gr_glide_save_screen; - gr_screen.gf_restore_screen = gr_glide_restore_screen; - gr_screen.gf_free_screen = gr_glide_free_screen; - - // Screen dumping stuff - gr_screen.gf_dump_frame_start = gr_glide_dump_frame_start; - gr_screen.gf_dump_frame_stop = gr_glide_dump_frame_stop; - gr_screen.gf_dump_frame = gr_glide_dump_frame; - - gr_screen.gf_set_gamma = gr_glide_set_gamma; - - // Lock/unlock stuff - gr_screen.gf_lock = gr_glide_lock; - gr_screen.gf_unlock = gr_glide_unlock; - - // region - gr_screen.gf_get_region = gr_glide_get_region; - - // fog stuff - gr_screen.gf_fog_set = gr_glide_fog_set; - - // pixel get - gr_screen.gf_get_pixel = gr_glide_get_pixel; - - // poly culling - gr_screen.gf_set_cull = gr_glide_set_cull; - - // cross fade - gr_screen.gf_cross_fade = gr_glide_cross_fade; - - // filter - gr_screen.gf_filter_set = gr_glide_filter_set; - - // texture cache set - gr_screen.gf_tcache_set = glide_tcache_set; - - // set clear color - gr_screen.gf_set_clear_color = gr_glide_set_clear_color; - - Glide_running=1; - - // default linear fog table - guFogGenerateLinear(Glide_linear_fogtable, 1.0f, 1000.0f); - - Mouse_hidden++; - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; -} - diff --git a/src/graphics/grglidetexture.cpp b/src/graphics/grglidetexture.cpp deleted file mode 100644 index 4bc9496..0000000 --- a/src/graphics/grglidetexture.cpp +++ /dev/null @@ -1,1063 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/GrGlideTexture.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Code to manage Glide texture RAM - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:17 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 14 10/13/99 9:22a Daveb - * Fixed Fred jumpnode placing bug. Fixed 1024 glide tiled texture problem - * related to movies. Fixed launcher spawning from PXO screen. - * - * 13 7/16/99 1:49p Dave - * 8 bit aabitmaps. yay. - * - * 12 7/13/99 1:15p Dave - * 32 bit support. Whee! - * - * 11 7/09/99 9:51a Dave - * Added thick polyline code. - * - * 10 7/08/99 8:10a Mikek - * Suppress compiler warning. Now I get an FS2 programming credit! :) - * - * 9 6/29/99 4:16p Dave - * Temporary speedup for tcache init. - * - * 8 6/29/99 10:35a Dave - * Interface polygon bitmaps! Whee! - * - * 7 6/16/99 4:06p Dave - * New pilot info popup. Added new draw-bitmap-as-poly function. - * - * 6 2/08/99 5:07p Dave - * FS2 chat server support. FS2 specific validated missions. - * - * 5 1/15/99 11:29a Neilk - * Fixed D3D screen/texture pixel formatting problem. - * - * 4 12/01/98 8:06a Dave - * Temporary checkin to fix some texture transparency problems in d3d. - * - * 3 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 18 5/14/98 5:39p John - * Added in code for multiple non-dimming lights. - * - * 17 4/27/98 9:33p John - * Removed mprintf - * - * 16 4/27/98 9:25p John - * Made Glide skip any 2MB boundry, not just first one. - * - * 15 4/27/98 9:09p John - * Fixed bug where texture was crossing a 2MB line on Voodoo2. Added code - * to tell how full VRAM is and how much got paged in each frame. - * - * 14 4/27/98 10:44a John - * Put in a new texture caching algorithm that doesn't flush everything - * every so oftem. - * - * 13 4/26/98 12:02p John - * Made glide texturing do its own allocation rather than using the gu_ - * functions. - * - * 12 4/26/98 11:14a John - * Restructured/Cleaned up the caching code in preparation for the new - * improved caching system. - * - * 11 4/22/98 9:13p John - * Added code to replace frames of animations in vram if so desired. - * - * 10 4/21/98 9:16a John - * Fixed bug with directives display in Glide. - * - * 9 4/20/98 8:41p John - * Made debris culling actually reduce Glide texture resolution. - * - * 8 4/09/98 4:38p John - * Made non-darkening and transparent textures work under Glide. Fixed - * bug with Jim's computer not drawing any bitmaps. - * - * 7 4/09/98 2:21p John - * Fixed transparency bug with Glide - * - * 6 4/08/98 9:16p John - * Made transparency work for textures in Glide by using chromakey. Made - * nondarkening colors work. - * - * 5 4/08/98 8:47a John - * Moved all texture caching into a new module - * - * 4 4/06/98 4:45p John - * Removed some debug code that made textures 2x too small. - * - * 3 3/04/98 5:43p Hoffoss - * Fixed warning. - * - * 2 3/04/98 3:50p John - * Made the Glide texture cache manager of Leighton's work with 256x256 - * maps. - * - * 1 3/03/98 4:42p John - * Added in Leighton's code to do texture caching on Glide. - * - * $NoKeywords: $ - */ - -//#define USE_8BPP_TEXTURES - -#include -#include -#include "glide.h" -#include "glideutl.h" - -#include "osapi.h" -#include "2d.h" -#include "bmpman.h" -#include "floating.h" -#include "palman.h" -#include "grinternal.h" -#include "grglide.h" -#include "line.h" -#include "font.h" -#include "mouse.h" -#include "key.h" -#include "systemvars.h" -#include "grglideinternal.h" - -#define TEXMEM_2MB_EDGE (2*1024*1024) - -// Hardware specific values -typedef struct tcache_data { - GrLOD_t lod; - GrAspectRatio_t aspect; - GrTextureFormat_t format; - uint vram_offset; - int vram_size; -} tcache_data; - -typedef struct tcache_slot { - int bitmap_id; - float uscale; - float vscale; - - tcache_data data; - tcache_slot *data_sections[MAX_BMAP_SECTIONS_X][MAX_BMAP_SECTIONS_Y]; // NULL if no subsections are present. - tcache_slot *parent; -} tcache_slot; - -#define MAX_AUX_TEXTURES 200 -#define MAX_TEXTURES MAX_BITMAPS - -// search for AUX to find all instancees of aux textures which can be put back in. - -// AUX -// static tcache_slot *Textures_aux = NULL; // auxiliary textures for storing sections of a texture -static void *Texture_sections = NULL; -static tcache_slot *Textures = NULL; -ubyte *Glide_tmp_ram = NULL; - -int Glide_last_bitmap_id = -1; -int Glide_last_bitmap_type = -1; -int Glide_last_section_x = -1; -int Glide_last_section_y = -1; -float Glide_last_u_ratio, Glide_last_v_ratio; - -static int Glide_last_detail = -1; - -uint Glide_total_memory; -uint Glide_start_address; -uint Glide_end_address; -uint Glide_current_address; - -int Glide_textures_in_frame = 0; - -int Glide_explosion_vram = 0; - -//======================================================= -// Code to manage texture memory. -// This basically allocates until out of VRAM, and then starts freeing -// blocks at the start of VRAM to make room for new textures. -// Based on code from Jason Scannell's webpage. -// http://members.home.net/jscannell. - -typedef struct { - int next; - uint start_address; - int size; - tcache_slot *texture_ptr; -} tblock; - -tblock *Tblocks = NULL; // Memory tracking blocks -int Tblock_num_blocks = 0; // How many blocks to use - -int Tblock_freelist_start; // First block in free list -int Tblock_usedlist_start; // First block in allocation list -int Tblock_usedlist_head; // Last block in allocation list - -uint Tblock_min_address; // Lowest address in texture memory -uint Tblock_max_address; // Highest address in texture memory - -void FlushBlocks() -{ - int i; - - memset(Tblocks,0,sizeof(tblock)*Tblock_num_blocks); - - for(i = 0; i < Tblock_num_blocks - 1; i++) { - Tblocks[i].next = i + 1; - } - - Tblocks[Tblock_num_blocks - 1].next = -1; - - Tblock_usedlist_start = -1; - Tblock_usedlist_head = -1; - Tblock_freelist_start = 0; -} - -void InitBlocks(uint min, uint max, int num_blocks) -{ - Tblock_num_blocks = num_blocks; - Tblock_min_address = min; - Tblock_max_address = max; - - if(Tblocks == NULL){ - Tblocks = (tblock *)malloc(Tblock_num_blocks*sizeof(tblock)); - SDL_assert(Tblocks!=NULL); - } - - FlushBlocks(); -} - -void ReleaseBlocks() -{ - if ( Tblocks ) { - free(Tblocks); - Tblocks = NULL; - } - Tblock_num_blocks = 0; -} - -void ReleaseSlotSub(tcache_slot *t) -{ - int idx, s_idx; - - if(t == NULL){ - return; - } - - t->bitmap_id = -1; - for(idx=0; idxdata_sections[idx][s_idx] != NULL){ - ReleaseSlotSub(t->data_sections[idx][s_idx]); - t->data_sections[idx][s_idx] = NULL; - } - } - } -} - -void ReleaseSlot(int nBlock) -{ - if ( Tblocks[nBlock].texture_ptr != NULL ) { - // if this guy has a parent (in the case of a sectioned bitmap), unset his bitmap - if(Tblocks[nBlock].texture_ptr->parent != NULL){ - Tblocks[nBlock].texture_ptr->parent->bitmap_id = -1; - } - Tblocks[nBlock].texture_ptr->bitmap_id = -1; - - // AUX - // ReleaseSlotSub(Tblocks[nBlock].texture_ptr); - Tblocks[nBlock].texture_ptr = NULL; - - - Glide_textures_in -= Tblocks[nBlock].size; - } -} - -void FreeBlock(int nBlock) -{ - int nFreeNext; - - ReleaseSlot(nBlock); - - //---- Save next indices ---- - nFreeNext = Tblock_freelist_start; - - //---- Move alloc list block to start of free list ---- - Tblock_freelist_start = nBlock; - Tblocks[nBlock].next = nFreeNext; - -} - -int AllocBlock(void) -{ - int nNewBlock; - - //---- Get block from free list ---- - nNewBlock = Tblock_freelist_start; - - //**** DOS NOT HANDLE EMPTY FREE LIST **** - Tblock_freelist_start = Tblocks[Tblock_freelist_start].next; - - if(Tblock_usedlist_head < 0) { - //---- Alloc list is empty, add to start ---- - Tblock_usedlist_start = nNewBlock; - Tblocks[nNewBlock].next = -1; - } else { - //---- Insert at head of alloc list ---- - Tblocks[nNewBlock].next = Tblocks[Tblock_usedlist_head].next; - Tblocks[Tblock_usedlist_head].next = nNewBlock; - } - - //---- Set new head index ---- - Tblock_usedlist_head = nNewBlock; - - return nNewBlock; -} - -// Macro to compute ending address of block -#define BLOCK_END(b) (Tblocks[b].start_address + Tblocks[b].size) - -uint AllocateTexture(uint size, tcache_slot *texture_ptr) -{ - int nNewBlock; - int next; - - if (Tblock_usedlist_start < 0) { - - //---- Alloc list is empty ---- - nNewBlock = AllocBlock(); - Tblocks[nNewBlock].start_address = Tblock_min_address; - } else { - - uint dwAddress = BLOCK_END(Tblock_usedlist_head); - if ( dwAddress + size < Tblock_max_address ) { - int a1 = dwAddress / TEXMEM_2MB_EDGE; - int a2 = (dwAddress+size) / TEXMEM_2MB_EDGE; - - if ( a2 > a1 ) { - //mprintf(( "GrGlideTexture: Skipping a 2MB edge!\n" )); - dwAddress = a2*TEXMEM_2MB_EDGE; - } - } - - if( (dwAddress + size > Tblock_max_address) || (Tblocks[Tblock_freelist_start].next<0) ) { - #ifndef NDEBUG - if ( Tblocks[Tblock_freelist_start].next < 0 ) { - mprintf(( "GrGlideTexture: AllocateTexture out of blocks! Get John.\n" )); - } - #endif - - //---- No room left, go back to start ---- - ReleaseSlot(Tblock_usedlist_start); - - nNewBlock = Tblock_usedlist_head = Tblock_usedlist_start; - dwAddress = Tblock_min_address; - } else { - - //---- Make new block ---- - nNewBlock = AllocBlock(); - } - - next = Tblocks[Tblock_usedlist_head].next; - - //---- Unlink blocks being overwritten ---- - while((next >= 0) && (dwAddress + size > Tblocks[next].start_address)) { - - int nTemp = Tblocks[next].next; - - FreeBlock(next); - next = nTemp; - } - - //---- Init new block ---- - Tblocks[nNewBlock].next = next; - Tblocks[nNewBlock].start_address = dwAddress; - } - - Tblocks[nNewBlock].size = size; - Tblocks[nNewBlock].texture_ptr = texture_ptr; - - return Tblocks[nNewBlock].start_address; -} - -void glide_tcache_set_initial_texture_mode() -{ - grTexMipMapMode( GR_TMU0, GR_MIPMAP_DISABLE, FXFALSE); - grTexLodBiasValue( GR_TMU0, .5f); - grTexClampMode( GR_TMU0, GR_TEXTURECLAMP_WRAP, GR_TEXTURECLAMP_WRAP); - grTexFilterMode( GR_TMU0, GR_TEXTUREFILTER_BILINEAR, GR_TEXTUREFILTER_BILINEAR); -} - -void glide_tcache_init() -{ - // if we're already inited, allocate nothing new) - if(Textures == NULL){ - Textures = (tcache_slot *)malloc((MAX_TEXTURES)*sizeof(tcache_slot)); - if ( !Textures ) { - exit(1); - } - } - - // AUX - /* - Textures_aux = (tcache_slot*)malloc((MAX_TEXTURES) * MAX_BMAP_SECTIONS_X * MAX_BMAP_SECTIONS_Y sizeof(tcache_slot)); - if( !Textures_aux){ - exit(1); - } - */ - // if we're already inited, allocate nothing new) - if(Texture_sections == NULL){ - Texture_sections = malloc(MAX_TEXTURES * MAX_BMAP_SECTIONS_X * MAX_BMAP_SECTIONS_Y * sizeof(tcache_slot)); - if(!Texture_sections){ - exit(1); - } - } - - // if we're already inited, allocate nothing new) - if(Glide_tmp_ram == NULL){ - Glide_tmp_ram = (ubyte *)malloc(256*256*2); - if ( !Glide_tmp_ram ) { - exit(1); - } - } - - Glide_total_memory = guTexMemQueryAvail(GR_TMU0); - Glide_start_address = grTexMinAddress(GR_TMU0); - Glide_end_address = grTexMaxAddress(GR_TMU0); - Glide_current_address = Glide_start_address; - - mprintf(( "Total texture memory on 3dfx card=%d bytes\n", Glide_total_memory )); - - glide_tcache_set_initial_texture_mode(); - - InitBlocks(Glide_start_address,Glide_end_address, MAX_TEXTURES); - - // Init the texture structures - int i, idx, s_idx, count; - count = 0; - for( i=0; iparent = &Textures[i]; - } - } - } - - // AUX - /* - for( i=0; i 1){ - return NULL; - } - - ga_reentrant++; - - for(idx=0; idx -1) && (Textures[idx].data_sections[0][0] != NULL)){ - ReleaseSlot(&Textures[idx] - Textures); - } - } - - ret = glide_get_aux_slot(); - - ga_reentrant--; - return ret; - } - - // hmm - int s_idx; - Textures_aux[index].bitmap_id = -1; - Textures_aux[index].data.vram_offset = 0; - Textures_aux[index].data.vram_size = 0; - for(idx=0; idxdata.vram_offset == 0) || ((tslot->data.vram_offset>0)&&(bytes_needed>tslot->data.vram_size))) { - tslot->data.vram_offset = AllocateTexture( bytes_needed, tslot ); - tslot->data.vram_size = bytes_needed; - Glide_textures_in += bytes_needed; - // } - - tslot->data.format = tex_format; - tslot->data.lod = lod; - tslot->data.aspect = aspect; - tslot->bitmap_id = bitmap_handle; - tslot->uscale = uscale; - tslot->vscale = vscale; - - grTexDownloadMipMap(GR_TMU0, tslot->data.vram_offset, GR_MIPMAPLEVELMASK_BOTH, &info); - Glide_textures_in_frame += bytes_needed; - - return 1; -} - -int glide_create_texture( int bitmap_handle, int bitmap_type, tcache_slot *tslot ) -{ - int ret; - ubyte flags; - bitmap *bmp; - ubyte bpp = 16; - - // setup texture/bitmap flags - flags = 0; - switch(bitmap_type){ - case TCACHE_TYPE_AABITMAP: - flags |= BMP_AABITMAP; - bpp = 8; - break; - case TCACHE_TYPE_XPARENT: - case TCACHE_TYPE_BITMAP_SECTION: - flags |= BMP_TEX_XPARENT; - break; - case TCACHE_TYPE_NORMAL: - flags |= BMP_TEX_OTHER; - break; - case TCACHE_TYPE_NONDARKENING: - flags |= BMP_TEX_NONDARK; - break; - } - - // lock the bitmap in the proper format - bmp = bm_lock(bitmap_handle, bpp, flags); - if ( bmp == NULL ) { - mprintf(("Couldn't lock bitmap %d.\n", bitmap_handle )); - return 0; - } - - int max_w = bmp->w; - int max_h = bmp->h; - - if ( bitmap_type != TCACHE_TYPE_AABITMAP ) { - // Detail.debris_culling goes from 0 to 4. - max_w /= 16>>Detail.hardware_textures; - max_h /= 16>>Detail.hardware_textures; - } - - // call the helper - ret = glide_create_texture_sub(bitmap_type, bitmap_handle, (ushort*)bmp->data, 0, 0, bmp->w, bmp->h, bmp->w, bmp->h, max_w, max_h, tslot); - - // unlock the bitmap - bm_unlock(bitmap_handle); - - // return - return ret; -} - -// create a sectioned texture -int glide_create_texture_sectioned(int bitmap_handle, int bitmap_type, tcache_slot *tslot, int sx, int sy) -{ - int ret; - ubyte flags; - bitmap *bmp; - int section_x, section_y; - - // setup texture/bitmap flags - SDL_assert(bitmap_type == TCACHE_TYPE_BITMAP_SECTION); - if(bitmap_type != TCACHE_TYPE_BITMAP_SECTION){ - bitmap_type = TCACHE_TYPE_BITMAP_SECTION; - } - flags = BMP_TEX_XPARENT; - - // lock the bitmap in the proper format - bmp = bm_lock(bitmap_handle, 16, flags); - if ( bmp == NULL ) { - mprintf(("Couldn't lock bitmap %d.\n", bitmap_handle )); - return 0; - } - - // determine the width and height of this section - bm_get_section_size(bitmap_handle, sx, sy, §ion_x, §ion_y); - - // call the helper - ret = glide_create_texture_sub(bitmap_type, bitmap_handle, (ushort*)bmp->data, bmp->sections.sx[sx], bmp->sections.sy[sy], section_x, section_y, bmp->w, bmp->h, section_x, section_y, tslot); - - // unlock the bitmap - bm_unlock(bitmap_handle); - - // return - return ret; -} - - -DCF(exp_flush, "") -{ - Glide_explosion_vram = 0; -} - -extern int bm_get_cache_slot( int bitmap_id, int separate_ani_frames ); - -// Returns FALSE if error -int glide_tcache_set( int bitmap_id, int bitmap_type, float *u_ratio, float *v_ratio, int fail_on_full, int sx, int sy, int force ) -{ - bitmap *bmp; - int idx, s_idx; - - if ( Glide_last_detail != Detail.hardware_textures ) { - Glide_last_detail = Detail.hardware_textures; - glide_tcache_flush(); - } - - // Check if this is the same as the last one... if so, we don't need to - // do anything. - if ( (Glide_last_bitmap_id == bitmap_id) && (Glide_last_bitmap_type==bitmap_type) && (Glide_last_section_x == sx) && (Glide_last_section_y == sy) && !force) { - *u_ratio = Glide_last_u_ratio; - *v_ratio = Glide_last_v_ratio; - return 1; - } - - int n; - n = bm_get_cache_slot( bitmap_id, 1 ); - - tcache_slot * t = &Textures[n]; - - // if this is a sectioned bitmap - if(bitmap_type == TCACHE_TYPE_BITMAP_SECTION){ - // if the texture sections haven't been created yet - if((t->bitmap_id < 0) || (t->bitmap_id != bitmap_id) || force){ - - if(t->bitmap_id < 0){ - t->data.vram_offset = 0; - } - - // lock the bitmap in the proper format - bmp = bm_lock(bitmap_id, 16, BMP_TEX_XPARENT); - bm_unlock(bitmap_id); - - // first we need to get enough free aux textures - // AUX - /* - for(idx=0; idxsections.num_x; idx++){ - for(s_idx=0; s_idxsections.num_y; s_idx++){ - // try and get a feww slot - t->data_sections[idx][s_idx] = glide_get_aux_slot(); - if(t->data_sections[idx][s_idx] == NULL){ - Int3(); - return 0; - } - t->data_sections[idx][s_idx]->bitmap_id = bitmap_id; - } - } - */ - - // now lets do something for each texture - for(idx=0; idxsections.num_x; idx++){ - for(s_idx=0; s_idxsections.num_y; s_idx++){ - if(t->bitmap_id < 0){ - t->data_sections[idx][s_idx]->data.vram_offset = 0; - } - - t->data_sections[idx][s_idx]->bitmap_id = bitmap_id; - glide_create_texture_sectioned( bitmap_id, bitmap_type, t->data_sections[idx][s_idx], idx, s_idx); - } - } - - t->bitmap_id = bitmap_id; - } - - // swap in the texture we want - t = t->data_sections[sx][sy]; - } - // all other "normal" textures - else { - // no texture yet - if ( t->bitmap_id < 0) { - t->data.vram_offset = 0; - glide_create_texture( bitmap_id, bitmap_type, t ); - } - // different bitmap altogether - else if ( (t->bitmap_id != bitmap_id) || force) { - glide_create_texture( bitmap_id, bitmap_type, t ); - } - } - - *u_ratio = t->uscale; - *v_ratio = t->vscale; - - GrTexInfo info; - - info.smallLod = t->data.lod; //GR_LOD_256; - info.largeLod = t->data.lod; //GR_LOD_256; - info.aspectRatio = t->data.aspect; //GR_ASPECT_1x1; - info.format = t->data.format; //GR_TEXFMT_ARGB_1555; - info.data = 0; //source data - - grTexSource( GR_TMU0, t->data.vram_offset, GR_MIPMAPLEVELMASK_BOTH, &info ); - - // Save current state so we don't have to do anything time consuming next time - // we set this exact same texture - Glide_last_bitmap_id = bitmap_id; - Glide_last_bitmap_type = bitmap_type; - Glide_last_section_x = sx; - Glide_last_section_y = sy; - Glide_last_u_ratio = t->uscale; - Glide_last_v_ratio = t->vscale; - - return 1; -} - - - - - diff --git a/src/graphics/gropengl.cpp b/src/graphics/gropengl.cpp index b22ecbc..612caed 100644 --- a/src/graphics/gropengl.cpp +++ b/src/graphics/gropengl.cpp @@ -229,23 +229,25 @@ void gr_opengl_set_shader( shader * shade ) int gr_opengl_zbuffer_get() { - if ( !gr_global_zbuffering ) { + if ( !Gr_global_zbuffering ) { return GR_ZBUFF_NONE; } - return gr_zbuffering_mode; + + return Gr_zbuffering_mode; } int gr_opengl_zbuffer_set(int mode) { - int tmp = gr_zbuffering_mode; + int tmp = Gr_zbuffering_mode; - gr_zbuffering_mode = mode; + Gr_zbuffering_mode = mode; - if (gr_zbuffering_mode == GR_ZBUFF_NONE ) { - gr_zbuffering = 0; + if (Gr_zbuffering_mode == GR_ZBUFF_NONE) { + Gr_zbuffering = 0; } else { - gr_zbuffering = 1; + Gr_zbuffering = 1; } + return tmp; } diff --git a/src/graphics/gropengl1.cpp b/src/graphics/gropengl1.cpp index 3df5fe8..5078b11 100644 --- a/src/graphics/gropengl1.cpp +++ b/src/graphics/gropengl1.cpp @@ -499,16 +499,16 @@ void gr_opengl1_set_cull(int cull) void gr_opengl1_zbuffer_clear(int mode) { if (mode) { - gr_zbuffering = 1; - gr_zbuffering_mode = GR_ZBUFF_FULL; - gr_global_zbuffering = 1; + Gr_zbuffering = 1; + Gr_zbuffering_mode = GR_ZBUFF_FULL; + Gr_global_zbuffering = 1; opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_NONE, ZBUFFER_TYPE_FULL ); glClear ( GL_DEPTH_BUFFER_BIT ); } else { - gr_zbuffering = 0; - gr_zbuffering_mode = GR_ZBUFF_NONE; - gr_global_zbuffering = 0; + Gr_zbuffering = 0; + Gr_zbuffering_mode = GR_ZBUFF_NONE; + Gr_global_zbuffering = 0; } } diff --git a/src/graphics/gropengl1render.cpp b/src/graphics/gropengl1render.cpp index d77b79e..dfa98aa 100644 --- a/src/graphics/gropengl1render.cpp +++ b/src/graphics/gropengl1render.cpp @@ -205,7 +205,7 @@ static void opengl1_tmapper_internal( int nv, vertex ** verts, uint flags, int i gr_alpha_blend alpha_blend = (gr_alpha_blend)-1; gr_zbuffer_type zbuffer_type = (gr_zbuffer_type)-1; - if ( gr_zbuffering ) { + if (Gr_zbuffering) { if ( is_scaler || (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) ) { zbuffer_type = ZBUFFER_TYPE_READ; } else { @@ -332,7 +332,7 @@ static void opengl1_tmapper_internal( int nv, vertex ** verts, uint flags, int i float rhw = 1.0f; int a; - if ( gr_zbuffering || (flags & TMAP_FLAG_NEBULA) ) { + if ( Gr_zbuffering || (flags & TMAP_FLAG_NEBULA) ) { sz = 1.0 - 1.0 / (1.0 + va->z / (32768.0 / 256.0)); if ( sz > 0.98f ) { diff --git a/src/graphics/grsoft.cpp b/src/graphics/grsoft.cpp deleted file mode 100644 index 6e2041e..0000000 --- a/src/graphics/grsoft.cpp +++ /dev/null @@ -1,1943 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/GrSoft.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Code for our software renderer using standard Win32 functions. (Dibsections, etc) - * - * $Log$ - * Revision 1.10 2002/07/30 05:24:38 relnev - * command line - * - * Revision 1.9 2002/06/09 04:41:17 relnev - * added copyright header - * - * Revision 1.8 2002/06/09 03:16:04 relnev - * added _splitpath. - * - * removed unneeded asm, old sdl 2d setup. - * - * fixed crash caused by opengl_get_region. - * - * Revision 1.7 2002/06/05 08:05:29 relnev - * stub/warning removal. - * - * reworked the sound code. - * - * Revision 1.6 2002/05/28 21:36:10 relnev - * some more timer junk. - * - * tried to fix software mode. - * - * Revision 1.5 2002/05/28 17:26:57 theoddone33 - * Fill in some timer and palette setting stubs. Still no display - * - * Revision 1.4 2002/05/28 17:03:29 theoddone33 - * fs2 gets to the main game loop now - * - * Revision 1.3 2002/05/28 04:56:51 theoddone33 - * runs a little bit now - * - * Revision 1.2 2002/05/28 04:07:28 theoddone33 - * New graphics stubbing arrangement - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 12 7/14/99 9:42a Dave - * Put in clear_color debug function. Put in base for 3dnow stuff / P3 - * stuff - * - * 11 7/09/99 9:51a Dave - * Added thick polyline code. - * - * 10 6/29/99 10:35a Dave - * Interface polygon bitmaps! Whee! - * - * 9 2/03/99 11:44a Dave - * Fixed d3d transparent textures. - * - * 8 1/24/99 11:37p Dave - * First full rev of beam weapons. Very customizable. Removed some bogus - * Int3()'s in low level net code. - * - * 7 12/18/98 1:13a Dave - * Rough 1024x768 support for Direct3D. Proper detection and usage through - * the launcher. - * - * 6 12/06/98 2:36p Dave - * Drastically improved nebula fogging. - * - * 5 11/30/98 5:31p Dave - * Fixed up Fred support for software mode. - * - * 4 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 3 11/11/98 5:37p Dave - * Checkin for multiplayer testing. - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 84 5/20/98 9:46p John - * added code so the places in code that change half the palette don't - * have to clear the screen. - * - * 83 5/18/98 11:17a John - * Fixed some bugs with software window and output window. - * - * 82 5/17/98 5:03p John - * Fixed some bugs that make the taskbar interfere with the DEBUG-only - * mouse cursor. - * - * 81 5/15/98 2:44p John - * Made windowed mode not touch the window if no handle to window found. - * - * 80 5/14/98 5:42p John - * Revamped the whole window position/mouse code for the graphics windows. - * - * 79 5/07/98 6:58p Hoffoss - * Made changes to mouse code to fix a number of problems. - * - * 78 5/06/98 5:30p John - * Removed unused cfilearchiver. Removed/replaced some unused/little used - * graphics functions, namely gradient_h and _v and pixel_sp. Put in new - * DirectX header files and libs that fixed the Direct3D alpha blending - * problems. - * - * 77 4/23/98 8:24a John - * Changed the way palette effect works so that: - * 1. If gr_flash isn't called this frame, screen shows no flash. - * 2. With hardware, only 3d portion of screen gets flashed. - * - * 76 4/21/98 5:22p John - * Fixed all the &^#@$ cursor bugs with popups. For Glide, had problem - * with mouse restoring assuming back buffer was same buffer last frame, - * for software, problems with half drawn new frames, then mouse got - * restored on top of that with old data. - * - * 75 4/14/98 12:15p John - * Made 16-bpp movies work. - * - * 74 4/11/98 12:48p John - * Made software fade out actually clear screen to black. - * - * 73 4/01/98 9:21p John - * Made NDEBUG, optimized build with no warnings or errors. - * - * 72 3/25/98 8:07p John - * Restructured software rendering into two modules; One for windowed - * debug mode and one for DirectX fullscreen. - * - * 71 3/24/98 3:58p John - * Put in (hopefully) final gamma setting code. - * - * 70 3/17/98 5:55p John - * Added code to dump Glide frames. Moved Allender's "hack" code out of - * Freespace.cpp into the proper place, graphics lib. - * - * 69 3/14/98 5:46p John - * - * 68 3/14/98 5:43p John - * Saved area under mouse cursor. Made save_Screen restore it so no mouse - * is on those screens. - * - * 67 3/12/98 8:50a John - * took out "allocating zbuffer" mprintf - * - * 66 3/10/98 4:18p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 65 3/06/98 4:09p John - * Changed the way we do bitmap RLE'ing... this speds up HUD bitmaps by - * about 2x - * - * 64 3/05/98 4:28p John - * Made mouse cursor hide while setting palette. - * - * 63 3/02/98 5:42p John - * Removed WinAVI stuff from Freespace. Made all HUD gauges wriggle from - * afterburner. Made gr_set_clip work good with negative x &y. Made - * model_caching be on by default. Made each cached model have it's own - * bitmap id. Made asteroids not rotate when model_caching is on. - * - * 62 2/24/98 3:50p John - * Made Alt+Tabbing work with Glide. Made Int3's restore Glide screen on - * next flip. - * - * 61 2/24/98 1:59p John - * Made gr_aabitmap_ex clip properly - * - * 60 2/05/98 9:21p John - * Some new Direct3D code. Added code to monitor a ton of stuff in the - * game. - * - * 59 1/19/98 6:15p John - * Fixed all my Optimized Build compiler warnings - * - * 58 1/15/98 4:07p John - * added grx_set_palette_internal which doesn't clear the screen and flip - * before setting the palette. - * - * 57 1/15/98 4:02p John - * Fixed stupid bug on my part where I called graphics rendering functions - * from another thread!!! Duh! Fixed it by setting a variable and then - * resetting the palette at the next flip. - * - * 56 1/08/98 5:06p John - * Replaced Int3 with a mprintf - * - * 55 1/08/98 3:10p John - * Undid my palette changes for interplay rev - * - * 54 1/08/98 3:03p John - * - * 53 1/05/98 11:52a Jasen - * JAS: Made graphics code work if os_get_window returns NULL when trying - * to go fullscreen. - * - * 52 12/30/97 6:47p John - * Made fade time correct - * - * 51 12/30/97 6:46p John - * Added first rev of palette fade in out functions - * - * 50 12/21/97 4:33p John - * Made debug console functions a class that registers itself - * automatically, so you don't need to add the function to - * debugfunctions.cpp. - * - * 49 12/05/97 4:26p John - * made palette set code be like it was before. - * - * 48 12/04/97 8:05p John - * added test code to brighten palette - * - * 47 12/03/97 2:16p John - * Took out blur code and fake_vram buffer. - * - * 46 12/02/97 4:00p John - * Added first rev of thruster glow, along with variable levels of - * translucency, which retquired some restructing of palman. - * - * 45 11/30/97 12:18p John - * added more 24 & 32-bpp primitives - * - * 44 11/29/97 2:06p John - * added mode 16-bpp support - * - * 43 11/21/97 11:32a John - * Added nebulas. Fixed some warpout bugs. - * - * 42 11/20/97 9:51a John - * added code to force screen to 16-bit even if rendering 8. - * - * 41 11/17/97 10:33a John - * updated force_windowed code. - * - * 40 11/14/97 3:54p John - * Added triple buffering. - * - * 39 11/14/97 3:08p Johnson - * fixed bug with fred. - * - * 38 11/14/97 12:30p John - * Fixed some DirectX bugs. Moved the 8-16 xlat tables into Graphics - * libs. Made 16-bpp DirectX modes know what bitmap format they're in. - * - * 37 11/06/97 4:12p John - * Took out debug code that returned NULL for DD. - * - * 36 11/05/97 12:35p John - * added correct gr_bitmap_ex that does clipping - * - * - * 35 10/31/97 9:43a John - * fixed red background color bug. - * - * 34 10/19/97 1:53p John - * hacked in a fix to a zbuffer error caused by inaccuracies. - * - * 33 10/19/97 12:55p John - * new code to lock / unlock surfaces for smooth directx integration. - * - * 32 10/15/97 4:48p John - * added 16-bpp aascaler - * - * 31 10/14/97 4:50p John - * more 16 bpp stuff. - * - * 30 10/14/97 8:08a John - * added a bunch more 16 bit support - * - * 29 10/09/97 5:23p John - * Added support for more 16-bpp functions - * - * 28 10/03/97 9:10a John - * added better antialiased line drawer - * - * 27 9/23/97 11:50a Lawrance - * jas: added xparency to rle'd bitblts - * - * 26 9/23/97 10:45a John - * made so you can tell bitblt code to rle a bitmap by passing flag to - * gr_set_bitmap - * - * 25 9/20/97 10:48a John - * added motion blur code. - * - * 24 9/09/97 10:39a Sandeep - * fixed warning level 4 - * - * 23 9/07/97 2:34p John - * fixed bug with fullscreen toggling not working when in > 8bpp mode. - * - * 22 9/03/97 4:32p John - * changed bmpman to only accept ani and pcx's. made passing .pcx or .ani - * to bm_load functions not needed. Made bmpman keep track of palettes - * for bitmaps not mapped into game palettes. - * - * 21 8/26/97 11:30a John - * removed call to restoredisplymode when going from fullscreen to - * windowed, which hopefully fixes the screwey taskbar problem. - * - * 20 8/04/97 4:47p John - * added gr_aascaler. - * - * 19 7/17/97 9:31a John - * made all directX header files name start with a v - * - * 18 7/10/97 2:06p John - * added code to specify alphablending type for bitmaps. - * - * 17 6/20/97 1:50p John - * added rle code to bmpman. made gr8_aabitmap use it. - * - * 16 6/17/97 12:03p John - * Moved color/alphacolor functions into their own module. Made all color - * functions be part of the low-level graphics drivers, not just the - * grsoft. - * - * 15 6/13/97 5:35p John - * added some antialiased bitmaps and lines - * - * 14 6/12/97 2:50a Lawrance - * bm_unlock() now passed bitmap number, not pointer - * - * 13 6/11/97 5:49p John - * Changed palette code to only recalculate alphacolors when needed, not - * when palette changes. - * - * 12 6/11/97 1:12p John - * Started fixing all the text colors in the game. - * - * 11 6/06/97 5:03p John - * fixed bug withalpha colors failing after gr_init - * - * 10 6/06/97 4:41p John - * Fixed alpha colors to be smoothly integrated into gr_set_color_fast - * code. - * - * 9 5/29/97 3:09p John - * Took out debug menu. - * Made software scaler draw larger bitmaps. - * Optimized Direct3D some. - * - * 8 5/16/97 9:11a John - * fixed bug that made Ctrl+Break in fullscreen hang - * - * 7 5/14/97 4:40p John - * took out mprintf - * - * 6 5/14/97 4:38p John - * Fixed print_screen bug. - * - * 5 5/14/97 2:09p John - * made fullscreen use 254 palette entries. Used - * CreateCompatibleDC(NULL) Instead of GetDC(HWND_DESKTOP) because the - * GetDC method fails when you change screen depth dynamically under NT. - * - * 4 5/14/97 10:53a John - * fixed some discrepencies between d3d and software palette setting. - * - * 3 5/14/97 8:53a John - * Fixed a palette bug when switching into/outof d3d mode. - * - * 2 5/13/97 12:39p John - * Got fullscreen mode working. - * - * 1 5/12/97 12:14p John - * - * $NoKeywords: $ - */ - -#include -#ifndef PLAT_UNIX -#include -#include -#endif - -#include "osapi.h" -#include "2d.h" -#include "bmpman.h" -#include "key.h" -#include "floating.h" -#include "palman.h" -#include "grsoft.h" -#include "grinternal.h" -#include "systemvars.h" - -// Headers for 2d functions -#include "pixel.h" -#include "line.h" -#include "scaler.h" -#include "tmapper.h" -#include "circle.h" -#include "shade.h" -#include "rect.h" -#include "gradient.h" -#include "pcxutils.h" -#include "osapi.h" -#include "mouse.h" -#include "font.h" -#include "timer.h" -#include "colors.h" -#include "bitblt.h" - - // Window's specific - -// This structure is the same as LOGPALETTE except that LOGPALETTE -// requires you to malloc out space for the palette, which just isn't -// worth the trouble. - -#ifndef PLAT_UNIX -typedef struct { - WORD palVersion; - WORD palNumEntries; - PALETTEENTRY palPalEntry[256]; -} EZ_LOGPALETTE; - -// This structure is the same as BITMAPINFO except that BITMAPINFO -// requires you to malloc out space for the palette, which just isn't -// worth the trouble. I also went ahead and threw a handy union to -// easily reference the hicolor masks in 15/16 bpp modes. -typedef struct { - BITMAPINFOHEADER Header; - union { - RGBQUAD aColors[256]; - ushort PalIndex[256]; - uint hicolor_masks[3]; - } Colors; -} EZ_BITMAPINFO; - -EZ_BITMAPINFO DibInfo; -HBITMAP hDibSection = NULL; -HBITMAP hOldBitmap = NULL; -HDC hDibDC = NULL; -void *lpDibBits=NULL; - -HPALETTE hOldPalette=NULL, hPalette = NULL; -#endif - -int Gr_soft_inited = 0; - -static volatile int Grsoft_activated = 1; // If set, that means application got focus, so reset palette - -void gr_buffer_release() -{ -#ifndef PLAT_UNIX - if ( hPalette ) { - if (hDibDC) - SelectPalette( hDibDC, hOldPalette, FALSE ); - if (!DeleteObject(hPalette)) { - mprintf(( "JOHN: Couldn't delete palette object\n" )); - } - hPalette = NULL; - } - - if ( hDibDC ) { - SelectObject(hDibDC, hOldBitmap ); - DeleteDC(hDibDC); - hDibDC = NULL; - } - - if ( hDibSection ) { - DeleteObject(hDibSection); - hDibSection = NULL; - } -#endif -} - - -void gr_buffer_create( int w, int h, int bpp ) -{ - if (w & 3) { - Int3(); // w must be multiple 4 - return; - } - - gr_buffer_release(); - -#ifndef PLAT_UNIX - memset( &DibInfo, 0, sizeof(EZ_BITMAPINFO)); - DibInfo.Header.biSize = sizeof(BITMAPINFOHEADER); - DibInfo.Header.biWidth = w; - DibInfo.Header.biHeight = h; - DibInfo.Header.biPlanes = 1; - DibInfo.Header.biClrUsed = 0; -#endif - - switch( bpp ) { - case 8: - Gr_red.bits = 8; - Gr_red.shift = 16; - Gr_red.scale = 1; - Gr_red.mask = 0xff0000; - - Gr_green.bits = 8; - Gr_green.shift = 8; - Gr_green.scale = 1; - Gr_green.mask = 0xff00; - - Gr_blue.bits = 8; - Gr_blue.shift = 0; - Gr_blue.scale = 1; - Gr_blue.mask = 0xff; - -#ifndef PLAT_UNIX - DibInfo.Header.biCompression = BI_RGB; - DibInfo.Header.biBitCount = 8; - for (int i=0; i<256; i++ ) { - DibInfo.Colors.aColors[i].rgbRed = 0; - DibInfo.Colors.aColors[i].rgbGreen = 0; - DibInfo.Colors.aColors[i].rgbBlue = 0; - DibInfo.Colors.aColors[i].rgbReserved = 0; - } - break; -#endif - - case 15: - Gr_red.bits = 5; - Gr_red.shift = 10; - Gr_red.scale = 8; - Gr_red.mask = 0x7C00; - - Gr_green.bits = 5; - Gr_green.shift = 5; - Gr_green.scale = 8; - Gr_green.mask = 0x3E0; - - Gr_blue.bits = 5; - Gr_blue.shift = 0; - Gr_blue.scale = 8; - Gr_blue.mask = 0x1F; - -#ifndef PLAT_UNIX - DibInfo.Header.biCompression = BI_BITFIELDS; - DibInfo.Header.biBitCount = 16; - DibInfo.Colors.hicolor_masks[0] = Gr_red.mask; - DibInfo.Colors.hicolor_masks[1] = Gr_green.mask; - DibInfo.Colors.hicolor_masks[2] = Gr_blue.mask; -#endif - - - break; - - case 16: - Gr_red.bits = 5; - Gr_red.shift = 11; - Gr_red.scale = 8; - Gr_red.mask = 0xF800; - - Gr_green.bits = 6; - Gr_green.shift = 5; - Gr_green.scale = 4; - Gr_green.mask = 0x7E0; - - Gr_blue.bits = 5; - Gr_blue.shift = 0; - Gr_blue.scale = 8; - Gr_blue.mask = 0x1F; - -#ifndef PLAT_UNIX - DibInfo.Header.biCompression = BI_BITFIELDS; - DibInfo.Header.biBitCount = 16; - DibInfo.Colors.hicolor_masks[0] = Gr_red.mask; - DibInfo.Colors.hicolor_masks[1] = Gr_green.mask; - DibInfo.Colors.hicolor_masks[2] = Gr_blue.mask; -#endif - break; - - case 24: - case 32: - Gr_red.bits = 8; - Gr_red.shift = 16; - Gr_red.scale = 1; - Gr_red.mask = 0xff0000; - - Gr_green.bits = 8; - Gr_green.shift = 8; - Gr_green.scale = 1; - Gr_green.mask = 0xff00; - - Gr_blue.bits = 8; - Gr_blue.shift = 0; - Gr_blue.scale = 1; - Gr_blue.mask = 0xff; - -#ifndef PLAT_UNIX - DibInfo.Header.biCompression = BI_RGB; - DibInfo.Header.biBitCount = unsigned short(bpp); -#endif - break; - - default: - Int3(); // Illegal bpp - } - -#ifndef PLAT_UNIX - lpDibBits = NULL; - - hDibDC = CreateCompatibleDC(NULL); - hDibSection = CreateDIBSection(hDibDC,(BITMAPINFO *)&DibInfo,DIB_RGB_COLORS,&lpDibBits,NULL,NULL); - hOldBitmap = (HBITMAP)SelectObject(hDibDC, hDibSection ); - - if ( hDibSection == NULL ) { - Int3(); // couldn't allocate dib section - } -#endif -} - - -// This makes a best-fit palette from the 256 target colors and -// the system colors which should look better than only using the -// colors in the range 10-246, but it will totally reorder the palette. -// All colors get changed in target_palette. - - -#ifndef PLAT_UNIX -HPALETTE gr_create_palette_0(ubyte * target_palette) -{ - EZ_LOGPALETTE LogicalPalette; - HDC ScreenDC; - HPALETTE hpal,hpalOld; - PALETTEENTRY pe[256]; - int NumSysColors, NumColors; - int i; - - // Create a 1-1 mapping of the system palette - LogicalPalette.palVersion = 0x300; - LogicalPalette.palNumEntries = 256; - - // Pack in all the colors - for (i=0;i<256; i++) { - LogicalPalette.palPalEntry[i].peRed = target_palette[i*3+0]; - LogicalPalette.palPalEntry[i].peGreen = target_palette[i*3+1]; - LogicalPalette.palPalEntry[i].peBlue = target_palette[i*3+2]; - LogicalPalette.palPalEntry[i].peFlags = 0; //PC_EXPLICIT; - } - - hpal = CreatePalette( (LOGPALETTE *)&LogicalPalette ); - - ScreenDC = CreateCompatibleDC(NULL); - - if ( !(GetDeviceCaps(ScreenDC,RASTERCAPS) & RC_PALETTE) ) { - DeleteDC(ScreenDC); - return hpal; - } - - NumSysColors = GetDeviceCaps( ScreenDC, NUMCOLORS ); - NumColors = GetDeviceCaps( ScreenDC, SIZEPALETTE ); - - // Reset all the Palette Manager tables - SetSystemPaletteUse( ScreenDC, SYSPAL_NOSTATIC ); - SetSystemPaletteUse( ScreenDC, SYSPAL_STATIC ); - - // Enter our palette's values into the free slots - hpalOld=SelectPalette( ScreenDC, hpal, FALSE ); - RealizePalette( ScreenDC ); - SelectPalette( ScreenDC, hpalOld, FALSE ); - - GetSystemPaletteEntries(ScreenDC,0,NumColors,pe); - - for (i=0; i= 236 ); - - GetSystemPaletteEntries(ScreenDC,0,NumSysColors/2,LogicalPalette.palPalEntry); - GetSystemPaletteEntries(ScreenDC,UserHighest+1,NumSysColors/2,LogicalPalette.palPalEntry+1+UserHighest); - - DeleteDC(ScreenDC); - - for (i=0; i<256; i++ ) { - - if ( (i >= UserLowest) && (i<=UserHighest) ) { - LogicalPalette.palPalEntry[i].peFlags = PC_NOCOLLAPSE; - } else - LogicalPalette.palPalEntry[i].peFlags = 0; - - target_palette[i*3+0] = LogicalPalette.palPalEntry[i].peRed; - target_palette[i*3+1] = LogicalPalette.palPalEntry[i].peGreen; - target_palette[i*3+2] = LogicalPalette.palPalEntry[i].peBlue; - } - - return CreatePalette( (LOGPALETTE *)&LogicalPalette ); -} - -HPALETTE gr_create_palette_254( ubyte * target_palette ) -{ - EZ_LOGPALETTE LogicalPalette; - HDC ScreenDC; - int NumSysColors, NumColors, UserLowest, UserHighest; - int i; - - // Pack in all the colors - for (i=0;i<256; i++) { - LogicalPalette.palPalEntry[i].peRed = target_palette[i*3+0]; - LogicalPalette.palPalEntry[i].peGreen = target_palette[i*3+1]; - LogicalPalette.palPalEntry[i].peBlue = target_palette[i*3+2]; - LogicalPalette.palPalEntry[i].peFlags = 0; //PC_EXPLICIT; - } - - // Create a 1-1 mapping of the system palette - LogicalPalette.palVersion = 0x300; - LogicalPalette.palNumEntries = 256; - - ScreenDC = CreateCompatibleDC(NULL); - - // Reset all the Palette Manager tables - SetSystemPaletteUse( ScreenDC, SYSPAL_NOSTATIC ); - SetSystemPaletteUse( ScreenDC, SYSPAL_STATIC ); - - if ( !(GetDeviceCaps(ScreenDC,RASTERCAPS) & RC_PALETTE) ) { - DeleteDC(ScreenDC); - return CreatePalette( (LOGPALETTE *)&LogicalPalette ); - } - - SetSystemPaletteUse( ScreenDC, SYSPAL_NOSTATIC ); - NumSysColors = 2; - NumColors = GetDeviceCaps( ScreenDC, SIZEPALETTE ); - - SDL_assert( NumColors <= 256 ); - - UserLowest = NumSysColors/2; // 10 normally - UserHighest = NumColors - NumSysColors/2 - 1; // 245 normally - - SDL_assert( (UserHighest - UserLowest + 1) >= 236 ); - - GetSystemPaletteEntries(ScreenDC,0,NumSysColors/2,LogicalPalette.palPalEntry); - GetSystemPaletteEntries(ScreenDC,UserHighest+1,NumSysColors/2,LogicalPalette.palPalEntry+1+UserHighest); - - DeleteDC(ScreenDC); - - for (i=0; i<256; i++ ) { - - if ( (i >= UserLowest) && (i<=UserHighest) ) { - LogicalPalette.palPalEntry[i].peFlags = PC_NOCOLLAPSE; - } else - LogicalPalette.palPalEntry[i].peFlags = 0; - - target_palette[i*3+0] = LogicalPalette.palPalEntry[i].peRed; - target_palette[i*3+1] = LogicalPalette.palPalEntry[i].peGreen; - target_palette[i*3+2] = LogicalPalette.palPalEntry[i].peBlue; - } - - return CreatePalette( (LOGPALETTE *)&LogicalPalette ); -} -#endif // !PLAT_UNIX - -void grx_set_palette_internal( ubyte * new_pal ) -{ -#ifndef PLAT_UNIX - if ( hPalette ) { - if (hDibDC) - SelectPalette( hDibDC, hOldPalette, FALSE ); - if (!DeleteObject(hPalette)) { - mprintf(( "JOHN: Couldn't delete palette object\n" )); - } - hPalette = NULL; - } -#endif - - - // Make sure color 0 is black - if ( (new_pal[0]!=0) || (new_pal[1]!=0) || (new_pal[2]!=0) ) { - // color 0 isn't black!! switch it! - int i; - int black_index = -1; - - for (i=1; i<256; i++ ) { - if ( (new_pal[i*3+0]==0) && (new_pal[i*3+1]==0) && (new_pal[i*3+2]==0) ) { - black_index = i; - break; - } - } - if ( black_index > -1 ) { - // swap black and color 0, so color 0 is black - ubyte tmp[3]; - tmp[0] = new_pal[black_index*3+0]; - tmp[1] = new_pal[black_index*3+1]; - tmp[2] = new_pal[black_index*3+2]; - - new_pal[black_index*3+0] = new_pal[0]; - new_pal[black_index*3+1] = new_pal[1]; - new_pal[black_index*3+2] = new_pal[2]; - - new_pal[0] = tmp[0]; - new_pal[1] = tmp[1]; - new_pal[2] = tmp[2]; - } else { - // no black in palette, force color 0 to be black. - new_pal[0] = 0; - new_pal[1] = 0; - new_pal[2] = 0; - } - } - - - - if ( gr_screen.bits_per_pixel==8 ) { - - // Name n_preserved One-one Speed Windowed? - // ------------------------------------------------------------------- - // gr_create_palette_256 256 0-255 Slow Yes - // gr_create_palette_254 254 1-254 Fast No - // gr_create_palette_236 236 10-245 Fast Yes - // gr_create_palette_0 0 none Fast Yes - -/* - n_preserved = 256; - - if ( n_preserved <= 0 ) { - hPalette = gr_create_palette_0(new_pal); // No colors mapped one-to-one, but probably has close to all 256 colors in it somewhere. - } else if ( n_preserved <= 236 ) { - hPalette = gr_create_palette_236(new_pal); // All colors except low 10 and high 10 mapped one-to-one - } else if ( n_preserved <= 254 ) { - hPalette = gr_create_palette_254(new_pal); // All colors except 0 and 255 mapped one-to-one, but changes system colors. Not pretty in a window. - } else { -*/ -#ifndef PLAT_UNIX - hPalette = gr_create_palette_256(new_pal); // All 256 mapped one-to-one, but BLT's are slow. - - if ( hDibDC ) { - int i; - for (i=0; i<256; i++ ) { - DibInfo.Colors.aColors[i].rgbRed = new_pal[i*3+0]; - DibInfo.Colors.aColors[i].rgbGreen = new_pal[i*3+1]; - DibInfo.Colors.aColors[i].rgbBlue = new_pal[i*3+2]; - DibInfo.Colors.aColors[i].rgbReserved = 0; - } - - hOldPalette = SelectPalette( hDibDC, hPalette, FALSE ); - SetDIBColorTable( hDibDC, 0, 256, DibInfo.Colors.aColors ); - } -#endif - } else { -#ifndef PLAT_UNIX - hPalette = NULL; -#endif - } -} - - -void grx_set_palette( ubyte * new_pal, int is_alphacolor ) -{ -#ifdef PLAT_UNIX - Mouse_hidden++; - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; - - grx_set_palette_internal(new_pal); -#else - if ( hPalette ) { - Mouse_hidden++; - gr_reset_clip(); - gr_clear(); - gr_flip(); - Mouse_hidden--; - } - - grx_set_palette_internal(new_pal); -#endif -} - - -void grx_print_screen(char * filename) -{ - int i; - ubyte **row_data = (ubyte **)malloc( gr_screen.max_h * sizeof(ubyte *) ); - if ( !row_data ) { - mprintf(( "couldn't allocate enough memory to dump screen\n" )); - return; - } - - gr_lock(); - - for (i=0; i (r2)) (x) = (r2); } while(0) - -void grx_save_mouse_area(int x, int y, int w, int h ) -{ - Grx_mouse_saved_x1 = x; - Grx_mouse_saved_y1 = y; - Grx_mouse_saved_x2 = x+w-1; - Grx_mouse_saved_y2 = y+h-1; - - CLAMP(Grx_mouse_saved_x1, gr_screen.clip_left, gr_screen.clip_right ); - CLAMP(Grx_mouse_saved_x2, gr_screen.clip_left, gr_screen.clip_right ); - CLAMP(Grx_mouse_saved_y1, gr_screen.clip_top, gr_screen.clip_bottom ); - CLAMP(Grx_mouse_saved_y2, gr_screen.clip_top, gr_screen.clip_bottom ); - - Grx_mouse_saved_w = Grx_mouse_saved_x2 - Grx_mouse_saved_x1 + 1; - Grx_mouse_saved_h = Grx_mouse_saved_y2 - Grx_mouse_saved_y1 + 1; - - if ( Grx_mouse_saved_w < 1 ) return; - if ( Grx_mouse_saved_h < 1 ) return; - - // Make sure we're not saving too much! - SDL_assert( (Grx_mouse_saved_w*Grx_mouse_saved_h) <= MAX_SAVE_SIZE ); - - Grx_mouse_saved = 1; - - gr_lock(); - - ubyte *sptr, *dptr; - - dptr = Grx_mouse_saved_data; - - for (int i=0; i gr_screen.max_w-1 ) { - gr_screen.clip_left = gr_screen.max_w-1-x; - } - if ( gr_screen.clip_right+x < 0 ) { - gr_screen.clip_right = -x; - } else if ( gr_screen.clip_right+x >= gr_screen.max_w-1 ) { - gr_screen.clip_right = gr_screen.max_w-1-x; - } - - if ( gr_screen.clip_top+y < 0 ) { - gr_screen.clip_top = -y; - } else if ( gr_screen.clip_top+y > gr_screen.max_h-1 ) { - gr_screen.clip_top = gr_screen.max_h-1-y; - } - - if ( gr_screen.clip_bottom+y < 0 ) { - gr_screen.clip_bottom = -y; - } else if ( gr_screen.clip_bottom+y > gr_screen.max_h-1 ) { - gr_screen.clip_bottom = gr_screen.max_h-1-y; - } - - gr_screen.clip_width = gr_screen.clip_right - gr_screen.clip_left + 1; - gr_screen.clip_height = gr_screen.clip_bottom - gr_screen.clip_top + 1; -} - -// resets the clipping region to entire screen -// -// should call this before gr_surface_flip() if you clipped some portion of the screen but still -// want a full-screen display -void grx_reset_clip() -{ - gr_screen.offset_x = 0; - gr_screen.offset_y = 0; - gr_screen.clip_left = 0; - gr_screen.clip_top = 0; - gr_screen.clip_right = gr_screen.max_w - 1; - gr_screen.clip_bottom = gr_screen.max_h - 1; - gr_screen.clip_width = gr_screen.max_w; - gr_screen.clip_height = gr_screen.max_h; -} - - -// Sets the current bitmap -void grx_set_bitmap( int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha, int sx, int sy ) -{ - gr_screen.current_alpha = alpha; - gr_screen.current_alphablend_mode = alphablend_mode; - gr_screen.current_bitblt_mode = bitblt_mode; - gr_screen.current_bitmap = bitmap_num; - gr_screen.current_bitmap_sx = sx; - gr_screen.current_bitmap_sy = sy; -} - - -// clears entire clipping region to black. -void grx_clear() -{ - if (Is_standalone) { - return; - } - - gr_lock(); - - int i,w; - ubyte *pDestBits; - - w = gr_screen.clip_right-gr_screen.clip_left+1; - for (i=gr_screen.clip_top; i<=gr_screen.clip_bottom; i++) { - pDestBits = GR_SCREEN_PTR(ubyte,gr_screen.clip_left,i); - memset( pDestBits, 0, w ); - } - - gr_unlock(); -} - - - -void grx_start_frame() -{ -} - -void grx_stop_frame() -{ -} - -void gr_soft_fog_set(int fog_mode, int r, int g, int b, float near, float far) -{ -} - -void gr_soft_get_pixel(int x, int y, int *r, int *g, int *b) -{ -} - -void grx_fade_in(int instantaneous); -void grx_fade_out(int instantaneous); -void grx_flash(int r, int g, int b); - -static ubyte *Gr_saved_screen = NULL; -static uint Gr_saved_screen_palette_checksum = 0; -static ubyte Gr_saved_screen_palette[768]; - -int gr8_save_screen() -{ - int i; - gr_reset_clip(); - - if (gr_screen.bits_per_pixel != 8) { - mprintf(( "Save Screen only works in 8 bpp!\n" )); - return -1; - } - - if ( Gr_saved_screen ) { - mprintf(( "Screen alread saved!\n" )); - return -1; - } - - Gr_saved_screen = (ubyte *)malloc( gr_screen.max_w*gr_screen.max_h ); - if (!Gr_saved_screen) { - mprintf(( "Couldn't get memory for saved screen!\n" )); - return -1; - } - - Gr_saved_screen_palette_checksum = gr_palette_checksum; - memcpy( Gr_saved_screen_palette, gr_palette, 768 ); - - gr_lock(); - - for (i=0; i 255 ) { - v = 255; - } else if ( v < 0 ) { - v = 0; - } - Gr_gamma_lookup[i] = v; - } - -// ubyte new_pal[768]; -// if ( gr_screen.bits_per_pixel!=8 ) return; -// -// for (i=0; i<768; i++ ) { -// new_pal[i] = ubyte(Gr_gamma_lookup[gr_palette[i]]); -// } -// grx_change_palette( new_pal ); - - gr_screen.signature = Gr_signature++; -} - - -void gr_soft_init() -{ -// int i; - - // software mode only supports 640x480 - SDL_assert(gr_screen.res == GR_640); - if(gr_screen.res != GR_640){ - gr_screen.res = GR_640; - gr_screen.max_w = 640; - gr_screen.max_h = 480; - } - - // Prepare the window to go full screen -#ifndef PLAT_UNIX - HWND hwnd = (HWND)os_get_window(); - - if ( hwnd ) { - DWORD style, exstyle; - RECT client_rect; - - exstyle = 0; - style = WS_CAPTION | WS_SYSMENU; - - // Create Game Window - client_rect.left = client_rect.top = 0; - client_rect.right = gr_screen.max_w; - client_rect.bottom = gr_screen.max_h; - AdjustWindowRect(&client_rect,style,FALSE); - - RECT work_rect; - SystemParametersInfo( SPI_GETWORKAREA, 0, &work_rect, 0 ); - int x = work_rect.left + (( work_rect.right - work_rect.left )-(client_rect.right - client_rect.left))/2; - int y = work_rect.top; - if ( x < work_rect.left ) { - x = work_rect.left; - } - int WinX = x; - int WinY = y; - int WinW = client_rect.right - client_rect.left; - int WinH = client_rect.bottom - client_rect.top; - - ShowWindow(hwnd, SW_SHOWNORMAL ); - SetWindowLong( hwnd, GWL_STYLE, style ); - SetWindowLong( hwnd, GWL_EXSTYLE, exstyle ); - SetWindowPos( hwnd, HWND_NOTOPMOST, WinX, WinY, WinW, WinH, SWP_SHOWWINDOW ); - SetActiveWindow(hwnd); - SetForegroundWindow(hwnd); - } -#endif - - Palette_flashed = 0; - Palette_flashed_last_frame = 0; - - gr_screen.bits_per_pixel = 8; - gr_screen.bytes_per_pixel = 1; - - gr_buffer_create( gr_screen.max_w, gr_screen.max_h, gr_screen.bits_per_pixel ); - -#ifndef PLAT_UNIX - gr_screen.offscreen_buffer_base = lpDibBits; - - gr_screen.rowsize = DibInfo.Header.biWidth*((gr_screen.bits_per_pixel+7)/8); - SDL_assert( DibInfo.Header.biWidth == gr_screen.max_w ); - - if (DibInfo.Header.biHeight > 0) { - // top down - gr_screen.offscreen_buffer = (void *)((uint)gr_screen.offscreen_buffer_base + (gr_screen.max_h - 1) * gr_screen.rowsize); - gr_screen.rowsize *= -1; - } else { - // top up - gr_screen.offscreen_buffer = gr_screen.offscreen_buffer_base; - } -#endif - - grx_init_alphacolors(); - - gr_screen.gf_flip = grx_flip; - gr_screen.gf_flip_window = grx_flip_window; - gr_screen.gf_set_clip = grx_set_clip; - gr_screen.gf_reset_clip = grx_reset_clip; - gr_screen.gf_set_font = grx_set_font; - gr_screen.gf_set_color = grx_set_color; - gr_screen.gf_set_bitmap = grx_set_bitmap; - gr_screen.gf_create_shader = grx_create_shader; - gr_screen.gf_set_shader = grx_set_shader; - gr_screen.gf_clear = grx_clear; - // gr_screen.gf_bitmap = grx_bitmap; - // ]gr_screen.gf_bitmap_ex = grx_bitmap_ex; - - gr_screen.gf_aabitmap = grx_aabitmap; - gr_screen.gf_aabitmap_ex = grx_aabitmap_ex; - - gr_screen.gf_rect = grx_rect; - gr_screen.gf_shade = gr8_shade; - gr_screen.gf_string = gr8_string; - gr_screen.gf_circle = gr8_circle; - - gr_screen.gf_line = gr8_line; - gr_screen.gf_aaline = gr8_aaline; - gr_screen.gf_pixel = gr8_pixel; - gr_screen.gf_scaler = gr8_scaler; - gr_screen.gf_aascaler = gr8_aascaler; - gr_screen.gf_tmapper = grx_tmapper; - - gr_screen.gf_gradient = gr8_gradient; - - gr_screen.gf_set_palette = grx_set_palette; - gr_screen.gf_get_color = grx_get_color; - gr_screen.gf_init_color = grx_init_color; - gr_screen.gf_init_alphacolor = grx_init_alphacolor; - gr_screen.gf_set_color_fast = grx_set_color_fast; - gr_screen.gf_print_screen = grx_print_screen; - gr_screen.gf_start_frame = grx_start_frame; - gr_screen.gf_stop_frame = grx_stop_frame; - - gr_screen.gf_fade_in = grx_fade_in; - gr_screen.gf_fade_out = grx_fade_out; - gr_screen.gf_flash = grx_flash; - - - // Retrieves the zbuffer mode. - gr_screen.gf_zbuffer_get = gr8_zbuffer_get; - gr_screen.gf_zbuffer_set = gr8_zbuffer_set; - gr_screen.gf_zbuffer_clear = gr8_zbuffer_clear; - - gr_screen.gf_save_screen = gr8_save_screen; - gr_screen.gf_restore_screen = gr8_restore_screen; - gr_screen.gf_free_screen = gr8_free_screen; - - // Screen dumping stuff - gr_screen.gf_dump_frame_start = gr8_dump_frame_start; - gr_screen.gf_dump_frame_stop = gr8_dump_frame_stop; - gr_screen.gf_dump_frame = gr8_dump_frame; - - // Gamma stuff - gr_screen.gf_set_gamma = gr8_set_gamma; - - // Lock/unlock stuff - gr_screen.gf_lock = gr_soft_lock; - gr_screen.gf_unlock = gr_soft_unlock; - - // region - gr_screen.gf_get_region = grx_get_region; - - // fog stuff - gr_screen.gf_fog_set = gr_soft_fog_set; - - // pixel get - gr_screen.gf_get_pixel = gr_soft_get_pixel; - - // poly culling - gr_screen.gf_set_cull = gr_soft_set_cull; - - // cross fade - gr_screen.gf_cross_fade = gr_soft_cross_fade; - - // filter - gr_screen.gf_filter_set = gr_soft_filter_set; - - // tcache set - gr_screen.gf_tcache_set = gr_soft_tcache_set; - - // set clear color - gr_screen.gf_set_clear_color = gr_soft_set_clear_color; - - gr_reset_clip(); - gr_clear(); - gr_flip(); -} - -void gr_soft_force_windowed() -{ -} - -void gr_soft_cleanup() -{ - if (Gr_soft_inited) { - gr_buffer_release(); - Gr_soft_inited = 0; - } -} - -void grx_change_palette( ubyte * new_pal ) -{ -#ifndef PLAT_UNIX - if ( hPalette ) { - if (hDibDC) - SelectPalette( hDibDC, hOldPalette, FALSE ); - if (!DeleteObject(hPalette)) - Int3(); - hPalette = NULL; - } - - hPalette = gr_create_palette_256(new_pal); // All 256 mapped one-to-one, but BLT's are slow. - - if ( hDibDC ) { - int i; - for (i=0; i<256; i++ ) { - DibInfo.Colors.aColors[i].rgbRed = new_pal[i*3+0]; - DibInfo.Colors.aColors[i].rgbGreen = new_pal[i*3+1]; - DibInfo.Colors.aColors[i].rgbBlue = new_pal[i*3+2]; - DibInfo.Colors.aColors[i].rgbReserved = 0; - } - - hOldPalette = SelectPalette( hDibDC, hPalette, FALSE ); - SetDIBColorTable( hDibDC, 0, 256, DibInfo.Colors.aColors ); - } -#endif -} - -void grx_flash( int r, int g, int b ) -{ - int t,i; - ubyte new_pal[768]; - - if ( (r==0) && (g==0) && (b==0) ) { - return; - } - - Palette_flashed++; - - for (i=0; i<256; i++ ) { - t = gr_palette[i*3+0] + r; - if ( t < 0 ) t = 0; else if (t>255) t = 255; - new_pal[i*3+0] = (ubyte)t; - - t = gr_palette[i*3+1] + g; - if ( t < 0 ) t = 0; else if (t>255) t = 255; - new_pal[i*3+1] = (ubyte)t; - - t = gr_palette[i*3+2] + b; - if ( t < 0 ) t = 0; else if (t>255) t = 255; - new_pal[i*3+2] = (ubyte)t; - } - - grx_change_palette( new_pal ); -} - -#ifndef HARDWARE_ONLY -static int gr_palette_faded_out = 0; -#endif - -#define FADE_TIME (F1_0/4) // How long to fade out - -void grx_fade_out(int instantaneous) -{ -#ifndef HARDWARE_ONLY - int i; - ubyte new_pal[768]; - - if (!gr_palette_faded_out) { - - if ( !instantaneous ) { - - int count = 0; - fix start_time, stop_time, t1; - - start_time = timer_get_fixed_seconds(); - t1 = 0; - - do { - for (i=0; i<768; i++ ) { - int c = (gr_palette[i]*(FADE_TIME-t1))/FADE_TIME; - if (c < 0 ) - c = 0; - else if ( c > 255 ) - c = 255; - - new_pal[i] = (ubyte)c; - } - grx_change_palette( new_pal ); - gr_flip(); - count++; - - t1 = timer_get_fixed_seconds() - start_time; - - } while ( (t1 < FADE_TIME) && (t1>=0) ); // Loop as long as time not up and timer hasn't rolled - - stop_time = timer_get_fixed_seconds(); - - mprintf(( "Took %d frames (and %.1f secs) to fade out\n", count, f2fl(stop_time-start_time) )); - - } - gr_palette_faded_out = 1; - } - - gr_reset_clip(); - gr_clear(); - gr_flip(); - memset( new_pal, 0, 768 ); - grx_change_palette( new_pal ); -#else - Int3(); -#endif -} - - -void grx_fade_in(int instantaneous) -{ -#ifndef HARDWARE_ONLY - int i; - ubyte new_pal[768]; - - if (gr_palette_faded_out) { - - if ( !instantaneous ) { - int count = 0; - fix start_time, stop_time, t1; - - start_time = timer_get_fixed_seconds(); - t1 = 0; - - do { - for (i=0; i<768; i++ ) { - int c = (gr_palette[i]*t1)/FADE_TIME; - if (c < 0 ) - c = 0; - else if ( c > 255 ) - c = 255; - - new_pal[i] = (ubyte)c; - } - grx_change_palette( new_pal ); - gr_flip(); - count++; - - t1 = timer_get_fixed_seconds() - start_time; - - } while ( (t1 < FADE_TIME) && (t1>=0) ); // Loop as long as time not up and timer hasn't rolled - - stop_time = timer_get_fixed_seconds(); - - mprintf(( "Took %d frames (and %.1f secs) to fade in\n", count, f2fl(stop_time-start_time) )); - } - gr_palette_faded_out = 0; - } - - memcpy( new_pal, gr_palette, 768 ); - grx_change_palette( new_pal ); -#else - Int3(); -#endif -} - - diff --git a/src/graphics/grzbuffer.cpp b/src/graphics/grzbuffer.cpp deleted file mode 100644 index ed25bec..0000000 --- a/src/graphics/grzbuffer.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/GrZbuffer.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Code for the software renderer's zbuffer - * - * $Log$ - * Revision 1.3 2002/06/09 04:41:18 relnev - * added copyright header - * - * Revision 1.2 2002/05/07 03:16:45 theoddone33 - * The Great Newline Fix - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 1 3/25/98 8:07p John - * Split software renderer into Win32 and DirectX - * - * $NoKeywords: $ - */ - -#include "osapi.h" -#include "2d.h" -#include "floating.h" -#include "grsoft.h" -#include "grinternal.h" - -int gr_zcount=GR_Z_COUNT; -int gr_zoffset=0; - -uint *gr_zbuffer = NULL; -int gr_zbuffer_w = 0; -int gr_zbuffer_h = 0; - -int gr_zbuffering = 0; -int gr_zbuffering_mode = 0; -int gr_global_zbuffering = 0; - -// If mode is FALSE, turn zbuffer off the entire frame, -// no matter what people pass to gr_zbuffer_set. -void gr8_zbuffer_clear(int mode) -{ - if ( mode ) { - gr_zbuffering = 1; - gr_zbuffering_mode = GR_ZBUFF_FULL; - gr_global_zbuffering = 1; - - if ( (!gr_zbuffer) || (gr_screen.max_w!=gr_zbuffer_w) || (gr_screen.max_h!=gr_zbuffer_h) ) { - //mprintf(( "Allocating a %d x %d zbuffer\n", gr_screen.max_w, gr_screen.max_h )); - if ( gr_zbuffer ) { - free(gr_zbuffer); - gr_zbuffer = NULL; - } - gr_zbuffer_w = gr_screen.max_w; - gr_zbuffer_h = gr_screen.max_h; - gr_zbuffer = (uint *)malloc(gr_zbuffer_w*gr_zbuffer_h*sizeof(uint)); - if ( !gr_zbuffer ) { - Error( LOCATION, "Couldn't allocate zbuffer\n" ); - gr_zbuffering = 0; - return; - } - memset( gr_zbuffer, 0, gr_zbuffer_w*gr_zbuffer_h*sizeof(uint) ); - } - - - gr_zcount++; - gr_zoffset += GR_Z_RANGE; - if ( gr_zcount >= (GR_Z_COUNT-16) ) { - //mprintf(( "Bing!\n" )); - memset( gr_zbuffer, 0, gr_zbuffer_w*gr_zbuffer_h*sizeof(uint) ); - gr_zcount = 0; - gr_zoffset = GR_Z_RANGE*16; - } - } else { - gr_zbuffering = 0; - gr_zbuffering_mode = GR_ZBUFF_NONE; - gr_global_zbuffering = 0; - } -} - - -int gr8_zbuffer_get() -{ - if ( !gr_global_zbuffering ) { - return GR_ZBUFF_NONE; - } - return gr_zbuffering_mode; -} - -int gr8_zbuffer_set(int mode) -{ - if ( !gr_global_zbuffering ) { - gr_zbuffering = 0; - return GR_ZBUFF_NONE; - } - - int tmp = gr_zbuffering_mode; - - gr_zbuffering_mode = mode; - - if ( gr_zbuffering_mode == GR_ZBUFF_NONE ) { - gr_zbuffering = 0; - } else { - gr_zbuffering = 1; - } - return tmp; -} - diff --git a/src/graphics/line.cpp b/src/graphics/line.cpp deleted file mode 100644 index 485395b..0000000 --- a/src/graphics/line.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/Line.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Routines for drawing lines. - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:18 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 3 12/02/98 5:47p Dave - * Put in interface xstr code. Converted barracks screen to new format. - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 21 5/06/98 5:30p John - * Removed unused cfilearchiver. Removed/replaced some unused/little used - * graphics functions, namely gradient_h and _v and pixel_sp. Put in new - * DirectX header files and libs that fixed the Direct3D alpha blending - * problems. - * - * 20 3/10/98 4:18p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 19 1/13/98 10:20a John - * Added code to support "glass" in alphacolors - * - * 18 11/30/97 12:18p John - * added more 24 & 32-bpp primitives - * - * 17 11/29/97 2:06p John - * added mode 16-bpp support - * - * 16 10/19/97 12:55p John - * new code to lock / unlock surfaces for smooth directx integration. - * - * 15 10/14/97 8:08a John - * added a bunch more 16 bit support - * - * 14 10/03/97 9:10a John - * added better antialiased line drawer - * - * 13 9/09/97 10:39a Sandeep - * Fixed compiler warnings level 4 (sorta, john is fixing most of it) - * - * 12 6/13/97 5:35p John - * added some antialiased bitmaps and lines - * - * 11 6/06/97 2:40p John - * Made all the radar dim in/out - * - * 10 5/12/97 12:27p John - * Restructured Graphics Library to add support for multiple renderers. - * - * 9 11/26/96 6:50p John - * Added some more hicolor primitives. Made windowed mode run as current - * bpp, if bpp is 8,16,or 32. - * - * 8 10/26/96 2:56p John - * Got gradient code working. - * - * 7 10/26/96 1:40p John - * Added some now primitives to the 2d library and - * cleaned up some old ones. - * - * $NoKeywords: $ - */ - -#ifndef PLAT_UNIX -#include -#include -#endif - -#include "2d.h" -#include "grinternal.h" -#include "floating.h" -#include "line.h" -#include "key.h" - - -void gr8_uline(int x1,int y1,int x2,int y2) -{ - int i; - int xstep,ystep; - int dy=y2-y1; - int dx=x2-x1; - int error_term=0; - - gr_lock(); - ubyte *dptr = GR_SCREEN_PTR(ubyte,x1,y1); - ubyte color = gr_screen.current_color.raw8; - - if(dy<0) { - dy=-dy; - ystep=-gr_screen.rowsize / gr_screen.bytes_per_pixel; - } else { - ystep=gr_screen.rowsize / gr_screen.bytes_per_pixel; - } - - if(dx<0) { - dx=-dx; - xstep=-1; - } else { - xstep=1; - } - - /* HARDWARE_ONLY - removed alpha color table stuff - if ( Current_alphacolor ) { - if(dx>dy) { - - for(i=dx+1;i>0;i--) { - *dptr = Current_alphacolor->table.lookup[14][*dptr]; - dptr += xstep; - error_term+=dy; - - if(error_term>dx) { - error_term-=dx; - dptr+=ystep; - } - } - } else { - - for(i=dy+1;i>0;i--) { - *dptr = Current_alphacolor->table.lookup[14][*dptr]; - dptr += ystep; - error_term+=dx; - if(error_term>0) { - error_term-=dy; - dptr+=xstep; - } - - } - - } - } else { - */ - if(dx>dy) { - - for(i=dx+1;i>0;i--) { - *dptr = color; - dptr += xstep; - error_term+=dy; - - if(error_term>dx) { - error_term-=dx; - dptr+=ystep; - } - } - } else { - - for(i=dy+1;i>0;i--) { - *dptr = color; - dptr += ystep; - error_term+=dx; - if(error_term>0) { - error_term-=dy; - dptr+=xstep; - } - - } - - } - gr_unlock(); -} - - - -void gr8_line(int x1,int y1,int x2,int y2) -{ - int clipped = 0, swapped=0; - - INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,gr_screen.clip_right,gr_screen.clip_bottom,return,clipped=1,swapped=1); - - gr8_uline(x1,y1,x2,y2); -} - - - diff --git a/src/graphics/pixel.cpp b/src/graphics/pixel.cpp deleted file mode 100644 index 583c031..0000000 --- a/src/graphics/pixel.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/Pixel.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Routines to plot a dot. - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:18 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 3 12/02/98 5:47p Dave - * Put in interface xstr code. Converted barracks screen to new format. - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 14 5/06/98 5:30p John - * Removed unused cfilearchiver. Removed/replaced some unused/little used - * graphics functions, namely gradient_h and _v and pixel_sp. Put in new - * DirectX header files and libs that fixed the Direct3D alpha blending - * problems. - * - * 13 3/10/98 4:18p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 12 1/13/98 10:20a John - * Added code to support "glass" in alphacolors - * - * 11 10/19/97 12:55p John - * new code to lock / unlock surfaces for smooth directx integration. - * - * 10 10/14/97 8:08a John - * added a bunch more 16 bit support - * - * 9 10/09/97 5:23p John - * Added support for more 16-bpp functions - * - * 8 6/06/97 2:40p John - * Made all the radar dim in/out - * - * 7 5/29/97 3:09p John - * Took out debug menu. - * Made software scaler draw larger bitmaps. - * Optimized Direct3D some. - * - * 6 5/12/97 12:27p John - * Restructured Graphics Library to add support for multiple renderers. - * - * 5 1/09/97 11:35a John - * Added some 2d functions to get/put screen images. - * - * 4 11/07/96 6:19p John - * Added a bunch of 16bpp primitives so the game sort of runs in 16bpp - * mode. - * - * 3 10/26/96 1:40p John - * Added some now primitives to the 2d library and - * cleaned up some old ones. - * - * $NoKeywords: $ - */ - -#include "2d.h" -#include "grinternal.h" -#include "pixel.h" -#include "palman.h" - -void gr8_pixel( int x, int y ) -{ - ubyte * dptr; - - if ( x < gr_screen.clip_left ) return; - if ( x > gr_screen.clip_right ) return; - if ( y < gr_screen.clip_top ) return; - if ( y > gr_screen.clip_bottom ) return; - - gr_lock(); - - dptr = GR_SCREEN_PTR(ubyte,x, y); - if ( Current_alphacolor ) { - // *dptr = Current_alphacolor->table.lookup[14][*dptr]; - } else { - *dptr = gr_screen.current_color.raw8; - } - - gr_unlock(); -} - - - diff --git a/src/graphics/rect.cpp b/src/graphics/rect.cpp deleted file mode 100644 index ba2d198..0000000 --- a/src/graphics/rect.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/Rect.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Routines to draw rectangles. - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:18 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 3 12/02/98 5:47p Dave - * Put in interface xstr code. Converted barracks screen to new format. - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 3 3/10/98 4:18p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 2 10/26/96 2:56p John - * Got gradient code working. - * - * 1 10/26/96 1:32p John - * Initial rev - * - * $NoKeywords: $ - */ - -#include "2d.h" -#include "grinternal.h" - -void grx_rect(int x,int y,int w,int h) -{ - int i; - int x1 = x, x2; - int y1 = y, y2; - - if ( w > 0 ) - x2 = x + w - 1; - else - x2 = x + w + 1; - - if ( h > 0 ) - y2 = y + h - 1; - else - y2 = y + h + 1; - - if ( x2 < x1 ) { - int tmp; - tmp = x1; - x1 = x2; - x2 = tmp; - } - - if ( y2 < y1 ) { - int tmp; - tmp = y1; - y1 = y2; - y2 = tmp; - } - - // Check for completely offscreen! - if ( x1 > gr_screen.clip_right ) - return; - - if ( x2 < gr_screen.clip_left ) - return; - - if ( y1 > gr_screen.clip_bottom ) - return; - - if ( y2 < gr_screen.clip_top ) - return; - - // Now clip - if ( x1 < gr_screen.clip_left ) - x1 = gr_screen.clip_left; - - if ( x2 > gr_screen.clip_right ) - x2 = gr_screen.clip_right; - - if ( y1 < gr_screen.clip_top ) - y1 = gr_screen.clip_top; - - if ( y2 > gr_screen.clip_bottom ) - y2 = gr_screen.clip_bottom; - - w = x2-x1+1; - if ( w < 1 ) return; - - h = y2-y1+1; - if ( h < 1 ) return; - - gr_lock(); - - ubyte *dptr; - - /* HARDWARE_ONLY - if ( Current_alphacolor ) { - for (i=0; itable.lookup[14][*dptr]; - } - } - } else { - */ - for (i=0; i8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 34 2/05/98 9:21p John - * Some new Direct3D code. Added code to monitor a ton of stuff in the - * game. - * - * 33 1/27/98 10:18a John - * fixed warning for optimized build - * - * 32 1/26/98 5:12p John - * Added in code for Pentium Pro specific optimizations. Speed up - * zbuffered correct tmapper about 35%. Speed up non-zbuffered scalers - * by about 25%. - * - * 31 1/19/98 6:15p John - * Fixed all my Optimized Build compiler warnings - * - * 30 12/04/97 12:09p John - * Made glows use scaler instead of tmapper so they don't rotate. Had to - * add a zbuffered scaler. - * - * 29 12/02/97 4:00p John - * Added first rev of thruster glow, along with variable levels of - * translucency, which retquired some restructing of palman. - * - * 28 11/30/97 4:33p John - * added 32-bpp aascaler - * - * 27 11/30/97 3:57p John - * Made fixed 32-bpp translucency. Made BmpMan always map translucent - * color into 255 even if you aren't supposed to remap and make it's - * palette black. - * - * 26 11/30/97 12:18p John - * added more 24 & 32-bpp primitives - * - * 25 11/29/97 2:06p John - * added mode 16-bpp support - * - * 24 11/14/97 12:30p John - * Fixed some DirectX bugs. Moved the 8-16 xlat tables into Graphics - * libs. Made 16-bpp DirectX modes know what bitmap format they're in. - * - * 23 10/19/97 12:55p John - * new code to lock / unlock surfaces for smooth directx integration. - * - * 22 10/15/97 4:48p John - * added 16-bpp aascaler - * - * 21 10/14/97 8:08a John - * added a bunch more 16 bit support - * - * 20 10/09/97 5:23p John - * Added support for more 16-bpp functions - * - * 19 8/04/97 4:47p John - * added gr_aascaler. - * - * 18 7/28/97 11:31a John - * made compiled code save all registers that it changes. When building - * optimized, my code was using EBX, and so was the compiler, so weird - * errors happened. Pushing/popping ebx fixed this. - * - * 17 7/16/97 5:29p John - * added palette table caching and made scaler and liner no light tmapper - * do alpha blending in 8 bpp mode. - * - * 16 7/10/97 2:06p John - * added code to specify alphablending type for bitmaps. - * - * 15 6/12/97 2:50a Lawrance - * bm_unlock() now passed bitmap number, not pointer - * - * 14 5/29/97 3:10p John - * Took out debug menu. - * Made software scaler draw larger bitmaps. - * Optimized Direct3D some. - * - * 13 5/12/97 12:27p John - * Restructured Graphics Library to add support for multiple renderers. - * - * 12 12/04/96 2:02p John - * Added fast compiled code to the scaler in 8,16,32 bpp modes. - * - * 11 12/03/96 8:08p John - * Added compiled code to 8bpp scaler. Made bitmaps that are trying to - * scale up too big to not draw. - * - * 10 12/03/96 11:12a John - * added commented out "filtering" code to scaler. - * - * 9 11/19/96 2:42p Allender - * fix up 32 bit scaler - * - * 8 11/15/96 11:27a Allender - * 16bpp version of scaler - * - * 7 11/07/96 6:19p John - * Added a bunch of 16bpp primitives so the game sort of runs in 16bpp - * mode. - * - * 6 10/26/96 1:40p John - * Added some now primitives to the 2d library and - * cleaned up some old ones. - * - * $NoKeywords: $ - */ - -#include -#include -#include -#ifndef PLAT_UNIX -#include -#endif -#include - -#include "scaler.h" -#include "2d.h" -#include "grinternal.h" -#include "floating.h" -#include "bmpman.h" -#include "palman.h" -#include "tmapscanline.h" -#include "systemvars.h" -#include "key.h" -#include "colors.h" - -#define MIN_SCALE_FACTOR 0.0001f - -#define USE_COMPILED_CODE - -#define TRANSPARENCY_COLOR_8 0xff -#define TRANSPARENCY_COLOR_16 0xffff -#define TRANSPARENCY_COLOR_32 0xffffffff - -#define FIND_SCALED_NUM(x,x0,x1,y0,y1) (((((x)-(x0))*((y1)-(y0)))/((x1)-(x0)))+(y0)) - -#define MAX_CODE_SIZE 32768 //65536 JAS: Determed to be 8208 on April1,98, 16K seems safe - -ubyte compiled_code[MAX_CODE_SIZE]; - -#ifdef FIND_MAX_SIZE -static int Max_size = 0; -#endif - -/* -void test_code() -{ - _asm mov ax, [esi+0xabcdef12] - _asm cmp ax, 255 - _asm je 0xabcdef12 - _asm mov [edi+0xabcdef12], ax - _asm mov ax, [esi+0xabcdef12] -} -*/ - - - -//---------------------------------------------------- -// scaler_create_compiled_code8 -// -// Creates code that looks like: -// -// @@: mov al, [esi+????] -// cmp al, TRANSPARENCY_COLOR_8 -// je @f ; jump to next @@ label -// mov [edi+???], al ; If the source pixel is scaled up -// mov [edi+???], al ; there might be a lot of these lines -// ... -// @@: mov al, [esi+????] -// - -ubyte *scaler_create_compiled_code8( int w, fix u, fix du ) -{ - int last_u, x; - ubyte * cc; - uint * last_jmp_pos; - - cc = compiled_code; - - //if ( abs(du) < F1_0 / 4 ) *cc++ = 0xCC; - -// *cc++ = 0xCC; // Int3 -// *cc++ = 0xc3; // RET - - last_u = -1; - - last_jmp_pos=NULL; - - for (x=0; x= &compiled_code[MAX_CODE_SIZE] ) - Int3(); // GET JOHN NOW! - -#ifdef FIND_MAX_SIZE - int size = cc - compiled_code; - if ( size > Max_size ) { - Max_size = size; - mprintf(( "Max size = %d\n", size )); - } -#endif - - return compiled_code; -} - -ubyte *scaler_create_compiled_code8_stippled( int w, fix u, fix du ) -{ - int last_u, x; - ubyte * cc; - uint * last_jmp_pos; - - cc = compiled_code; - - //if ( abs(du) < F1_0 / 4 ) *cc++ = 0xCC; - -// *cc++ = 0xCC; // Int3 -// *cc++ = 0xc3; // RET - - last_u = -1; - - last_jmp_pos=NULL; - - for (x=0; x= &compiled_code[MAX_CODE_SIZE] ) - Int3(); // GET JOHN NOW! - -#ifdef FIND_MAX_SIZE - int size = cc - compiled_code; - if ( size > Max_size ) { - Max_size = size; - mprintf(( "Max size = %d\n", size )); - } -#endif - - return compiled_code; -} - -void test_code1() -{ -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm mov ebx, -1 - _asm xor eax, eax - _asm xor ebx, ebx - _asm mov bl, BYTE PTR [edi-1412567278] - _asm add ebx, eax - _asm mov ebx, [ecx+ebx] ; blend it - _asm cmp ebp, [edx] - _asm add edx, 4 - _asm jl [0xABCDEF12] - -// xor eax, eax ; avoid ppro partial register stall -// mov ah, [esi+????] ; get the foreground pixel -// ; the following lines might be repeated -// xor ebx, ebx ; avoid ppro partial register stall -// mov bl, [edi+????] ; get the background pixel -// mov ebx, [ecx+ebx] ; blend it -// mov [edi+????], bl ; write it -#endif -} - -/* - 00130 b8 00 00 00 00 mov eax, 0 - 00135 8a a6 12 ef cd ab mov ah, BYTE PTR [esi-1412567278] - 0013b 8a 87 12 ef cd ab mov al, BYTE PTR [edi-1412567278] - 00141 8a 1c 01 mov bl, BYTE PTR [ecx+eax] - 00141 8b 1c 01 mov ebx, DWORD PTR [ecx+eax] - 00144 88 9f 12 ef cd ab mov BYTE PTR [edi-1412567278], bl - - - 00130 33 c0 xor eax, eax - 00132 33 db xor ebx, ebx - 00134 8a 9f 12 ef cd ab mov bl, BYTE PTR [edi-1412567278] - 0013a 03 d8 add ebx, eax - 0013c 8b 1c 19 mov ebx, DWORD PTR [ecx+ebx] - - 0013f 3b 2a cmp ebp, DWORD PTR [edx] - 00141 83 c2 04 add edx, 4 - - -*/ - -//---------------------------------------------------- -// scaler_create_compiled_code8_alpha -// -// Creates code that looks like: - -//=============== Pentium ====================== -// mov eax, 0 -// mov ah, [esi+????] ; get the foreground pixel -// ; the following lines might be repeated -// mov al, [edi+????] ; get the background pixel -// mov bl, [ecx+eax] ; blend it -// mov [edi+????], bl ; write it -// ... - -//============= Pentium Pro code ============= -// xor eax, eax ; avoid ppro partial register stall -// mov ah, [esi+????] ; get the foreground pixel -// ; the following lines might be repeated -// xor ebx, ebx ; avoid ppro partial register stall -// mov bl, [edi+????] ; get the background pixel -// mov ebx, [ecx+ebx] ; blend it -// mov [edi+????], bl ; write it - - -ubyte *scaler_create_compiled_code8_alpha( int w, fix u, fix du ) -{ - int last_u, x; - ubyte * cc; - - cc = compiled_code; - - //if ( abs(du) < F1_0 / 4 ) *cc++ = 0xCC; - - //*cc++ = 0xCC; // Int3 - //*cc++ = 0xc3; // RET - - last_u = -1; - - if ( Gr_cpu > 5 ) { - // Pentium Pro optimized code. - - for (x=0; x= &compiled_code[MAX_CODE_SIZE] ) - Int3(); // GET JOHN NOW! - -#ifdef FIND_MAX_SIZE - int size = cc - compiled_code; - if ( size > Max_size ) { - Max_size = size; - mprintf(( "Max size = %d\n", size )); - } -#endif - - return compiled_code; -} - -/* - for (x=0; x *zbuf ) { - uint c = sbits[ tmp_u >> 16 ]<<8; - *dbits = *((ubyte *)(lookup + (*dbits | c))); - } - dbits++; - zbuf++; - tmp_u += du; - } -*/ - -//---------------------------------------------------- -// scaler_create_compiled_code8_alpha_zbuffered -// -// Creates code that looks like: -// mov eax, 0 -// mov ah, [esi+????] ; get the foreground pixel -// ; the following lines might be repeated -// cmp fx_w, [edx+?????] -// jle @f -// mov al, [edi+????] ; get the background pixel -// mov bl, [ecx+eax] ; blend it -// mov [edi+????], bl ; write it -// @@: -// ... - - - - -//void test_code1() -//{ -// _asm cmp 0xFFFFFFFF, [edx+0xabcdef12] -// _asm cmp ebp, [edx+0xabcdef12] -// _asm jle 0xabcdef12 -//} -//; 302 : _asm cmp ebp, [edx+0xabcdef12] -// 00244 3b aa 12 ef cd ab cmp ebp, DWORD PTR [edx-1412567278] -//; 303 : _asm jle 0xabcdef12 -// 0024a 0f 8e 12 ef cd ab jle -1412567278 ; abcdef12H - -ubyte *scaler_create_compiled_code8_alpha_zbuffered( int w, fix u, fix du ) -{ - int last_u, x; - ubyte * cc; - uint *last_jmp_pos=NULL; - - cc = compiled_code; - - // xor eax, eax ; avoid ppro partial register stall -// mov ah, [esi+????] ; get the foreground pixel -// ; the following lines might be repeated -// xor ebx, ebx ; avoid ppro partial register stall -// mov bl, [edi+????] ; get the background pixel -// mov ebx, [ecx+ebx] ; blend it -// mov [edi+????], bl ; write it - - //if ( abs(du) < F1_0 / 4 ) *cc++ = 0xCC; - - //*cc++ = 0xCC; // Int3 - //*cc++ = 0xc3; // RET - last_u = -1; - - if ( Gr_cpu > 5 ) { - // Pentium Pro optimized code. - - for (x=0; x= &compiled_code[MAX_CODE_SIZE] ) - Int3(); // GET JOHN NOW! - -#ifdef FIND_MAX_SIZE - int size = cc - compiled_code; - if ( size > Max_size ) { - Max_size = size; - mprintf(( "Max sizeZ = %d\n", size )); - } -#endif - - return compiled_code; -} - - - -int Gr_scaler_zbuffering = 0; -uint Gr_global_z; - -MONITOR( ScalerNumCalls ); - - -//---------------------------------------------------- -// Scales current bitmap, between va and vb -void gr8_scaler(vertex *va, vertex *vb ) -{ -#if 1 - if(Pofview_running){ - return; - } - - float x0, y0, x1, y1; - float u0, v0, u1, v1; - float clipped_x0, clipped_y0, clipped_x1, clipped_y1; - float clipped_u0, clipped_v0, clipped_u1, clipped_v1; - float xmin, xmax, ymin, ymax; - int dx0, dy0, dx1, dy1; - - MONITOR_INC( ScalerNumCalls, 1 ); - - //============= CLIP IT ===================== - - x0 = va->sx; y0 = va->sy; - x1 = vb->sx; y1 = vb->sy; - - xmin = i2fl(gr_screen.clip_left); ymin = i2fl(gr_screen.clip_top); - xmax = i2fl(gr_screen.clip_right); ymax = i2fl(gr_screen.clip_bottom); - - u0 = va->u; v0 = va->v; - u1 = vb->u; v1 = vb->v; - - // Check for obviously offscreen bitmaps... - if ( (y1<=y0) || (x1<=x0) ) return; - if ( (x1xmax) ) return; - if ( (y1ymax) ) return; - - clipped_u0 = u0; clipped_v0 = v0; - clipped_u1 = u1; clipped_v1 = v1; - - clipped_x0 = x0; clipped_y0 = y0; - clipped_x1 = x1; clipped_y1 = y1; - - // Clip the left, moving u0 right as necessary - if ( x0 < xmin ) { - clipped_u0 = FIND_SCALED_NUM(xmin,x0,x1,u0,u1); - clipped_x0 = xmin; - } - - // Clip the right, moving u1 left as necessary - if ( x1 > xmax ) { - clipped_u1 = FIND_SCALED_NUM(xmax,x0,x1,u0,u1); - clipped_x1 = xmax; - } - - // Clip the top, moving v0 down as necessary - if ( y0 < ymin ) { - clipped_v0 = FIND_SCALED_NUM(ymin,y0,y1,v0,v1); - clipped_y0 = ymin; - } - - // Clip the bottom, moving v1 up as necessary - if ( y1 > ymax ) { - clipped_v1 = FIND_SCALED_NUM(ymax,y0,y1,v0,v1); - clipped_y1 = ymax; - } - - dx0 = fl2i(clipped_x0); dx1 = fl2i(clipped_x1); - dy0 = fl2i(clipped_y0); dy1 = fl2i(clipped_y1); - - if (dx1<=dx0) return; - if (dy1<=dy0) return; - - //============= DRAW IT ===================== - int u, v, du, dv; - int y, w; - ubyte * sbits, * dbits; - bitmap * bp; - ubyte * spixels; - float tmpu, tmpv; - - tmpu = (clipped_u1-clipped_u0) / (dx1-dx0); - if ( fl_abs(tmpu) < MIN_SCALE_FACTOR ) { - return; // scaled up way too far! - } - tmpv = (clipped_v1-clipped_v0) / (dy1-dy0); - if ( fl_abs(tmpv) < MIN_SCALE_FACTOR ) { - return; // scaled up way too far! - } - - int is_stippled = 0; - - /* - if ( !Detail.alpha_effects ) { - is_stippled = 1; - Gr_scaler_zbuffering = 0; - } - */ - - if ( is_stippled ) { - bp = bm_lock( gr_screen.current_bitmap, 8, 0 ); - } else { - bp = bm_lock( gr_screen.current_bitmap, 8, 0 ); - } - - - du = fl2f(tmpu*(bp->w-1)); - dv = fl2f(tmpv*(bp->h-1)); - - v = fl2f(clipped_v0*(bp->h-1)); - u = fl2f(clipped_u0*(bp->w-1)); - w = dx1 - dx0 + 1; - if ( w < 2 ) { - bm_unlock(gr_screen.current_bitmap); - return; - } - - uint fx_w = 0; - if ( Gr_scaler_zbuffering && gr_zbuffering ) { - fx_w = (uint)fl2i(va->sw * GR_Z_RANGE)+gr_zoffset; - Gr_global_z = fx_w; - } - -#ifdef USE_COMPILED_CODE - ubyte *cc=NULL; - - if ( Gr_scaler_zbuffering && gr_zbuffering ) { - if ( gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER ) { - cc = scaler_create_compiled_code8_alpha_zbuffered( w, u, du ); - } - } else { - if ( gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER ) { - if ( is_stippled ) { - cc = scaler_create_compiled_code8_stippled( w, u, du ); - } else { - cc = scaler_create_compiled_code8_alpha( w, u, du ); - } - } else { - cc = scaler_create_compiled_code8( w, u, du ); - } - } - -#endif - - spixels = (ubyte *)bp->data; - - gr_lock(); - Tmap.pScreenBits = (uint)gr_screen.offscreen_buffer_base; - - uint *zbuf; - - for (y=dy0; y<=dy1; v += dv, y++ ) { - if ( is_stippled && (y&1) ) { - sbits = &spixels[bp->rowsize*(v>>16)+f2i(du)]; - dbits = GR_SCREEN_PTR(ubyte,dx0+1,y); - } else { - sbits = &spixels[bp->rowsize*(v>>16)]; - dbits = GR_SCREEN_PTR(ubyte,dx0,y); - } - uint lookup = 0; - - if ( gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER ) { - lookup = (uint)palette_get_blend_table(gr_screen.current_alpha); - } - - if ( Gr_scaler_zbuffering && gr_zbuffering ) { - zbuf = (uint *)&gr_zbuffer[(uint)dbits-(uint)Tmap.pScreenBits]; - } - -#ifdef USE_COMPILED_CODE - // Call the compiled code to draw one scanline - if ( Gr_scaler_zbuffering && gr_zbuffering && (gr_screen.current_alphablend_mode != GR_ALPHABLEND_FILTER)) { - Int3(); - - /* - int x, tmp_u; - tmp_u = u; - - for (x=0; x *zbuf ) { - ubyte c = sbits[ tmp_u >> 16 ]; - if ( c != TRANSPARENCY_COLOR_8 ) *dbits = c; - } - zbuf++; - dbits++; - tmp_u += du; - } - */ - } else { -/* { - int x, tmp_u; - tmp_u = u; - - - for (x=0; x *zbuf ) { - uint c = sbits[ tmp_u >> 16 ]<<8; - *dbits = *((ubyte *)(lookup + (*dbits | c))); - } - dbits++; - zbuf++; - tmp_u += du; - } - } -*/ -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm push esi - _asm push edi - _asm push edx - _asm push ecx - _asm push ebx - _asm push eax - _asm mov ecx, lookup - _asm mov esi, sbits - _asm mov edi, dbits - _asm mov eax, cc - _asm mov edx, zbuf - _asm push ebp - _asm mov ebp, Gr_global_z - _asm call eax - _asm pop ebp - _asm pop eax - _asm pop ebx - _asm pop ecx - _asm pop edx - _asm pop edi - _asm pop esi -#endif - } -#else - if ( gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER ) { - if ( Gr_scaler_zbuffering && gr_zbuffering ) { - int x, tmp_u; - tmp_u = u; - - for (x=0; x *zbuf ) { - uint c = sbits[ tmp_u >> 16 ]<<8; - *dbits = *((ubyte *)(lookup + (*dbits | c))); - } - dbits++; - zbuf++; - tmp_u += du; - } - } else { - int x, tmp_u; - tmp_u = u; - for (x=0; x> 16 ]<<8; - *dbits++ = palette_blend[*dbits|c]; - tmp_u += du; - } - } - } else { - if ( Gr_scaler_zbuffering && gr_zbuffering ) { - int x, tmp_u; - tmp_u = u; - - for (x=0; x *zbuf ) { - ubyte c = sbits[ tmp_u >> 16 ]; - if ( c != TRANSPARENCY_COLOR_8 ) *dbits = c; - } - zbuf++; - dbits++; - tmp_u += du; - } - } else { - int x, tmp_u; - tmp_u = u; - for (x=0; x> 16 ]; - if ( c != TRANSPARENCY_COLOR_8 ) *dbits = c; - dbits++; - tmp_u += du; - } - } - } -#endif - } - - gr_unlock(); - bm_unlock(gr_screen.current_bitmap); -#endif -} - -int aiee = 0; -alphacolor_old old_alphac; -//---------------------------------------------------- -// Scales current bitmap, between va and vb -void gr8_aascaler(vertex *va, vertex *vb ) -{ - float x0, y0, x1, y1; - float u0, v0, u1, v1; - float clipped_x0, clipped_y0, clipped_x1, clipped_y1; - float clipped_u0, clipped_v0, clipped_u1, clipped_v1; - float xmin, xmax, ymin, ymax; - int dx0, dy0, dx1, dy1; - - //if ( !Current_alphacolor ) return; - - MONITOR_INC( ScalerNumCalls, 1 ); - - SDL_assert(Fred_running); - if(!aiee){ - old_alphac.used = 1; - old_alphac.r = 93; - old_alphac.g = 93; - old_alphac.b = 128; - old_alphac.alpha = 255; - //ac->type = type; - //ac->clr=clr; - //93, 93, 128, 255 - calc_alphacolor_old(&old_alphac); - aiee = 1; - } - - //============= CLIP IT ===================== - - x0 = va->sx; y0 = va->sy; - x1 = vb->sx; y1 = vb->sy; - - xmin = i2fl(gr_screen.clip_left); ymin = i2fl(gr_screen.clip_top); - xmax = i2fl(gr_screen.clip_right); ymax = i2fl(gr_screen.clip_bottom); - - u0 = va->u; v0 = va->v; - u1 = vb->u; v1 = vb->v; - - // Check for obviously offscreen bitmaps... - if ( (y1<=y0) || (x1<=x0) ) return; - if ( (x1xmax) ) return; - if ( (y1ymax) ) return; - - clipped_u0 = u0; clipped_v0 = v0; - clipped_u1 = u1; clipped_v1 = v1; - - clipped_x0 = x0; clipped_y0 = y0; - clipped_x1 = x1; clipped_y1 = y1; - - // Clip the left, moving u0 right as necessary - if ( x0 < xmin ) { - clipped_u0 = FIND_SCALED_NUM(xmin,x0,x1,u0,u1); - clipped_x0 = xmin; - } - - // Clip the right, moving u1 left as necessary - if ( x1 > xmax ) { - clipped_u1 = FIND_SCALED_NUM(xmax,x0,x1,u0,u1); - clipped_x1 = xmax; - } - - // Clip the top, moving v0 down as necessary - if ( y0 < ymin ) { - clipped_v0 = FIND_SCALED_NUM(ymin,y0,y1,v0,v1); - clipped_y0 = ymin; - } - - // Clip the bottom, moving v1 up as necessary - if ( y1 > ymax ) { - clipped_v1 = FIND_SCALED_NUM(ymax,y0,y1,v0,v1); - clipped_y1 = ymax; - } - - dx0 = fl2i(clipped_x0); dx1 = fl2i(clipped_x1); - dy0 = fl2i(clipped_y0); dy1 = fl2i(clipped_y1); - - if (dx1<=dx0) return; - if (dy1<=dy0) return; - - //============= DRAW IT ===================== - int u, v, du, dv; - int y, w; - ubyte * sbits, * dbits; - bitmap * bp; - ubyte * spixels; - float tmpu, tmpv; - - tmpu = (clipped_u1-clipped_u0) / (dx1-dx0); - if ( fl_abs(tmpu) < MIN_SCALE_FACTOR ) { - return; // scaled up way too far! - } - tmpv = (clipped_v1-clipped_v0) / (dy1-dy0); - if ( fl_abs(tmpv) < MIN_SCALE_FACTOR ) { - return; // scaled up way too far! - } - - bp = bm_lock( gr_screen.current_bitmap, 8, BMP_AABITMAP ); - - du = fl2f(tmpu*(bp->w-1)); - dv = fl2f(tmpv*(bp->h-1)); - - v = fl2f(clipped_v0*(bp->h-1)); - u = fl2f(clipped_u0*(bp->w-1)); - w = dx1 - dx0 + 1; - -#ifdef USE_COMPILED_CODE - ubyte *cc; - - if ( Gr_scaler_zbuffering && gr_zbuffering ) { - //cc = scaler_create_compiled_code8_alpha_zbuffered( w, u, du ); - } else { - cc = scaler_create_compiled_code8_alpha( w, u, du ); - } - -#endif - - spixels = (ubyte *)bp->data; - - gr_lock(); - - uint fx_w = 0; - if ( Gr_scaler_zbuffering && gr_zbuffering ) { - fx_w = (uint)fl2i(va->sw * GR_Z_RANGE)+gr_zoffset; - } - - for (y=dy0; y<=dy1; y++ ) { - sbits = &spixels[bp->rowsize*(v>>16)]; - dbits = GR_SCREEN_PTR(ubyte,dx0,y); - -#ifdef USE_COMPILED_CODE - // uint lookup = (uint)&Current_alphacolor->table.lookup[0][0]; - //uint lookup = (uint)&old_alphac.table.lookup[0][0]; // Unused - DDOI - - // Call the compiled code to draw one scanline - if ( Gr_scaler_zbuffering && gr_zbuffering ) { - int x, tmp_u; - tmp_u = u; - - uint *zbuf = (uint *)&gr_zbuffer[(uint)dbits-(uint)Tmap.pScreenBits]; - - for (x=0; x *zbuf ) { - // uint c = sbits[ tmp_u >> 16 ]; - // *dbits = Current_alphacolor->table.lookup[c][*dbits]; - *dbits = (ubyte)0x00; - } - zbuf++; - dbits++; - tmp_u += du; - } - } else { -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm push esi - _asm push edi - _asm push ecx - _asm push ebx - _asm push eax - _asm mov ecx, lookup - _asm mov esi, sbits - _asm mov edi, dbits - _asm mov eax, cc - _asm call eax - _asm pop eax - _asm pop ebx - _asm pop ecx - _asm pop edi - _asm pop esi -#endif - } -#else - if ( Gr_scaler_zbuffering && gr_zbuffering ) { - int x, tmp_u; - tmp_u = u; - - uint *zbuf = (uint *)&gr_zbuffer[(uint)dbits-(uint)Tmap.pScreenBits]; - - for (x=0; x *zbuf ) { - uint c = sbits[ tmp_u >> 16 ]; - *dbits = Current_alphacolor->table.lookup[c][*dbits]; - } - zbuf++; - dbits++; - tmp_u += du; - } - } else { - int x, tmp_u; - tmp_u = u; - for (x=0; x> 16 ]; - *dbits = Current_alphacolor->table.lookup[c][*dbits]; - dbits++; - tmp_u += du; - } - } -#endif - v += dv; - } - - gr_unlock(); - - bm_unlock(gr_screen.current_bitmap); -} - diff --git a/src/graphics/shade.cpp b/src/graphics/shade.cpp deleted file mode 100644 index 4eb7e94..0000000 --- a/src/graphics/shade.cpp +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/Shade.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Routines to shade an area. - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:18 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 19 3/12/98 5:36p John - * Took out any unused shaders. Made shader code take rgbc instead of - * matrix and vector since noone used it like a matrix and it would have - * been impossible to do in hardware. Made Glide implement a basic - * shader for online help. - * - * 18 3/10/98 4:19p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 17 11/30/97 12:18p John - * added more 24 & 32-bpp primitives - * - * 16 10/19/97 12:55p John - * new code to lock / unlock surfaces for smooth directx integration. - * - * 15 10/09/97 5:23p John - * Added support for more 16-bpp functions - * - * 14 10/03/97 12:16p John - * optimized the shader. About 50% faster. - * - * 13 10/03/97 9:10a John - * added better antialiased line drawer - * - * 12 9/09/97 10:41a Sandeep - * fixed warning level 4 - * - * 11 6/18/97 12:07p John - * fixed some color bugs - * - * 10 6/17/97 7:04p John - * added d3d support for gradients. - * fixed some color bugs by adding screen signatures instead of watching - * flags and palette changes. - * - * 9 5/28/97 8:59a John - * Fixed bug with shader not working when switching to fullscreen. - * - * 8 5/12/97 12:27p John - * Restructured Graphics Library to add support for multiple renderers. - * - * 7 11/19/96 2:44p Allender - * fix up shader for 15 bpp - * - * 6 11/18/96 2:27p Allender - * made faster hacked version of shader for 16 bits - * - * 5 11/18/96 1:48p Allender - * added 16 bit version of (very slow) shader - * - * 4 11/15/96 3:34p Allender - * started on 16 bit support for the shader - * - * 3 10/26/96 1:40p John - * Added some now primitives to the 2d library and - * cleaned up some old ones. - * - * $NoKeywords: $ - */ - -#include "2d.h" -#include "grinternal.h" -#include "floating.h" -#include "line.h" -#include "palman.h" - -void grx_create_shader(shader * shade, float r, float g, float b, float c ) -{ - int i; - float Sr, Sg, Sb; - float Dr, Dg, Db; - int ri, gi, bi; - - shade->screen_sig = gr_screen.signature; - shade->r = r; - shade->g = g; - shade->b = b; - shade->c = c; - - for (i=0; i<256; i++ ) { - Sr = i2fl( gr_palette[i*3+0] ); - Sg = i2fl( gr_palette[i*3+1] ); - Sb = i2fl( gr_palette[i*3+2] ); - Dr = Sr*r + Sg*r + Sb*r + c*256.0f; - Dg = Sr*g + Sg*g + Sb*g + c*256.0f; - Db = Sr*b + Sg*b + Sb*b + c*256.0f; - ri = fl2i(Dr); if ( ri < 0 ) ri = 0; else if (ri>255) ri = 255; - gi = fl2i(Dg); if ( gi < 0 ) gi = 0; else if (gi>255) gi = 255; - bi = fl2i(Db); if ( bi < 0 ) bi = 0; else if (bi>255) bi = 255; - shade->lookup[i] = (unsigned char)(palette_find(ri,gi,bi)); - } - -} - -void grx_set_shader( shader * shade ) -{ - if ( shade ) { - if (shade->screen_sig != gr_screen.signature) { - gr_create_shader( shade, shade->r, shade->g, shade->b, shade->c ); - } - gr_screen.current_shader = *shade; - } else { - gr_create_shader( &gr_screen.current_shader, 0.0f, 0.0f, 0.0f, 0.0f ); - } -} - - -void gr8_shade(int x,int y,int w,int h) -{ - int x1, y1, x2, y2; - ubyte *xlat_table; - - x1 = x; - if (x1 < gr_screen.clip_left) x1 = gr_screen.clip_left; - if (x1 > gr_screen.clip_right) x1 = gr_screen.clip_right; - - x2 = x+w-1; - if (x2 < gr_screen.clip_left) x2 = gr_screen.clip_left; - if (x2 > gr_screen.clip_right) x2 = gr_screen.clip_right; - - y1 = y; - if (y1 < gr_screen.clip_top) y1 = gr_screen.clip_top; - if (y1 > gr_screen.clip_bottom) y1 = gr_screen.clip_bottom; - - y2 = y+h-1; - if (y2 < gr_screen.clip_top) y2 = gr_screen.clip_top; - if (y2 > gr_screen.clip_bottom) y2 = gr_screen.clip_bottom; - - w = x2 - x1 + 1; - if ( w < 1 ) return; - - h = y2 - y1 + 1; - if ( h < 1 ) return; - - int i; - xlat_table = gr_screen.current_shader.lookup; - - gr_lock(); - - for (i=0; i 0 ) { -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm push eax - _asm push ebx - _asm push ecx - _asm push edx - _asm push edi - _asm push esi - _asm mov esi, xlat_table - _asm mov edi, dp - _asm mov edi, dp - _asm mov ecx, wd4 - _asm mov eax, 0 - _asm mov ebx, 0 - _asm mov edx, 0 - - NextPixel: - _asm mov eax, [edi] - - _asm mov dl, al - _asm mov bl, ah - - _asm add edi, 4 - - _asm mov al, [edx+esi] - _asm mov ah, [ebx+esi] - - _asm ror eax, 16 - - _asm mov dl, al - _asm mov bl, ah - - _asm mov al, [edx+esi] - _asm mov ah, [ebx+esi] - - _asm ror eax, 16 - - _asm mov [edi-4], eax - - _asm dec ecx - _asm jnz NextPixel - - - _asm mov dp, edi - - _asm pop esi - _asm pop edi - _asm pop edx - _asm pop ecx - _asm pop ebx - _asm pop eax -#endif - } - - for (int j=0; j 255 ) v = 255; - rgbtable1[i] = v; - rgbtable2[i] = v<<8; - rgbtable3[i] = v<<16; - } -} - - -void asm_tmap_scanline_lln(); -void asm_tmap_scanline_lln_tiled(); - -void tmapscan_lln8( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - Tmap1.dest_row_data = GR_SCREEN_PTR(ubyte,lx,y); - Tmap1.loop_count = rx - lx; - Tmap1.pixptr = (unsigned char *)tmap_bitmap->data; - Tmap1.bp = tmap_bitmap; - Tmap1.src_offset = tmap_bitmap->w; - - Tmap1.fx_u = fl2f(p->u); - Tmap1.fx_v = fl2f(p->v); - Tmap1.fx_l = fl2f(p->l*32.0); - Tmap1.fx_dl_dx = fl2f(dp->l*32.0); - Tmap1.fx_du_dx = fl2f(dp->u); - Tmap1.fx_dv_dx = fl2f(dp->v); - Tmap1.fx_u_right = fl2f(rp->u); - Tmap1.fx_v_right = fl2f(rp->v); - - asm_tmap_scanline_lln(); -} - -extern void asm_tmap_scanline_lnt(); - -void tmapscan_lnt8( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - Tmap1.dest_row_data = GR_SCREEN_PTR(ubyte,lx,y); - Tmap1.loop_count = rx - lx; - Tmap1.pixptr = (unsigned char *)tmap_bitmap->data; - Tmap1.bp = tmap_bitmap; - Tmap1.src_offset = tmap_bitmap->w; - - Tmap1.fx_u = fl2f(p->u); - Tmap1.fx_v = fl2f(p->v); - Tmap1.fx_du_dx = fl2f(dp->u); - Tmap1.fx_dv_dx = fl2f(dp->v); - Tmap1.fx_u_right = fl2f(rp->u); - Tmap1.fx_v_right = fl2f(rp->v); - - asm_tmap_scanline_lnt(); -} - -extern void asm_tmap_scanline_lnn(); - -void tmapscan_lnn8( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - Tmap1.dest_row_data = GR_SCREEN_PTR(ubyte,lx,y); - Tmap1.loop_count = rx - lx; - Tmap1.pixptr = (unsigned char *)tmap_bitmap->data; - Tmap1.bp = tmap_bitmap; - Tmap1.src_offset = tmap_bitmap->w; - - Tmap1.fx_u = fl2f(p->u); - Tmap1.fx_v = fl2f(p->v); - Tmap1.fx_du_dx = fl2f(dp->u); - Tmap1.fx_dv_dx = fl2f(dp->v); - Tmap1.fx_u_right = fl2f(rp->u); - Tmap1.fx_v_right = fl2f(rp->v); - - asm_tmap_scanline_lnn(); -} - - -void tmapscan_lln8_tiled( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - Tmap1.dest_row_data = GR_SCREEN_PTR(ubyte,lx,y); - Tmap1.loop_count = rx - lx; - Tmap1.fx_u = fl2f(p->u); - Tmap1.fx_v = fl2f(p->v); - Tmap1.fx_l = fl2f(p->l*32.0); - Tmap1.fx_du_dx = fl2f(dp->u); - Tmap1.fx_dv_dx = fl2f(dp->v); - Tmap1.fx_dl_dx = fl2f(dp->l*32.0); - Tmap1.fx_u_right = fl2f(rp->u); - Tmap1.fx_v_right = fl2f(rp->v); - Tmap1.pixptr = (unsigned char *)tmap_bitmap->data; - Tmap1.bp = tmap_bitmap; - Tmap1.src_offset = tmap_bitmap->w; - - Tmap1.BitmapWidth = tmap_bitmap->w; - Tmap1.BitmapHeight = tmap_bitmap->h; - - -// asm_tmap_scanline_lln_tiled(); - - -} - - - -void c_tmap_scanline_per_sub_new(); - -void tmapscan_pln8( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - Tmap1.dest_row_data = GR_SCREEN_PTR(ubyte,lx,y); - Tmap1.loop_count = rx - lx; - Tmap1.fx_l = fl2f(p->l*32.0); - Tmap1.fx_dl_dx = fl2f(dp->l*32.0); - - Tmap1.UOverZ = p->u; - Tmap1.VOverZ = p->v; - Tmap1.OneOverZ = p->sw; - - Tmap1.dUOverZdX8 = dp->u*32.0f; - Tmap1.dVOverZdX8 = dp->v*32.0f; - Tmap1.dOneOverZdX8 = dp->sw*32.0f; - - Tmap1.dUOverZdX = dp->u; - Tmap1.dVOverZdX = dp->v; - Tmap1.dOneOverZdX = dp->sw; - - Tmap1.RightUOverZ = rp->u; - Tmap1.RightVOverZ = rp->v; - Tmap1.RightOneOverZ = rp->sw; - - if ( Tmap1.fx_dl_dx < 0 ) { - Tmap1.fx_dl_dx = -Tmap1.fx_dl_dx; - Tmap1.fx_l = (67*F1_0)-Tmap1.fx_l; - Tmap1.fx_l_right = (67*F1_0)-Tmap1.fx_l_right; -// return; -// SDL_assert( Tmap1.fx_l > 31*F1_0 ); -// SDL_assert( Tmap1.fx_l < 66*F1_0 ); -// SDL_assert( Tmap1.fx_dl_dx >= 0 ); -// SDL_assert( Tmap1.fx_dl_dx < 31*F1_0 ); - } - -// return; - - - if (0) { - ubyte *dest, c; - int x; - fix l, dldx; - - l = Tmap1.fx_l; - dldx = Tmap1.fx_dl_dx; - dest = Tmap1.dest_row_data; - - for (x=Tmap1.loop_count; x >= 0; x-- ) { - //*dest++ = gr_fade_table[ ((l>>8)&(0xff00)) + 35 ]; - c = *dest; - *dest++ = c+1; - l += dldx; - } - return; - } - - - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - - // put the FPU in 32 bit mode - // @todo move this out of here! - - fstcw Tmap1.OldFPUCW // store copy of CW - mov ax,Tmap1.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap1.FPUCW,ax // store it - fldcw Tmap1.FPUCW // load the FPU - - mov ecx, Tmap1.loop_count // ecx = width - inc ecx - mov edi, Tmap1.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? -// jmp Return - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap1.Subdivisions,ecx // store widths - mov Tmap1.WidthModLength,eax - -// mov ebx,pLeft ; get left edge pointer -// mov edx,pGradients ; get gradients pointer - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap1.VOverZ // V/ZL - fld Tmap1.UOverZ // U/ZL V/ZL - fld Tmap1.OneOverZ // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap1.dOneOverZdX8 // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap1.dUOverZdX8 // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap1.dVOverZdX8 // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap1.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap1.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap1.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap1.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap1.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap1.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap1.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap1.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span ; st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms---->; V/ZL 1/ZL U/ZL UL VL - - fadd Tmap1.dVOverZdX8 ; V/ZR 1/ZL U/ZL UL VL - fxch st(1) ; 1/ZL V/ZR U/ZL UL VL - fadd Tmap1.dOneOverZdX8 ; 1/ZR V/ZR U/ZL UL VL - fxch st(2) ; U/ZL V/ZR 1/ZR UL VL - fadd Tmap1.dUOverZdX8 ; U/ZR V/ZR 1/ZR UL VL - fxch st(2) ; 1/ZR V/ZR U/ZR UL VL - fxch st(1) ; V/ZR 1/ZR U/ZR UL VL - - - ; set up affine registers - - ; setup delta values - - mov eax,Tmap1.DeltaV ; get v 16.16 step - mov ebx,eax ; copy it - sar eax,16 ; get v int step - shl ebx,16 ; get v frac step - mov Tmap1.DeltaVFrac,ebx ; store it - imul eax,Tmap1.src_offset ; calculate texture step for v int step - - mov ebx,Tmap1.DeltaU ; get u 16.16 step - mov ecx,ebx ; copy it - sar ebx,16 ; get u int step - shl ecx,16 ; get u frac step - mov Tmap1.DeltaUFrac,ecx ; store it - add eax,ebx ; calculate uint + vint step - mov Tmap1.UVintVfracStepVNoCarry,eax; save whole step in non-v-carry slot - add eax,Tmap1.src_offset ; calculate whole step + v carry - mov Tmap1.UVintVfracStepVCarry,eax ; save in v-carry slot - -; setup initial coordinates - mov esi,Tmap1.UFixed ; get u 16.16 fixedpoint coordinate - - mov ebx,esi ; copy it - sar esi,16 ; get integer part - shl ebx,16 ; get fractional part - - mov ecx,Tmap1.VFixed ; get v 16.16 fixedpoint coordinate - - mov edx,ecx ; copy it - sar edx,16 ; get integer part - shl ecx,16 ; get fractional part - imul edx,Tmap1.src_offset ; calc texture scanline address - add esi,edx ; calc texture offset - add esi,Tmap1.pixptr ; calc address - - mov edx,Tmap1.DeltaUFrac ; get register copy - - mov eax, Tmap1.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap1.fx_dl_dx - shl ebp, 5 //*32 - add Tmap1.fx_l, ebp - - mov ebp, Tmap1.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - - ; calculate right side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 ; 1 V/ZR 1/ZR U/ZR UL VL - fdiv st,st(2) ; ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - - mov al,[esi] // get texture pixel 0 - mov ah, bh - mov al, gr_fade_table[eax] - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry -// mov al, 0 // Uncomment this line to show divisions - mov [edi+0],al // store pixel 0 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 1 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+1],al // store pixel 1 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 2 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+2],al // store pixel 2 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 3 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+3],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+4],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+5],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+6],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+7],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+8],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+9],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+10],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+11],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+12],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+13],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+14],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+15],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+16],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+17],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+18],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+19],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+20],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+21],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+22],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+23],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+24],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+25],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - - - sbb ebp,ebp // get -1 if carry - mov [edi+26],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+27],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+28],al // store pixel 4 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 5 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+29],al // store pixel 5 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 6 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+30],al // store pixel 6 - - add ebx,edx // increment u fraction - - mov al,[esi] // get texture pixel 7 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - - mov [edi+31],al // store pixel 7 - - - - ; ************** Okay to Access Stack Frame **************** - ; ************** Okay to Access Stack Frame **************** - ; ************** Okay to Access Stack Frame **************** - - - ; the fdiv is done, finish right ; st0 st1 st2 st3 st4 st5 st6 st7 - ; ZR V/ZR 1/ZR U/ZR UL VL - - fld st ; ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) ; VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) ; ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) ; UR VR V/ZR 1/ZR U/ZR UL VL - - add edi,32 ; increment to next span - dec Tmap1.Subdivisions ; decrement span count - jnz SpanLoop ; loop back - - // save new lighting values -// xor eax, eax -// mov ax, bx -// mov Tmap1.fx_l, eax - -// xor eax, eax -// mov ax, dx -// mov Tmap1.fx_dl_dx, eax - -HandleLeftoverPixels: -// jmp FPUReturn - - mov esi,Tmap1.pixptr ; load texture pointer - - ; edi = dest dib bits - ; esi = current texture dib bits - ; at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - ; inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap1.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - ; convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap1.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap1.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap1.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap1.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap1.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas - - ; calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - ; r -> R+1 - - ; @todo rearrange things so we don't need these two instructions - fstp Tmap1.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap1.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap1.RightVOverZ ; V/Zr inv. inv. inv. UL VL - fsub Tmap1.dVOverZdX ; V/ZR inv. inv. inv. UL VL - fld Tmap1.RightUOverZ ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap1.dUOverZdX ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap1.RightOneOverZ ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap1.dOneOverZdX ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap1.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - ; calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap1.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap1.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap1.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap1.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap1.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap1.DeltaU ; inv. inv. inv. UR VR - - ; @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - -//jmp OldWay - - - ; setup delta values - mov eax, Tmap1.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap1.DeltaVFrac, ebx // store it - imul eax, Tmap1.src_offset // calc texture step for v int step - - mov ebx, Tmap1.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap1.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap1.UVintVfracStepVNoCarry, eax // save whole step in non-v-carry slot - add eax, Tmap1.src_offset // calc whole step + v carry - mov Tmap1.UVintVfracStepVCarry, eax // save in v-carry slot - - - -OnePixelSpan: - -/* -; check coordinate ranges - mov eax, Tmap1.UFixed - cmp eax, Tmap1.MinUFixed - jge UNotTooSmall_2 - mov eax, Tmap1.MinUFixed - mov Tmap1.UFixed, eax - jmp CheckV_2 -UNotTooSmall_2: - cmp eax, Tmap1.MaxUFixed - jle CheckV_2 - mov eax, Tmap1.MaxUFixed - mov Tmap1.UFixed, eax -CheckV_2: - mov eax, Tmap1.VFixed - cmp eax, Tmap1.MinVFixed - jge VNotTooSmall_2 - mov eax, Tmap1.MinVFixed - mov Tmap1.VFixed, eax - jmp DoneCheck_2 -VNotTooSmall_2: - cmp eax, Tmap1.MaxVFixed - jle DoneCheck_2 - mov eax, Tmap1.MaxVFixed - mov Tmap1.VFixed, eax -DoneCheck_2: -*/ - - - - - ; setup initial coordinates - mov esi, Tmap1.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap1.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap1.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap1.pixptr // calc address - - ; set edi = address of first pixel to modify -; mov edi, Tmap1.dest_row_data - - - - - mov eax, Tmap1.fx_l - shr eax, 8 - mov bx, ax - - mov edx, Tmap1.DeltaUFrac - - cmp Tmap1.WidthModLength, 1 - jle NoDeltaLight - - push ebx - - mov ebx, Tmap1.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - -#if 0 - // slow but maybe better - push edx - cdq - mov ebx, Tmap1.WidthModLength - dec ebx - idiv ebx - pop edx -#else - mov eax, Tmap1.fx_dl_dx - shr eax, 8 -#endif - - mov dx, ax - - pop ebx - -NoDeltaLight: - - inc Tmap1.WidthModLength - mov eax,Tmap1.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap1.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -NextPixel: - mov al,[esi] // get texture pixel 0 - mov ah, bh - mov al, gr_fade_table[eax] - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov [edi+0],al // store pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 1 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov [edi+1],al // store pixel 1 - - add edi, 2 - dec Tmap1.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - - mov al,[esi] // get texture pixel 2 - mov ah, bh - mov al, gr_fade_table[eax] - mov [edi],al // store pixel 2 - - - - - - - - - - - - - -/* -OldWay: // This is 6% slower than above - - mov ebx,Tmap1.UFixed ; get starting coordinates - mov ecx,Tmap1.VFixed ; for span - - ; leftover pixels loop - ; edi = dest dib bits - ; esi = texture dib bits - - ; ebx = u 16.16 - ; ecx = v 16.16 - - - mov eax,ecx ; copy v - sar eax,16 ; int(v) - imul eax,Tmap1.src_offset ; scan offset - mov edx,ebx ; copy u - sar edx,16 ; int(u) - add eax,edx ; texture offset - mov al,[esi+eax] ; get source pixel -mov al, 0 - mov [edi],al ; store it - inc edi - add ebx,Tmap1.DeltaU ; increment u coordinate - add ecx,Tmap1.DeltaV ; increment v coordinate - - dec Tmap1.WidthModLength ; decrement loop count - jl FPUReturn ; finish up - - -LeftoverLoop: - mov eax,ecx ; copy v - sar eax,16 ; int(v) - imul eax,Tmap1.src_offset ; scan offset - mov edx,ebx ; copy u - sar edx,16 ; int(u) - add eax,edx ; texture offset - mov al,[esi+eax] ; get source pixel - mov [edi],al ; store it - inc edi - add ebx,Tmap1.DeltaU ; increment u coordinate - add ecx,Tmap1.DeltaV ; increment v coordinate - - dec Tmap1.WidthModLength ; decrement loop count - jge LeftoverLoop ; finish up -*/ - -FPUReturn: - - ; busy FPU registers: ; st0 st1 st2 st3 st4 st5 st6 st7 - ; xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap1.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } - - -} - - -void tmapscan_lln8_old( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - _fx_srcptr = (uint)tmap_bitmap->data; - _fx_destptr = (uint)GR_SCREEN_PTR(ubyte,lx,y); - _loop_count = rx - lx; - _fx_u = fl2f(p->u*64.0f); - _fx_v = fl2f(p->v*64.0f); - _fx_l = fl2f(p->l*32.0+1.0); - _fx_du = fl2f(dp->u*64.0f); - _fx_dv = fl2f(dp->v*64.0f); - _fx_dl = fl2f(dp->l*32.0); - light_table = (uint)&gr_fade_table[0]; - - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; set edi = address of first pixel to modify - mov edi, _fx_destptr - - - mov eax, _fx_v - shr eax, 6 - mov edx, _fx_u - shl edx, 10 - mov dx, ax ; EDX=U:V in 6.10 format - - mov eax, _fx_dv - shr eax, 6 - mov esi, _fx_du - shl esi, 10 - mov si, ax ; ESI=DU:DV in 6.10 format - - mov ebx, _fx_l - sar ebx, 8 - mov ebp, _fx_dl - sar ebp, 8 - - mov ecx, _fx_srcptr - - mov eax, _loop_count - inc eax - mov _loop_count, eax - - shr eax, 3 - je DoLeftOverPixels - - mov num_big_steps, eax - and _loop_count, 7 - -NextPixelBlock: - ; pixel 0 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+0], al - - ; pixel 1 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+1], al - - ; pixel 2 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+2], al - - ; pixel 3 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+3], al - - ; pixel 4 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+4], al - - ; pixel 5 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+5], al - - ; pixel 6 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+6], al - - ; pixel 7 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+7], al - - add edi, 8 - dec num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - mov eax,_loop_count - test eax, -1 - jz _none_to_do - shr eax, 1 - je one_more_pix - mov _loop_count, eax - pushf - - -NextPixel: - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+0], al - - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+1], al - - - add edi, 2 - dec _loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - mov al, [ecx+eax] - mov ah, bh - mov al, gr_fade_table[eax] - mov [edi], al - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } - - -} - - -void tmapscan_flat16( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - int i; - ushort *pDestBits; - - pDestBits = GR_SCREEN_PTR(ushort,lx,y); - - for (i=0; i<(rx-lx+1); i++ ) - *pDestBits++ = gr_screen.current_color.raw16; -} - -float tmap_max_z = 0.0f; - -void tmapscan_lln8_z( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - int count; - ubyte *pDestBits, tmp; - float u, dudx, v, dvdx, l, dldx; - float z, dzdx; - - pDestBits = GR_SCREEN_PTR(ubyte,lx,y); - - ubyte * cdata = (ubyte *)tmap_bitmap->data; - - u = p->u; - v = p->v; - l = p->l*32.0f; - z = p->nz; - dudx = dp->u; - dvdx = dp->v; - dldx = dp->l*32.0f; - dzdx = dp->nz; - - for ( count = rx - lx + 1 ; count > 0; count-- ) { - if ( z < tmap_max_z ) { - tmp = cdata[fl2i(v)*tmap_bitmap->w+fl2i(u)]; - *pDestBits = gr_fade_table[ fl2i(l)*256+tmp ]; - } - pDestBits++; - u += dudx; - v += dvdx; - l += dldx; - z += dzdx; - } -} - - -void tmapscan_generic8( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - int count; - ubyte *pDestBits, tmp; - int u, dudx, v, dvdx, w, dwdx, l, dldx; - - pDestBits = GR_SCREEN_PTR(ubyte,lx,y); - - if ( Tmap1.flags & TMAP_FLAG_TEXTURED ) { - ubyte * cdata = (ubyte *)tmap_bitmap->data; - if ( flags & TMAP_FLAG_RAMP ) { - if ( Tmap1.flags & TMAP_FLAG_CORRECT ) { - float fu, fv, fw, fdu, fdv, fdw; - - tmapscan_pln8( lx, rx, y, p, dp, rp,Tmap1.flags ); - return; - - - fu = p->u; - fv = p->v; - fw = p->sw; - l = fl2f(p->l*32.0f); - - fdu = dp->u; - fdv = dp->v; - fdw = dp->sw; - dldx = fl2f(dp->l*32.0f); - - for ( count = rx - lx + 1 ; count > 0; count-- ) { - u = fl2i(fu/fw); - v = fl2i(fv/fw); - tmp = cdata[v*tmap_bitmap->w+u]; - *pDestBits++ = tmp; //gr_fade_table[ (l>>16)*256+tmp ]; - //tmp = *pDestBits; - //*pDestBits++ = tmp+1; - fu += fdu; - fv += fdv; - fw += fdw; - l += dldx; - } - - } else { -#if 1 - tmapscan_lln8( lx, rx, y, p, dp, rp, flags ); -#else - u = fl2f(p->u*64.0f); - v = fl2f(p->v*64.0f); - l = fl2f(p->l*32.0f); - dudx = fl2f(dp->u*64.0f); - dvdx = fl2f(dp->v*64.0f); - dldx = fl2f(dp->l*32.0f); - - for ( count = rx - lx + 1 ; count > 0; count-- ) { - - //tmp = cdata[((v>>16)&63)*64+((u>>16)&63)]; - //*pDestBits++ = ;//gr_fade_table[ (l>>16)*256+tmp ]; - (*pDestBits)++; - pDestBits++; - u += dudx; - v += dvdx; - l += dldx; - } -#endif - } - } else { - if ( flags & TMAP_FLAG_CORRECT ) { - u = fl2f(p->u*64.0f); - v = fl2f(p->v*64.0f); - w = fl2f(p->sw*16.0f); - - dudx = fl2f(dp->u*64.0f); - dvdx = fl2f(dp->v*64.0f); - dwdx = fl2f(dp->sw*16.0f); - - for ( count = rx - lx + 1 ; count > 0; count-- ) { - tmp = cdata[((v/w)&63)*64+((u/w)&63)]; - *pDestBits++ = tmp; - u += dudx; - v += dvdx; - w += dwdx; - } - } else { - u = fl2f(p->u*64.0f); - v = fl2f(p->v*64.0f); - dudx = fl2f(dp->u*64.0f); - dvdx = fl2f(dp->v*64.0f); - - for ( count = rx - lx + 1 ; count > 0; count-- ) { - tmp = cdata[((v>>16)&63)*64+((u>>16)&63)]; - *pDestBits++ = tmp; - u += dudx; - v += dvdx; - } - } - } - } else { - if ( Tmap1.flags & TMAP_FLAG_RAMP ) { - l = fl2f(p->l*32.0f); - dldx = fl2f(dp->l*32.0f); - - for ( count = rx - lx + 1 ; count > 0; count-- ) { - *pDestBits++ = gr_fade_table[ (l>>16)*256+gr_screen.current_color.raw8 ]; - l += dldx; - } - } else { - memset( pDestBits, gr_screen.current_color.raw8, (rx-lx+1) ); - } - } -} - -uint testpixel; -uint fsave_area[64]; - -unsigned __int64 packrgb( int r, int g, int b ) -{ - unsigned __int64 tmp; - unsigned int *tmps; - - tmp = 0; - - tmps = (unsigned int *)&r; - tmp |= *tmps & 0xFFFF; - tmp <<= 16; - - tmps = (unsigned int *)&g; - tmp |= *tmps & 0xFFFF; - tmp <<= 16; - - tmps = (unsigned int *)&b; - tmp |= *tmps & 0xFFFF; - - return tmp; -} - - - -void tmapscan_generic( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - int count; - uint *pDestBits, tmp, tmp1; - int u, dudx, v, dvdx, w, dwdx; - int r, g, b, dr, dg, db; - - if ( !rgbtable_inited ) - rgbtable_init(); - - pDestBits = GR_SCREEN_PTR(uint,lx,y); - - if ( Tmap1.flags & TMAP_FLAG_TEXTURED ) { - uint * cdata = (uint *)tmap_bitmap->data; - - if ( Tmap1.flags & TMAP_FLAG_GOURAUD ) { - if ( Tmap1.flags & TMAP_FLAG_CORRECT ) { - u = fl2f(p->u*64.0f); - v = fl2f(p->v*64.0f); - w = fl2f(p->sw); - - r = fl2f(p->r*255.0f); - g = fl2f(p->g*255.0f); - b = fl2f(p->b*255.0f); - - dr = fl2f(dp->r*255.0f); - dg = fl2f(dp->g*255.0f); - db = fl2f(dp->b*255.0f); - - dudx = fl2f(dp->u*64.0f); - dvdx = fl2f(dp->v*64.0f); - dwdx = fl2f(dp->sw); - - for ( count = rx - lx + 1 ; count > 0; count-- ) { - tmp = cdata[((v/w)&63)*64+((u/w)&63)]; - tmp1 = rgbtable1[ (tmp & 0xFF)+ (b>>16) ]; - tmp1 |= rgbtable2[ ((tmp>>8) & 0xFF)+ (g>>16) ]; - tmp1 |= rgbtable3[ ((tmp>>16) & 0xFF)+ (r>>16) ]; - *pDestBits++ = tmp1; - u += dudx; - v += dvdx; - w += dwdx; - r += dr; - g += dg; - b += db; - } - } else { - // MMX!!! - __int64 light, deltalight; - - u = fl2f(p->u*64.0f); - v = fl2f(p->v*64.0f); - dudx = fl2f(dp->u*64.0f); - dvdx = fl2f(dp->v*64.0f); - -#if 0 - r = fl2f(p->r*255.0f)>>8; - g = fl2f(p->g*255.0f)>>8; - b = fl2f(p->b*255.0f)>>8; - - dr = fl2f(dp->r*255.0f)>>8; - dg = fl2f(dp->g*255.0f)>>8; - db = fl2f(dp->b*255.0f)>>8; -#else - r = fl2f(p->r)>>7; - g = fl2f(p->g)>>7; - b = fl2f(p->b)>>7; - - dr = fl2f(dp->r)>>7; - dg = fl2f(dp->g)>>7; - db = fl2f(dp->b)>>7; - - //r = 256*2; - //g = 256*2; - //b = 256*2; - //dr = dg = db = 0; -#endif - - light = packrgb( r, g, b ); - deltalight = packrgb( dr, dg, db ); - - _asm fstenv fsave_area - _asm movq mm3, light - _asm movq mm4, deltalight - _asm pxor mm2, mm2 ; mm0 = 0 - - for ( count = rx - lx + 1 ; count > 0; count-- ) { - testpixel = cdata[((v>>16)&63)*64+((u>>16)&63)]; - - _asm punpcklbw mm2, testpixel ; mm0 = 8.8,8.8, 8.8 rgb - _asm pmulhw mm2, mm3 ; - _asm paddsw mm3, mm4 ; light += deltalight - _asm packuswb mm2, mm2 ;mm2 is who cares - _asm movd testpixel, mm2 ; load tmp - _asm pxor mm2, mm2 ; mm0 = 0 - - *pDestBits++ = testpixel; - u += dudx; - v += dvdx; - } - _asm emms - _asm frstor fsave_area - } - } else { - if ( Tmap1.flags & TMAP_FLAG_CORRECT ) { - u = fl2f(p->u*64.0f); - v = fl2f(p->v*64.0f); - w = fl2f(p->sw); - dudx = fl2f(dp->u*64.0f); - dvdx = fl2f(dp->v*64.0f); - dwdx = fl2f(dp->sw); - - for ( count = rx - lx + 1 ; count > 0; count-- ) { - *pDestBits++ = cdata[((v/w)&63)*64+((u/w)&63)]; - u += dudx; - v += dvdx; - w += dwdx; - } - } else { - u = fl2f(p->u*64.0f); - v = fl2f(p->v*64.0f); - dudx = fl2f(dp->u*64.0f); - dvdx = fl2f(dp->v*64.0f); - - for ( count = rx - lx + 1 ; count > 0; count-- ) { - *pDestBits++ = cdata[((v>>16)&63)*64+((u>>16)&63)]; - u += dudx; - v += dvdx; - } - } - } - } else if ( Tmap1.flags & TMAP_FLAG_GOURAUD ) { - - r = fl2f(p->r*255.0f); - g = fl2f(p->g*255.0f); - b = fl2f(p->b*255.0f); - - dr = fl2f(dp->r*255.0f); - dg = fl2f(dp->g*255.0f); - db = fl2f(dp->b*255.0f); - - for ( count = rx - lx + 1 ; count > 0; count-- ) { - *pDestBits++ = (r&0xFF0000)|((g>>8)&0xFF00)|(b>>16); - r += dr; - g += dg; - b += db; - //*pDestBits++ = 100; - } - } else { - memset( pDestBits, gr_screen.current_color.raw32, (rx-lx+1)*4 ); - } -} - -void tmapscan_flat( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - int w; - uint *pDestBits; - - pDestBits = GR_SCREEN_PTR(uint,lx,y); - w = (rx-lx+1); -#ifdef USE_INLINE_ASM - _asm mov eax, gr_screen.current_color.raw32 - _asm mov ecx, w - _asm mov edi, pDestBits - _asm cld - _asm rep stosd -#else - for (i=0; iz; - dz = dp->z; -//#ifdef USE_INLINE_ASM -#if 0 - _asm mov eax, gr_screen.current_color.raw32 - _asm mov ecx, w - _asm mov edi, pDestBits - _asm cld - _asm rep stosd -#else - { int i; - for (i=0; idata; - _fx_destptr = (uint)GR_SCREEN_PTR(uint,lx,y); - _loop_count = rx - lx; - _fx_u = fl2f(p->u*64.0f); - _fx_v = fl2f(p->v*64.0f); - _fx_w = fl2f(p->sw*16.0); - _fx_du = fl2f(dp->u*64.0f); - _fx_dv = fl2f(dp->v*64.0f); - _fx_dw = fl2f(dp->sw*16.0); - - _fx_u_right = fl2f(rp->u*64.0f); - _fx_v_right = fl2f(rp->v*64.0f); - _fx_w_right = fl2f(rp->sw*16.0); - - r = fl2f(p->r)>>7; - g = fl2f(p->g)>>7; - b = fl2f(p->b)>>7; - - dr = fl2f(dp->r)>>7; - dg = fl2f(dp->g)>>7; - db = fl2f(dp->b)>>7; - - light = ((__int64)r<<32)|((__int64)g<<16)|(__int64)b; - deltalight = ((__int64)dr<<32)|((__int64)dg<<16)|(__int64)db; - - _asm fstenv fsave_area1 - _asm movq mm3, light - _asm movq mm4, deltalight - - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - mov ebx,_fx_u - mov ebp,_fx_v - mov ecx,_fx_w - mov edi,_fx_destptr - -; compute initial v coordinate - mov eax,ebp ; get v - mov edx,eax - sar edx,16 - shl eax,16 - idiv ecx ; eax = (v/z) - mov V0, eax - -; compute initial u coordinate - mov eax,ebx ; get u - mov edx,eax - sar edx,16 - shl eax,16 - idiv ecx ; eax = (v/z) - mov U0, eax - - mov ecx, _fx_w - -; find number of subdivisions - mov eax, _loop_count - inc eax - mov esi, eax - and esi, 15 - sar eax, NBITS - mov num_left_over, esi - jz DoEndPixels ;there are no 2^NBITS chunks, do divide/pixel for whole scanline - mov _loop_count, eax - -; Set deltas to NPIXS pixel increments - mov eax, _fx_du - shl eax, NBITS - mov DU1, eax - mov eax, _fx_dv - shl eax, NBITS - mov DV1, eax - mov eax, _fx_dw - shl eax, NBITS - mov DZ1, eax - - align 4 -TopOfLoop4: - add ebx, DU1 - add ebp, DV1 - add ecx, DZ1 - -; Done with ebx, ebp, ecx until next iteration - push ebx - push ecx - push ebp - push edi - - -; Find fixed U1 - mov eax, ebx - mov edx,eax - sar edx,16 - shl eax,16 - idiv ecx ; eax = (v/z) - mov ebx, eax ; ebx = U1 until pop's - -; Find fixed V1 - mov eax, ebp - mov edx,eax - sar edx,16 - shl eax,16 - idiv ecx ; eax = (v/z) - mov ebp, eax ; ebx = V1 until pop's - -; Get last correct U,Vs - mov ecx, U0 ; ecx = U0 until pop's - mov edi, V0 ; edi = V0 until pop's - -; Make ESI = V0:U0 in 6:10,6:10 format - mov eax, edi - shr eax, 6 - mov esi, ecx - shl esi, 10 - mov si, ax - -; Make EDX = DV:DU in 6:10,6:10 format - mov eax, ebp - sub eax, edi - sar eax, NBITS+6 - mov edx, ebx - sub edx, ecx - shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac - mov dx, ax ; put delta u in low word - -; Save the U1 and V1 so we don't have to divide on the next iteration - mov U0, ebx - mov V0, ebp - - pop edi ; Restore EDI before using it - - mov ecx, _fx_srcptr - mov ebx, 1 << NBITS - -PixelRun: - mov eax, esi - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add esi, edx - movd mm1, [eax*4+ecx] - pxor mm2, mm2 ; mm2 = 0 - punpcklbw mm2, mm1 ; mm0 = 8.8,8.8, 8.8 rgb - pmulhw mm2, mm3 - paddsw mm3, mm4 ; light += deltalight - packuswb mm2, mm2 ;mm2 is who cares - movd [edi], mm2 ; load tmp - add edi, 4 - dec ebx - jnz PixelRun - - pop ebp - pop ecx - pop ebx - dec _loop_count - jnz TopOfLoop4 - -;EndOfLoop4: - - test num_left_over, -1 - je _none_to_do - - cmp num_left_over, 4 - ja DoEndPixels - - ; If less than 4, then just keep interpolating without - ; calculating a new DU:DV. - mov ecx, _fx_srcptr - jmp FinishOff - -; ----------------------------------------- Start of LeftOver Pixels ------------------------------------------ -DoEndPixels: - - push edi - mov ecx, _fx_w_right - -; Find fixed U1 - mov eax, _fx_u_right - mov edx,eax - sar edx,16 - shl eax,16 - idiv ecx ; eax = (v/z) - mov ebx, eax ; ebx = U1 until pop's - -; Find fixed V1 - mov eax, _fx_v_right - mov edx,eax - sar edx,16 - shl eax,16 - idiv ecx ; eax = (v/z) - mov ebp, eax ; ebp = V1 until pop's - - mov ecx, U0 ; ecx = U0 until pop's - mov edi, V0 ; edi = V0 until pop's - -; Make EDX = DV:DU in 6:10,6:10 format - mov eax, ebx - sub eax, ecx - mov edx, eax ; These two lines are faster than cdq - sar edx, 31 - idiv num_left_over ; eax = (v1-v0)/num_left_over - shl eax, 16-6 ; go from 16.16 to 6.10, and move into high 16 bits - mov esi, eax ; esi = dvdx<<16 - - mov eax, ebp - sub eax, edi - mov edx, eax ; These two lines are faster than cdq - sar edx, 31 - idiv num_left_over ; eax = (u1-u0)/num_left_over - sar eax, 6 ; go from 16.16 to 6.10 (ax=dvdx in 6.10) - mov si, ax ; esi = dvdx:dudx - mov edx, esi - -; Make ESI = V0:U0 in 6:10,6:10 format - mov eax, edi - shr eax, 6 - mov esi, ecx - shl esi, 10 - mov si, ax - - pop edi ; Restore EDI before using it - -; LIGHTING CODE - mov ecx, _fx_srcptr - -FinishOff: - mov eax, esi - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add esi, edx -; mov eax, [eax*4+ecx] -; mov [edi],eax - movd mm1, [eax*4+ecx] - pxor mm2, mm2 ; mm2 = 0 - punpcklbw mm2, mm1 ; mm0 = 8.8,8.8, 8.8 rgb - pmulhw mm2, mm3 - paddsw mm3, mm4 ; light += deltalight - packuswb mm2, mm2 ;mm2 is who cares - movd [edi], mm2 ; load tmp - add edi, 4 - - dec num_left_over - jnz FinishOff - - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } // end asm - - _asm emms - _asm frstor fsave_area1 -} - - -void tmapscan_lln( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - __int64 light, deltalight; - int r, g, b, dr, dg, db; - _fx_srcptr = (uint)tmap_bitmap->data; - _fx_destptr = (uint)GR_SCREEN_PTR(uint,lx,y); - _loop_count = rx - lx; - _fx_u = fl2f(p->u*64.0f); - _fx_v = fl2f(p->v*64.0f); - _fx_du = fl2f(dp->u*64.0f); - _fx_dv = fl2f(dp->v*64.0f); - - r = fl2f(p->r)>>7; - g = fl2f(p->g)>>7; - b = fl2f(p->b)>>7; - - dr = fl2f(dp->r)>>7; - dg = fl2f(dp->g)>>7; - db = fl2f(dp->b)>>7; - - light = ((__int64)r<<32)|((__int64)g<<16)|(__int64)b; - deltalight = ((__int64)dr<<32)|((__int64)dg<<16)|(__int64)db; - - _asm fstenv fsave_area1 - _asm movq mm3, light - _asm movq mm4, deltalight - - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - mov ebx,_fx_u - mov ebp,_fx_v - mov edi,_fx_destptr - -; find number of subdivisions - mov eax, _loop_count - inc eax - jz none_to_do - mov _loop_count, eax - -; Make ESI = V0:U0 in 6:10,6:10 format - mov eax, edi - shr eax, 6 - mov esi, ecx - shl esi, 10 - mov si, ax - -; Make EDX = DV:DU in 6:10,6:10 format - mov eax, ebp - sub eax, edi - sar eax, NBITS+6 - mov edx, ebx - sub edx, ecx - shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac - mov dx, ax ; put delta u in low word - - mov ecx, _fx_srcptr - mov ebx, _loop_count - -PixelRun: - mov eax, esi - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add esi, edx - movd mm1, [eax*4+ecx] - pxor mm2, mm2 ; mm2 = 0 - punpcklbw mm2, mm1 ; mm0 = 8.8,8.8, 8.8 rgb - pmulhw mm2, mm3 - paddsw mm3, mm4 ; light += deltalight - packuswb mm2, mm2 ;mm2 is who cares - movd [edi], mm2 ; load tmp - add edi, 4 - dec ebx - jnz PixelRun - -none_to_do: - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } // end asm - - _asm emms - _asm frstor fsave_area1 -} - - - - -void tmapscan_pln8_tiled( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - Tmap1.dest_row_data = GR_SCREEN_PTR(ubyte,lx,y); - Tmap1.loop_count = rx - lx; - Tmap1.fx_u = fl2f(p->u); - Tmap1.fx_v = fl2f(p->v); - Tmap1.fx_du_dx = fl2f(dp->u); - Tmap1.fx_dv_dx = fl2f(dp->v); - - Tmap1.fx_l = fl2f(p->l*32.0); - Tmap1.fx_dl_dx = fl2f(dp->l*32.0); - - Tmap1.fx_u_right = fl2f(rp->u); - Tmap1.fx_v_right = fl2f(rp->v); - Tmap1.pixptr = (unsigned char *)tmap_bitmap->data; - Tmap1.bp = tmap_bitmap; - Tmap1.src_offset = tmap_bitmap->w; - - - Tmap1.FixedScale = 65536.0f; - Tmap1.FixedScale8 = 2048.0f; //8192.0f; // 2^16 / 8 - Tmap1.One = 1.0f; - - - Tmap1.UOverZ = p->u; - Tmap1.VOverZ = p->v; - Tmap1.OneOverZ = p->sw; - - Tmap1.dUOverZdX8 = dp->u*32.0f; - Tmap1.dVOverZdX8 = dp->v*32.0f; - Tmap1.dOneOverZdX8 = dp->sw*32.0f; - - Tmap1.dUOverZdX = dp->u; - Tmap1.dVOverZdX = dp->v; - Tmap1.dOneOverZdX = dp->sw; - - Tmap1.RightUOverZ = rp->u; - Tmap1.RightVOverZ = rp->v; - Tmap1.RightOneOverZ = rp->sw; - - Tmap1.BitmapWidth = Tmap1.bp->w; - Tmap1.BitmapHeight = Tmap1.bp->h; - - if (Tmap1.BitmapWidth!=64) return; - if (Tmap1.BitmapHeight!=64) return; - - - - if ( Tmap1.fx_dl_dx < 0 ) { - Tmap1.fx_dl_dx = -Tmap1.fx_dl_dx; - Tmap1.fx_l = (67*F1_0)-Tmap1.fx_l; - Tmap1.fx_l_right = (67*F1_0)-Tmap1.fx_l_right; - } - - - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - - // put the FPU in 32 bit mode - // @todo move this out of here! - - fstcw Tmap1.OldFPUCW // store copy of CW - mov ax,Tmap1.OldFPUCW // get it in ax -//hh and eax,NOT 1100000000y // 24 bit precision - and eax, ~0x300L - mov Tmap1.FPUCW,ax // store it - fldcw Tmap1.FPUCW // load the FPU - - mov ecx, Tmap1.loop_count // ecx = width - inc ecx - mov edi, Tmap1.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? -// jmp Return - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap1.Subdivisions,ecx // store widths - mov Tmap1.WidthModLength,eax - -// mov ebx,pLeft ; get left edge pointer -// mov edx,pGradients ; get gradients pointer - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap1.VOverZ // V/ZL - fld Tmap1.UOverZ // U/ZL V/ZL - fld Tmap1.OneOverZ // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap1.dOneOverZdX8 // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap1.dUOverZdX8 // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap1.dVOverZdX8 // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap1.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap1.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap1.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap1.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap1.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap1.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap1.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap1.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span ; st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms---->; V/ZL 1/ZL U/ZL UL VL - - fadd Tmap1.dVOverZdX8 ; V/ZR 1/ZL U/ZL UL VL - fxch st(1) ; 1/ZL V/ZR U/ZL UL VL - fadd Tmap1.dOneOverZdX8 ; 1/ZR V/ZR U/ZL UL VL - fxch st(2) ; U/ZL V/ZR 1/ZR UL VL - fadd Tmap1.dUOverZdX8 ; U/ZR V/ZR 1/ZR UL VL - fxch st(2) ; 1/ZR V/ZR U/ZR UL VL - fxch st(1) ; V/ZR 1/ZR U/ZR UL VL - - ; calculate right side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 ; 1 V/ZR 1/ZR U/ZR UL VL - fdiv st,st(2) ; ZR V/ZR 1/ZR U/ZR UL VL - - - ; ************** Can't Access Stack Frame ****************** - ; ************** Can't Access Stack Frame ****************** - ; ************** Can't Access Stack Frame ****************** - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - //need to have: - // eax = ? - // ebx = l in 24.8 - // ecx = source pixels - // edx = u v in 6.10 6.10 - // esi = du dv in 6.10 6.10 - // edi = dest pixels - // ebp = dldx in 24.8 - - - mov eax, Tmap1.fx_l - shr eax, 8 - mov ebx, eax - - mov ebp, Tmap1.fx_dl_dx - shl ebp, 5 //*32 - add Tmap1.fx_l, ebp - - mov ebp, Tmap1.fx_l - shr ebp, 8 - sub ebp, eax - shr ebp, 5 - - mov ecx, Tmap1.pixptr // ecx = source pixels - -; Make ESI = DV:DU in 6:10,6:10 format - mov eax, Tmap1.DeltaU - shr eax, 6 - mov esi, Tmap1.DeltaV - shl esi, 10 - mov si, ax - -; Make EDX = DV:DU in 6:10,6:10 format - - mov eax, Tmap1.UFixed - shr eax, 6 - mov edx, Tmap1.VFixed - shl edx, 10 - mov dx, ax - - ; Draw 32 pixels - - ; pixel 0 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+0], al - - ; pixel 1 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+1], al - - ; pixel 2 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+2], al - - ; pixel 3 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+3], al - - ; pixel 4 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+4], al - - ; pixel 5 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+5], al - - ; pixel 6 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+6], al - - ; pixel 7 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+7], al - - ; pixel 8 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+8], al - - ; pixel 9 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+9], al - - ; pixel 10 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+10], al - - ; pixel 11 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+11], al - - ; pixel 12 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+12], al - - ; pixel 13 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+13], al - - ; pixel 14 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+14], al - - ; pixel 15 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+15], al - - ; pixel 16 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+16], al - - ; pixel 17 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+17], al - - ; pixel 18 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+18], al - - ; pixel 19 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+19], al - - ; pixel 20 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+20], al - - ; pixel 21 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+21], al - - ; pixel 22 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+22], al - - ; pixel 23 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+23], al - - ; pixel 24 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+24], al - - ; pixel 25 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+25], al - - ; pixel 26 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+26], al - - ; pixel 27 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+27], al - - ; pixel 28 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+28], al - - ; pixel 29 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+29], al - - ; pixel 30 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+30], al - - ; pixel 31 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+31], al - - - ; ************** Okay to Access Stack Frame **************** - ; ************** Okay to Access Stack Frame **************** - ; ************** Okay to Access Stack Frame **************** - - - ; the fdiv is done, finish right ; st0 st1 st2 st3 st4 st5 st6 st7 - ; ZR V/ZR 1/ZR U/ZR UL VL - - fld st ; ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) ; VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) ; ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) ; UR VR V/ZR 1/ZR U/ZR UL VL - - add edi,32 ; increment to next span - dec Tmap1.Subdivisions ; decrement span count - jnz SpanLoop ; loop back - -HandleLeftoverPixels: - - mov esi,Tmap1.pixptr ; load texture pointer - - ; edi = dest dib bits - ; esi = current texture dib bits - ; at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - ; inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap1.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - ; convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap1.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap1.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap1.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap1.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap1.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas - - ; calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - ; r -> R+1 - - ; @todo rearrange things so we don't need these two instructions - fstp Tmap1.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap1.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap1.RightVOverZ ; V/Zr inv. inv. inv. UL VL - fsub Tmap1.dVOverZdX ; V/ZR inv. inv. inv. UL VL - fld Tmap1.RightUOverZ ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap1.dUOverZdX ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap1.RightOneOverZ ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap1.dOneOverZdX ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap1.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - ; calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap1.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap1.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap1.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap1.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap1.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap1.DeltaU ; inv. inv. inv. UR VR - - ; @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - -OnePixelSpan: - mov eax, Tmap1.fx_l - shr eax, 8 - mov ebx, eax - - mov ebp, Tmap1.fx_dl_dx - shl ebp, 5 //*32 - add Tmap1.fx_l, ebp - - mov ebp, Tmap1.fx_l - shr ebp, 8 - sub ebp, eax - shr ebp, 5 - - -; Make ESI = DV:DU in 6:10,6:10 format - mov eax, Tmap1.DeltaU - shr eax, 6 - mov esi, Tmap1.DeltaV - shl esi, 10 - mov si, ax - -; Make EDX = DV:DU in 6:10,6:10 format - - mov eax, Tmap1.UFixed - shr eax, 6 - mov edx, Tmap1.VFixed - shl edx, 10 - mov dx, ax - - mov ecx, Tmap1.pixptr // ecx = source pixels - - inc Tmap1.WidthModLength - mov eax,Tmap1.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap1.WidthModLength, eax - - -NextPixel: - - ; Draw two pixels - - ; pixel 0 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+0], al - - ; pixel 1 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+1], al - - - add edi, 2 - dec Tmap1.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - - ; Draw one pixel - ; pixel 0 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+0], al - -FPUReturn: - - ; busy FPU registers: ; st0 st1 st2 st3 st4 st5 st6 st7 - ; xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - -//Return: - - fldcw Tmap1.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } - - -} - -void c_tmap_scanline_flat() -{ - switch( gr_screen.bits_per_pixel ) { - case 8: - #if 1 - memset( Tmap1.dest_row_data, gr_screen.current_color.raw8, Tmap1.loop_count ); - #else - ubyte *dest; - int x; - - dest = Tmap1.dest_row_data; - - for (x=Tmap1.loop_count; x >= 0; x-- ) { - //(*dest)++;dest++; - *dest++ = Tmap1.tmap_flat_color; - } - #endif - break; - case 15: - case 16: - _asm mov ecx, Tmap1.loop_count - _asm mov ax, gr_screen.current_color.raw16; - _asm mov edi, Tmap1.dest_row_data16 - _asm cld - _asm rep stosw - break; - case 24: - _asm mov ecx, Tmap1.loop_count - _asm mov ax, gr_screen.current_color.raw16; - _asm mov edi, Tmap1.dest_row_data16 - _asm cld - _asm rep stosw - break; - case 32: - _asm mov ecx, Tmap1.loop_count - _asm mov eax, gr_screen.current_color.raw32; - _asm mov edi, Tmap1.dest_row_data32 - _asm cld - _asm rep stosd - break; - } - -} - -void c_tmap_scanline_shaded() -{ - int fade; - ubyte *dest; - int x; - - dest = Tmap1.dest_row_data; - - fade = Tmap1.tmap_flat_shade_value<<8; - for (x=Tmap1.loop_count; x >= 0; x-- ) { - *dest++ = gr_fade_table[ fade |(*dest)]; - } -} - -void c_tmap_scanline_lin_nolight() -{ - ubyte *dest; - uint c; - int x; - fix u,v,dudx, dvdx; - - u = Tmap1.fx_u; - v = Tmap1.fx_v*64; - dudx = Tmap1.fx_du_dx; - dvdx = Tmap1.fx_dv_dx*64; - - dest = Tmap1.dest_row_data; - - if (!Tmap1.Transparency_on) { - for (x=Tmap1.loop_count; x >= 0; x-- ) { - *dest++ = (uint)Tmap1.pixptr[ (f2i(v)&(64*63)) + (f2i(u)&63) ]; - u += dudx; - v += dvdx; - } - } else { - for (x=Tmap1.loop_count; x >= 0; x-- ) { - c = (uint)Tmap1.pixptr[ (f2i(v)&(64*63)) + (f2i(u)&63) ]; - if ( c!=255) - *dest = c; - dest++; - u += dudx; - v += dvdx; - } - } -} - - -void c_tmap_scanline_lin() -{ - -} - - - -void c_tmap_scanline_per_nolight() -{ - ubyte *dest; - uint c; - int x; - fix u,v,z,dudx, dvdx, dzdx; - - u = Tmap1.fx_u; - v = Tmap1.fx_v*64; - z = Tmap1.fx_z; - dudx = Tmap1.fx_du_dx; - dvdx = Tmap1.fx_dv_dx*64; - dzdx = Tmap1.fx_dz_dx; - - dest = Tmap1.dest_row_data; - - if (!Tmap1.Transparency_on) { - for (x=Tmap1.loop_count; x >= 0; x-- ) { - *dest++ = (uint)Tmap1.pixptr[ ( (v/z)&(64*63) ) + ((u/z)&63) ]; - u += dudx; - v += dvdx; - z += dzdx; - } - } else { - for (x=Tmap1.loop_count; x >= 0; x-- ) { - c = (uint)Tmap1.pixptr[ ( (v/z)&(64*63) ) + ((u/z)&63) ]; - if ( c!=255) - *dest = c; - dest++; - u += dudx; - v += dvdx; - z += dzdx; - } - } -} - -void c_tmap_scanline_per1() -{ - ubyte *dest; - uint c; - int x; - fix u,v,z,l,dudx, dvdx, dzdx, dldx; - - u = Tmap1.fx_u; - v = Tmap1.fx_v*64; - z = Tmap1.fx_z; - dudx = Tmap1.fx_du_dx; - dvdx = Tmap1.fx_dv_dx*64; - dzdx = Tmap1.fx_dz_dx; - - l = Tmap1.fx_l; - dldx = Tmap1.fx_dl_dx; - dest = Tmap1.dest_row_data; - - if (!Tmap1.Transparency_on) { - for (x=Tmap1.loop_count; x >= 0; x-- ) { - *dest++ = gr_fade_table[ (l&(0xff00)) + (uint)Tmap1.pixptr[ ( (v/z)&(64*63) ) + ((u/z)&63) ] ]; - l += dldx; - u += dudx; - v += dvdx; - z += dzdx; - } - } else { - for (x=Tmap1.loop_count; x >= 0; x-- ) { - c = (uint)Tmap1.pixptr[ ( (v/z)&(64*63) ) + ((u/z)&63) ]; - if ( c!=255) - *dest = gr_fade_table[ (l&(0xff00)) + c ]; - dest++; - l += dldx; - u += dudx; - v += dvdx; - z += dzdx; - } - } -} - -#define zonk 1 - -void c_tmap_scanline_editor() -{ - ubyte *dest; - uint c; - int x; - fix u,v,z,dudx, dvdx, dzdx; - - u = Tmap1.fx_u; - v = Tmap1.fx_v*64; - z = Tmap1.fx_z; - dudx = Tmap1.fx_du_dx; - dvdx = Tmap1.fx_dv_dx*64; - dzdx = Tmap1.fx_dz_dx; - - dest = Tmap1.dest_row_data; - - if (!Tmap1.Transparency_on) { - for (x=Tmap1.loop_count; x >= 0; x-- ) { - *dest++ = zonk; - //(uint)pixptr[ ( (v/z)&(64*63) ) + ((u/z)&63) ]; - u += dudx; - v += dvdx; - z += dzdx; - } - } else { - for (x=Tmap1.loop_count; x >= 0; x-- ) { - c = (uint)Tmap1.pixptr[ ( (v/z)&(64*63) ) + ((u/z)&63) ]; - if ( c!=255) - *dest = zonk; - dest++; - u += dudx; - v += dvdx; - z += dzdx; - } - } -} - -void asm_tmap_scanline_lln_tiled() -{ - if ( Tmap1.BitmapWidth != 64 ) return; - if ( Tmap1.BitmapHeight != 64 ) return; - - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; set edi = address of first pixel to modify - mov edi, Tmap1.dest_row_data - - mov eax, Tmap1.fx_v - shr eax, 6 - mov edx, Tmap1.fx_u - shl edx, 10 - mov dx, ax ; EDX=U:V in 6.10 format - - mov eax, Tmap1.fx_dv_dx - shr eax, 6 - mov esi, Tmap1.fx_du_dx - shl esi, 10 - mov si, ax ; ESI=DU:DV in 6.10 format - - mov ebx, Tmap1.fx_l - sar ebx, 8 - mov ebp, Tmap1.fx_dl_dx - sar ebp, 8 - - mov ecx, Tmap1.pixptr - - mov eax, Tmap1.loop_count - inc eax - mov Tmap1.loop_count, eax - - shr eax, 3 - je DoLeftOverPixels - - mov Tmap1.num_big_steps, eax - and Tmap1.loop_count, 7 - -NextPixelBlock: - ; pixel 0 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+0], al - - ; pixel 1 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+1], al - - ; pixel 2 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+2], al - - ; pixel 3 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+3], al - - ; pixel 4 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+4], al - - ; pixel 5 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+5], al - - ; pixel 6 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+6], al - - ; pixel 7 - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+7], al - - add edi, 8 - dec Tmap1.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - mov eax,Tmap1.loop_count - test eax, -1 - jz _none_to_do - shr eax, 1 - je one_more_pix - mov Tmap1.loop_count, eax - pushf - - -NextPixel: - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+0], al - - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - add edx, esi - mov al, [ecx+eax] - mov ah, bh - add ebx, ebp - mov al, gr_fade_table[eax] - mov [edi+1], al - - - add edi, 2 - dec Tmap1.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - mov eax, edx - shr ax, 10 - rol eax, 6 - and eax, 0ffffh - mov al, [ecx+eax] - mov ah, bh - mov al, gr_fade_table[eax] - mov [edi], al - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } - -} - -void asm_tmap_scanline_lln32(); - -void asm_tmap_scanline_lln() -{ - int end; - -// return; - if ( Tmap1.tmap_flags & TMAP_FLAG_TILED ) { - asm_tmap_scanline_lln_tiled(); - return; - } - - end = f2i(Tmap1.fx_u); - if ( end >= Tmap1.bp->w ) return; - - end = f2i(Tmap1.fx_v); - if ( end >= Tmap1.bp->h ) return; - - end = f2i(Tmap1.fx_u_right); - if ( end >= Tmap1.bp->w ) return; - - end = f2i(Tmap1.fx_v_right); - if ( end >= Tmap1.bp->h ) return; - - if ( Tmap1.fx_dl_dx < 0 ) { - Tmap1.fx_dl_dx = -Tmap1.fx_dl_dx; - Tmap1.fx_l = (67*F1_0)-Tmap1.fx_l; - Tmap1.fx_l_right = (67*F1_0)-Tmap1.fx_l_right; -// return; -// SDL_assert( Tmap1.fx_l > 31*F1_0 ); -// SDL_assert( Tmap1.fx_l < 66*F1_0 ); -// SDL_assert( Tmap1.fx_dl_dx >= 0 ); -// SDL_assert( Tmap1.fx_dl_dx < 31*F1_0 ); - } - - - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; setup delta values - mov eax, Tmap1.fx_dv_dx // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap1.DeltaVFrac, ebx // store it - imul eax, Tmap1.src_offset // calc texture step for v int step - - mov ebx, Tmap1.fx_du_dx // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap1.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap1.UVintVfracStepVNoCarry, eax // save whole step in non-v-carry slot - add eax, Tmap1.src_offset // calc whole step + v carry - mov Tmap1.UVintVfracStepVCarry, eax // save in v-carry slot - - ; setup initial coordinates - mov esi, Tmap1.fx_u // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap1.fx_v // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap1.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap1.pixptr // calc address - - ; set edi = address of first pixel to modify - mov edi, Tmap1.dest_row_data - - mov edx, Tmap1.DeltaUFrac - - mov eax, Tmap1.loop_count - inc eax - mov Tmap1.loop_count, eax - - shr eax, 3 - je DoLeftOverPixels - - mov Tmap1.num_big_steps, eax - and Tmap1.loop_count, 7 - - -NextPixelBlock: - - mov eax, Tmap1.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap1.fx_dl_dx - shl ebp, 3 //*32 - add Tmap1.fx_l, ebp - - mov ebp, Tmap1.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 3 - - mov dx, bp - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov al,[esi] // get texture pixel 0 - mov ah, bh - mov al, gr_fade_table[eax] - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+0],al // store pixel 0 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 1 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+1],al // store pixel 1 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 2 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+2],al // store pixel 2 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 3 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+3],al // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+4],al // store pixel 4 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 5 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+5],al // store pixel 5 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 6 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+6],al // store pixel 6 - - add ebx,edx // increment u fraction - - mov al,[esi] // get texture pixel 7 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - - mov [edi+7],al // store pixel 7 - - ; end - - - add edi, 8 - dec Tmap1.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - - mov eax,Tmap1.loop_count - test eax, -1 - jz _none_to_do - shr eax, 1 - je one_more_pix - mov Tmap1.loop_count, eax - pushf - - xor eax, eax - - - mov eax, Tmap1.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap1.fx_dl_dx - shr ebp, 8 - mov dx, bp - - mov al,[edi] // preread the destination cache line -// add ebx,edx // increment u fraction - -NextPixel: - - mov al,[esi] // get texture pixel 0 - mov ah, bh - mov al, gr_fade_table[eax] - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov [edi+0],al // store pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 1 - mov ah, bh - mov al, gr_fade_table[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov [edi+1],al // store pixel 1 - - add edi, 2 - dec Tmap1.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - - mov al,[esi] // get texture pixel 2 - mov ah, bh - mov al, gr_fade_table[eax] - mov [edi],al // store pixel 2 - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -} - - -void asm_tmap_scanline_lln32() -{ - int end; - - end = f2i(Tmap1.fx_u); - if ( end >= Tmap1.bp->w ) return; - - end = f2i(Tmap1.fx_v); - if ( end >= Tmap1.bp->h ) return; - - end = f2i(Tmap1.fx_u_right); - if ( end >= Tmap1.bp->w ) return; - - end = f2i(Tmap1.fx_v_right); - if ( end >= Tmap1.bp->h ) return; - - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; setup delta values - mov eax, Tmap1.fx_dv_dx // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap1.DeltaVFrac, ebx // store it - imul eax, Tmap1.src_offset // calc texture step for v int step - - mov ebx, Tmap1.fx_du_dx // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap1.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap1.UVintVfracStepVNoCarry, eax // save whole step in non-v-carry slot - add eax, Tmap1.src_offset // calc whole step + v carry - mov Tmap1.UVintVfracStepVCarry, eax // save in v-carry slot - - ; setup initial coordinates - mov esi, Tmap1.fx_u // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap1.fx_v // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap1.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap1.pixptr // calc address - - ; set edi = address of first pixel to modify - mov edi, Tmap1.dest_row_data32 - - mov edx, Tmap1.DeltaUFrac - - mov eax, Tmap1.fx_l // use bx and dx to do lighting - mov bx, ax - mov eax, Tmap1.fx_dl_dx // use bx and dx to do lighting - mov dx, ax - - mov eax, Tmap1.loop_count - inc eax - mov Tmap1.loop_count, eax - - shr eax, 3 - je DoLeftOverPixels - - mov Tmap1.num_big_steps, eax - and Tmap1.loop_count, 7 - - -NextPixelBlock: - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov al,[esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+0],eax // store pixel 0 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 1 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+4],al // store pixel 1 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 2 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+8],eax // store pixel 2 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 3 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+12],eax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+16],eax // store pixel 4 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 5 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+20],eax // store pixel 5 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 6 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+24],eax // store pixel 6 - - add ebx,edx // increment u fraction - - mov al,[esi] // get texture pixel 7 - mov ah, bh - mov eax, gr_fade_table32[eax] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - - mov [edi+28],eax // store pixel 7 - - ; end - - - add edi, 8*4 - dec Tmap1.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - - mov eax,Tmap1.loop_count - test eax, -1 - jz _none_to_do - shr eax, 1 - je one_more_pix - mov Tmap1.loop_count, eax - pushf - - xor eax, eax - -NextPixel: - mov al,[edi] // preread the destination cache line - - mov al,[esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov [edi+0],eax // store pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 1 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov [edi+1],al // store pixel 1 - - add edi, 2*4 - dec Tmap1.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - - mov al,[esi] // get texture pixel 2 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - mov [edi],eax // store pixel 2 - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -} - -void asm_tmap_scanline_lnt() -{ - int end; - - end = f2i(Tmap1.fx_u); - if ( end >= Tmap1.bp->w ) return; - - end = f2i(Tmap1.fx_v); - if ( end >= Tmap1.bp->h ) return; - - end = f2i(Tmap1.fx_u_right); - if ( end >= Tmap1.bp->w ) return; - - end = f2i(Tmap1.fx_v_right); - if ( end >= Tmap1.bp->h ) return; - - - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; setup delta values - mov eax, Tmap1.fx_dv_dx // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap1.DeltaVFrac, ebx // store it - imul eax, Tmap1.src_offset // calc texture step for v int step - - mov ebx, Tmap1.fx_du_dx // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap1.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap1.UVintVfracStepVNoCarry, eax // save whole step in non-v-carry slot - add eax, Tmap1.src_offset // calc whole step + v carry - mov Tmap1.UVintVfracStepVCarry, eax // save in v-carry slot - - ; setup initial coordinates - mov esi, Tmap1.fx_u // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap1.fx_v // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap1.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap1.pixptr // calc address - - ; set edi = address of first pixel to modify - mov edi, Tmap1.dest_row_data - - mov edx, Tmap1.DeltaUFrac - - mov eax, Tmap1.loop_count - inc eax - mov Tmap1.loop_count, eax - - shr eax, 3 - je DoLeftOverPixels - - mov Tmap1.num_big_steps, eax - and Tmap1.loop_count, 7 - - -NextPixelBlock: - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov al,[esi] // get texture pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - cmp al, 255 - je skip0 - mov [edi+0],al // store pixel 0 -skip0: - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 1 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - cmp al, 255 - je skip1 - mov [edi+1],al // store pixel 0 -skip1: - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 2 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - cmp al, 255 - je skip2 - mov [edi+2],al // store pixel 0 -skip2: - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 3 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - cmp al, 255 - je skip3 - mov [edi+3],al // store pixel 0 -skip3: - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - cmp al, 255 - je skip4 - mov [edi+4],al // store pixel 0 -skip4: - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 5 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - cmp al, 255 - je skip5 - mov [edi+5],al // store pixel 0 -skip5: - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 6 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - cmp al, 255 - je skip6 - mov [edi+6],al // store pixel 0 -skip6: - - add ebx,edx // increment u fraction - - mov al,[esi] // get texture pixel 7 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - - cmp al, 255 - je skip7 - mov [edi+7],al // store pixel 0 -skip7: - - ; end - - - add edi, 8 - dec Tmap1.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - - mov eax,Tmap1.loop_count - test eax, -1 - jz _none_to_do - shr eax, 1 - je one_more_pix - mov Tmap1.loop_count, eax - pushf - - xor eax, eax - - mov al,[edi] // preread the destination cache line -// add ebx,edx // increment u fraction - -NextPixel: - - mov al,[esi] // get texture pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - cmp al, 255 - je skipA0 - mov [edi+0],al // store pixel 0 -skipA0: - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 1 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - cmp al, 255 - je skipA1 - mov [edi+1],al // store pixel 0 -skipA1: - - add edi, 2 - dec Tmap1.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - - mov al,[esi] // get texture pixel 2 - cmp al, 255 - je skipB - mov [edi],al // store pixel 0 -skipB: - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -} - - -void asm_tmap_scanline_lnn() -{ - int end; - - end = f2i(Tmap1.fx_u); - if ( end >= Tmap1.bp->w ) return; - - end = f2i(Tmap1.fx_v); - if ( end >= Tmap1.bp->h ) return; - - end = f2i(Tmap1.fx_u_right); - if ( end >= Tmap1.bp->w ) return; - - end = f2i(Tmap1.fx_v_right); - if ( end >= Tmap1.bp->h ) return; - - - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; setup delta values - mov eax, Tmap1.fx_dv_dx // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap1.DeltaVFrac, ebx // store it - imul eax, Tmap1.src_offset // calc texture step for v int step - - mov ebx, Tmap1.fx_du_dx // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap1.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap1.UVintVfracStepVNoCarry, eax // save whole step in non-v-carry slot - add eax, Tmap1.src_offset // calc whole step + v carry - mov Tmap1.UVintVfracStepVCarry, eax // save in v-carry slot - - ; setup initial coordinates - mov esi, Tmap1.fx_u // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap1.fx_v // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap1.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap1.pixptr // calc address - - ; set edi = address of first pixel to modify - mov edi, Tmap1.dest_row_data - - mov edx, Tmap1.DeltaUFrac - - mov eax, Tmap1.loop_count - inc eax - mov Tmap1.loop_count, eax - - shr eax, 3 - je DoLeftOverPixels - - mov Tmap1.num_big_steps, eax - and Tmap1.loop_count, 7 - - -NextPixelBlock: - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov al,[esi] // get texture pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+0],al // store pixel 0 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 1 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+1],al // store pixel 0 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 2 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+2],al // store pixel 0 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 3 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+3],al // store pixel 0 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+4],al // store pixel 0 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 5 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+5],al // store pixel 0 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 6 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+6],al // store pixel 0 - - add ebx,edx // increment u fraction - - mov al,[esi] // get texture pixel 7 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - - mov [edi+7],al // store pixel 0 - - ; end - - - add edi, 8 - dec Tmap1.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - - mov eax,Tmap1.loop_count - test eax, -1 - jz _none_to_do - shr eax, 1 - je one_more_pix - mov Tmap1.loop_count, eax - pushf - - xor eax, eax - - mov al,[edi] // preread the destination cache line -// add ebx,edx // increment u fraction - -NextPixel: - - mov al,[esi] // get texture pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov [edi+0],al // store pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 1 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov [edi+1],al // store pixel 0 - - add edi, 2 - dec Tmap1.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - - mov al,[esi] // get texture pixel 2 - mov [edi],al // store pixel 0 - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -} - -void tmapscan_pln16( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - Tmap1.dest_row_data = (ubyte *)GR_SCREEN_PTR(ushort,lx,y); - Tmap1.loop_count = rx - lx; - Tmap1.fx_u = fl2f(p->u); - Tmap1.fx_v = fl2f(p->v); - Tmap1.fx_du_dx = fl2f(dp->u); - Tmap1.fx_dv_dx = fl2f(dp->v); - - Tmap1.fx_l = fl2f(p->l*32.0); - Tmap1.fx_dl_dx = fl2f(dp->l*32.0); - - Tmap1.fx_u_right = fl2f(rp->u); - Tmap1.fx_v_right = fl2f(rp->v); - Tmap1.pixptr = (unsigned char *)tmap_bitmap->data; - Tmap1.bp = tmap_bitmap; - Tmap1.src_offset = tmap_bitmap->w; - - - Tmap1.FixedScale = 65536.0f; - Tmap1.FixedScale8 = 2048.0f; //8192.0f; // 2^16 / 8 - Tmap1.One = 1.0f; - - - Tmap1.UOverZ = p->u; - Tmap1.VOverZ = p->v; - Tmap1.OneOverZ = p->sw; - - Tmap1.dUOverZdX8 = dp->u*32.0f; - Tmap1.dVOverZdX8 = dp->v*32.0f; - Tmap1.dOneOverZdX8 = dp->sw*32.0f; - - Tmap1.dUOverZdX = dp->u; - Tmap1.dVOverZdX = dp->v; - Tmap1.dOneOverZdX = dp->sw; - - Tmap1.RightUOverZ = rp->u; - Tmap1.RightVOverZ = rp->v; - Tmap1.RightOneOverZ = rp->sw; - - - - Tmap1.BitmapWidth = Tmap1.bp->w; - Tmap1.BitmapHeight = Tmap1.bp->h; - - - if ( Tmap1.fx_dl_dx < 0 ) { - Tmap1.fx_dl_dx = -Tmap1.fx_dl_dx; - Tmap1.fx_l = (67*F1_0)-Tmap1.fx_l; - Tmap1.fx_l_right = (67*F1_0)-Tmap1.fx_l_right; -// return; -// SDL_assert( Tmap1.fx_l > 31*F1_0 ); -// SDL_assert( Tmap1.fx_l < 66*F1_0 ); -// SDL_assert( Tmap1.fx_dl_dx >= 0 ); -// SDL_assert( Tmap1.fx_dl_dx < 31*F1_0 ); - } - -// return; - - - - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - - // put the FPU in 32 bit mode - // @todo move this out of here! - - fstcw Tmap1.OldFPUCW // store copy of CW - mov ax,Tmap1.OldFPUCW // get it in ax -//hh and eax,NOT 1100000000y // 24 bit precision - and eax, ~0x300L - mov Tmap1.FPUCW,ax // store it - fldcw Tmap1.FPUCW // load the FPU - - mov ecx, Tmap1.loop_count // ecx = width - inc ecx - mov edi, Tmap1.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? -// jmp Return - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap1.Subdivisions,ecx // store widths - mov Tmap1.WidthModLength,eax - -// mov ebx,pLeft ; get left edge pointer -// mov edx,pGradients ; get gradients pointer - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap1.VOverZ // V/ZL - fld Tmap1.UOverZ // U/ZL V/ZL - fld Tmap1.OneOverZ // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap1.dOneOverZdX8 // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap1.dUOverZdX8 // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap1.dVOverZdX8 // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap1.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap1.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap1.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap1.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap1.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap1.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap1.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap1.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span ; st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms---->; V/ZL 1/ZL U/ZL UL VL - - fadd Tmap1.dVOverZdX8 ; V/ZR 1/ZL U/ZL UL VL - fxch st(1) ; 1/ZL V/ZR U/ZL UL VL - fadd Tmap1.dOneOverZdX8 ; 1/ZR V/ZR U/ZL UL VL - fxch st(2) ; U/ZL V/ZR 1/ZR UL VL - fadd Tmap1.dUOverZdX8 ; U/ZR V/ZR 1/ZR UL VL - fxch st(2) ; 1/ZR V/ZR U/ZR UL VL - fxch st(1) ; V/ZR 1/ZR U/ZR UL VL - - ; calculate right side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 ; 1 V/ZR 1/ZR U/ZR UL VL - fdiv st,st(2) ; ZR V/ZR 1/ZR U/ZR UL VL - - - ; set up affine registers - - ; setup delta values - - mov eax,Tmap1.DeltaV ; get v 16.16 step - mov ebx,eax ; copy it - sar eax,16 ; get v int step - shl ebx,16 ; get v frac step - mov Tmap1.DeltaVFrac,ebx ; store it - imul eax,Tmap1.src_offset ; calculate texture step for v int step - - mov ebx,Tmap1.DeltaU ; get u 16.16 step - mov ecx,ebx ; copy it - sar ebx,16 ; get u int step - shl ecx,16 ; get u frac step - mov Tmap1.DeltaUFrac,ecx ; store it - add eax,ebx ; calculate uint + vint step - mov Tmap1.UVintVfracStepVNoCarry,eax; save whole step in non-v-carry slot - add eax,Tmap1.src_offset ; calculate whole step + v carry - mov Tmap1.UVintVfracStepVCarry,eax ; save in v-carry slot - - -/* -; check coordinate ranges - mov eax, Tmap1.UFixed - cmp eax, Tmap1.MinUFixed - jge UNotTooSmall_1 - mov eax, Tmap1.MinUFixed - mov Tmap1.UFixed, eax - jmp CheckV_1 -UNotTooSmall_1: - cmp eax, Tmap1.MaxUFixed - jle CheckV_1 - mov eax, Tmap1.MaxUFixed - mov Tmap1.UFixed, eax -CheckV_1: - mov eax, Tmap1.VFixed - cmp eax, Tmap1.MinVFixed - jge VNotTooSmall_1 - mov eax, Tmap1.MinVFixed - mov Tmap1.VFixed, eax - jmp DoneCheck_1 -VNotTooSmall_1: - cmp eax, Tmap1.MaxVFixed - jle DoneCheck_1 - mov eax, Tmap1.MaxVFixed - mov Tmap1.VFixed, eax -DoneCheck_1: -*/ - -; setup initial coordinates - mov esi,Tmap1.UFixed ; get u 16.16 fixedpoint coordinate - - mov ebx,esi ; copy it - sar esi,16 ; get integer part - shl ebx,16 ; get fractional part - - mov ecx,Tmap1.VFixed ; get v 16.16 fixedpoint coordinate - - mov edx,ecx ; copy it - sar edx,16 ; get integer part - shl ecx,16 ; get fractional part - imul edx,Tmap1.src_offset ; calc texture scanline address - add esi,edx ; calc texture offset - add esi,Tmap1.pixptr ; calc address - - mov edx,Tmap1.DeltaUFrac ; get register copy - - mov eax, Tmap1.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap1.fx_dl_dx - shl ebp, 5 //*32 - add Tmap1.fx_l, ebp - - mov ebp, Tmap1.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - -// add Tmap1.fx_l, eax - - -// mov eax, Tmap1.fx_l // use bx and dx to do lighting -//mov eax, 31*256 -// mov bx, ax -// mov eax, Tmap1.fx_dl_dx // use bx and dx to do lighting -//mov eax, 0 -// mov dx, ax - - - - ; ************** Can't Access Stack Frame ****************** - ; ************** Can't Access Stack Frame ****************** - ; ************** Can't Access Stack Frame ****************** - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - - mov al,[esi] // get texture pixel 0 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry -// mov al, 0 // Uncomment this line to show divisions - mov [edi+0],ax // store pixel 0 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 1 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+2],ax // store pixel 1 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 2 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+4],ax // store pixel 2 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 3 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+6],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+8],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+10],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+12],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+14],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+16],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+18],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+20],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+22],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+24],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+26],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+28],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+30],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+32],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+34],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+36],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+38],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+40],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+42],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+44],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+46],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+48],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+50],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - - - sbb ebp,ebp // get -1 if carry - mov [edi+52],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+54],ax // store pixel 3 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 4 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+56],ax // store pixel 4 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 5 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+58],ax // store pixel 5 - - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 6 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+60],ax // store pixel 6 - - add ebx,edx // increment u fraction - - mov al,[esi] // get texture pixel 7 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - - mov [edi+62],ax // store pixel 7 - - - - ; ************** Okay to Access Stack Frame **************** - ; ************** Okay to Access Stack Frame **************** - ; ************** Okay to Access Stack Frame **************** - - - ; the fdiv is done, finish right ; st0 st1 st2 st3 st4 st5 st6 st7 - ; ZR V/ZR 1/ZR U/ZR UL VL - - fld st ; ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) ; VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) ; ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) ; UR VR V/ZR 1/ZR U/ZR UL VL - - add edi,64 ; increment to next span - dec Tmap1.Subdivisions ; decrement span count - jnz SpanLoop ; loop back - - // save new lighting values -// xor eax, eax -// mov ax, bx -// mov Tmap1.fx_l, eax - -// xor eax, eax -// mov ax, dx -// mov Tmap1.fx_dl_dx, eax - -HandleLeftoverPixels: -// jmp FPUReturn - - mov esi,Tmap1.pixptr ; load texture pointer - - ; edi = dest dib bits - ; esi = current texture dib bits - ; at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - ; inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap1.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - ; convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap1.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap1.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap1.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap1.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap1.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas - - ; calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - ; r -> R+1 - - ; @todo rearrange things so we don't need these two instructions - fstp Tmap1.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap1.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap1.RightVOverZ ; V/Zr inv. inv. inv. UL VL - fsub Tmap1.dVOverZdX ; V/ZR inv. inv. inv. UL VL - fld Tmap1.RightUOverZ ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap1.dUOverZdX ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap1.RightOneOverZ ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap1.dOneOverZdX ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap1.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - ; calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap1.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap1.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap1.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap1.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap1.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap1.DeltaU ; inv. inv. inv. UR VR - - ; @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - -//jmp OldWay - - - ; setup delta values - mov eax, Tmap1.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap1.DeltaVFrac, ebx // store it - imul eax, Tmap1.src_offset // calc texture step for v int step - - mov ebx, Tmap1.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap1.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap1.UVintVfracStepVNoCarry, eax // save whole step in non-v-carry slot - add eax, Tmap1.src_offset // calc whole step + v carry - mov Tmap1.UVintVfracStepVCarry, eax // save in v-carry slot - - - -OnePixelSpan: - -/* -; check coordinate ranges - mov eax, Tmap1.UFixed - cmp eax, Tmap1.MinUFixed - jge UNotTooSmall_2 - mov eax, Tmap1.MinUFixed - mov Tmap1.UFixed, eax - jmp CheckV_2 -UNotTooSmall_2: - cmp eax, Tmap1.MaxUFixed - jle CheckV_2 - mov eax, Tmap1.MaxUFixed - mov Tmap1.UFixed, eax -CheckV_2: - mov eax, Tmap1.VFixed - cmp eax, Tmap1.MinVFixed - jge VNotTooSmall_2 - mov eax, Tmap1.MinVFixed - mov Tmap1.VFixed, eax - jmp DoneCheck_2 -VNotTooSmall_2: - cmp eax, Tmap1.MaxVFixed - jle DoneCheck_2 - mov eax, Tmap1.MaxVFixed - mov Tmap1.VFixed, eax -DoneCheck_2: -*/ - - - - - ; setup initial coordinates - mov esi, Tmap1.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap1.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap1.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap1.pixptr // calc address - - ; set edi = address of first pixel to modify -; mov edi, Tmap1.dest_row_data - - - - - mov eax, Tmap1.fx_l - shr eax, 8 - mov bx, ax - - mov edx, Tmap1.DeltaUFrac - - cmp Tmap1.WidthModLength, 1 - jle NoDeltaLight - - push ebx - - mov ebx, Tmap1.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - -#if 0 - // slow but maybe better - push edx - cdq - mov ebx, Tmap1.WidthModLength - dec ebx - idiv ebx - pop edx -#else - mov eax, Tmap1.fx_dl_dx - shr eax, 8 -#endif - - mov dx, ax - - pop ebx - -NoDeltaLight: - - inc Tmap1.WidthModLength - mov eax,Tmap1.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap1.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -NextPixel: - mov al,[esi] // get texture pixel 0 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov [edi+0],ax // store pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - mov al,[esi] // get texture pixel 1 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov [edi+2],ax // store pixel 1 - - add edi, 4 - dec Tmap1.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - - mov al,[esi] // get texture pixel 2 - mov ah, bh - mov ax, gr_fade_table16[eax*2] - mov [edi],ax // store pixel 2 - - - - - - - - - - - - - -/* -OldWay: // This is 6% slower than above - - mov ebx,Tmap1.UFixed ; get starting coordinates - mov ecx,Tmap1.VFixed ; for span - - ; leftover pixels loop - ; edi = dest dib bits - ; esi = texture dib bits - - ; ebx = u 16.16 - ; ecx = v 16.16 - - - mov eax,ecx ; copy v - sar eax,16 ; int(v) - imul eax,Tmap1.src_offset ; scan offset - mov edx,ebx ; copy u - sar edx,16 ; int(u) - add eax,edx ; texture offset - mov al,[esi+eax] ; get source pixel -mov al, 0 - mov [edi],al ; store it - inc edi - add ebx,Tmap1.DeltaU ; increment u coordinate - add ecx,Tmap1.DeltaV ; increment v coordinate - - dec Tmap1.WidthModLength ; decrement loop count - jl FPUReturn ; finish up - - -LeftoverLoop: - mov eax,ecx ; copy v - sar eax,16 ; int(v) - imul eax,Tmap1.src_offset ; scan offset - mov edx,ebx ; copy u - sar edx,16 ; int(u) - add eax,edx ; texture offset - mov al,[esi+eax] ; get source pixel - mov [edi],al ; store it - inc edi - add ebx,Tmap1.DeltaU ; increment u coordinate - add ecx,Tmap1.DeltaV ; increment v coordinate - - dec Tmap1.WidthModLength ; decrement loop count - jge LeftoverLoop ; finish up -*/ - -FPUReturn: - - ; busy FPU registers: ; st0 st1 st2 st3 st4 st5 st6 st7 - ; xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - -//Return: - - fldcw Tmap1.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } - - -} - - - - -void tmapscan_lnn16( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - Tmap1.dest_row_data = (ubyte *)GR_SCREEN_PTR(ushort,lx,y); - Tmap1.loop_count = rx - lx; - Tmap1.pixptr = (unsigned char *)tmap_bitmap->data; - Tmap1.bp = tmap_bitmap; - Tmap1.src_offset = tmap_bitmap->w; - - Tmap1.fx_u = fl2f(p->u); - Tmap1.fx_v = fl2f(p->v); - Tmap1.fx_du_dx = fl2f(dp->u); - Tmap1.fx_dv_dx = fl2f(dp->v); - Tmap1.fx_u_right = fl2f(rp->u); - Tmap1.fx_v_right = fl2f(rp->v); - - int end; - - end = f2i(Tmap1.fx_u); - if ( end >= Tmap1.bp->w ) return; - - end = f2i(Tmap1.fx_v); - if ( end >= Tmap1.bp->h ) return; - - end = f2i(Tmap1.fx_u_right); - if ( end >= Tmap1.bp->w ) return; - - end = f2i(Tmap1.fx_v_right); - if ( end >= Tmap1.bp->h ) return; - - - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; setup delta values - mov eax, Tmap1.fx_dv_dx // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap1.DeltaVFrac, ebx // store it - imul eax, Tmap1.src_offset // calc texture step for v int step - - mov ebx, Tmap1.fx_du_dx // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap1.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap1.UVintVfracStepVNoCarry, eax // save whole step in non-v-carry slot - add eax, Tmap1.src_offset // calc whole step + v carry - mov Tmap1.UVintVfracStepVCarry, eax // save in v-carry slot - - ; setup initial coordinates - mov esi, Tmap1.fx_u // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap1.fx_v // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap1.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap1.pixptr // calc address - - ; set edi = address of first pixel to modify - mov edi, Tmap1.dest_row_data - - mov edx, Tmap1.DeltaUFrac - - mov eax, Tmap1.loop_count - inc eax - mov Tmap1.loop_count, eax - - shr eax, 3 - je DoLeftOverPixels - - mov Tmap1.num_big_steps, eax - and Tmap1.loop_count, 7 - - xor eax, eax - -NextPixelBlock: - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - movzx eax,byte ptr [esi] // get texture pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov ax, palman_8_16_xlat[eax*2] - mov [edi+0],ax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov ax, palman_8_16_xlat[eax*2] - mov [edi+2],ax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov ax, palman_8_16_xlat[eax*2] - mov [edi+4],ax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov ax, palman_8_16_xlat[eax*2] - mov [edi+6],ax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov ax, palman_8_16_xlat[eax*2] - mov [edi+8],ax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov ax, palman_8_16_xlat[eax*2] - mov [edi+10],ax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov ax, palman_8_16_xlat[eax*2] - mov [edi+12],ax // store pixel 0 - - add ebx,edx // increment u fraction - - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - - mov ax, palman_8_16_xlat[eax*2] - mov [edi+14],ax // store pixel 0 - - ; end - - - add edi, 16 - dec Tmap1.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - - mov eax,Tmap1.loop_count - test eax, -1 - jz _none_to_do - shr eax, 1 - je one_more_pix - mov Tmap1.loop_count, eax - pushf - - xor eax, eax - - mov al,[edi] // preread the destination cache line -// add ebx,edx // increment u fraction - -NextPixel: - - movzx eax,byte ptr [esi] // get texture pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov ax, palman_8_16_xlat[eax*2] - mov [edi+0],ax // store pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov ax, palman_8_16_xlat[eax*2] - mov [edi+2],ax // store pixel 0 - - add edi, 4 - dec Tmap1.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ax, palman_8_16_xlat[eax*2] - mov [edi],ax // store pixel 0 - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -} - - - -void tmapscan_lnn32( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - Tmap1.dest_row_data = (ubyte *)GR_SCREEN_PTR(uint,lx,y); - Tmap1.loop_count = rx - lx; - Tmap1.pixptr = (unsigned char *)tmap_bitmap->data; - Tmap1.bp = tmap_bitmap; - Tmap1.src_offset = tmap_bitmap->w; - - Tmap1.fx_u = fl2f(p->u); - Tmap1.fx_v = fl2f(p->v); - Tmap1.fx_du_dx = fl2f(dp->u); - Tmap1.fx_dv_dx = fl2f(dp->v); - Tmap1.fx_u_right = fl2f(rp->u); - Tmap1.fx_v_right = fl2f(rp->v); - - int end; - - end = f2i(Tmap1.fx_u); - if ( end >= Tmap1.bp->w ) return; - - end = f2i(Tmap1.fx_v); - if ( end >= Tmap1.bp->h ) return; - - end = f2i(Tmap1.fx_u_right); - if ( end >= Tmap1.bp->w ) return; - - end = f2i(Tmap1.fx_v_right); - if ( end >= Tmap1.bp->h ) return; - - - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; setup delta values - mov eax, Tmap1.fx_dv_dx // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap1.DeltaVFrac, ebx // store it - imul eax, Tmap1.src_offset // calc texture step for v int step - - mov ebx, Tmap1.fx_du_dx // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap1.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap1.UVintVfracStepVNoCarry, eax // save whole step in non-v-carry slot - add eax, Tmap1.src_offset // calc whole step + v carry - mov Tmap1.UVintVfracStepVCarry, eax // save in v-carry slot - - ; setup initial coordinates - mov esi, Tmap1.fx_u // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap1.fx_v // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap1.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap1.pixptr // calc address - - ; set edi = address of first pixel to modify - mov edi, Tmap1.dest_row_data - - mov edx, Tmap1.DeltaUFrac - - mov eax, Tmap1.loop_count - inc eax - mov Tmap1.loop_count, eax - - shr eax, 3 - je DoLeftOverPixels - - mov Tmap1.num_big_steps, eax - and Tmap1.loop_count, 7 - - xor eax, eax - -NextPixelBlock: - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - movzx eax,byte ptr [esi] // get texture pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov eax, palman_8_32_xlat[eax*4] - mov [edi+0],eax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov eax, palman_8_32_xlat[eax*4] - mov [edi+4],eax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov eax, palman_8_32_xlat[eax*4] - mov [edi+8],eax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov eax, palman_8_32_xlat[eax*4] - mov [edi+12],eax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov eax, palman_8_32_xlat[eax*4] - mov [edi+16],eax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov eax, palman_8_32_xlat[eax*4] - mov [edi+20],eax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov eax, palman_8_32_xlat[eax*4] - mov [edi+24],eax // store pixel 0 - - add ebx,edx // increment u fraction - - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - - mov eax, palman_8_32_xlat[eax*4] - mov [edi+28],eax // store pixel 0 - - ; end - - - add edi, 32 - dec Tmap1.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - - mov eax,Tmap1.loop_count - test eax, -1 - jz _none_to_do - shr eax, 1 - je one_more_pix - mov Tmap1.loop_count, eax - pushf - - xor eax, eax - - mov al,[edi] // preread the destination cache line -// add ebx,edx // increment u fraction - -NextPixel: - - movzx eax,byte ptr [esi] // get texture pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov eax, palman_8_32_xlat[eax*4] - mov [edi+0],eax // store pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov eax, palman_8_32_xlat[eax*4] - mov [edi+4],eax // store pixel 0 - - add edi, 8 - dec Tmap1.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - - movzx eax,byte ptr [esi] // get texture pixel 0 - mov eax, palman_8_32_xlat[eax*4] - mov [edi],eax // store pixel 0 - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -} - - -void tmapscan_pln32( int lx, int rx, int y, vertex *p, vertex *dp, vertex * rp,uint flags ) -{ - Tmap1.dest_row_data = (ubyte *)GR_SCREEN_PTR(uint,lx,y); - Tmap1.loop_count = rx - lx; - Tmap1.fx_u = fl2f(p->u); - Tmap1.fx_v = fl2f(p->v); - Tmap1.fx_du_dx = fl2f(dp->u); - Tmap1.fx_dv_dx = fl2f(dp->v); - - Tmap1.fx_l = fl2f(p->l*32.0); - Tmap1.fx_dl_dx = fl2f(dp->l*32.0); - - Tmap1.fx_u_right = fl2f(rp->u); - Tmap1.fx_v_right = fl2f(rp->v); - Tmap1.pixptr = (unsigned char *)tmap_bitmap->data; - Tmap1.bp = tmap_bitmap; - Tmap1.src_offset = tmap_bitmap->w; - - - Tmap1.FixedScale = 65536.0f; - Tmap1.FixedScale8 = 2048.0f; //8192.0f; // 2^16 / 8 - Tmap1.One = 1.0f; - - - Tmap1.UOverZ = p->u; - Tmap1.VOverZ = p->v; - Tmap1.OneOverZ = p->sw; - - Tmap1.dUOverZdX8 = dp->u*32.0f; - Tmap1.dVOverZdX8 = dp->v*32.0f; - Tmap1.dOneOverZdX8 = dp->sw*32.0f; - - Tmap1.dUOverZdX = dp->u; - Tmap1.dVOverZdX = dp->v; - Tmap1.dOneOverZdX = dp->sw; - - Tmap1.RightUOverZ = rp->u; - Tmap1.RightVOverZ = rp->v; - Tmap1.RightOneOverZ = rp->sw; - - - Tmap1.BitmapWidth = Tmap1.bp->w; - Tmap1.BitmapHeight = Tmap1.bp->h; - - - if ( Tmap1.fx_dl_dx < 0 ) { - Tmap1.fx_dl_dx = -Tmap1.fx_dl_dx; - Tmap1.fx_l = (67*F1_0)-Tmap1.fx_l; - Tmap1.fx_l_right = (67*F1_0)-Tmap1.fx_l_right; -// return; -// SDL_assert( Tmap1.fx_l > 31*F1_0 ); -// SDL_assert( Tmap1.fx_l < 66*F1_0 ); -// SDL_assert( Tmap1.fx_dl_dx >= 0 ); -// SDL_assert( Tmap1.fx_dl_dx < 31*F1_0 ); - } - -// return; - - - - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - - // put the FPU in 32 bit mode - // @todo move this out of here! - - fstcw Tmap1.OldFPUCW // store copy of CW - mov ax,Tmap1.OldFPUCW // get it in ax -//hh and eax,NOT 1100000000y // 24 bit precision - and eax, ~0x300L - mov Tmap1.FPUCW,ax // store it - fldcw Tmap1.FPUCW // load the FPU - - mov ecx, Tmap1.loop_count // ecx = width - inc ecx - mov edi, Tmap1.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? -// jmp Return - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap1.Subdivisions,ecx // store widths - mov Tmap1.WidthModLength,eax - -// mov ebx,pLeft ; get left edge pointer -// mov edx,pGradients ; get gradients pointer - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap1.VOverZ // V/ZL - fld Tmap1.UOverZ // U/ZL V/ZL - fld Tmap1.OneOverZ // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap1.dOneOverZdX8 // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap1.dUOverZdX8 // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap1.dVOverZdX8 // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap1.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap1.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap1.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap1.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap1.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap1.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap1.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap1.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span ; st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms---->; V/ZL 1/ZL U/ZL UL VL - - fadd Tmap1.dVOverZdX8 ; V/ZR 1/ZL U/ZL UL VL - fxch st(1) ; 1/ZL V/ZR U/ZL UL VL - fadd Tmap1.dOneOverZdX8 ; 1/ZR V/ZR U/ZL UL VL - fxch st(2) ; U/ZL V/ZR 1/ZR UL VL - fadd Tmap1.dUOverZdX8 ; U/ZR V/ZR 1/ZR UL VL - fxch st(2) ; 1/ZR V/ZR U/ZR UL VL - fxch st(1) ; V/ZR 1/ZR U/ZR UL VL - - ; calculate right side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 ; 1 V/ZR 1/ZR U/ZR UL VL - fdiv st,st(2) ; ZR V/ZR 1/ZR U/ZR UL VL - - - ; set up affine registers - - ; setup delta values - - mov eax,Tmap1.DeltaV ; get v 16.16 step - mov ebx,eax ; copy it - sar eax,16 ; get v int step - shl ebx,16 ; get v frac step - mov Tmap1.DeltaVFrac,ebx ; store it - imul eax,Tmap1.src_offset ; calculate texture step for v int step - - mov ebx,Tmap1.DeltaU ; get u 16.16 step - mov ecx,ebx ; copy it - sar ebx,16 ; get u int step - shl ecx,16 ; get u frac step - mov Tmap1.DeltaUFrac,ecx ; store it - add eax,ebx ; calculate uint + vint step - mov Tmap1.UVintVfracStepVNoCarry,eax; save whole step in non-v-carry slot - add eax,Tmap1.src_offset ; calculate whole step + v carry - mov Tmap1.UVintVfracStepVCarry,eax ; save in v-carry slot - - -/* -; check coordinate ranges - mov eax, Tmap1.UFixed - cmp eax, Tmap1.MinUFixed - jge UNotTooSmall_1 - mov eax, Tmap1.MinUFixed - mov Tmap1.UFixed, eax - jmp CheckV_1 -UNotTooSmall_1: - cmp eax, Tmap1.MaxUFixed - jle CheckV_1 - mov eax, Tmap1.MaxUFixed - mov Tmap1.UFixed, eax -CheckV_1: - mov eax, Tmap1.VFixed - cmp eax, Tmap1.MinVFixed - jge VNotTooSmall_1 - mov eax, Tmap1.MinVFixed - mov Tmap1.VFixed, eax - jmp DoneCheck_1 -VNotTooSmall_1: - cmp eax, Tmap1.MaxVFixed - jle DoneCheck_1 - mov eax, Tmap1.MaxVFixed - mov Tmap1.VFixed, eax -DoneCheck_1: -*/ - -; setup initial coordinates - mov esi,Tmap1.UFixed ; get u 16.16 fixedpoint coordinate - - mov ebx,esi ; copy it - sar esi,16 ; get integer part - shl ebx,16 ; get fractional part - - mov ecx,Tmap1.VFixed ; get v 16.16 fixedpoint coordinate - - mov edx,ecx ; copy it - sar edx,16 ; get integer part - shl ecx,16 ; get fractional part - imul edx,Tmap1.src_offset ; calc texture scanline address - add esi,edx ; calc texture offset - add esi,Tmap1.pixptr ; calc address - - mov edx,Tmap1.DeltaUFrac ; get register copy - - mov eax, Tmap1.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap1.fx_dl_dx - shl ebp, 5 //*32 - add Tmap1.fx_l, ebp - - mov ebp, Tmap1.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - -// add Tmap1.fx_l, eax - - -// mov eax, Tmap1.fx_l // use bx and dx to do lighting -//mov eax, 31*256 -// mov bx, ax -// mov eax, Tmap1.fx_dl_dx // use bx and dx to do lighting -//mov eax, 0 -// mov dx, ax - - - - ; ************** Can't Access Stack Frame ****************** - ; ************** Can't Access Stack Frame ****************** - ; ************** Can't Access Stack Frame ****************** - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry -// mov al, 0 // Uncomment this line to show divisions - mov [edi+0],eax // store pixel 0 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+4],eax // store pixel 1 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+8],eax // store pixel 2 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+12],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+16],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+20],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+24],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+28],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+32],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+36],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+40],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+44],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+48],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+52],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+56],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+60],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+64],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+68],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+72],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+76],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+80],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+84],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+88],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+92],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+96],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+100],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - - - sbb ebp,ebp // get -1 if carry - mov [edi+104],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+108],eax // store pixel 3 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+112],eax // store pixel 4 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+116],eax // store pixel 5 - - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - add ecx,Tmap1.DeltaVFrac // increment v fraction - - sbb ebp,ebp // get -1 if carry - mov [edi+120],eax // store pixel 6 - - add ebx,edx // increment u fraction - - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - - mov [edi+124],eax // store pixel 7 - - - - ; ************** Okay to Access Stack Frame **************** - ; ************** Okay to Access Stack Frame **************** - ; ************** Okay to Access Stack Frame **************** - - - ; the fdiv is done, finish right ; st0 st1 st2 st3 st4 st5 st6 st7 - ; ZR V/ZR 1/ZR U/ZR UL VL - - fld st ; ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) ; VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) ; ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) ; UR VR V/ZR 1/ZR U/ZR UL VL - - add edi,128 ; increment to next span - dec Tmap1.Subdivisions ; decrement span count - jnz SpanLoop ; loop back - - // save new lighting values -// xor eax, eax -// mov ax, bx -// mov Tmap1.fx_l, eax - -// xor eax, eax -// mov ax, dx -// mov Tmap1.fx_dl_dx, eax - -HandleLeftoverPixels: -// jmp FPUReturn - - mov esi,Tmap1.pixptr ; load texture pointer - - ; edi = dest dib bits - ; esi = current texture dib bits - ; at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - ; inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap1.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - ; convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap1.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap1.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap1.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap1.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap1.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas - - ; calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - ; r -> R+1 - - ; @todo rearrange things so we don't need these two instructions - fstp Tmap1.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap1.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap1.RightVOverZ ; V/Zr inv. inv. inv. UL VL - fsub Tmap1.dVOverZdX ; V/ZR inv. inv. inv. UL VL - fld Tmap1.RightUOverZ ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap1.dUOverZdX ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap1.RightOneOverZ ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap1.dOneOverZdX ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap1.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - ; calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap1.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap1.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap1.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap1.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap1.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap1.DeltaU ; inv. inv. inv. UR VR - - ; @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - -//jmp OldWay - - - ; setup delta values - mov eax, Tmap1.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap1.DeltaVFrac, ebx // store it - imul eax, Tmap1.src_offset // calc texture step for v int step - - mov ebx, Tmap1.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap1.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap1.UVintVfracStepVNoCarry, eax // save whole step in non-v-carry slot - add eax, Tmap1.src_offset // calc whole step + v carry - mov Tmap1.UVintVfracStepVCarry, eax // save in v-carry slot - - - -OnePixelSpan: - -/* -; check coordinate ranges - mov eax, Tmap1.UFixed - cmp eax, Tmap1.MinUFixed - jge UNotTooSmall_2 - mov eax, Tmap1.MinUFixed - mov Tmap1.UFixed, eax - jmp CheckV_2 -UNotTooSmall_2: - cmp eax, Tmap1.MaxUFixed - jle CheckV_2 - mov eax, Tmap1.MaxUFixed - mov Tmap1.UFixed, eax -CheckV_2: - mov eax, Tmap1.VFixed - cmp eax, Tmap1.MinVFixed - jge VNotTooSmall_2 - mov eax, Tmap1.MinVFixed - mov Tmap1.VFixed, eax - jmp DoneCheck_2 -VNotTooSmall_2: - cmp eax, Tmap1.MaxVFixed - jle DoneCheck_2 - mov eax, Tmap1.MaxVFixed - mov Tmap1.VFixed, eax -DoneCheck_2: -*/ - - - - - ; setup initial coordinates - mov esi, Tmap1.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap1.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap1.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap1.pixptr // calc address - - ; set edi = address of first pixel to modify -; mov edi, Tmap1.dest_row_data - - - - - mov eax, Tmap1.fx_l - shr eax, 8 - mov bx, ax - - mov edx, Tmap1.DeltaUFrac - - cmp Tmap1.WidthModLength, 1 - jle NoDeltaLight - - push ebx - - mov ebx, Tmap1.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - -#if 0 - // slow but maybe better - push edx - cdq - mov ebx, Tmap1.WidthModLength - dec ebx - idiv ebx - pop edx -#else - mov eax, Tmap1.fx_dl_dx - shr eax, 8 -#endif - - mov dx, ax - - pop ebx - -NoDeltaLight: - - inc Tmap1.WidthModLength - mov eax,Tmap1.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap1.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -NextPixel: - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov [edi+0],eax // store pixel 0 - - add ecx,Tmap1.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - - adc esi,UVintVfracStep[4*ebp] // add in step ints & carries - mov [edi+4],eax // store pixel 1 - - add edi, 8 - dec Tmap1.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - - movzx eax,byte ptr [esi] // get texture pixel 0 - mov ah, bh - mov eax, gr_fade_table32[eax*4] - mov [edi],eax // store pixel 2 - - - - - - - - - - - - - -/* -OldWay: // This is 6% slower than above - - mov ebx,Tmap1.UFixed ; get starting coordinates - mov ecx,Tmap1.VFixed ; for span - - ; leftover pixels loop - ; edi = dest dib bits - ; esi = texture dib bits - - ; ebx = u 16.16 - ; ecx = v 16.16 - - - mov eax,ecx ; copy v - sar eax,16 ; int(v) - imul eax,Tmap1.src_offset ; scan offset - mov edx,ebx ; copy u - sar edx,16 ; int(u) - add eax,edx ; texture offset - mov al,[esi+eax] ; get source pixel -mov al, 0 - mov [edi],al ; store it - inc edi - add ebx,Tmap1.DeltaU ; increment u coordinate - add ecx,Tmap1.DeltaV ; increment v coordinate - - dec Tmap1.WidthModLength ; decrement loop count - jl FPUReturn ; finish up - - -LeftoverLoop: - mov eax,ecx ; copy v - sar eax,16 ; int(v) - imul eax,Tmap1.src_offset ; scan offset - mov edx,ebx ; copy u - sar edx,16 ; int(u) - add eax,edx ; texture offset - mov al,[esi+eax] ; get source pixel - mov [edi],al ; store it - inc edi - add ebx,Tmap1.DeltaU ; increment u coordinate - add ecx,Tmap1.DeltaV ; increment v coordinate - - dec Tmap1.WidthModLength ; decrement loop count - jge LeftoverLoop ; finish up -*/ - -FPUReturn: - - ; busy FPU registers: ; st0 st1 st2 st3 st4 st5 st6 st7 - ; xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - -//Return: - - fldcw Tmap1.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } - - -} - - - - -add edx,DeltaVFrac ; Add in 0.32 DeltaVFrac to VFrac -sbb ebp,ebp ; ebp will equal -1 if there was a carry -mov BYTE PTR [edi], al ; blit destination pixel -mov al, BYTE PTR [esi] ; get next texel -add ecx,ebx ; add 0.32 DeltaUFrac to UFrac, plus light -adc esi, [UVStepCarry1+(ebp*4)] -mov ah, ch ; move lighting value into place -mov al, ShadeTable[eax] ; Get shaded pixel - - - - - - - - - - -#endif - diff --git a/src/graphics/tmapper.cpp b/src/graphics/tmapper.cpp deleted file mode 100644 index 8e59270..0000000 --- a/src/graphics/tmapper.cpp +++ /dev/null @@ -1,907 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/Tmapper.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Routines to draw a texture map. - * - * $Log$ - * Revision 1.4 2002/06/09 04:41:18 relnev - * added copyright header - * - * Revision 1.3 2002/06/09 03:16:04 relnev - * added _splitpath. - * - * removed unneeded asm, old sdl 2d setup. - * - * fixed crash caused by opengl_get_region. - * - * Revision 1.2 2002/05/28 08:52:03 relnev - * implemented two assembly stubs. - * - * cleaned up a few warnings. - * - * added a little demo hackery to make it progress a little farther. - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 3 12/06/98 3:08p Dave - * Fixed grx_tmapper to handle pixel fog flag. First run fog support for - * D3D. - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 78 5/13/98 2:53p John - * Made subspace effect work under software. Had to add new inner loop to - * tmapper. Added glows to end of subspace effect. Made subspace effect - * levels use gamepalette-subspace palette. - * - * 77 4/10/98 5:20p John - * Changed RGB in lighting structure to be ubytes. Removed old - * not-necessary 24 bpp software stuff. - * - * 76 4/09/98 7:58p John - * Cleaned up tmapper code a bit. Put NDEBUG around some ndebug stuff. - * Took out XPARENT flag settings in all the alpha-blended texture stuff. - * - * 75 4/09/98 7:16p John - * Fixed bug causing software to not render - * - * 74 3/27/98 8:34p Mike - * Minor optimization. - * - * 73 3/25/98 8:08p John - * Restructured software rendering into two modules; One for windowed - * debug mode and one for DirectX fullscreen. - * - * 72 3/23/98 5:00p John - * Improved missile trails. Made smooth alpha under hardware. Made end - * taper. Made trail touch weapon. - * - * 71 3/22/98 2:33p John - * Took out fx_v/v_right. Made fx_u etc get calculated in tmapper. - * - * 70 3/10/98 4:19p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 69 2/10/98 5:34p John - * - * 68 2/05/98 9:21p John - * Some new Direct3D code. Added code to monitor a ton of stuff in the - * game. - * - * 67 1/29/98 8:18a John - * Put in some commented out hooks for RGB lighting - * - * 66 1/28/98 1:27p John - * Really fixed bug with exception on mov al, [esi] - * - * 65 1/28/98 1:22p John - * Fixed bug with unitialized dwdx_wide. - * - * 64 1/27/98 5:13p John - * Moved all float to int conversions out of inner loops and into outer. - * Made outer loop use FISTP instead of ftol, saved about 10%. - * - * 63 1/23/98 5:08p John - * Took L out of vertex structure used B (blue) instead. Took all small - * fireballs out of fireball types and used particles instead. Fixed some - * debris explosion things. Restructured fireball code. Restructured - * some lighting code. Made dynamic lighting on by default. Made groups - * of lasers only cast one light. Made fireballs not cast light. - * - * 62 1/19/98 6:15p John - * Fixed all my Optimized Build compiler warnings - * - * 61 12/15/97 11:32a John - * New Laser Code - * - * 60 12/02/97 4:00p John - * Added first rev of thruster glow, along with variable levels of - * translucency, which retquired some restructing of palman. - * - * 59 11/30/97 4:40p John - * made 32-bpp tiled tmapper call scanline - * - * 58 11/30/97 3:57p John - * Made fixed 32-bpp translucency. Made BmpMan always map translucent - * color into 255 even if you aren't supposed to remap and make it's - * palette black. - * - * 57 11/30/97 12:18p John - * added more 24 & 32-bpp primitives - * - * 56 11/29/97 2:06p John - * added mode 16-bpp support - * - * 55 11/21/97 11:32a John - * Added nebulas. Fixed some warpout bugs. - * - * 54 11/14/97 12:30p John - * Fixed some DirectX bugs. Moved the 8-16 xlat tables into Graphics - * libs. Made 16-bpp DirectX modes know what bitmap format they're in. - * - * 53 11/06/97 11:18a John - * added 16-bpp gouraud flat shader - * - * 52 10/19/97 12:55p John - * new code to lock / unlock surfaces for smooth directx integration. - * - * 51 10/16/97 10:55a John - * added tmapper to draw a monochrome alpha blended bitmap. - * - * 50 10/14/97 8:08a John - * added a bunch more 16 bit support - * - * 49 10/09/97 5:23p John - * Added support for more 16-bpp functions - * - * 48 9/30/97 2:30p John - * test code for texture fading - * - * 47 9/24/97 10:37a John - * made tmapper not trash uv values anymore. - * - * 46 9/09/97 11:01a Sandeep - * fixed warning level 4 bugs - * - * 45 7/11/97 11:54a John - * added rotated 3d bitmaps. - * - * 44 6/18/97 5:02p John - * fixed bug with 32x32 and 16x16 tmapper - * - * 43 6/12/97 5:04p John - * Initial rev of Glide support - * - * 42 6/12/97 2:50a Lawrance - * bm_unlock() now passed bitmap number, not pointer - * - * 41 6/02/97 11:45a John - * fixed bugs with 64x64 and 128x128 tmappers. - * - * 40 6/01/97 3:41p John - * made non-tilable textures on tilable models bash uvs to 0-1. - * - * 39 5/12/97 12:27p John - * Restructured Graphics Library to add support for multiple renderers. - * - * 38 5/07/97 4:14p John - * Reenabled calls to gr_start/end_frame. - * - * 37 4/21/97 10:06a John - * Got capital ships working again. - * - * 36 4/17/97 6:06p John - * New code/data for v19 of BSPGEN with smoothing and zbuffer - * optimizations. - * - * 35 4/08/97 5:18p John - * First rev of decent (dynamic, correct) lighting in FreeSpace. - * - * 34 3/18/97 9:42a John - * - * 33 3/15/97 2:44p John - * got scanline sorting method working. Bummer it is slower than zbuffer! - * - * 32 3/14/97 3:55p John - * Made tiled tmapper not always be zbuffered. - * - * 31 3/13/97 10:32a John - * Added code for tiled 256x256 textures in certain models. - * - * 30 3/12/97 2:51p John - * Added some test code for tmapper. - * - * 29 3/12/97 9:25a John - * fixed a bug with zbuffering. Reenabled it by default. - * - * 28 3/11/97 4:36p John - * added zbuffering to textest. Made zbuffered tmapper a bit faster by - * rearranging some instructions. - * - * 27 3/10/97 5:20p John - * Differentiated between Gouraud and Flat shading. Since we only do flat - * shading as of now, we don't need to interpolate L in the outer loop. - * This should save a few percent. - * - * 26 3/10/97 2:24p John - * added some commets about precompiled inner loop - * - * 25 3/05/97 7:15p John - * took out the old z stop tmapper used for briefing. - * - * 24 1/20/97 4:17p John - * - * 23 1/06/97 2:44p John - * Added in slow (but correct) zbuffering - * - * 22 12/30/96 3:46p John - * - * 21 12/23/96 10:56a John - * Totally restructured the POF stuff to support multiple - * detail levels in one POF file. - * - * - * 20 12/10/96 10:37a John - * Restructured texture mapper to remove some overhead from each scanline - * setup. This gave about a 30% improvement drawing trans01.pof, which is - * a really complex model. In the process, I cleaned up the scanline - * functions and separated them into different modules for each pixel - * depth. - * - * 19 11/26/96 6:50p John - * Added some more hicolor primitives. Made windowed mode run as current - * bpp, if bpp is 8,16,or 32. - * - * 18 11/07/96 6:19p John - * Added a bunch of 16bpp primitives so the game sort of runs in 16bpp - * mode. - * - * 17 11/07/96 3:08p John - * Inlined more Tmapper functions in preparation for cleaning up the Tmap1 - * interface to the assembly. - * - * 16 11/07/96 2:17p John - * Took out the OldTmapper stuff. - * - * 15 11/07/96 12:04p John - * Sped up outer loop by 35% by inlining the incrementing of the variables - * for each scanline step and inlined the calculation for deltas at the - * start of each scanline. - * - * 14 11/06/96 2:33p John - * Added more asserts for checking that non-tiled UV's are between 0 and - * 1.0. Put code in the model_init code that checks for polys that have - * a vertex duplicated and throws them out. - * - * 13 11/05/96 4:05p John - * Added roller. Added code to draw a distant planet. Made bm_load - * return -1 if invalid bitmap. - * - * 12 10/31/96 7:20p John - * Added per,tiled tmapper. Made models tile if they use 64x64 textures. - * - * 11 10/26/96 1:40p John - * Added some now primitives to the 2d library and - * cleaned up some old ones. - * - * $NoKeywords: $ - */ - -#include -#include -#include -#ifndef PLAT_UNIX -#include -#endif -#include - -#include "2d.h" -#include "grinternal.h" -#include "3d.h" -#include "tmapper.h" -#include "bmpman.h" -#include "tmapscanline.h" -#include "key.h" -#include "floating.h" -#include "palman.h" - -typedef void (* pscanline)(); - -pscanline tmap_scanline; - -int Tmap_screen_flags = -1; -int Tmap_npolys=0; -int Tmap_nverts=0; -int Tmap_nscanlines=0; -int Tmap_npixels=0; -tmapper_data Tmap; -int Tmap_show_layers=0; - -typedef struct tmap_scan_desc { - uint flags; - pscanline scan_func; -} tmap_scan_desc; - -// Convert from a 0-255 byte to a 0-1.0 float. -float Light_table[256]; - - -//====================== 8-BPP SCANLINES ======================== -tmap_scan_desc tmap_scanlines8[] = { - { 0, tmapscan_flat8 }, - { TMAP_FLAG_TEXTURED, tmapscan_lnn8 }, - { TMAP_FLAG_TEXTURED|TMAP_FLAG_XPARENT, tmapscan_lnt8 }, - { TMAP_FLAG_TEXTURED|TMAP_FLAG_RAMP, tmapscan_lln8 }, - { TMAP_FLAG_TEXTURED|TMAP_FLAG_RAMP|TMAP_FLAG_CORRECT, tmapscan_pln8 }, - - { TMAP_FLAG_RAMP|TMAP_FLAG_GOURAUD, tmapscan_flat_gouraud }, - - { TMAP_FLAG_TEXTURED|TMAP_FLAG_RAMP|TMAP_FLAG_GOURAUD, tmapscan_lln8 }, - { TMAP_FLAG_TEXTURED|TMAP_FLAG_RAMP|TMAP_FLAG_GOURAUD|TMAP_FLAG_CORRECT, tmapscan_pln8 }, - - { TMAP_FLAG_TEXTURED|TMAP_FLAG_RAMP|TMAP_FLAG_CORRECT|TMAP_FLAG_TILED, tmapscan_pln8_tiled }, - { TMAP_FLAG_TEXTURED|TMAP_FLAG_RAMP|TMAP_FLAG_CORRECT|TMAP_FLAG_GOURAUD|TMAP_FLAG_TILED, tmapscan_pln8_tiled }, - - { TMAP_FLAG_RAMP|TMAP_FLAG_GOURAUD|TMAP_FLAG_NEBULA, tmapscan_nebula8 }, - -// { TMAP_FLAG_TEXTURED|TMAP_FLAG_TILED, tmapscan_lnn8_tiled_256x256 }, - // Totally non-general specific inner loop for subspace effect - { TMAP_FLAG_TEXTURED|TMAP_FLAG_CORRECT|TMAP_FLAG_TILED, tmapscan_pnn8_tiled_256x256_subspace }, - - - { 0, NULL }, // Dummy element to mark the end of fast scanlines. -}; - - -pscanline tmap_scanline_table[TMAP_MAX_SCANLINES]; - - -// ------------------------------------------------------------------------------------- -// This sets up the tmapper at the start of a given frame, so everything -// can can be pre-calculated should be calculated in here. -// This just fills in the tmap_scanline_table for the -// appropriate scan lines. - -void tmapper_setup() -{ - int i; - tmap_scan_desc * func_table = NULL; - - Tmap_screen_flags = gr_screen.mode; - - // Some constants for the inner loop - Tmap.FixedScale = 65536.0f; - Tmap.FixedScale8 = 2048.0f; //8192.0f; // 2^16 / 8 - Tmap.One = 1.0f; - - // Set tmap_scanline to not call a function - for (i=0; iscan_func != NULL) { - tmap_scanline_table[func_table->flags] = func_table->scan_func; - func_table++; - } - - for (i=0; i<256; i++ ) { - Light_table[i] = i2fl(i)/255.0f; - } - - -} - -// Sets up flat-shaded lighting -void tmapper_set_light(vertex *v, uint flags) -{ - if ( flags & TMAP_FLAG_GOURAUD ) return; - - if ( (flags & (TMAP_FLAG_RAMP|TMAP_FLAG_RGB))==(TMAP_FLAG_RAMP|TMAP_FLAG_RGB)) { - Int3(); // You're doing RGB and RAMP lighting!!! - } - - if ( flags & TMAP_FLAG_RAMP ) { - Tmap.l.b = Tmap.r.b = i2fl(v->b)/255.0f; - Tmap.deltas.b = 0.0f; - } -} - -void tmapper_show_layers() -{ - int i; - ubyte * ptr = (ubyte *)Tmap.dest_row_data; - - for (i=0; i (int)gr_zbuffer[tmp] ) { - gr_zbuffer[tmp] = Tmap.fx_w; - - ui = fl2i( u / w ) % Tmap.bp->w; - vi = fl2i( v / w ) % Tmap.bp->h; - - c = Tmap.pixptr[vi*Tmap.bp->w+ui]; - *dptr = gr_fade_table[fl2i(l*31)*256+c]; - - } - Tmap.fx_w += Tmap.fx_dwdx; - l+=dl; - u+=du; - v+=dv; - w+=dw; - dptr++; - } -} -*/ - - -// Same as ftol except that it might round up or down, -// unlike C's ftol, which must always round down. -// But, in the tmapper, we don't care, since this is -// just for Z and L. -inline int tmap_ftol(float f) -{ -#ifdef PLAT_UNIX - STUB_FUNCTION; - - return 0; -#else - int x; - - _asm fld f - _asm fistp x - - return x; -#endif -} - -/* -#define tmap_ftol(f) ((int)(f)) - -__ftol: -004569c0 push ebp -004569c1 mov ebp,esp -004569c3 add esp,fffffff4 -004569c6 wait -004569c7 fnstcw [ebp-02] -004569ca wait -004569cb mov ax,word ptr [ebp-02] -004569cf or ah,0c -004569d2 mov word ptr [ebp-04],ax -004569d6 fldcw [ebp-04] -004569d9 fistp qword ptr [ebp-0c] -004569dc fldcw [ebp-02] -004569df mov eax,dword ptr [ebp-0c] -004569e2 mov edx,dword ptr [ebp-08] -004569e5 leave -004569e6 ret -*/ - -#ifdef RGB_LIGHTING - -extern ubyte gr_palette[768]; - -uint last_code = 0xf; -void change_fade_table(uint code) -{ - int i,l; - - if ( last_code == code ) return; - last_code = code; - - int r1=0, g1=0, b1=0; - - for (i=0; i<256; i++ ) { - int r, g, b; - int ur, ug, ub; - r = gr_palette[i*3+0]; - g = gr_palette[i*3+1]; - b = gr_palette[i*3+2]; - - if ( (r == 255) && (g == 255) && (b == 255) ) { - // Make pure white not fade - for (l=0; l<32; l++ ) { - gr_fade_table[((l+1)*256)+i] = (unsigned char)i; - } - } else { - for (l=24; l<32; l++ ) { - - int x,y; - int gi, gr, gg, gb; - - gi = (r+g+b)/3; - - //gr = r*2; - //gg = g*2; - //gb = b*2; - - if ( code & 4 ) gr = gi*2; else gr = r; - if ( code & 2 ) gg = gi*2; else gg = g; - if ( code & 1 ) gb = gi*2; else gb = b; - -// gr = r1; -// gg = g1; -// gb = b1; //gi*2; - - x = l-24; // x goes from 0 to 7 - y = 31-l; // y goes from 7 to 0 - - ur = ((gr*x)+(r*y))/7; if ( ur > 255 ) ur = 255; - ug = ((gg*x)+(g*y))/7; if ( ug > 255 ) ug = 255; - ub = ((gb*x)+(b*y))/7; if ( ub > 255 ) ub = 255; - - gr_fade_table[((l+1)*256)+i] = (unsigned char)palette_find( ur, ug, ub ); - - } - } - gr_fade_table[ (0*256)+i ] = gr_fade_table[ (1*256)+i ]; - gr_fade_table[ (33*256)+i ] = gr_fade_table[ (32*256)+i ]; - } - - // Mirror the fade table - for (i=0; i<34; i++ ) { - for ( l = 0; l < 256; l++ ) { - gr_fade_table[ ((67-i)*256)+l ] = gr_fade_table[ (i*256)+l ]; - } - } - -} -#endif - - -void grx_tmapper( int nverts, vertex **verts, uint flags ) -{ - int i, y, li, ri, ly, ry, top, rem; - float ymin; - int next_break; - float ulist[TMAP_MAX_VERTS], vlist[TMAP_MAX_VERTS], llist[TMAP_MAX_VERTS]; - - flags &= (~TMAP_FLAG_ALPHA); - flags &= (~TMAP_FLAG_NONDARKENING); - flags &= (~TMAP_FLAG_PIXEL_FOG); - - // Check for invalid flags -#ifndef NDEBUG - if ( (flags & (TMAP_FLAG_RAMP|TMAP_FLAG_RGB))==(TMAP_FLAG_RAMP|TMAP_FLAG_RGB)) { - Int3(); // You're doing RGB and RAMP lighting!!! - } - - if ( flags & TMAP_FLAG_RGB ) { - Int3(); // RGB not supported! - } - - if ( (flags & TMAP_FLAG_GOURAUD) && (!(flags & TMAP_FLAG_RAMP)) ) { - Int3(); // Ramp mode required for gouraud! - } - - if ( gr_screen.bits_per_pixel != 8 ) { - Int3(); // Only 8-bpp tmapper supported - } - - Tmap_npolys++; - Tmap_nverts += nverts; - - SDL_assert(nverts <= TMAP_MAX_VERTS ); - -#endif - - if ( flags & (TMAP_FLAG_RAMP|TMAP_FLAG_GOURAUD) ) { - for (i=0; ib]; - } - } - - if ( Tmap_screen_flags != gr_screen.mode ) { - tmapper_setup(); - } - - tmap_scanline = tmap_scanline_table[flags]; -// tmap_scanline = tmap_scan_generic; - -#ifndef NDEBUG - SDL_assert( tmap_scanline != NULL ); - - if (Tmap_show_layers) - tmap_scanline = tmapper_show_layers; -#endif - - if ( tmap_scanline == NULL ) return; - - Tmap.FadeLookup = (uint)palette_get_fade_table(); - Tmap.BlendLookup = (uint)palette_get_blend_table(gr_screen.current_alpha); - - if ( flags & TMAP_FLAG_TEXTURED ) { - - Tmap.bp = bm_lock( gr_screen.current_bitmap, 8, 0 ); - - int was_tiled = 0, can_tile = 0; - if ( flags & TMAP_FLAG_TILED ) { - if ( (Tmap.bp->w==16) && (Tmap.bp->h==16) ) can_tile = 1; - if ( (Tmap.bp->w==32) && (Tmap.bp->h==32) ) can_tile = 1; - if ( (Tmap.bp->w==64) && (Tmap.bp->h==64) ) can_tile = 1; - if ( (Tmap.bp->w==128) && (Tmap.bp->h==128) ) can_tile = 1; - if ( (Tmap.bp->w==256) && (Tmap.bp->h==256) ) can_tile = 1; - - if ( !can_tile ) { - was_tiled = 1; - flags &= (~TMAP_FLAG_TILED); - } - } - - float max_u = i2fl(Tmap.bp->w) - 0.5f; - float max_v = i2fl(Tmap.bp->h) - 0.5f; - - for (i=0; iu * Tmap.bp->w; - vlist[i] = verts[i]->v * Tmap.bp->h; - - if ( !(flags & TMAP_FLAG_TILED) ) { - if ( ulist[i] < 1.0f ) ulist[i] = 1.0f; - if ( vlist[i] < 1.0f ) vlist[i] = 1.0f; - if ( ulist[i] > max_u ) ulist[i] = max_u; - if ( vlist[i] > max_v ) vlist[i] = max_v; - } - - // Multiply all u,v's by sw for perspective correction - if ( flags & TMAP_FLAG_CORRECT ) { - ulist[i] *= verts[i]->sw; - vlist[i] *= verts[i]->sw; - } - } - - Tmap.pixptr = (unsigned char *)Tmap.bp->data; - Tmap.src_offset = Tmap.bp->rowsize; - } - - // Find the topmost vertex - //top = -1; // Initialize to dummy value to avoid compiler warning - //ymin = 0.0f; // Initialize to dummy value to avoid compiler warning - // Instead of initializing to avoid compiler warnings, set to first value outside loop and remove (i==0) - // comparison, which otherwise happens nverts times. MK, 3/20/98 (was tracing code figuring out my shield effect bug...) - ymin = verts[0]->sy; - top = 0; - for (i=1; isy < ymin) { - ymin = verts[i]->sy; - top = i; - } - } - - li = ri = top; - rem = nverts; - y = fl_round_2048(ymin); //(int)floor(ymin + 0.5); - ly = ry = y - 1; - - gr_lock(); - Tmap.pScreenBits = (uint)gr_screen.offscreen_buffer_base; - - while( rem > 0 ) { - while ( ly<=y && rem>0 ) { // Advance left edge? - float dy, frac, recip; - rem--; - i = li-1; - if ( i<0 ) i = nverts-1; - ly = fl_round_2048(verts[i]->sy); //(int)floor(verts[i]->sy+0.5); - - dy = verts[i]->sy - verts[li]->sy; - if ( dy == 0.0f ) dy = 1.0f; - - frac = y + 0.5f - verts[li]->sy; - recip = 1.0f / dy; - - Tmap.dl.sx = (verts[i]->sx - verts[li]->sx)*recip; - Tmap.l.sx = verts[li]->sx + Tmap.dl.sx*frac; - - if ( flags & TMAP_FLAG_TEXTURED ) { - Tmap.dl.u = (ulist[i] - ulist[li])*recip; - Tmap.l.u = ulist[li] + Tmap.dl.u*frac; - Tmap.dl.v = (vlist[i] - vlist[li])*recip; - Tmap.l.v = vlist[li] + Tmap.dl.v*frac; - } - - if ( (flags & TMAP_FLAG_CORRECT) || gr_zbuffering ) { - Tmap.dl.sw = (verts[i]->sw - verts[li]->sw)*recip; - Tmap.l.sw = verts[li]->sw + Tmap.dl.sw*frac; - } - - if ( flags & TMAP_FLAG_GOURAUD ) { - if ( flags & TMAP_FLAG_RAMP ) { - Tmap.dl.b = (llist[i] - llist[li])*recip; - Tmap.l.b = llist[li] + Tmap.dl.b*frac; - } - } - - li = i; - } - while ( ry<=y && rem>0 ) { // Advance right edge? - float dy, frac, recip; - rem--; - i = ri+1; - if ( i>=nverts ) i = 0; - ry = fl_round_2048(verts[i]->sy); //(int)floor(verts[i]->sy+0.5); - - dy = verts[i]->sy - verts[ri]->sy; - if ( dy == 0.0f ) dy = 1.0f; - - frac = y + 0.5f - verts[ri]->sy; - recip = 1.0f / dy; - - Tmap.dr.sx = (verts[i]->sx - verts[ri]->sx)*recip; - Tmap.r.sx = verts[ri]->sx + Tmap.dr.sx*frac; - - if ( flags & TMAP_FLAG_TEXTURED ) { - Tmap.dr.u = (ulist[i] - ulist[ri])*recip; - Tmap.r.u = ulist[ri] + Tmap.dr.u*frac; - Tmap.dr.v = (vlist[i] - vlist[ri])*recip; - Tmap.r.v = vlist[ri] + Tmap.dr.v*frac; - } - - if ( (flags & TMAP_FLAG_CORRECT) || gr_zbuffering ) { - Tmap.dr.sw = (verts[i]->sw - verts[ri]->sw)*recip; - Tmap.r.sw = verts[ri]->sw + Tmap.dr.sw*frac; - } - - if ( flags & TMAP_FLAG_GOURAUD ) { - if ( flags & TMAP_FLAG_RAMP ) { - Tmap.dr.b = (llist[i] - llist[ri])*recip; - Tmap.r.b = llist[ri] + Tmap.dr.b*frac; - } - } - - ri = i; - } - - if ( ly < ry ) - next_break = ly; - else - next_break = ry; - - for ( ; y= gr_screen.clip_top) && ( y<=gr_screen.clip_bottom) ) { - int lx, rx; - - - lx = fl_round_2048(Tmap.l.sx); - if ( lx < gr_screen.clip_left ) { - Tmap.clipped_left = i2fl(gr_screen.clip_left) - Tmap.l.sx; - lx = gr_screen.clip_left; - } else { - Tmap.clipped_left = 0.0f; - } - rx = fl_round_2048(Tmap.r.sx-1.0f); - - if ( rx > gr_screen.clip_right ) rx = gr_screen.clip_right; - if ( lx <= rx ) { - float dx, recip; //frac; - - dx = Tmap.r.sx - Tmap.l.sx; - if ( dx == 0.0f ) dx = 1.0f; - - //frac = lx + 0.5f - Tmap.l.sx; - recip = 1.0f / dx; - - Tmap.y = y; - Tmap.rx = rx; - Tmap.lx = lx; - Tmap.loop_count = rx - lx + 1; - #ifndef NDEBUG - Tmap_npixels += Tmap.loop_count; - Tmap_nscanlines++; - #endif - - if ( (flags & TMAP_FLAG_CORRECT) || gr_zbuffering ) { - Tmap.deltas.sw = (Tmap.r.sw - Tmap.l.sw)*recip; - Tmap.fl_dwdx_wide = Tmap.deltas.sw*32.0f; - } - - if ( flags & TMAP_FLAG_TEXTURED ) { - Tmap.deltas.u = (Tmap.r.u - Tmap.l.u)*recip; - Tmap.deltas.v = (Tmap.r.v - Tmap.l.v)*recip; - - if ( flags & TMAP_FLAG_CORRECT ) { - Tmap.fl_dudx_wide = Tmap.deltas.u*32.0f; - Tmap.fl_dvdx_wide = Tmap.deltas.v*32.0f; - } else { - Tmap.fx_u = tmap_ftol((Tmap.l.u+Tmap.clipped_left*Tmap.deltas.u)*65536.0f); - Tmap.fx_v = tmap_ftol((Tmap.l.v+Tmap.clipped_left*Tmap.deltas.v)*65536.0f); - Tmap.fx_du_dx = tmap_ftol(Tmap.deltas.u*65536.0f); - Tmap.fx_dv_dx = tmap_ftol(Tmap.deltas.v*65536.0f); - } - } - - if ( flags & TMAP_FLAG_GOURAUD ) { - if ( flags & TMAP_FLAG_RAMP ) { - Tmap.deltas.b = (Tmap.r.b - Tmap.l.b)*recip; - - Tmap.fx_l = tmap_ftol(Tmap.l.b*32.0f*65536.0f); - Tmap.fx_l_right = tmap_ftol(Tmap.r.b*32.0f*65536.0f); - Tmap.fx_dl_dx = tmap_ftol(Tmap.deltas.b*32.0f*65536.0f); - - if ( Tmap.fx_dl_dx < 0 ) { - Tmap.fx_dl_dx = -Tmap.fx_dl_dx; - Tmap.fx_l = (67*F1_0)-Tmap.fx_l; - Tmap.fx_l_right = (67*F1_0)-Tmap.fx_l_right; - // SDL_assert( Tmap.fx_l > 31*F1_0 ); - // SDL_assert( Tmap.fx_l < 66*F1_0 ); - // SDL_assert( Tmap.fx_dl_dx >= 0 ); - // SDL_assert( Tmap.fx_dl_dx < 31*F1_0 ); - } - } - } - - if ( gr_zbuffering ) { - Tmap.fx_w = tmap_ftol(Tmap.l.sw * GR_Z_RANGE)+gr_zoffset; - Tmap.fx_dwdx = tmap_ftol(Tmap.deltas.sw * GR_Z_RANGE); - } - - Tmap.dest_row_data = GR_SCREEN_PTR_SIZE(gr_screen.bytes_per_pixel,Tmap.lx,Tmap.y); - - (*tmap_scanline)(); - - } - - } - - Tmap.l.sx += Tmap.dl.sx; - Tmap.r.sx += Tmap.dr.sx; - - if ( flags & TMAP_FLAG_TEXTURED ) { - Tmap.l.u += Tmap.dl.u; - Tmap.l.v += Tmap.dl.v; - - Tmap.r.u += Tmap.dr.u; - Tmap.r.v += Tmap.dr.v; - } - - if ( (flags & TMAP_FLAG_CORRECT) || gr_zbuffering ) { - Tmap.l.sw += Tmap.dl.sw; - Tmap.r.sw += Tmap.dr.sw; - } - - if ( flags & TMAP_FLAG_GOURAUD ) { - if ( flags & TMAP_FLAG_RAMP ) { - Tmap.l.b += Tmap.dl.b; - Tmap.r.b += Tmap.dr.b; - } - } - } - } - - gr_unlock(); - - if ( flags & TMAP_FLAG_TEXTURED ) { - bm_unlock(gr_screen.current_bitmap); - } - - -} diff --git a/src/graphics/tmapscanline.cpp b/src/graphics/tmapscanline.cpp deleted file mode 100644 index e0dc5ab..0000000 --- a/src/graphics/tmapscanline.cpp +++ /dev/null @@ -1,4585 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/TmapScanline.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Routines to draw one textured mapped scanline. - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:18 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 5 12/02/98 5:47p Dave - * Put in interface xstr code. Converted barracks screen to new format. - * - * 4 11/30/98 5:31p Dave - * Fixed up Fred support for software mode. - * - * 3 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 21 4/20/98 4:44p John - * Fixed problems with black being xparent on model cache rneders. Made - * model cache key off of detail level setting and framerate. - * - * 20 4/09/98 7:58p John - * Cleaned up tmapper code a bit. Put NDEBUG around some ndebug stuff. - * Took out XPARENT flag settings in all the alpha-blended texture stuff. - * - * 19 3/22/98 2:33p John - * Took out fx_v/v_right. Made fx_u etc get calculated in tmapper. - * - * 18 3/10/98 4:19p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 17 12/10/96 10:37a John - * Restructured texture mapper to remove some overhead from each scanline - * setup. This gave about a 30% improvement drawing trans01.pof, which is - * a really complex model. In the process, I cleaned up the scanline - * functions and separated them into different modules for each pixel - * depth. - * - * 16 12/02/96 4:03p John - * made texture divide pipeline better. 2.5% speedup. - * - * 15 11/26/96 6:50p John - * Added some more hicolor primitives. Made windowed mode run as current - * bpp, if bpp is 8,16,or 32. - * - * 14 11/18/96 9:58a John - * Fixed warnings - * - * 13 11/07/96 6:19p John - * Added a bunch of 16bpp primitives so the game sort of runs in 16bpp - * mode. - * - * 12 11/07/96 3:49p John - * Fixed some old 'c' inner loop code for testing. - * - * 11 11/07/96 2:17p John - * Took out the OldTmapper stuff. - * - * 10 11/05/96 4:05p John - * Added roller. Added code to draw a distant planet. Made bm_load - * return -1 if invalid bitmap. - * - * 9 10/31/96 7:20p John - * Added per,tiled tmapper. Made models tile if they use 64x64 textures. - * - * 8 10/26/96 1:40p John - * Added some now primitives to the 2d library and - * cleaned up some old ones. - * - * $NoKeywords: $ - */ - -#include "3d.h" -#include "2d.h" -#include "grinternal.h" -#include "tmapper.h" -#include "tmapscanline.h" -#include "floating.h" -#include "palman.h" -#include "fix.h" -#include "key.h" - -// Needed to keep warning 4725 to stay away. See PsTypes.h for details why. -void disable_warning_4725_stub_ts32() -{ -} - - -extern void tmapscan_pln8_tiled_256x256(); -extern void tmapscan_pln8_tiled_128x128(); -extern void tmapscan_pln8_tiled_64x64(); -extern void tmapscan_pln8_tiled_32x32(); -extern void tmapscan_pln8_tiled_16x16(); - - -void tmapscan_pln8_tiled() -{ - if ( (Tmap.bp->w == 256) && (Tmap.bp->h == 256) ) { - tmapscan_pln8_tiled_256x256(); - } else if ( (Tmap.bp->w == 128) && (Tmap.bp->h == 128) ) { - tmapscan_pln8_tiled_128x128(); - } else if ( (Tmap.bp->w == 64) && (Tmap.bp->h == 64) ) { - tmapscan_pln8_tiled_64x64(); - } else if ( (Tmap.bp->w == 32) && (Tmap.bp->h == 32) ) { - tmapscan_pln8_tiled_32x32(); - } else if ( (Tmap.bp->w == 16) && (Tmap.bp->h == 16) ) { - tmapscan_pln8_tiled_16x16(); - } else { - // argh! write another texure mapper! - tmapscan_pln8(); - } -} - - -void tmapscan_write_z() -{ - int i; - ubyte * dptr; - uint w, dw; - - dptr = (ubyte *)Tmap.dest_row_data; - - w = Tmap.fx_w; - dw = Tmap.fx_dwdx; - - uint *zbuf = (uint *)&gr_zbuffer[(uint)dptr-(uint)Tmap.pScreenBits]; - - for (i=0; i *zbuf ) { - *zbuf = w; - *dptr = gr_fade_table[(f2i(l)<<8)+c]; - } - zbuf++; - w += dw; - l+=dl; - dptr++; - } -} - -// ADAM: Change Nebula colors here: -#define NEBULA_COLORS 20 - -void tmapscan_nebula8() -{ - ubyte * dptr; - int l1,l2, dldx; - - dptr = (ubyte *)Tmap.dest_row_data; - - float max_neb_color = i2fl(NEBULA_COLORS-1); - - l1 = (int)(Tmap.l.b*max_neb_color*256.0f); - l2 = l1 + 256/2; // dithering - dldx = (int)(Tmap.deltas.b*max_neb_color*2.0f*256.0f); - - #ifdef USE_INLINE_ASM -// memset( dptr, 31, Tmap.loop_count ); -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm push eax - _asm push ebx - _asm push ecx - _asm push edx - _asm push edi - - // eax - l1 - // ebx - l2 - // ecx - count - // edx - dldx - // edi - dest - _asm mov eax, l1 - _asm mov ebx, l2 - _asm mov edx, dldx - _asm mov edi, dptr - - _asm mov ecx, Tmap.loop_count - _asm shr ecx, 1 - _asm jz DoFinal - _asm pushf - - Next2Pixels: - _asm mov [edi], ah - _asm add eax, edx - - _asm mov [edi+1], bh - _asm add ebx, edx - - _asm add edi, 2 - _asm dec ecx - _asm jnz Next2Pixels - - _asm popf - DoFinal: - _asm jnc NotDoFinal - _asm mov [edi], ah - NotDoFinal: - - _asm pop edi - _asm pop edx - _asm pop ecx - _asm pop ebx - _asm pop eax -#endif - - #else - int i; - if ( Tmap.loop_count > 1 ) { - for (i=0; i>8); - l1+=dldx; - dptr[1] = (ubyte)((l2&0xFF00)>>8); - l2+=dldx; - dptr+=2; - } - } - if ( Tmap.loop_count & 1 ) { - dptr[0] = (ubyte)((l1&0xFF00)>>8); - dptr++; - } - #endif -} - - -void tmapscan_flat_gouraud() -{ - if (gr_zbuffering) { - switch(gr_zbuffering_mode) { - case GR_ZBUFF_NONE: - break; - case GR_ZBUFF_FULL: // both - tmapscan_flat_gouraud_zbuffered(); - return; - case GR_ZBUFF_WRITE: // write only - tmapscan_flat_gouraud_zbuffered(); - break; - case GR_ZBUFF_READ: // read only - tmapscan_flat_gouraud_zbuffered(); - return; - } - } - - /* HARDWARE_ONLY - if ( Current_alphacolor ) { - ubyte *lookup = &Current_alphacolor->table.lookup[0][0]; - - int i; - ubyte * dptr; - fix l, dl; - - dptr = (ubyte *)Tmap.dest_row_data; - - l = Tmap.fx_l; - dl = Tmap.fx_dl_dx; - - for (i=0; i (int)gr_zbuffer[tmp] ) { - gr_zbuffer[tmp] = Tmap.fx_w; - *dptr = c; - } - Tmap.fx_w += Tmap.fx_dwdx; - dptr++; - } -} - -void tmapscan_flat8() -{ - if (gr_zbuffering) { - switch(gr_zbuffering_mode) { - case GR_ZBUFF_NONE: - break; - case GR_ZBUFF_FULL: // both - tmapscan_flat8_zbuffered(); - return; - case GR_ZBUFF_WRITE: // write only - tmapscan_write_z(); - break; - case GR_ZBUFF_READ: // read only - tmapscan_flat8_zbuffered(); - return; - } - } - - memset( (ubyte *)Tmap.dest_row_data, gr_screen.current_color.raw8, Tmap.loop_count ); -} - -void tmapscan_pln8_zbuffered(); - - -void tmapscan_pln8_ppro() -{ -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - mov edx,Tmap.DeltaUFrac // get register copy - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - xor eax, eax - mov al,[edi] // preread the destination cache line - xor eax, eax - mov al,[esi] // get texture pixel 0 - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - -InnerInnerLoop: - - push ebx - and ebx, 0ff00h - mov eax, DWORD PTR gr_fade_table[eax+ebx] // Get shaded pixel - pop ebx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+0],al // store pixel - xor eax, eax - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - push ebx - and ebx, 0ff00h - mov eax, DWORD PTR gr_fade_table[eax+ebx] // Get shaded pixel - pop ebx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+1],al // store pixel - xor eax, eax - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - push ebx - and ebx, 0ff00h - mov eax, DWORD PTR gr_fade_table[eax+ebx] // Get shaded pixel - pop ebx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+2],al // store pixel - xor eax, eax - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - push ebx - and ebx, 0ff00h - mov eax, DWORD PTR gr_fade_table[eax+ebx] // Get shaded pixel - pop ebx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+3],al // store pixel - xor eax, eax - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - add edi, 4 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, do not do deltas - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov edx, Tmap.DeltaUFrac - - cmp Tmap.WidthModLength, 1 - jle NoDeltaLight - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov dx, ax - - pop ebx - -NoDeltaLight: - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - mov al,[esi] - -NextPixel: - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+0],al // store pixel - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+1],al // store pixel - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - add edi, 2 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - - mov al,[esi] // get texture pixel 2 - mov ah, bh - mov al, gr_fade_table[eax] - mov [edi],al // store pixel 2 - - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - - -void tmapscan_pln8_pentium() -{ -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - mov edx,Tmap.DeltaUFrac // get register copy - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - - mov al,[edi] // preread the destination cache line - - mov al,[esi] // get texture pixel 0 - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - -InnerInnerLoop: - - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - - - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+0],al // store pixel - - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - - - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+1],al // store pixel - - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - - - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+2],al // store pixel - - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - - - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+3],al // store pixel - - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - add edi, 4 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, do not do deltas - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov edx, Tmap.DeltaUFrac - - cmp Tmap.WidthModLength, 1 - jle NoDeltaLight - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov dx, ax - - pop ebx - -NoDeltaLight: - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - mov al,[esi] - -NextPixel: - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+0],al // store pixel - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+1],al // store pixel - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - add edi, 2 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - - mov al,[esi] // get texture pixel 2 - mov ah, bh - mov al, gr_fade_table[eax] - mov [edi],al // store pixel 2 - - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - - - - -void tmapscan_pln8() -{ - if (gr_zbuffering) { - switch(gr_zbuffering_mode) { - case GR_ZBUFF_NONE: - break; - case GR_ZBUFF_FULL: // both - tmapscan_pln8_zbuffered(); - return; - case GR_ZBUFF_WRITE: // write only - tmapscan_write_z(); - break; - case GR_ZBUFF_READ: // read only - tmapscan_pln8_zbuffered(); - return; - } - - } - - if ( Gr_cpu > 5 ) { - tmapscan_pln8_ppro(); - } else { - tmapscan_pln8_pentium(); - } -} - - -void tmapscan_lln8() -{ -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; setup delta values - mov eax, Tmap.fx_dv_dx // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.fx_du_dx // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - ; setup initial coordinates - mov esi, Tmap.fx_u // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.fx_v // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - ; set edi = address of first pixel to modify - mov edi, Tmap.dest_row_data - - mov edx, Tmap.DeltaUFrac - - mov eax, Tmap.loop_count - shr eax, 2 - je DoLeftOverPixels - - mov Tmap.num_big_steps, eax - and Tmap.loop_count, 3 - - mov al,[edi] // preread the destination cache line - mov al,[esi] // get texture pixel 0 - -NextPixelBlock: - - push eax - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 2 //*4 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 2 - - mov dx, bp - pop eax - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+0],al // store pixel - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+1],al // store pixel - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+2],al // store pixel - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+3],al // store pixel - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - add edi, 4 - dec Tmap.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - - mov ebp, Tmap.fx_l - shr ebp, 8 - mov bx, bp - - mov ebp, Tmap.fx_dl_dx - shr ebp, 8 - mov dx, bp - - mov eax,Tmap.loop_count - test eax, -1 - jz _none_to_do - shr eax, 1 - je one_more_pix - mov Tmap.loop_count, eax - pushf - - xor eax, eax - - mov al, [edi] // preread the destination cache line - mov al, [esi] // Get first texel - -NextPixel: - - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+0],al // store pixel - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - mov ah, bh // move lighting value into place - mov al, gr_fade_table[eax] // Get shaded pixel - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - mov [edi+1],al // store pixel - mov al,[esi] // get texture pixel - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - - add edi, 2 - dec Tmap.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - xor eax, eax - mov al, [esi] // Get first texel - mov ah, bh - mov al, gr_fade_table[eax] - mov [edi],al // store pixel 2 - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - - -void tmapscan_lna8_zbuffered_ppro() -{ -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; setup delta values - mov eax, Tmap.fx_dv_dx // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.fx_du_dx // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - ; setup initial coordinates - mov esi, Tmap.fx_u // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.fx_v // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - ; set edi = address of first pixel to modify - mov edi, Tmap.dest_row_data - - xor eax, eax - mov al,[edi] // get the destination pixel - - mov ebp, Tmap.fx_w - mov edx, gr_zbuffer - mov eax, edi - sub eax, Tmap.pScreenBits - shl eax, 2 - add edx, eax - - mov eax, Tmap.loop_count - - shr eax, 2 - je DoLeftOverPixels - - mov Tmap.num_big_steps, eax - and Tmap.loop_count, 3 - -NextPixelBlock: - - // 8 pixel span code - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = zbuffer pointer - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // ebp = zvalue - // esp = stack - - cmp ebp, [edx+4*0] // Compare the Z depth of this pixel with zbuffer - jle Skip0a // If pixel is covered, skip drawing -// mov [edx+4*0], ebp // Write new Z value - - // Get pixel and blend it - push ebx - xor ebx, ebx - mov bl, [edi+0] - xor eax, eax // Clear all bits of EAX. This avoids a partial register stall on Pentium Pros - mov ah, [esi] // Get texel into AL - add eax, Tmap.BlendLookup - mov eax, [eax+ebx] // Lookup pixel in lighting table - pop ebx - - mov [edi+0],al // store pixel -Skip0a: - add ebp,Tmap.fx_dwdx // increment z value - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - - cmp ebp, [edx+4*1] // Compare the Z depth of this pixel with zbuffer - jle Skip1a // If pixel is covered, skip drawing -// mov [edx+4*1], ebp // Write new Z value - - // Get pixel and blend it - push ebx - xor ebx, ebx - mov bl, [edi+1] - xor eax, eax // Clear all bits of EAX. This avoids a partial register stall on Pentium Pros - mov ah, [esi] // Get texel into AL - add eax, Tmap.BlendLookup - mov eax, [eax+ebx] // Lookup pixel in lighting table - pop ebx - - mov [edi+1],al // store pixel -Skip1a: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - cmp ebp, [edx+4*2] // Compare the Z depth of this pixel with zbuffer - jle Skip2a // If pixel is covered, skip drawing -// mov [edx+4*2], ebp // Write new Z value - - push ebx - xor ebx, ebx - mov bl, [edi+2] - xor eax, eax // Clear all bits of EAX. This avoids a partial register stall on Pentium Pros - mov ah, [esi] // Get texel into AL - add eax, Tmap.BlendLookup - mov eax, [eax+ebx] // Lookup pixel in lighting table - pop ebx - - mov [edi+2],al // store pixel -Skip2a: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - cmp ebp, [edx+4*3] // Compare the Z depth of this pixel with zbuffer - jle Skip3a // If pixel is covered, skip drawing -// mov [edx+4*3], ebp // Write new Z value - - push ebx - xor ebx, ebx - mov bl, [edi+3] - xor eax, eax // Clear all bits of EAX. This avoids a partial register stall on Pentium Pros - mov ah, [esi] // Get texel into AL - add eax, Tmap.BlendLookup - mov eax, [eax+ebx] // Lookup pixel in lighting table - pop ebx - - mov [edi+3],al // store pixel -Skip3a: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - add edx, 16 - add edi, 4 - dec Tmap.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - - mov eax,Tmap.loop_count - test eax, -1 - jz _none_to_do - shr eax, 1 - je one_more_pix - mov Tmap.loop_count, eax - pushf - - xor eax, eax - mov al,[edi] // get the destination pixel - -NextPixel: - - cmp ebp, [edx+4*0] // Compare the Z depth of this pixel with zbuffer - jle Skip0b // If pixel is covered, skip drawing -// mov [edx+4*0], ebp // Write new Z value - mov al,[edi+0] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi+0],al // store pixel -Skip0b: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - cmp ebp, [edx+4*1] // Compare the Z depth of this pixel with zbuffer - jle Skip1b // If pixel is covered, skip drawing -// mov [edx+4*1], ebp // Write new Z value - mov al,[edi+1] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi+1],al // store pixel -Skip1b: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - add edi, 2 - add edx, 8 - dec Tmap.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - cmp ebp, [edx] // Compare the Z depth of this pixel with zbuffer - jle Skip0c // If pixel is covered, skip drawing -// mov [edx], ebp // Write new Z value - mov al,[edi] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi],al // store pixel -Skip0c: - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - -void tmapscan_lna8_zbuffered_pentium() -{ -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; setup delta values - mov eax, Tmap.fx_dv_dx // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.fx_du_dx // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - ; setup initial coordinates - mov esi, Tmap.fx_u // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.fx_v // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - ; set edi = address of first pixel to modify - mov edi, Tmap.dest_row_data - - xor eax, eax - mov al,[edi] // get the destination pixel - - mov ebp, Tmap.fx_w - mov edx, gr_zbuffer - mov eax, edi - sub eax, Tmap.pScreenBits - shl eax, 2 - add edx, eax - - mov eax, Tmap.loop_count - - shr eax, 2 - je DoLeftOverPixels - - mov Tmap.num_big_steps, eax - and Tmap.loop_count, 3 - -NextPixelBlock: - - // 8 pixel span code - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = zbuffer pointer - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // ebp = zvalue - // esp = stack - - cmp ebp, [edx+4*0] // Compare the Z depth of this pixel with zbuffer - jle Skip0a // If pixel is covered, skip drawing -// mov [edx+4*0], ebp // Write new Z value - mov al,[edi+0] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - - - - - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - - - mov [edi+0],al // store pixel -Skip0a: - add ebp,Tmap.fx_dwdx // increment z value - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - - cmp ebp, [edx+4*1] // Compare the Z depth of this pixel with zbuffer - jle Skip1a // If pixel is covered, skip drawing -// mov [edx+4*1], ebp // Write new Z value - mov al,[edi+1] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - - - - - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - - - mov [edi+1],al // store pixel -Skip1a: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - cmp ebp, [edx+4*2] // Compare the Z depth of this pixel with zbuffer - jle Skip2a // If pixel is covered, skip drawing -// mov [edx+4*2], ebp // Write new Z value - mov al,[edi+2] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - - - - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - - - mov [edi+2],al // store pixel -Skip2a: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - cmp ebp, [edx+4*3] // Compare the Z depth of this pixel with zbuffer - jle Skip3a // If pixel is covered, skip drawing -// mov [edx+4*3], ebp // Write new Z value - mov al,[edi+3] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - - - - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - - - mov [edi+3],al // store pixel -Skip3a: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - add edx, 16 - add edi, 4 - dec Tmap.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - - mov eax,Tmap.loop_count - test eax, -1 - jz _none_to_do - shr eax, 1 - je one_more_pix - mov Tmap.loop_count, eax - pushf - - xor eax, eax - mov al,[edi] // get the destination pixel - -NextPixel: - - cmp ebp, [edx+4*0] // Compare the Z depth of this pixel with zbuffer - jle Skip0b // If pixel is covered, skip drawing -// mov [edx+4*0], ebp // Write new Z value - mov al,[edi+0] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi+0],al // store pixel -Skip0b: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - cmp ebp, [edx+4*1] // Compare the Z depth of this pixel with zbuffer - jle Skip1b // If pixel is covered, skip drawing -// mov [edx+4*1], ebp // Write new Z value - mov al,[edi+1] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi+1],al // store pixel -Skip1b: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - add edi, 2 - add edx, 8 - dec Tmap.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - cmp ebp, [edx] // Compare the Z depth of this pixel with zbuffer - jle Skip0c // If pixel is covered, skip drawing -// mov [edx], ebp // Write new Z value - mov al,[edi] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi],al // store pixel -Skip0c: - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - -void tmapscan_lna8_zbuffered() -{ - if ( Gr_cpu > 5 ) { - tmapscan_lna8_zbuffered_ppro(); - } else { - tmapscan_lna8_zbuffered_pentium(); - } -} - - - -extern float Tmap_clipped_left; - -void tmapscan_lna8() -{ - if (gr_zbuffering) { - switch(gr_zbuffering_mode) { - case GR_ZBUFF_NONE: - break; - case GR_ZBUFF_FULL: // both - case GR_ZBUFF_WRITE: // write only - case GR_ZBUFF_READ: // read only - tmapscan_lna8_zbuffered(); - return; - } - - } - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; setup delta values - mov eax, Tmap.fx_dv_dx // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.fx_du_dx // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - ; setup initial coordinates - mov esi, Tmap.fx_u // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.fx_v // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - ; set edi = address of first pixel to modify - mov edi, Tmap.dest_row_data - - mov edx, Tmap.DeltaUFrac - - xor eax, eax - mov al,[edi] // get the destination pixel - - mov ebp, Tmap.loop_count - - shr ebp, 2 - je DoLeftOverPixels - - mov Tmap.num_big_steps, ebp - and Tmap.loop_count, 3 - - mov eax, 0 - -NextPixelBlock: - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - - xor eax, eax - mov al,[edi+0] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi+0],al // store pixel - - xor eax, eax - mov al,[edi+1] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi+1],al // store pixel - - xor eax, eax - mov al,[edi+2] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi+2],al // store pixel - - xor eax, eax - mov al,[edi+3] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi+3],al // store pixel - - add edi, 4 - dec Tmap.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - - mov ebp,Tmap.loop_count - test ebp, -1 - jz _none_to_do - shr ebp, 1 - je one_more_pix - mov Tmap.loop_count, ebp - pushf - - mov al,[edi] // get the destination pixel - -NextPixel: - - xor eax, eax - mov al,[edi+0] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi+0],al // store pixel - - xor eax, eax - mov al,[edi+1] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi+1],al // store pixel - - add edi, 2 - dec Tmap.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - mov eax, 0 - mov al,[edi] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add eax, Tmap.BlendLookup - mov al, [eax] // blend them - mov [edi],al // store pixel - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - -// HACKED IN SYSTEM FOR DOING MODEL CACHING -int Tmap_scan_read = 0; // 0 = normal mapper, 1=read, 2=write - -// HACKED IN SYSTEM FOR DOING MODEL CACHING -void tmapscan_lnn8_read() -{ - Tmap.fx_u = fl2f(Tmap.l.u); - Tmap.fx_v = fl2f(Tmap.l.v); - Tmap.fx_du_dx = fl2f(Tmap.deltas.u); - Tmap.fx_dv_dx = fl2f(Tmap.deltas.v); - -/* - int i; - - ubyte * src = (ubyte *)Tmap.pixptr; - ubyte * dst = (ubyte *)Tmap.dest_row_data; - - for (i=0; i// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov edx, Tmap.DeltaUFrac - mov dx, bp - mov Tmap.DeltaUFrac, edx - - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - mov al,[esi] // get texture pixel 0 - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - - mov ebp, Tmap.fx_w - - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - -InnerInnerLoop: - - // Pixel 0 - cmp ebp, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0 // If pixel is covered, skip drawing - mov [edx+0], ebp // Write new Z value - - // Get pixel and light it - push ebx - xor eax, eax // Clear all bits of EAX. This avoids a partial register stall on Pentium Pros - mov al, [esi] // Get texel into AL - and ebx, 0ff00h // Clear out fractional part of EBX - mov eax, DWORD PTR gr_fade_table[eax+ebx] // Lookup pixel in lighting table - pop ebx - - mov [edi+0],al // Write new pixel - -Skip0: add ecx,Tmap.DeltaVFrac - sbb eax,eax - add ebp,Tmap.fx_dwdx - add ebx,Tmap.DeltaUFrac - adc esi,Tmap.uv_delta[4*eax+4] - - - // Pixel 1 - cmp ebp, [edx+4] // Compare the Z depth of this pixel with zbuffer - jle Skip1 // If pixel is covered, skip drawing - mov [edx+4], ebp // Write new Z value - - // Get pixel and light it - push ebx - xor eax, eax // Clear all bits of EAX. This avoids a partial register stall on Pentium Pros - mov al, [esi] // Get texel into AL - and ebx, 0ff00h // Clear out fractional part of EBX - mov eax, DWORD PTR gr_fade_table[eax+ebx] // Lookup pixel in lighting table - pop ebx - - mov [edi+1],al // Write new pixel - -Skip1: add ecx,Tmap.DeltaVFrac - sbb eax,eax - add ebp,Tmap.fx_dwdx - add ebx,Tmap.DeltaUFrac - adc esi,Tmap.uv_delta[4*eax+4] - - - // Pixel 2 - cmp ebp, [edx+8] // Compare the Z depth of this pixel with zbuffer - jle Skip2 // If pixel is covered, skip drawing - mov [edx+8], ebp // Write new Z value - - // Get pixel and light it - push ebx - xor eax, eax // Clear all bits of EAX. This avoids a partial register stall on Pentium Pros - mov al, [esi] // Get texel into AL - and ebx, 0ff00h // Clear out fractional part of EBX - mov eax, DWORD PTR gr_fade_table[eax+ebx] // Lookup pixel in lighting table - pop ebx - - mov [edi+2],al // Write new pixel - -Skip2: add ecx,Tmap.DeltaVFrac - sbb eax,eax - add ebp,Tmap.fx_dwdx - add ebx,Tmap.DeltaUFrac - adc esi,Tmap.uv_delta[4*eax+4] - - - // Pixel 3 - cmp ebp, [edx+12] // Compare the Z depth of this pixel with zbuffer - jle Skip3 // If pixel is covered, skip drawing - mov [edx+12], ebp // Write new Z value - - // Get pixel and light it - push ebx - xor eax, eax // Clear all bits of EAX. This avoids a partial register stall on Pentium Pros - mov al, [esi] // Get texel into AL - and ebx, 0ff00h // Clear out fractional part of EBX - mov eax, DWORD PTR gr_fade_table[eax+ebx] // Lookup pixel in lighting table - pop ebx - - mov [edi+3],al // Write new pixel - -Skip3: add ecx,Tmap.DeltaVFrac - sbb eax,eax - add ebp,Tmap.fx_dwdx - add ebx,Tmap.DeltaUFrac - adc esi,Tmap.uv_delta[4*eax+4] - - - - add edi, 4 - add edx, 16 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, ebp - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, do not do deltas - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - -// mov edx, Tmap.DeltaUFrac - - cmp Tmap.WidthModLength, 1 - jle NoDeltaLight - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov edx, Tmap.DeltaUFrac - mov dx, ax - mov Tmap.DeltaUFrac, edx - - pop ebx - -NoDeltaLight: - - mov ebp, Tmap.fx_w - - mov eax, edi - sub eax, Tmap.pScreenBits - shl eax, 2 - mov edx, gr_zbuffer - add edx, eax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - mov al,[esi] - - - -NextPixel: - // Pixel 0 - cmp ebp, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0a // If pixel is covered, skip drawing - mov [edx+0], ebp // Write new Z value - - // Get pixel and light it - push ebx - xor eax, eax // Clear all bits of EAX. This avoids a partial register stall on Pentium Pros - mov al, [esi] // Get texel into AL - and ebx, 0ff00h // Clear out fractional part of EBX - mov eax, DWORD PTR gr_fade_table[eax+ebx] // Lookup pixel in lighting table - pop ebx - - mov [edi+0],al // Write new pixel - -Skip0a: add ecx,Tmap.DeltaVFrac - sbb eax,eax - - //add edx, 4 // Go to next - add ebp,Tmap.fx_dwdx - - add ebx,Tmap.DeltaUFrac - - adc esi,Tmap.uv_delta[4*eax+4] - - - // Pixel 1 - cmp ebp, [edx+4] // Compare the Z depth of this pixel with zbuffer - jle Skip1a // If pixel is covered, skip drawing - mov [edx+4], ebp // Write new Z value - - // Get pixel and light it - push ebx - xor eax, eax // Clear all bits of EAX. This avoids a partial register stall on Pentium Pros - mov al, [esi] // Get texel into AL - and ebx, 0ff00h // Clear out fractional part of EBX - mov eax, DWORD PTR gr_fade_table[eax+ebx] // Lookup pixel in lighting table - pop ebx - - mov [edi+1],al // Write new pixel - -Skip1a: add ecx,Tmap.DeltaVFrac - sbb eax,eax - - //add edx, 4 // Go to next - add ebp,Tmap.fx_dwdx - - add ebx,Tmap.DeltaUFrac - - adc esi,Tmap.uv_delta[4*eax+4] - - - add edi, 2 - add edx, 8 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - - cmp ebp, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0c // If pixel is covered, skip drawing - mov [edx+0], ebp // Write new Z value - - // Get pixel and light it - push ebx - xor eax, eax // Clear all bits of EAX. This avoids a partial register stall on Pentium Pros - mov al, [esi] // Get texel into AL - and ebx, 0ff00h // Clear out fractional part of EBX - mov eax, DWORD PTR gr_fade_table[eax+ebx] // Lookup pixel in lighting table - pop ebx - - mov [edi+0],al // Write new pixel - -Skip0c: - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - -void tmapscan_pln8_zbuffered_pentium() -{ -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov edx, Tmap.DeltaUFrac - mov dx, bp - mov Tmap.DeltaUFrac, edx - - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - mov al,[esi] // get texture pixel 0 - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - - mov ebp, Tmap.fx_w - - mov edx, gr_zbuffer - - mov eax, edi - sub eax, Tmap.pScreenBits - shl eax, 2 - add edx, eax - -InnerInnerLoop: - - // Pixel 0 - mov eax, ebx // Get lighting value from BH into AH - and eax, 0ffffh; // Clear upper bits of EAX - - cmp ebp, [edx+0] // Compare the Z depth of this pixel with zbuffer - mov al, [esi] // Get texel into AL - jle Skip0 // If pixel is covered, skip drawing - - mov [edx+0], ebp // Write new Z value - - mov al, gr_fade_table[eax] // Lookup pixel in lighting table - mov [edi+0],al // Write new pixel - -Skip0: add ecx,Tmap.DeltaVFrac - sbb eax,eax - - //add edx, 4 // Go to next - add ebp,Tmap.fx_dwdx - - add ebx,Tmap.DeltaUFrac - - adc esi,Tmap.uv_delta[4*eax+4] - - - // Pixel 1 - mov eax, ebx // Get lighting value from BH into AH - and eax, 0ffffh; // Clear upper bits of EAX - - cmp ebp, [edx+4] // Compare the Z depth of this pixel with zbuffer - mov al, [esi] // Get texel into AL - jle Skip1 // If pixel is covered, skip drawing - - - mov [edx+4], ebp // Write new Z value - - mov al, gr_fade_table[eax] // Lookup pixel in lighting table - mov [edi+1],al // Write new pixel - -Skip1: add ecx,Tmap.DeltaVFrac - sbb eax,eax - - //add edx, 4 // Go to next - add ebp,Tmap.fx_dwdx - - add ebx,Tmap.DeltaUFrac - - adc esi,Tmap.uv_delta[4*eax+4] - - // Pixel 2 - - mov eax, ebx // Get lighting value from BH into AH - and eax, 0ffffh; // Clear upper bits of EAX - - - cmp ebp, [edx+8] // Compare the Z depth of this pixel with zbuffer - mov al, [esi] // Get texel into AL - jle Skip2 // If pixel is covered, skip drawing - - - mov [edx+8], ebp // Write new Z value - - mov al, gr_fade_table[eax] // Lookup pixel in lighting table - mov [edi+2],al // Write new pixel - -Skip2: add ecx,Tmap.DeltaVFrac - sbb eax,eax - - //add edx, 4 // Go to next - add ebp,Tmap.fx_dwdx - - add ebx,Tmap.DeltaUFrac - - adc esi,Tmap.uv_delta[4*eax+4] - - // Pixel 3 - mov eax, ebx // Get lighting value from BH into AH - and eax, 0ffffh; // Clear upper bits of EAX - - - cmp ebp, [edx+12] // Compare the Z depth of this pixel with zbuffer - mov al, [esi] // Get texel into AL - jle Skip3 // If pixel is covered, skip drawing - - - mov [edx+12], ebp // Write new Z value - - mov al, gr_fade_table[eax] // Lookup pixel in lighting table - mov [edi+3],al // Write new pixel - -Skip3: add ecx,Tmap.DeltaVFrac - sbb eax,eax - - //add edx, 4 // Go to next - add ebp,Tmap.fx_dwdx - - add ebx,Tmap.DeltaUFrac - - adc esi,Tmap.uv_delta[4*eax+4] - - - add edi, 4 - add edx, 16 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, ebp - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, do not do deltas - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - -// mov edx, Tmap.DeltaUFrac - - cmp Tmap.WidthModLength, 1 - jle NoDeltaLight - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov edx, Tmap.DeltaUFrac - mov dx, ax - mov Tmap.DeltaUFrac, edx - - pop ebx - -NoDeltaLight: - - mov ebp, Tmap.fx_w - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - mov al,[esi] - - - -NextPixel: - // Pixel 0 - mov eax, ebx // Get lighting value from BH into AH - and eax, 0ffffh; // Clear upper bits of EAX - - cmp ebp, [edx+0] // Compare the Z depth of this pixel with zbuffer - mov al, [esi] // Get texel into AL - jle Skip0a // If pixel is covered, skip drawing - - - mov [edx+0], ebp // Write new Z value - - mov al, gr_fade_table[eax] // Lookup pixel in lighting table - mov [edi+0],al // Write new pixel - -Skip0a: add ecx,Tmap.DeltaVFrac - sbb eax,eax - - //add edx, 4 // Go to next - add ebp,Tmap.fx_dwdx - - add ebx,Tmap.DeltaUFrac - - adc esi,Tmap.uv_delta[4*eax+4] - - - // Pixel 1 - mov eax, ebx // Get lighting value from BH into AH - and eax, 0ffffh; // Clear upper bits of EAX - - - cmp ebp, [edx+4] // Compare the Z depth of this pixel with zbuffer - mov al, [esi] // Get texel into AL - jle Skip1a // If pixel is covered, skip drawing - - mov [edx+4], ebp // Write new Z value - - mov al, gr_fade_table[eax] // Lookup pixel in lighting table - mov [edi+1],al // Write new pixel - -Skip1a: add ecx,Tmap.DeltaVFrac - sbb eax,eax - - //add edx, 4 // Go to next - add ebp,Tmap.fx_dwdx - - add ebx,Tmap.DeltaUFrac - - adc esi,Tmap.uv_delta[4*eax+4] - - - add edi, 2 - add edx, 8 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - - mov eax, ebx // Get lighting value from BH into AH - and eax, 0ffffh; // Clear upper bits of EAX - - cmp ebp, [edx+0] // Compare the Z depth of this pixel with zbuffer - mov al, [esi] // Get texel into AL - jle Skip0c // If pixel is covered, skip drawing - - mov al, gr_fade_table[eax] // Lookup pixel in lighting table - - mov [edx+0], ebp // Write new Z value - - mov [edi+0],al // Write new pixel - -Skip0c: - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - -void tmapscan_pln8_zbuffered() -{ - if ( Gr_cpu > 5 ) { - // Pentium Pro optimized code. - tmapscan_pln8_zbuffered_ppro(); - } else { - tmapscan_pln8_zbuffered_pentium(); - } -} - -void tmapscan_lnaa8_zbuffered() -{ -#ifndef HARDWARE_ONLY - Tmap.lookup = (uint)&Current_alphacolor->table.lookup[0][0]; - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; setup delta values - mov eax, Tmap.fx_dv_dx // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.fx_du_dx // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - ; setup initial coordinates - mov esi, Tmap.fx_u // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.fx_v // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - ; set edi = address of first pixel to modify - mov edi, Tmap.dest_row_data - - xor eax, eax - mov al,[edi] // get the destination pixel - - mov ebp, Tmap.fx_w - mov edx, gr_zbuffer - mov eax, edi - sub eax, Tmap.pScreenBits - shl eax, 2 - add edx, eax - - mov eax, Tmap.loop_count - - shr eax, 2 - je DoLeftOverPixels - - mov Tmap.num_big_steps, eax - and Tmap.loop_count, 3 - -NextPixelBlock: - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - cmp ebp, [edx+4*0] // Compare the Z depth of this pixel with zbuffer - jle Skip0a // If pixel is covered, skip drawing -// mov [edx+4*0], ebp // Write new Z value - mov al,[edi+0] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi+0],al // store pixel -Skip0a: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - - cmp ebp, [edx+4*1] // Compare the Z depth of this pixel with zbuffer - jle Skip1a // If pixel is covered, skip drawing -// mov [edx+4*1], ebp // Write new Z value - mov al,[edi+1] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi+1],al // store pixel -Skip1a: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - cmp ebp, [edx+4*2] // Compare the Z depth of this pixel with zbuffer - jle Skip2a // If pixel is covered, skip drawing -// mov [edx+4*2], ebp // Write new Z value - mov al,[edi+2] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi+2],al // store pixel -Skip2a: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - cmp ebp, [edx+4*3] // Compare the Z depth of this pixel with zbuffer - jle Skip3a // If pixel is covered, skip drawing -// mov [edx+4*3], ebp // Write new Z value - mov al,[edi+3] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi+3],al // store pixel -Skip3a: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - add edx, 16 - add edi, 4 - dec Tmap.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - - mov eax,Tmap.loop_count - test eax, -1 - jz _none_to_do - shr eax, 1 - je one_more_pix - mov Tmap.loop_count, eax - pushf - - xor eax, eax - mov al,[edi] // get the destination pixel - -NextPixel: - - cmp ebp, [edx+4*0] // Compare the Z depth of this pixel with zbuffer - jle Skip0b // If pixel is covered, skip drawing -// mov [edx+4*0], ebp // Write new Z value - mov al,[edi+0] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi+0],al // store pixel -Skip0b: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - cmp ebp, [edx+4*1] // Compare the Z depth of this pixel with zbuffer - jle Skip1b // If pixel is covered, skip drawing -// mov [edx+4*1], ebp // Write new Z value - mov al,[edi+1] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi+1],al // store pixel -Skip1b: - add ebp, Tmap.fx_dwdx - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb eax,eax // get -1 if carry - add ebx,Tmap.DeltaUFrac // increment u fraction - adc esi,Tmap.uv_delta[4*eax+4] // add in step ints & carries - - add edi, 2 - add edx, 8 - dec Tmap.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - cmp ebp, [edx] // Compare the Z depth of this pixel with zbuffer - jle Skip0c // If pixel is covered, skip drawing -// mov [edx], ebp // Write new Z value - mov al,[edi] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - and eax, 0ffffh - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi],al // store pixel -Skip0c: - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -#else - Int3(); -#endif -} - -void tmapscan_lnaa8() -{ -#ifndef HARDWARE_ONLY - if (gr_zbuffering) { - switch(gr_zbuffering_mode) { - case GR_ZBUFF_NONE: - break; - case GR_ZBUFF_FULL: // both - case GR_ZBUFF_WRITE: // write only - case GR_ZBUFF_READ: // read only - tmapscan_lnaa8_zbuffered(); - return; - } - - } - - Tmap.lookup = (uint)&Current_alphacolor->table.lookup[0][0]; - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - ; setup delta values - mov eax, Tmap.fx_dv_dx // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.fx_du_dx // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - ; setup initial coordinates - mov esi, Tmap.fx_u // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.fx_v // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - ; set edi = address of first pixel to modify - mov edi, Tmap.dest_row_data - - mov edx, Tmap.DeltaUFrac - - xor eax, eax - mov al,[edi] // get the destination pixel - - mov ebp, Tmap.loop_count - - shr ebp, 2 - je DoLeftOverPixels - - mov Tmap.num_big_steps, ebp - and Tmap.loop_count, 3 - - -NextPixelBlock: - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - - mov al,[edi+0] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi+0],al // store pixel - - mov al,[edi+1] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi+1],al // store pixel - - mov al,[edi+2] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi+2],al // store pixel - - mov al,[edi+3] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi+3],al // store pixel - - add edi, 4 - dec Tmap.num_big_steps - jne NextPixelBlock - - -DoLeftOverPixels: - - mov ebp,Tmap.loop_count - test ebp, -1 - jz _none_to_do - shr ebp, 1 - je one_more_pix - mov Tmap.loop_count, ebp - pushf - - xor eax, eax - mov al,[edi] // get the destination pixel - -NextPixel: - - mov al,[edi+0] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi+0],al // store pixel - - mov al,[edi+1] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add ecx,Tmap.DeltaVFrac // increment v fraction - sbb ebp,ebp // get -1 if carry - add ebx,edx // increment u fraction - adc esi,Tmap.uv_delta[4*ebp+4] // add in step ints & carries - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi+1],al // store pixel - - add edi, 2 - dec Tmap.loop_count - jne NextPixel - - popf - jnc _none_to_do - -one_more_pix: - mov al,[edi] // get the destination pixel - mov ah,[esi] // get texture pixel 0 - add eax, Tmap.lookup - mov al, [eax] // blend them - mov [edi],al // store pixel - -_none_to_do: - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -#else - Int3(); -#endif -} - - - - - diff --git a/src/graphics/tmapscantiled128x128.cpp b/src/graphics/tmapscantiled128x128.cpp deleted file mode 100644 index d0efd66..0000000 --- a/src/graphics/tmapscantiled128x128.cpp +++ /dev/null @@ -1,1257 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/TmapScanTiled128x128.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Routines for drawing tiled 128x128 textues - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:18 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 4 11/30/98 5:31p Dave - * Fixed up Fred support for software mode. - * - * 3 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 9 4/23/98 9:55a John - * Fixed some bugs in the tiled tmapper causing bright dots to appear all - * over models. - * - * 8 3/10/98 4:19p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 7 1/27/98 5:13p John - * Moved all float to int conversions out of inner loops and into outer. - * Made outer loop use FISTP instead of ftol, saved about 10%. - * - * 6 1/23/98 5:08p John - * Took L out of vertex structure used B (blue) instead. Took all small - * fireballs out of fireball types and used particles instead. Fixed some - * debris explosion things. Restructured fireball code. Restructured - * some lighting code. Made dynamic lighting on by default. Made groups - * of lasers only cast one light. Made fireballs not cast light. - * - * 5 12/04/97 10:38a John - * Fixed tiled texture mappers that were swapping uvs. - * - * 4 10/14/97 9:19a John - * removed fdiv warnings. - * - * 3 6/02/97 11:45a John - * fixed bugs with 64x64 and 128x128 tmappers. - * - * 2 5/12/97 12:27p John - * Restructured Graphics Library to add support for multiple renderers. - * - * 1 4/24/97 4:42p John - * Initial version of the tiled texture mappers for 64 & 128 wide - * textures. - * - * $NoKeywords: $ - */ - - -#include "3d.h" -#include "2d.h" -#include "grinternal.h" -#include "tmapper.h" -#include "tmapscanline.h" -#include "floating.h" -#include "palman.h" -#include "fix.h" - -// Needed to keep warning 4725 to stay away. See PsTypes.h for details why. -void disable_warning_4725_stub_tst128() -{ -} - - -void tmapscan_pln8_zbuffered_tiled_128x128() -{ -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - - mov edx, gr_zbuffer - - mov eax, edi - sub eax, Tmap.pScreenBits - shl eax, 2 - add edx, eax - -// Make ESI = DV:DU in 7:9,7:9 format - mov eax, Tmap.DeltaV - shr eax, 7 - mov esi, Tmap.DeltaU - shl esi, 9 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 7:9,7:9 format - mov eax, Tmap.VFixed - shr eax, 7 - mov ecx, Tmap.UFixed - shl ecx, 9 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 7.9:7.9 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - -InnerInnerLoop: - - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0 // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 1 - cmp esi, [edx+4] // Compare the Z depth of this pixel with zbuffer - jle Skip1 // If pixel is covered, skip drawing - - mov [edx+4], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al -Skip1: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 2 - cmp esi, [edx+8] // Compare the Z depth of this pixel with zbuffer - jle Skip2 // If pixel is covered, skip drawing - - mov [edx+8], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+2], al -Skip2: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 3 - cmp esi, [edx+12] // Compare the Z depth of this pixel with zbuffer - jle Skip3 // If pixel is covered, skip drawing - - mov [edx+12], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+3], al -Skip3: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - - add edi, 4 - add edx, 16 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, esi - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas' - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - -// mov edx, Tmap.DeltaUFrac - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov bp, ax - - pop ebx - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -// Make ESI = DV:DU in 7:9,7:9 format - mov eax, Tmap.DeltaV - shr eax, 7 - mov esi, Tmap.DeltaU - shl esi, 9 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 7:9,7:9 format - mov eax, Tmap.VFixed - shr eax, 7 - mov ecx, Tmap.UFixed - shl ecx, 9 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 7.9:7.9 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - - -NextPixel: - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0a // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0a: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 1 - cmp esi, [edx+4] // Compare the Z depth of this pixel with zbuffer - jle Skip1a // If pixel is covered, skip drawing - - mov [edx+4], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al -Skip1a: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - - - add edi, 2 - add edx, 8 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0b // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0b: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - -void tmapscan_pln8_tiled_128x128() -{ - if (gr_zbuffering) { - switch(gr_zbuffering_mode) { - case GR_ZBUFF_NONE: - break; - case GR_ZBUFF_FULL: // both - tmapscan_pln8_zbuffered_tiled_128x128(); - return; - case GR_ZBUFF_WRITE: // write only - tmapscan_pln8_zbuffered_tiled_128x128(); - break; - case GR_ZBUFF_READ: // read only - tmapscan_pln8_zbuffered_tiled_128x128(); - return; - } - } - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - - mov edx, gr_zbuffer - - mov eax, edi - sub eax, Tmap.pScreenBits - shl eax, 2 - add edx, eax - -// Make ESI = DV:DU in 7:9,7:9 format - mov eax, Tmap.DeltaV - shr eax, 7 - mov esi, Tmap.DeltaU - shl esi, 9 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 7:9,7:9 format - mov eax, Tmap.VFixed - shr eax, 7 - mov ecx, Tmap.UFixed - shl ecx, 9 - mov cx, ax - - - // eax = tmp - // ebx = light - // ecx = V:U in 7.9:7.9 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - -InnerInnerLoop: - - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 1 - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 2 - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+2], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 3 - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+3], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - - add edi, 4 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, esi - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas' - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - -// mov edx, Tmap.DeltaUFrac - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov bp, ax - - pop ebx - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -// Make ESI = DV:DU in 7:9,7:9 format - mov eax, Tmap.DeltaV - shr eax, 7 - mov esi, Tmap.DeltaU - shl esi, 9 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 7:9,7:9 format - mov eax, Tmap.VFixed - shr eax, 7 - mov ecx, Tmap.UFixed - shl ecx, 9 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 7.9:7.9 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - - -NextPixel: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 1 - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - - - add edi, 2 - add edx, 8 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 7.9:7.9 - shr ax, 9 // EAX = V:U in 7.9:16.0 - rol eax, 7 // EAX = V:U in 0.0:7:7 - and eax, 03fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*128)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - diff --git a/src/graphics/tmapscantiled16x16.cpp b/src/graphics/tmapscantiled16x16.cpp deleted file mode 100644 index 5ac2737..0000000 --- a/src/graphics/tmapscantiled16x16.cpp +++ /dev/null @@ -1,1302 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/TmapScanTiled16x16.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Routines for drawing tiled 16x16 textues - * - * $Log$ - * Revision 1.3 2002/06/09 04:41:18 relnev - * added copyright header - * - * Revision 1.2 2002/05/07 03:16:45 theoddone33 - * The Great Newline Fix - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 4 11/30/98 5:31p Dave - * Fixed up Fred support for software mode. - * - * 3 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 6 4/23/98 9:55a John - * Fixed some bugs in the tiled tmapper causing bright dots to appear all - * over models. - * - * 5 3/10/98 4:19p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 4 1/23/98 5:08p John - * Took L out of vertex structure used B (blue) instead. Took all small - * fireballs out of fireball types and used particles instead. Fixed some - * debris explosion things. Restructured fireball code. Restructured - * some lighting code. Made dynamic lighting on by default. Made groups - * of lasers only cast one light. Made fireballs not cast light. - * - * 3 12/04/97 10:38a John - * Fixed tiled texture mappers that were swapping uvs. - * - * 2 10/14/97 9:19a John - * removed fdiv warnings. - * - * 1 6/18/97 4:02p John - * added new code for 16x16 and 32x32 tiled tmaps. - * - * $NoKeywords: $ - */ - - -#include "3d.h" -#include "2d.h" -#include "grinternal.h" -#include "tmapper.h" -#include "tmapscanline.h" -#include "floating.h" -#include "palman.h" -#include "fix.h" - -// Needed to keep warning 4725 to stay away. See PsTypes.h for details why. -void disable_warning_4725_stub_tst16() -{ -} - -void tmapscan_pln8_zbuffered_tiled_16x16() -{ - Tmap.fx_l = fl2f(Tmap.l.b*32.0); - Tmap.fx_l_right = fl2f(Tmap.r.b*32.0); - Tmap.fx_dl_dx = fl2f(Tmap.deltas.b*32.0); - - if ( Tmap.fx_dl_dx < 0 ) { - Tmap.fx_dl_dx = -Tmap.fx_dl_dx; - Tmap.fx_l = (67*F1_0)-Tmap.fx_l; - Tmap.fx_l_right = (67*F1_0)-Tmap.fx_l_right; -// SDL_assert( Tmap.fx_l > 31*F1_0 ); -// SDL_assert( Tmap.fx_l < 66*F1_0 ); -// SDL_assert( Tmap.fx_dl_dx >= 0 ); -// SDL_assert( Tmap.fx_dl_dx < 31*F1_0 ); - } - - Tmap.fl_dudx_wide = Tmap.deltas.u*32.0f; - Tmap.fl_dvdx_wide = Tmap.deltas.v*32.0f; - Tmap.fl_dwdx_wide = Tmap.deltas.sw*32.0f; - - Tmap.fx_w = fl2i(Tmap.l.sw * GR_Z_RANGE)+gr_zoffset; - Tmap.fx_dwdx = fl2i(Tmap.deltas.sw * GR_Z_RANGE); - -// SDL_assert(Tmap.fx_w < 65536 ); -// SDL_assert(Tmap.fx_w >= 0 ); -// SDL_assert(Tmap.fx_w+Tmap.fx_dwdx*Tmap.loop_count < 65536 ); -// SDL_assert(Tmap.fx_w+Tmap.fx_dwdx*Tmap.loop_count >= 0 ); - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - - mov edx, gr_zbuffer - - mov eax, edi - sub eax, Tmap.pScreenBits - shl eax, 2 - add edx, eax - -// Make ESI = DV:DU in 5:11,5:11 format - mov eax, Tmap.DeltaV - shr eax, 4 - mov esi, Tmap.DeltaU - shl esi, 12 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 5:11,5:11 format - mov eax, Tmap.VFixed - shr eax, 4 - mov ecx, Tmap.UFixed - shl ecx, 12 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 8.6:10.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - -InnerInnerLoop: - - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0 // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 1 - cmp esi, [edx+4] // Compare the Z depth of this pixel with zbuffer - jle Skip1 // If pixel is covered, skip drawing - - mov [edx+4], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al -Skip1: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 2 - cmp esi, [edx+8] // Compare the Z depth of this pixel with zbuffer - jle Skip2 // If pixel is covered, skip drawing - - mov [edx+8], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+2], al -Skip2: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 3 - cmp esi, [edx+12] // Compare the Z depth of this pixel with zbuffer - jle Skip3 // If pixel is covered, skip drawing - - mov [edx+12], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+3], al -Skip3: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - - add edi, 4 - add edx, 16 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, esi - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas' - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - -// mov edx, Tmap.DeltaUFrac - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov bp, ax - - pop ebx - - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -// Make ESI = DV:DU in 6:10,6:10 format - mov eax, Tmap.DeltaV - shr eax, 4 - mov esi, Tmap.DeltaU - shl esi, 12 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 6:10,6:10 format - mov eax, Tmap.VFixed - shr eax, 4 - mov ecx, Tmap.UFixed - shl ecx, 12 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 8.6:10.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - - -NextPixel: - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0a // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0a: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 1 - cmp esi, [edx+4] // Compare the Z depth of this pixel with zbuffer - jle Skip1a // If pixel is covered, skip drawing - - mov [edx+4], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al -Skip1a: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - - - add edi, 2 - add edx, 8 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0b // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0b: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - -void tmapscan_pln8_tiled_16x16() -{ - if (gr_zbuffering) { - switch(gr_zbuffering_mode) { - case GR_ZBUFF_NONE: - break; - case GR_ZBUFF_FULL: // both - tmapscan_pln8_zbuffered_tiled_16x16(); - return; - case GR_ZBUFF_WRITE: // write only - tmapscan_pln8_zbuffered_tiled_16x16(); - break; - case GR_ZBUFF_READ: // read only - tmapscan_pln8_zbuffered_tiled_16x16(); - return; - } - } - - Tmap.fx_l = fl2f(Tmap.l.b*32.0); - Tmap.fx_l_right = fl2f(Tmap.r.b*32.0); - Tmap.fx_dl_dx = fl2f(Tmap.deltas.b*32.0); - - if ( Tmap.fx_dl_dx < 0 ) { - Tmap.fx_dl_dx = -Tmap.fx_dl_dx; - Tmap.fx_l = (67*F1_0)-Tmap.fx_l; - Tmap.fx_l_right = (67*F1_0)-Tmap.fx_l_right; -// SDL_assert( Tmap.fx_l > 31*F1_0 ); -// SDL_assert( Tmap.fx_l < 66*F1_0 ); -// SDL_assert( Tmap.fx_dl_dx >= 0 ); -// SDL_assert( Tmap.fx_dl_dx < 31*F1_0 ); - } - - Tmap.fl_dudx_wide = Tmap.deltas.u*32.0f; - Tmap.fl_dvdx_wide = Tmap.deltas.v*32.0f; - Tmap.fl_dwdx_wide = Tmap.deltas.sw*32.0f; - - Tmap.fx_w = fl2i(Tmap.l.sw * GR_Z_RANGE)+gr_zoffset; - Tmap.fx_dwdx = fl2i(Tmap.deltas.sw * GR_Z_RANGE); - -// SDL_assert(Tmap.fx_w < 65536 ); -// SDL_assert(Tmap.fx_w >= 0 ); -// SDL_assert(Tmap.fx_w+Tmap.fx_dwdx*Tmap.loop_count < 65536 ); -// SDL_assert(Tmap.fx_w+Tmap.fx_dwdx*Tmap.loop_count >= 0 ); - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - - mov edx, gr_zbuffer - - mov eax, edi - sub eax, Tmap.pScreenBits - shl eax, 2 - add edx, eax - -// Make ESI = DV:DU in 6:10,6:10 format - mov eax, Tmap.DeltaV - shr eax, 4 - mov esi, Tmap.DeltaU - shl esi, 12 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 6:10,6:10 format - mov eax, Tmap.VFixed - shr eax, 4 - mov ecx, Tmap.UFixed - shl ecx, 12 - mov cx, ax - - - // eax = tmp - // ebx = light - // ecx = V:U in 8.6:10.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - -InnerInnerLoop: - - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 1 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 2 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+2], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 3 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+3], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - - add edi, 4 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, esi - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas' - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - -// mov edx, Tmap.DeltaUFrac - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov bp, ax - - pop ebx - - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -// Make ESI = DV:DU in 6:10,6:10 format - mov eax, Tmap.DeltaV - shr eax, 4 - mov esi, Tmap.DeltaU - shl esi, 12 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 6:10,6:10 format - mov eax, Tmap.VFixed - shr eax, 4 - mov ecx, Tmap.UFixed - shl ecx, 12 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 8.6:10.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - - -NextPixel: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 1 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - - - add edi, 2 - add edx, 8 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 12 // EAX = V:U in 6.10:16.0 - rol eax, 4 // EAX = V:U in 0.0:6:6 - and eax, 0ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - diff --git a/src/graphics/tmapscantiled256x256.cpp b/src/graphics/tmapscantiled256x256.cpp deleted file mode 100644 index 4f7de49..0000000 --- a/src/graphics/tmapscantiled256x256.cpp +++ /dev/null @@ -1,2267 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/TmapScanTiled256x256.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Routines for drawing tiled 256x256 textues - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:18 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 4 11/30/98 5:31p Dave - * Fixed up Fred support for software mode. - * - * 3 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 11 5/13/98 2:53p John - * Made subspace effect work under software. Had to add new inner loop to - * tmapper. Added glows to end of subspace effect. Made subspace effect - * levels use gamepalette-subspace palette. - * - * 10 4/23/98 9:55a John - * Fixed some bugs in the tiled tmapper causing bright dots to appear all - * over models. - * - * 9 3/10/98 4:19p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 8 1/27/98 5:13p John - * Moved all float to int conversions out of inner loops and into outer. - * Made outer loop use FISTP instead of ftol, saved about 10%. - * - * 7 1/23/98 5:08p John - * Took L out of vertex structure used B (blue) instead. Took all small - * fireballs out of fireball types and used particles instead. Fixed some - * debris explosion things. Restructured fireball code. Restructured - * some lighting code. Made dynamic lighting on by default. Made groups - * of lasers only cast one light. Made fireballs not cast light. - * - * 6 12/04/97 10:38a John - * Fixed tiled texture mappers that were swapping uvs. - * - * 5 10/14/97 9:19a John - * removed fdiv warnings. - * - * 4 9/10/97 11:38a Sandeep - * - * 3 9/09/97 3:39p Sandeep - * warning level 4 bugs - * - * 2 5/12/97 12:27p John - * Restructured Graphics Library to add support for multiple renderers. - * - * 1 4/24/97 4:42p John - * Initial version of the tiled texture mappers for 64 & 128 wide - * textures. - * - * $NoKeywords: $ - */ - - -#include "3d.h" -#include "2d.h" -#include "grinternal.h" -#include "tmapper.h" -#include "tmapscanline.h" -#include "floating.h" -#include "palman.h" -#include "fix.h" -#include "key.h" - -// Needed to keep warning 4725 to stay away. See PsTypes.h for details why. -void disable_warning_4725_stub_tst256() -{ -} - -void tmapscan_pln8_zbuffered_tiled_256x256() -{ -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - -// Make ESI = DV:DU in 8:8,8:8 format - mov eax, Tmap.DeltaV - shr eax, 8 - mov esi, Tmap.DeltaU - shl esi, 8 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 8:8,8:8 format - mov eax, Tmap.VFixed - shr eax, 8 - mov ecx, Tmap.UFixed - shl ecx, 8 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 8.8:8.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - -InnerInnerLoop: - - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0 // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 1 - cmp esi, [edx+4] // Compare the Z depth of this pixel with zbuffer - jle Skip1 // If pixel is covered, skip drawing - - mov [edx+4], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al -Skip1: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 2 - cmp esi, [edx+8] // Compare the Z depth of this pixel with zbuffer - jle Skip2 // If pixel is covered, skip drawing - - mov [edx+8], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+2], al -Skip2: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 3 - cmp esi, [edx+12] // Compare the Z depth of this pixel with zbuffer - jle Skip3 // If pixel is covered, skip drawing - - mov [edx+12], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+3], al -Skip3: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - - add edi, 4 - add edx, 16 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, esi - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas' - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - -// mov edx, Tmap.DeltaUFrac - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov bp, ax - - pop ebx - - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -// Make ESI = DV:DU in 8:8,8:8 format - mov eax, Tmap.DeltaV - shr eax, 8 - mov esi, Tmap.DeltaU - shl esi, 8 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 8:8,8:8 format - mov eax, Tmap.VFixed - shr eax, 8 - mov ecx, Tmap.UFixed - shl ecx, 8 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 8.8:8.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - - -NextPixel: - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0a // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0a: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 1 - cmp esi, [edx+4] // Compare the Z depth of this pixel with zbuffer - jle Skip1a // If pixel is covered, skip drawing - - mov [edx+4], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al -Skip1a: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - - - add edi, 2 - add edx, 8 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0b // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0b: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - -void tmapscan_pln8_tiled_256x256() -{ - if (gr_zbuffering) { - switch(gr_zbuffering_mode) { - case GR_ZBUFF_NONE: - break; - case GR_ZBUFF_FULL: // both - tmapscan_pln8_zbuffered_tiled_256x256(); - return; - case GR_ZBUFF_WRITE: // write only - tmapscan_pln8_zbuffered_tiled_256x256(); - break; - case GR_ZBUFF_READ: // read only - tmapscan_pln8_zbuffered_tiled_256x256(); - return; - } - } - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - -// Make ESI = DV:DU in 8:8,8:8 format - mov eax, Tmap.DeltaV - shr eax, 8 - mov esi, Tmap.DeltaU - shl esi, 8 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 8:8,8:8 format - mov eax, Tmap.VFixed - shr eax, 8 - mov ecx, Tmap.UFixed - shl ecx, 8 - mov cx, ax - - - // eax = tmp - // ebx = light - // ecx = V:U in 8.8:8.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - -InnerInnerLoop: - - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 1 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 2 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+2], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 3 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+3], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - - add edi, 4 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, esi - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas' - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - -// mov edx, Tmap.DeltaUFrac - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov bp, ax - - pop ebx - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -// Make ESI = DV:DU in 8:8,8:8 format - mov eax, Tmap.DeltaV - shr eax, 8 - mov esi, Tmap.DeltaU - shl esi, 8 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 8:8,8:8 format - mov eax, Tmap.UFixed - shr eax, 8 - mov ecx, Tmap.VFixed - shl ecx, 8 - mov cx, ax - - // eax = tmp - // ebx = light - // ecx = V:U in 8.8:8.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - - -NextPixel: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 1 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - - - add edi, 2 - add edx, 8 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*256)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - - -// Totally non-general function specifically made for the subpsace effect -void tmapscan_lnn8_tiled_256x256() -{ - if ( Tmap.src_offset != 256 ) { - Int3(); // This only works on 256 wide textures! - return; - } - -// Tmap.fx_u = fl2f(Tmap.l.u); -// Tmap.fx_v = fl2f(Tmap.l.v); -// Tmap.fx_du_dx = fl2f(Tmap.deltas.u); -// Tmap.fx_dv_dx = fl2f(Tmap.deltas.v); - - int i; - - ubyte * src = (ubyte *)Tmap.pixptr; - ubyte * dst = (ubyte *)Tmap.dest_row_data; - - for (i=0; i// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - // set up affine registers - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - -// Make EDX = DV:DU in 8:8,8:8 format - mov eax, Tmap.DeltaV - shr eax, 8 - mov edx, Tmap.DeltaU - shl edx, 8 - mov dx, ax - -// Make ECX = V:U in 8:8,8:8 format - mov eax, Tmap.VFixed - shr eax, 8 - mov ecx, Tmap.UFixed - shl ecx, 8 - mov cx, ax - - // eax = tmp - // ebx = - // ecx = V:U in 8.8:8.8 - // edx = zbuffer pointer - // esi = - // edi = screen data - // ebp = dl_dx - - -InnerInnerLoop: - - // pixel 0 -// mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - mov eax, ebx - shr eax, 1 - jnc L1 - xor eax, 0xA3000000 ; This makes 'r' take 2^32 iterations to repeat -L1: mov ebx, eax - and eax, MASK ; mask out all bits except 8.8:8.8 fraction - add eax, ecx - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+0], al - - // pixel 1 -// mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - mov eax, ebx - shr eax, 1 - jnc L2 - xor eax, 0xA3000000 ; This makes 'r' take 2^32 iterations to repeat -L2: mov ebx, eax - and eax, MASK ; mask out all bits except 8.8:8.8 fraction - add eax, ecx - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+1], al - - // pixel 2 -// mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - mov eax, ebx - shr eax, 1 - jnc L3 - xor eax, 0xA3000000 ; This makes 'r' take 2^32 iterations to repeat -L3: mov ebx, eax - and eax, MASK ; mask out all bits except 8.8:8.8 fraction - add eax, ecx - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+2], al - - // pixel 3 -// mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - mov eax, ebx - shr eax, 1 - jnc L4 - xor eax, 0xA3000000 ; This makes 'r' take 2^32 iterations to repeat -L4: mov ebx, eax - and eax, MASK ; mask out all bits except 8.8:8.8 fraction - add eax, ecx - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+3], al - - - add edi, 4 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, esi - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas' - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - -OnePixelSpan: - -// Make EDX = DV:DU in 8:8,8:8 format - mov eax, Tmap.DeltaV - shr eax, 8 - mov edx, Tmap.DeltaU - shl edx, 8 - mov dx, ax - -// Make ECX = V:U in 8:8,8:8 format - mov eax, Tmap.VFixed - shr eax, 8 - mov ecx, Tmap.UFixed - shl ecx, 8 - mov cx, ax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - // eax = tmp - // ebx = light - // ecx = V:U in 8.8:8.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - -NextPixel: - // pixel 0 -// mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - mov eax, ebx - shr eax, 1 - jnc L5 - xor eax, 0xA3000000 ; This makes 'r' take 2^32 iterations to repeat -L5: mov ebx, eax - and eax, MASK ; mask out all bits except 8.8:8.8 fraction - add eax, ecx - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+0], al - - // pixel 1 -// mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - mov eax, ebx - shr eax, 1 - jnc L6 - xor eax, 0xA3000000 ; This makes 'r' take 2^32 iterations to repeat -L6: mov ebx, eax - and eax, MASK ; mask out all bits except 8.8:8.8 fraction - add eax, ecx - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+1], al - - - add edi, 2 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - mov eax, ebx - shr eax, 1 - jnc L7 - xor eax, 0xA3000000 ; This makes 'r' take 2^32 iterations to repeat -L7: mov ebx, eax - and eax, MASK ; mask out all bits except 8.8:8.8 fraction - add eax, ecx - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+0], al - -FPUReturn: - - mov Rand_value, ebx - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - - -void tmapscan_pnn8_tiled_256x256_subspace() -{ - if ( Tmap.src_offset != 256 ) { - Int3(); // This only works on 256 wide textures! - return; - } - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Need EDI = pointer to dest row - mov edi, Tmap.dest_row_data - - // Need ESI = pointer to texture - mov esi, Tmap.pixptr - - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - mov ecx, Tmap.loop_count // ecx = width - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - // set up affine registers - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - -// Make EDX = DV:DU in 8:8,8:8 format - mov eax, Tmap.DeltaV - shr eax, 8 - mov edx, Tmap.DeltaU - shl edx, 8 - mov dx, ax - -// Make ECX = V:U in 8:8,8:8 format - mov eax, Tmap.VFixed - shr eax, 8 - mov ecx, Tmap.UFixed - shl ecx, 8 - mov cx, ax - - // eax = tmp - // ebx = - // ecx = V:U in 8.8:8.8 - // edx = zbuffer pointer - // esi = - // edi = screen data - // ebp = dl_dx - - -InnerInnerLoop: - - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+0], al - - // pixel 1 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+1], al - - // pixel 2 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+2], al - - // pixel 3 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+3], al - - - add edi, 4 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, esi - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas' - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - -OnePixelSpan: - -// Make EDX = DV:DU in 8:8,8:8 format - mov eax, Tmap.DeltaV - shr eax, 8 - mov edx, Tmap.DeltaU - shl edx, 8 - mov dx, ax - -// Make ECX = V:U in 8:8,8:8 format - mov eax, Tmap.VFixed - shr eax, 8 - mov ecx, Tmap.UFixed - shl ecx, 8 - mov cx, ax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - // eax = tmp - // ebx = light - // ecx = V:U in 8.8:8.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - -NextPixel: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+0], al - - // pixel 1 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+1], al - - - add edi, 2 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 8.8:8.8 - add ecx, edx - shr ax, 8 // EAX = V:U in 8.8:8.0 - rol eax, 8 // EAX = V:U in 0.0:8:8 - and eax, 0ffffh // clear upper bits - - mov al, [esi+eax] - mov [edi+0], al - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - - diff --git a/src/graphics/tmapscantiled32x32.cpp b/src/graphics/tmapscantiled32x32.cpp deleted file mode 100644 index 0d4ed16..0000000 --- a/src/graphics/tmapscantiled32x32.cpp +++ /dev/null @@ -1,1301 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/TmapScanTiled32x32.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Routines for drawing tiled 32x32 textues - * - * $Log$ - * Revision 1.3 2002/06/09 04:41:18 relnev - * added copyright header - * - * Revision 1.2 2002/05/07 03:16:45 theoddone33 - * The Great Newline Fix - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 4 11/30/98 5:31p Dave - * Fixed up Fred support for software mode. - * - * 3 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 6 4/23/98 9:55a John - * Fixed some bugs in the tiled tmapper causing bright dots to appear all - * over models. - * - * 5 3/10/98 4:19p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 4 1/23/98 5:08p John - * Took L out of vertex structure used B (blue) instead. Took all small - * fireballs out of fireball types and used particles instead. Fixed some - * debris explosion things. Restructured fireball code. Restructured - * some lighting code. Made dynamic lighting on by default. Made groups - * of lasers only cast one light. Made fireballs not cast light. - * - * 3 12/04/97 10:38a John - * Fixed tiled texture mappers that were swapping uvs. - * - * 2 10/14/97 9:19a John - * removed fdiv warnings. - * - * 1 6/18/97 4:02p John - * added new code for 16x16 and 32x32 tiled tmaps. - * - * $NoKeywords: $ - */ - - -#include "3d.h" -#include "2d.h" -#include "grinternal.h" -#include "tmapper.h" -#include "tmapscanline.h" -#include "floating.h" -#include "palman.h" -#include "fix.h" - -// Needed to keep warning 4725 to stay away. See PsTypes.h for details why. -void disable_warning_4725_stub_tst32() -{ -} - -void tmapscan_pln8_zbuffered_tiled_32x32() -{ - Tmap.fx_l = fl2f(Tmap.l.b*32.0); - Tmap.fx_l_right = fl2f(Tmap.r.b*32.0); - Tmap.fx_dl_dx = fl2f(Tmap.deltas.b*32.0); - - if ( Tmap.fx_dl_dx < 0 ) { - Tmap.fx_dl_dx = -Tmap.fx_dl_dx; - Tmap.fx_l = (67*F1_0)-Tmap.fx_l; - Tmap.fx_l_right = (67*F1_0)-Tmap.fx_l_right; -// SDL_assert( Tmap.fx_l > 31*F1_0 ); -// SDL_assert( Tmap.fx_l < 66*F1_0 ); -// SDL_assert( Tmap.fx_dl_dx >= 0 ); -// SDL_assert( Tmap.fx_dl_dx < 31*F1_0 ); - } - - Tmap.fl_dudx_wide = Tmap.deltas.u*32.0f; - Tmap.fl_dvdx_wide = Tmap.deltas.v*32.0f; - Tmap.fl_dwdx_wide = Tmap.deltas.sw*32.0f; - - Tmap.fx_w = fl2i(Tmap.l.sw * GR_Z_RANGE)+gr_zoffset; - Tmap.fx_dwdx = fl2i(Tmap.deltas.sw * GR_Z_RANGE); - -// SDL_assert(Tmap.fx_w < 65536 ); -// SDL_assert(Tmap.fx_w >= 0 ); -// SDL_assert(Tmap.fx_w+Tmap.fx_dwdx*Tmap.loop_count < 65536 ); -// SDL_assert(Tmap.fx_w+Tmap.fx_dwdx*Tmap.loop_count >= 0 ); - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - -// Make ESI = DV:DU in 5:11,5:11 format - mov eax, Tmap.DeltaV - shr eax, 5 - mov esi, Tmap.DeltaU - shl esi, 11 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 5:11,5:11 format - mov eax, Tmap.VFixed - shr eax, 5 - mov ecx, Tmap.UFixed - shl ecx, 11 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 8.6:10.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - -InnerInnerLoop: - - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0 // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 1 - cmp esi, [edx+4] // Compare the Z depth of this pixel with zbuffer - jle Skip1 // If pixel is covered, skip drawing - - mov [edx+4], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al -Skip1: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 2 - cmp esi, [edx+8] // Compare the Z depth of this pixel with zbuffer - jle Skip2 // If pixel is covered, skip drawing - - mov [edx+8], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+2], al -Skip2: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 3 - cmp esi, [edx+12] // Compare the Z depth of this pixel with zbuffer - jle Skip3 // If pixel is covered, skip drawing - - mov [edx+12], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+3], al -Skip3: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - - add edi, 4 - add edx, 16 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, esi - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas' - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - -// mov edx, Tmap.DeltaUFrac - - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov bp, ax - - pop ebx - - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -// Make ESI = DV:DU in 6:10,6:10 format - mov eax, Tmap.DeltaV - shr eax, 5 - mov esi, Tmap.DeltaU - shl esi, 11 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 6:10,6:10 format - mov eax, Tmap.VFixed - shr eax, 5 - mov ecx, Tmap.UFixed - shl ecx, 11 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 8.6:10.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - - -NextPixel: - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0a // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0a: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 1 - cmp esi, [edx+4] // Compare the Z depth of this pixel with zbuffer - jle Skip1a // If pixel is covered, skip drawing - - mov [edx+4], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al -Skip1a: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - - - add edi, 2 - add edx, 8 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0b // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0b: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - -void tmapscan_pln8_tiled_32x32() -{ - if (gr_zbuffering) { - switch(gr_zbuffering_mode) { - case GR_ZBUFF_NONE: - break; - case GR_ZBUFF_FULL: // both - tmapscan_pln8_zbuffered_tiled_32x32(); - return; - case GR_ZBUFF_WRITE: // write only - tmapscan_pln8_zbuffered_tiled_32x32(); - break; - case GR_ZBUFF_READ: // read only - tmapscan_pln8_zbuffered_tiled_32x32(); - return; - } - } - - Tmap.fx_l = fl2f(Tmap.l.b*32.0); - Tmap.fx_l_right = fl2f(Tmap.r.b*32.0); - Tmap.fx_dl_dx = fl2f(Tmap.deltas.b*32.0); - - if ( Tmap.fx_dl_dx < 0 ) { - Tmap.fx_dl_dx = -Tmap.fx_dl_dx; - Tmap.fx_l = (67*F1_0)-Tmap.fx_l; - Tmap.fx_l_right = (67*F1_0)-Tmap.fx_l_right; -// SDL_assert( Tmap.fx_l > 31*F1_0 ); -// SDL_assert( Tmap.fx_l < 66*F1_0 ); -// SDL_assert( Tmap.fx_dl_dx >= 0 ); -// SDL_assert( Tmap.fx_dl_dx < 31*F1_0 ); - } - - Tmap.fl_dudx_wide = Tmap.deltas.u*32.0f; - Tmap.fl_dvdx_wide = Tmap.deltas.v*32.0f; - Tmap.fl_dwdx_wide = Tmap.deltas.sw*32.0f; - - Tmap.fx_w = fl2i(Tmap.l.sw * GR_Z_RANGE)+gr_zoffset; - Tmap.fx_dwdx = fl2i(Tmap.deltas.sw * GR_Z_RANGE); - -// SDL_assert(Tmap.fx_w < 65536 ); -// SDL_assert(Tmap.fx_w >= 0 ); -// SDL_assert(Tmap.fx_w+Tmap.fx_dwdx*Tmap.loop_count < 65536 ); -// SDL_assert(Tmap.fx_w+Tmap.fx_dwdx*Tmap.loop_count >= 0 ); - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - -// Make ESI = DV:DU in 6:10,6:10 format - mov eax, Tmap.DeltaU - shr eax, 5 - mov esi, Tmap.DeltaV - shl esi, 11 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 6:10,6:10 format - mov eax, Tmap.UFixed - shr eax, 5 - mov ecx, Tmap.VFixed - shl ecx, 11 - mov cx, ax - - - // eax = tmp - // ebx = light - // ecx = V:U in 8.6:10.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - -InnerInnerLoop: - - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 1 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 2 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+2], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 3 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+3], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - - add edi, 4 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, esi - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas' - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - -// mov edx, Tmap.DeltaUFrac - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov bp, ax - - pop ebx - - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -// Make ESI = DV:DU in 6:10,6:10 format - mov eax, Tmap.DeltaU - shr eax, 5 - mov esi, Tmap.DeltaV - shl esi, 11 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 6:10,6:10 format - mov eax, Tmap.UFixed - shr eax, 5 - mov ecx, Tmap.VFixed - shl ecx, 11 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 8.6:10.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - - -NextPixel: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 1 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - - - add edi, 2 - add edx, 8 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 11 // EAX = V:U in 6.10:16.0 - rol eax, 5 // EAX = V:U in 0.0:6:6 - and eax, 03ffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - diff --git a/src/graphics/tmapscantiled64x64.cpp b/src/graphics/tmapscantiled64x64.cpp deleted file mode 100644 index cbc8ad1..0000000 --- a/src/graphics/tmapscantiled64x64.cpp +++ /dev/null @@ -1,1303 +0,0 @@ -/* - * Copyright (C) Volition, Inc. 1999. All rights reserved. - * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on - * the source. - */ - -/* - * $Logfile: /Freespace2/code/Graphics/TmapScanTiled64x64.cpp $ - * $Revision$ - * $Date$ - * $Author$ - * - * Routines for drawing tiled 64x64 textues - * - * $Log$ - * Revision 1.2 2002/06/09 04:41:18 relnev - * added copyright header - * - * Revision 1.1.1.1 2002/05/03 03:28:09 root - * Initial import. - * - * - * 4 11/30/98 5:31p Dave - * Fixed up Fred support for software mode. - * - * 3 11/30/98 1:07p Dave - * 16 bit conversion, first run. - * - * 2 10/07/98 10:53a Dave - * Initial checkin. - * - * 1 10/07/98 10:49a Dave - * - * 8 4/23/98 9:55a John - * Fixed some bugs in the tiled tmapper causing bright dots to appear all - * over models. - * - * 7 3/10/98 4:19p John - * Cleaned up graphics lib. Took out most unused gr functions. Made D3D - * & Glide have popups and print screen. Took out all >8bpp software - * support. Made Fred zbuffer. Made zbuffer allocate dynamically to - * support Fred. Made zbuffering key off of functions rather than one - * global variable. - * - * 6 1/23/98 5:08p John - * Took L out of vertex structure used B (blue) instead. Took all small - * fireballs out of fireball types and used particles instead. Fixed some - * debris explosion things. Restructured fireball code. Restructured - * some lighting code. Made dynamic lighting on by default. Made groups - * of lasers only cast one light. Made fireballs not cast light. - * - * 5 12/04/97 10:38a John - * Fixed tiled texture mappers that were swapping uvs. - * - * 4 10/14/97 9:19a John - * removed fdiv warnings. - * - * 3 6/02/97 11:45a John - * fixed bugs with 64x64 and 128x128 tmappers. - * - * 2 5/12/97 12:27p John - * Restructured Graphics Library to add support for multiple renderers. - * - * 1 4/24/97 4:42p John - * Initial version of the tiled texture mappers for 64 & 128 wide - * textures. - * - * $NoKeywords: $ - */ - - -#include "3d.h" -#include "2d.h" -#include "grinternal.h" -#include "tmapper.h" -#include "tmapscanline.h" -#include "floating.h" -#include "palman.h" -#include "fix.h" - -// Needed to keep warning 4725 to stay away. See PsTypes.h for details why. -void disable_warning_4725_stub_tst64() -{ -} - -void tmapscan_pln8_zbuffered_tiled_64x64() -{ - Tmap.fx_l = fl2f(Tmap.l.b*32.0); - Tmap.fx_l_right = fl2f(Tmap.r.b*32.0); - Tmap.fx_dl_dx = fl2f(Tmap.deltas.b*32.0); - - if ( Tmap.fx_dl_dx < 0 ) { - Tmap.fx_dl_dx = -Tmap.fx_dl_dx; - Tmap.fx_l = (67*F1_0)-Tmap.fx_l; - Tmap.fx_l_right = (67*F1_0)-Tmap.fx_l_right; -// SDL_assert( Tmap.fx_l > 31*F1_0 ); -// SDL_assert( Tmap.fx_l < 66*F1_0 ); -// SDL_assert( Tmap.fx_dl_dx >= 0 ); -// SDL_assert( Tmap.fx_dl_dx < 31*F1_0 ); - } - - Tmap.fl_dudx_wide = Tmap.deltas.u*32.0f; - Tmap.fl_dvdx_wide = Tmap.deltas.v*32.0f; - Tmap.fl_dwdx_wide = Tmap.deltas.sw*32.0f; - - Tmap.fx_w = fl2i(Tmap.l.sw * GR_Z_RANGE)+gr_zoffset; - Tmap.fx_dwdx = fl2i(Tmap.deltas.sw * GR_Z_RANGE); - -// SDL_assert(Tmap.fx_w < 65536 ); -// SDL_assert(Tmap.fx_w >= 0 ); -// SDL_assert(Tmap.fx_w+Tmap.fx_dwdx*Tmap.loop_count < 65536 ); -// SDL_assert(Tmap.fx_w+Tmap.fx_dwdx*Tmap.loop_count >= 0 ); - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - -// Make ESI = DU:DV in 6:10,6:10 format - mov eax, Tmap.DeltaV - shr eax, 6 - mov esi, Tmap.DeltaU - shl esi, 10 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = U:V in 6:10,6:10 format - mov eax, Tmap.VFixed - shr eax, 6 - mov ecx, Tmap.UFixed - shl ecx, 10 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 8.6:10.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - -InnerInnerLoop: - - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0 // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 1 - cmp esi, [edx+4] // Compare the Z depth of this pixel with zbuffer - jle Skip1 // If pixel is covered, skip drawing - - mov [edx+4], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al -Skip1: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 2 - cmp esi, [edx+8] // Compare the Z depth of this pixel with zbuffer - jle Skip2 // If pixel is covered, skip drawing - - mov [edx+8], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+2], al -Skip2: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 3 - cmp esi, [edx+12] // Compare the Z depth of this pixel with zbuffer - jle Skip3 // If pixel is covered, skip drawing - - mov [edx+12], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+3], al -Skip3: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - - add edi, 4 - add edx, 16 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, esi - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas' - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - -// mov edx, Tmap.DeltaUFrac - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov bp, ax - - pop ebx - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -// Make ESI = DV:DU in 6:10,6:10 format - mov eax, Tmap.DeltaV - shr eax, 6 - mov esi, Tmap.DeltaU - shl esi, 10 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 6:10,6:10 format - mov eax, Tmap.VFixed - shr eax, 6 - mov ecx, Tmap.UFixed - shl ecx, 10 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 8.6:10.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - - -NextPixel: - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0a // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0a: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - // pixel 1 - cmp esi, [edx+4] // Compare the Z depth of this pixel with zbuffer - jle Skip1a // If pixel is covered, skip drawing - - mov [edx+4], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al -Skip1a: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - - - add edi, 2 - add edx, 8 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - // pixel 0 - cmp esi, [edx+0] // Compare the Z depth of this pixel with zbuffer - jle Skip0b // If pixel is covered, skip drawing - - mov [edx+0], esi // Write z - - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al -Skip0b: - add ecx, Tmap.DeltaUFrac - add esi, Tmap.fx_dwdx - add ebx, ebp - - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - -void tmapscan_pln8_tiled_64x64() -{ - if (gr_zbuffering) { - switch(gr_zbuffering_mode) { - case GR_ZBUFF_NONE: - break; - case GR_ZBUFF_FULL: // both - tmapscan_pln8_zbuffered_tiled_64x64(); - return; - case GR_ZBUFF_WRITE: // write only - tmapscan_pln8_zbuffered_tiled_64x64(); - break; - case GR_ZBUFF_READ: // read only - tmapscan_pln8_zbuffered_tiled_64x64(); - return; - } - } - - Tmap.fx_l = fl2f(Tmap.l.b*32.0); - Tmap.fx_l_right = fl2f(Tmap.r.b*32.0); - Tmap.fx_dl_dx = fl2f(Tmap.deltas.b*32.0); - - if ( Tmap.fx_dl_dx < 0 ) { - Tmap.fx_dl_dx = -Tmap.fx_dl_dx; - Tmap.fx_l = (67*F1_0)-Tmap.fx_l; - Tmap.fx_l_right = (67*F1_0)-Tmap.fx_l_right; -// SDL_assert( Tmap.fx_l > 31*F1_0 ); -// SDL_assert( Tmap.fx_l < 66*F1_0 ); -// SDL_assert( Tmap.fx_dl_dx >= 0 ); -// SDL_assert( Tmap.fx_dl_dx < 31*F1_0 ); - } - - Tmap.fl_dudx_wide = Tmap.deltas.u*32.0f; - Tmap.fl_dvdx_wide = Tmap.deltas.v*32.0f; - Tmap.fl_dwdx_wide = Tmap.deltas.sw*32.0f; - - Tmap.fx_w = fl2i(Tmap.l.sw * GR_Z_RANGE)+gr_zoffset; - Tmap.fx_dwdx = fl2i(Tmap.deltas.sw * GR_Z_RANGE); - -// SDL_assert(Tmap.fx_w < 65536 ); -// SDL_assert(Tmap.fx_w >= 0 ); -// SDL_assert(Tmap.fx_w+Tmap.fx_dwdx*Tmap.loop_count < 65536 ); -// SDL_assert(Tmap.fx_w+Tmap.fx_dwdx*Tmap.loop_count >= 0 ); - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - _asm { - - push eax - push ecx - push edx - push ebx - push ebp - push esi - push edi - - // Put the FPU in low precision mode - fstcw Tmap.OldFPUCW // store copy of CW - mov ax,Tmap.OldFPUCW // get it in ax - and eax, ~0x300L - mov Tmap.FPUCW,ax // store it - fldcw Tmap.FPUCW // load the FPU - - - mov ecx, Tmap.loop_count // ecx = width - mov edi, Tmap.dest_row_data // edi = dest pointer - - // edi = pointer to start pixel in dest dib - // ecx = spanwidth - - mov eax,ecx // eax and ecx = width - shr ecx,5 // ecx = width / subdivision length - and eax,31 // eax = width mod subdivision length - jnz some_left_over // any leftover? - dec ecx // no, so special case last span - mov eax,32 // it's 8 pixels long -some_left_over: - mov Tmap.Subdivisions,ecx // store widths - mov Tmap.WidthModLength,eax - - // calculate ULeft and VLeft // FPU Stack (ZL = ZLeft) - // st0 st1 st2 st3 st4 st5 st6 st7 - fld Tmap.l.v // V/ZL - fld Tmap.l.u // U/ZL V/ZL - fld Tmap.l.sw // 1/ZL U/ZL V/ZL - fld1 // 1 1/ZL U/ZL V/ZL - fdiv st,st(1) // ZL 1/ZL U/ZL V/ZL - fld st // ZL ZL 1/ZL U/ZL V/ZL - fmul st,st(4) // VL ZL 1/ZL U/ZL V/ZL - fxch st(1) // ZL VL 1/ZL U/ZL V/ZL - fmul st,st(3) // UL VL 1/ZL U/ZL V/ZL - - fstp st(5) // VL 1/ZL U/ZL V/ZL UL - fstp st(5) // 1/ZL U/ZL V/ZL UL VL - - // calculate right side OverZ terms ; st0 st1 st2 st3 st4 st5 st6 st7 - - fadd Tmap.fl_dwdx_wide // 1/ZR U/ZL V/ZL UL VL - fxch st(1) // U/ZL 1/ZR V/ZL UL VL - fadd Tmap.fl_dudx_wide // U/ZR 1/ZR V/ZL UL VL - fxch st(2) // V/ZL 1/ZR U/ZR UL VL - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZR U/ZR UL VL - - // calculate right side coords // st0 st1 st2 st3 st4 st5 st6 st7 - - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // @todo overlap this guy - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - cmp ecx,0 // check for any full spans - jle HandleLeftoverPixels - -SpanLoop: - - // at this point the FPU contains // st0 st1 st2 st3 st4 st5 st6 st7 - // UR VR V/ZR 1/ZR U/ZR UL VL - - // convert left side coords - - fld st(5) ; UL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; UL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.UFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - fld st(6) ; VL UR VR V/ZR 1/ZR U/ZR UL VL - fmul Tmap.FixedScale ; VL16 UR VR V/ZR 1/ZR U/ZR UL VL - fistp Tmap.VFixed ; UR VR V/ZR 1/ZR U/ZR UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR V/ZR 1/ZR U/ZR dU VL - fxch st(1) ; VR UR V/ZR 1/ZR U/ZR dU VL - fsubr st(6),st ; VR UR V/ZR 1/ZR U/ZR dU dV - fxch st(6) ; dV UR V/ZR 1/ZR U/ZR dU VR - - fmul Tmap.FixedScale8 ; dV8 UR V/ZR 1/ZR U/ZR dU VR - fistp Tmap.DeltaV ; UR V/ZR 1/ZR U/ZR dU VR - - fxch st(4) ; dU V/ZR 1/ZR U/ZR UR VR - fmul Tmap.FixedScale8 ; dU8 V/ZR 1/ZR U/ZR UR VR - fistp Tmap.DeltaU ; V/ZR 1/ZR U/ZR UR VR - - // increment terms for next span // st0 st1 st2 st3 st4 st5 st6 st7 - // Right terms become Left terms--->// V/ZL 1/ZL U/ZL UL VL - - fadd Tmap.fl_dvdx_wide // V/ZR 1/ZL U/ZL UL VL - fxch st(1) // 1/ZL V/ZR U/ZL UL VL - fadd Tmap.fl_dwdx_wide // 1/ZR V/ZR U/ZL UL VL - fxch st(2) // U/ZL V/ZR 1/ZR UL VL - fadd Tmap.fl_dudx_wide // U/ZR V/ZR 1/ZR UL VL - fxch st(2) // 1/ZR V/ZR U/ZR UL VL - fxch st(1) // V/ZR 1/ZR U/ZR UL VL - - - // setup delta values - - mov eax,Tmap.DeltaV // get v 16.16 step - mov ebx,eax // copy it - sar eax,16 // get v int step - shl ebx,16 // get v frac step - mov Tmap.DeltaVFrac,ebx // store it - imul eax,Tmap.src_offset // calculate texture step for v int step - - mov ebx,Tmap.DeltaU // get u 16.16 step - mov ecx,ebx // copy it - sar ebx,16 // get u int step - shl ecx,16 // get u frac step - mov Tmap.DeltaUFrac,ecx // store it - add eax,ebx // calculate uint + vint step - mov Tmap.uv_delta[4],eax // save whole step in non-v-carry slot - add eax,Tmap.src_offset // calculate whole step + v carry - mov Tmap.uv_delta[0],eax // save in v-carry slot - - // setup initial coordinates - mov esi,Tmap.UFixed // get u 16.16 fixedpoint coordinate - - mov ebx,esi // copy it - sar esi,16 // get integer part - shl ebx,16 // get fractional part - - mov ecx,Tmap.VFixed // get v 16.16 fixedpoint coordinate - - mov edx,ecx // copy it - sar edx,16 // get integer part - shl ecx,16 // get fractional part - imul edx,Tmap.src_offset // calc texture scanline address - add esi,edx // calc texture offset - add esi,Tmap.pixptr // calc address - - // set up affine registers - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - - mov ebp, Tmap.fx_dl_dx - shl ebp, 5 //*32 - add Tmap.fx_l, ebp - - mov ebp, Tmap.fx_l - shr ebp, 8 - sub bp, ax - shr bp, 5 - - mov dx, bp - - // calculate right side coords st0 st1 st2 st3 st4 st5 st6 st7 - fld1 // 1 V/ZR 1/ZR U/ZR UL VL - // This divide should happen while the pixel span is drawn. - fdiv st,st(2) // ZR V/ZR 1/ZR U/ZR UL VL - - - // 8 pixel span code - // edi = dest dib bits at current pixel - // esi = texture pointer at current u,v - // eax = scratch - // ebx = u fraction 0.32 - // ecx = v fraction 0.32 - // edx = u frac step - // ebp = v carry scratch - - mov al,[edi] // preread the destination cache line - - mov Tmap.InnerLooper, 32/4 // Set up loop counter - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - -// Make ESI = DV:DU in 6:10,6:10 format - mov eax, Tmap.DeltaV - shr eax, 6 - mov esi, Tmap.DeltaU - shl esi, 10 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 6:10,6:10 format - mov eax, Tmap.VFixed - shr eax, 6 - mov ecx, Tmap.UFixed - shl ecx, 10 - mov cx, ax - - - // eax = tmp - // ebx = light - // ecx = V:U in 8.6:10.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - -InnerInnerLoop: - - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 1 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 2 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+2], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 3 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+3], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - - add edi, 4 - dec Tmap.InnerLooper - jnz InnerInnerLoop - - mov Tmap.fx_w, esi - - // the fdiv is done, finish right // st0 st1 st2 st3 st4 st5 st6 st7 - // ZR V/ZR 1/ZR U/ZR UL VL - - fld st // ZR ZR V/ZR 1/ZR U/ZR UL VL - fmul st,st(2) // VR ZR V/ZR 1/ZR U/ZR UL VL - fxch st(1) // ZR VR V/ZR 1/ZR U/ZR UL VL - fmul st,st(4) // UR VR V/ZR 1/ZR U/ZR UL VL - - dec Tmap.Subdivisions // decrement span count - jnz SpanLoop // loop back - - -HandleLeftoverPixels: - - mov esi,Tmap.pixptr // load texture pointer - - // edi = dest dib bits - // esi = current texture dib bits - // at this point the FPU contains ; st0 st1 st2 st3 st4 st5 st6 st7 - // inv. means invalid numbers ; inv. inv. inv. inv. inv. UL VL - - cmp Tmap.WidthModLength,0 ; are there remaining pixels to draw? - jz FPUReturn ; nope, pop the FPU and bail - - // convert left side coords ; st0 st1 st2 st3 st4 st5 st6 st7 - - fld st(5) ; UL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale ; UL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.UFixed ; inv. inv. inv. inv. inv. UL VL - - fld st(6) ; VL inv. inv. inv. inv. inv. UL VL - fmul Tmap.FixedScale // VL16 inv. inv. inv. inv. inv. UL VL - fistp Tmap.VFixed ; inv. inv. inv. inv. inv. UL VL - - dec Tmap.WidthModLength ; calc how many steps to take - jz OnePixelSpan ; just one, don't do deltas' - - // calculate right edge coordinates ; st0 st1 st2 st3 st4 st5 st6 st7 - // r -> R+1 - - // @todo rearrange things so we don't need these two instructions - fstp Tmap.FloatTemp ; inv. inv. inv. inv. UL VL - fstp Tmap.FloatTemp ; inv. inv. inv. UL VL - - fld Tmap.r.v ; V/Zr inv. inv. inv. UL VL - fsub Tmap.deltas.v ; V/ZR inv. inv. inv. UL VL - fld Tmap.r.u ; U/Zr V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.u ; U/ZR V/ZR inv. inv. inv. UL VL - fld Tmap.r.sw ; 1/Zr U/ZR V/ZR inv. inv. inv. UL VL - fsub Tmap.deltas.sw ; 1/ZR U/ZR V/ZR inv. inv. inv. UL VL - - fdivr Tmap.One ; ZR U/ZR V/ZR inv. inv. inv. UL VL - - fmul st(1),st ; ZR UR V/ZR inv. inv. inv. UL VL - fmulp st(2),st ; UR VR inv. inv. inv. UL VL - - // calculate deltas ; st0 st1 st2 st3 st4 st5 st6 st7 - - fsubr st(5),st ; UR VR inv. inv. inv. dU VL - fxch st(1) ; VR UR inv. inv. inv. dU VL - fsubr st(6),st ; VR UR inv. inv. inv. dU dV - fxch st(6) ; dV UR inv. inv. inv. dU VR - - fidiv Tmap.WidthModLength ; dv UR inv. inv. inv. dU VR - fmul Tmap.FixedScale ; dv16 UR inv. inv. inv. dU VR - fistp Tmap.DeltaV ; UR inv. inv. inv. dU VR - - fxch st(4) ; dU inv. inv. inv. UR VR - fidiv Tmap.WidthModLength ; du inv. inv. inv. UR VR - fmul Tmap.FixedScale ; du16 inv. inv. inv. UR VR - fistp Tmap.DeltaU ; inv. inv. inv. UR VR - - // @todo gross! these are to line up with the other loop - fld st(1) ; inv. inv. inv. inv. UR VR - fld st(2) ; inv. inv. inv. inv. inv. UR VR - - - // setup delta values - mov eax, Tmap.DeltaV // get v 16.16 step - mov ebx, eax // copy it - sar eax, 16 // get v int step - shl ebx, 16 // get v frac step - mov Tmap.DeltaVFrac, ebx // store it - imul eax, Tmap.src_offset // calc texture step for v int step - - mov ebx, Tmap.DeltaU // get u 16.16 step - mov ecx, ebx // copy it - sar ebx, 16 // get the u int step - shl ecx, 16 // get the u frac step - mov Tmap.DeltaUFrac, ecx // store it - add eax, ebx // calc uint + vint step - mov Tmap.uv_delta[4], eax // save whole step in non-v-carry slot - add eax, Tmap.src_offset // calc whole step + v carry - mov Tmap.uv_delta[0], eax // save in v-carry slot - - -OnePixelSpan: - - ; setup initial coordinates - mov esi, Tmap.UFixed // get u 16.16 - mov ebx, esi // copy it - sar esi, 16 // get integer part - shl ebx, 16 // get fractional part - - mov ecx, Tmap.VFixed // get v 16.16 - mov edx, ecx // copy it - sar edx, 16 // get integer part - shl ecx, 16 // get fractional part - imul edx, Tmap.src_offset // calc texture scanline address - add esi, edx // calc texture offset - add esi, Tmap.pixptr // calc address - - - mov eax, Tmap.fx_l - shr eax, 8 - mov bx, ax - -// mov edx, Tmap.DeltaUFrac - - push ebx - - mov ebx, Tmap.fx_l_right - shr ebx, 8 - - sub ebx, eax - mov eax, ebx - - mov eax, Tmap.fx_dl_dx - shr eax, 8 - - mov bp, ax - - pop ebx - - - mov eax, edi - sub eax, Tmap.pScreenBits - mov edx, gr_zbuffer - shl eax, 2 - add edx, eax - - inc Tmap.WidthModLength - mov eax,Tmap.WidthModLength - shr eax, 1 - jz one_more_pix - pushf - mov Tmap.WidthModLength, eax - - xor eax, eax - - mov al,[edi] // preread the destination cache line - -// Make ESI = DV:DU in 6:10,6:10 format - mov eax, Tmap.DeltaU - shr eax, 6 - mov esi, Tmap.DeltaV - shl esi, 10 - mov si, ax - mov Tmap.DeltaUFrac, esi - -// Make ECX = V:U in 6:10,6:10 format - mov eax, Tmap.UFixed - shr eax, 6 - mov ecx, Tmap.VFixed - shl ecx, 10 - mov cx, ax - - mov esi, Tmap.fx_w - - // eax = tmp - // ebx = light - // ecx = V:U in 8.6:10.8 - // edx = zbuffer pointer - // esi = z - // edi = screen data - // ebp = dl_dx - - - -NextPixel: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - // pixel 1 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+1], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - - - add edi, 2 - add edx, 8 - dec Tmap.WidthModLength - jg NextPixel - - popf - jnc FPUReturn - -one_more_pix: - // pixel 0 - mov eax, ecx // EAX = V.VF:U.UF in 6.10:6.10 - shr ax, 10 // EAX = V:U in 6.10:16.0 - rol eax, 6 // EAX = V:U in 0.0:6:6 - and eax, 0fffh // clear upper bits - add eax, Tmap.pixptr // EAX = (V*64)+U + Pixptr - - mov al, [eax] - mov ah, bh - and eax, 0ffffh // clear upper bits - mov al, gr_fade_table[eax] - mov [edi+0], al - add ecx, Tmap.DeltaUFrac - add ebx, ebp - - -FPUReturn: - - // busy FPU registers: // st0 st1 st2 st3 st4 st5 st6 st7 - // xxx xxx xxx xxx xxx xxx xxx - ffree st(0) - ffree st(1) - ffree st(2) - ffree st(3) - ffree st(4) - ffree st(5) - ffree st(6) - - fldcw Tmap.OldFPUCW // restore the FPU - - pop edi - pop esi - pop ebp - pop ebx - pop edx - pop ecx - pop eax - } -#endif -} - diff --git a/src/model/modelinterp.cpp b/src/model/modelinterp.cpp index 63d94de..ec07531 100644 --- a/src/model/modelinterp.cpp +++ b/src/model/modelinterp.cpp @@ -1400,7 +1400,7 @@ void interp_render_lightning( polymodel *pm, bsp_info * sm ) void model_interp_subcall(polymodel * pm, int mn, int detail_level) { int i; - int zbuf_mode = gr_zbuffering_mode; + int zbuf_mode = gr_zbuffer_get(); if ( (mn < 0) || (mn>=pm->n_models) ) return; @@ -2593,8 +2593,8 @@ void model_really_render(int model_num, matrix *orient, vector * pos, uint flags } } - save_gr_zbuffering_mode = gr_zbuffering_mode; - zbuf_mode = gr_zbuffering_mode; + save_gr_zbuffering_mode = gr_zbuffer_get(); + zbuf_mode = gr_zbuffer_get(); if (!(Game_detail_flags & DETAIL_FLAG_MODELS) ) { gr_set_color(0,128,0); -- 2.39.2