1  /********************************************************************** <BR>


2  This file is part of Crack dot Com's free source code release of


3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for


4  information about compiling & licensing issues visit this URL</a>


5  <PRE> If that doesn't help, contact Jonathan Clark at


6  golgotha_source@usa.net (Subject should have "GOLG" in it)


7  ***********************************************************************/


8 


9  #include "software/r1_software_globals.hh"


10  #include "software/inline_fpu.hh"


11 


12  void texture_scanline_perspective_unlit_true_alpha(w16 *start_pixel,


13  sw32 start_x,


14  void *_left,//perspective_span *left,


15  sw32 width)


16  {


17  //temporary stuff for lighting calculations


18  w32 accumulated_alpha = (1<<12);


19 


20  start_pixel = (w16 *)((w8 *)start_pixel + start_x);


21 


22  perspective_span *left = (perspective_span *)_left;


23 


24  left_z = 1.f / left>ooz;


25  left_s = qftoi(left>soz * left_z) + cur_grads.s_adjust;


26  left_t = qftoi(left>toz * left_z) + cur_grads.t_adjust;


27 


28  sw32 had_subdivisions = width & (~15);


29 


30  num_subdivisions = width >> 4;


31  num_leftover = width & 15;


32 


33  if (num_subdivisions)


34  {


35  ooz_right = left>ooz + (cur_grads.doozdxspan);


36  soz_right = left>soz + (cur_grads.dsozdxspan);


37  toz_right = left>toz + (cur_grads.dtozdxspan);


38 


39  right_z = 1.f / ooz_right;


40 


41  while (num_subdivisions)


42  {


43 


44  right_s = qftoi(soz_right * right_z) + cur_grads.s_adjust;


45  if (right_s < 0)


46  right_s = 0;


47  else


48  if (right_s > s_mask)


49  right_s = s_mask;


50 


51  right_t = qftoi(toz_right * right_z) + cur_grads.t_adjust;


52  if (right_t < 0)


53  right_t = 0;


54  else


55  if (right_t > t_mask)


56  right_t = t_mask;


57 


58  temp_dsdx = (right_s  left_s) >> 4;


59  temp_dtdx = (right_t  left_t) >> 4;


60 


61  if (num_subdivisions!=1)


62  {


63  ooz_right += (cur_grads.doozdxspan);


64  soz_right += (cur_grads.dsozdxspan);


65  toz_right += (cur_grads.dtozdxspan);


66 


67  right_z = 1.f / ooz_right;


68  }


69 


70  width_global = 16;


71 


72  while (width_global)


73  {


74  w16 alpha_texel = *(r1_software_texture_ptr + (left_s>>16) + ((left_t>>16)<<r1_software_twidth_log2));


75 


76  w32 l_lookup_1 = (alpha_texel & (w16)(15<<12)) >> (8NUM_LIGHT_SHADES_LOG2);


77  w32 l_lookup_2 = l_lookup_1 ^ (NUM_LIGHT_SHADES<<8);


78 


79  w16 texel = alpha_table[alpha_texel & 4095];


80 


81  //lookup low bits


82  w16 t1 = ((w32 *)(software_color_tables))[l_lookup_1 + (texel & 0xFF)];


83 


84  //lookup high bits


85  w16 t2 = ((w32 *)(software_color_tables)+ctable_size)[l_lookup_1 + (texel>>8)];


86 


87  texel = *start_pixel;


88 


89  //lookup low bits


90  w16 t3 = ((w32 *)(software_color_tables))[l_lookup_2 + (texel & 0xFF)];


91 


92  //lookup high bits


93  w16 t4 = ((w32 *)(software_color_tables)+ctable_size)[l_lookup_2 + (texel>>8)];


94 


95  *start_pixel = (w16)(t1+t2+t3+t4);


96 


97  start_pixel++;


98 


99  left_s += temp_dsdx;


100  left_t += temp_dtdx;


101 


102  width_global;


103  }


104 


105  left_s = right_s;


106  left_t = right_t;


107 


108  num_subdivisions;


109  }


110  }


111 


112  if (num_leftover)


113  {


114  if (num_leftover > 1)


115  {


116  if (had_subdivisions!=0)


117  {


118  ooz_right += (cur_grads.doozdx * num_leftover);


119  soz_right += (cur_grads.dsozdx * num_leftover);


120  toz_right += (cur_grads.dtozdx * num_leftover);


121 


122  right_z = 1.f / ooz_right;


123  }


124  else


125  {


126  ooz_right = left>ooz + (cur_grads.doozdx * num_leftover);


127  soz_right = left>soz + (cur_grads.dsozdx * num_leftover);


128  toz_right = left>toz + (cur_grads.dtozdx * num_leftover);


129 


130  right_z = 1.f / ooz_right;


131  }


132 


133  right_s = qftoi(soz_right * right_z) + cur_grads.s_adjust;


134  if (right_s < 0)


135  right_s = 0;


136  else


137  if (right_s > s_mask)


138  right_s = s_mask;


139 


140  right_t = qftoi(toz_right * right_z) + cur_grads.t_adjust;


141  if (right_t < 0)


142  right_t = 0;


143  else


144  if (right_t > t_mask)


145  right_t = t_mask;


146 


147  temp_dsdx = qftoi((float)(right_s  left_s) * inverse_leftover_lookup[num_leftover]);


148  temp_dtdx = qftoi((float)(right_t  left_t) * inverse_leftover_lookup[num_leftover]);


149 


150  while (num_leftover)


151  {


152  register w32 alpha_texel = *(r1_software_texture_ptr + (left_s>>16) + ((left_t>>16)<<r1_software_twidth_log2));


153 


154  register w32 l_lookup = (alpha_texel & (w16)(15<<12)) >> (8NUM_LIGHT_SHADES_LOG2);


155 


156  if (l_lookup)


157  {


158  register w32 texel = (w32)alpha_table[alpha_texel & 4095];


159 


160  //lookup low bits


161  register w32 output_texel = ((w32 *)(software_color_tables))[l_lookup + (texel & 0xFF)];


162 


163  //lookup high bits


164  output_texel += ((w32 *)(software_color_tables)+ctable_size)[l_lookup + (texel>>8)];


165 


166  l_lookup ^= (NUM_LIGHT_SHADES<<8);


167 


168  if (l_lookup)


169  {


170  texel = (w32)*start_pixel;


171 


172  //lookup low bits


173  output_texel += ((w32 *)(software_color_tables))[l_lookup + (texel & 0xFF)];


174 


175  //lookup high bits


176  output_texel += ((w32 *)(software_color_tables)+ctable_size)[l_lookup + (texel>>8)];


177  }


178 


179  *start_pixel = (w16)(output_texel);


180  }


181 


182  start_pixel++;


183 


184  left_s += temp_dsdx;


185  left_t += temp_dtdx;


186 


187  num_leftover;


188  }


189  }


190  else


191  {


192  register w32 alpha_texel = *(r1_software_texture_ptr + (left_s>>16) + ((left_t>>16)<<r1_software_twidth_log2));


193 


194  register w32 l_lookup = (alpha_texel & (w16)(15<<12)) >> (8NUM_LIGHT_SHADES_LOG2);


195 


196  if (l_lookup)


197  {


198  register w32 texel = (w32)alpha_table[alpha_texel & 4095];


199 


200  //lookup low bits


201  register w32 output_texel = ((w32 *)(software_color_tables))[l_lookup + (texel & 0xFF)];


202 


203  //lookup high bits


204  output_texel += ((w32 *)(software_color_tables)+ctable_size)[l_lookup + (texel>>8)];


205 


206  l_lookup ^= (NUM_LIGHT_SHADES<<8);


207 


208  if (l_lookup)


209  {


210  texel = (w32)*start_pixel;


211 


212  //lookup low bits


213  output_texel += ((w32 *)(software_color_tables))[l_lookup + (texel & 0xFF)];


214 


215  //lookup high bits


216  output_texel += ((w32 *)(software_color_tables)+ctable_size)[l_lookup + (texel>>8)];


217  }


218 


219  *start_pixel = (w16)(output_texel);


220  }


221  }


222  }


223  }

