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_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 texel = *( r1_software_texture_ptr + (left_s>>16) + ((left_t>>16) << r1_software_twidth_log2) );


75 


76  accumulated_alpha += ((w32)(texel) & (w32)(15<<12));


77 


78  if (accumulated_alpha & 65536)


79  {


80  *start_pixel = alpha_table[texel & 4095];


81  accumulated_alpha &= (~65536);


82  accumulated_alpha += (1<<12);


83  }


84 


85  start_pixel++;


86 


87  left_s += temp_dsdx;


88  left_t += temp_dtdx;


89 


90  width_global;


91  }


92 


93  left_s = right_s;


94  left_t = right_t;


95 


96  num_subdivisions;


97  }


98  }


99 


100  if (num_leftover)


101  {


102  if (num_leftover > 1)


103  {


104  if (had_subdivisions!=0)


105  {


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


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


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


109 


110  right_z = 1.f / ooz_right;


111  }


112  else


113  {


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


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


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


117 


118  right_z = 1.f / ooz_right;


119  }


120 


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


122  if (right_s < 0)


123  right_s = 0;


124  else


125  if (right_s > s_mask)


126  right_s = s_mask;


127 


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


129  if (right_t < 0)


130  right_t = 0;


131  else


132  if (right_t > t_mask)


133  right_t = t_mask;


134 


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


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


137 


138  while (num_leftover)


139  {


140  w16 texel = *(r1_software_texture_ptr + (left_s>>16) + ((left_t>>16)<<r1_software_twidth_log2));


141 


142  accumulated_alpha += ((w32)(texel) & (w32)(15<<12));


143 


144  if (accumulated_alpha & 65536)


145  {


146  *start_pixel = alpha_table[texel & 4095];


147  accumulated_alpha &= (~65536);


148  accumulated_alpha += (1<<12);


149  }


150 


151  start_pixel++;


152 


153  left_s += temp_dsdx;


154  left_t += temp_dtdx;


155 


156  num_leftover;


157  }


158  }


159  else


160  {


161  *start_pixel = *(r1_software_texture_ptr + (left_s>>16) + ((left_t>>16)<<r1_software_twidth_log2));


162  }


163  }


164  }

