Пример #1
0
void rastBBox_uPoly_fix( u_Poly< long , ushort >& poly,
				zbuff& z, 
				long screen_w, 
				long screen_h,
				long si, //sample interval 
				int  si_lg2, //log2 of sample interval
				long r_shift, 
				long r_val )
{

  //Calculate BBox
  
  bool valid ; // is u_poly valid based on bbox

  long ll_x, ll_y, ur_x, ur_y ;
  long s_x , s_y ;
  long j_x , j_y ;

  int x , y , ss_x , ss_y , vert;
  fragment f ;

  rastBBox_bbox_fix( poly, ll_x, ll_y, ur_x, ur_y, 
		     z.ss_w_lg2, screen_w, screen_h, 
		     valid, r_shift, r_val  );

  //Iterate over Samples, Test if In uPoly
  for( s_x = ll_x ; s_x <= ur_x ; s_x += si ){
    for( s_y = ll_y ; s_y <= ur_y ; s_y += si ){
 
      rastBBox_jhash_jit_fix( s_x, s_y, z.ss_w_lg2, &j_x, &j_y);
      j_x = j_x << 2;
      j_y = j_y << 2;
      vert = rastBBox_stest_fix( poly , s_x + j_x , s_y + j_y );
 
      if( vert != -1 ){
	x =  s_x >> r_shift;
	y =  s_y >> r_shift;
	ss_x = (s_x - (x << r_shift)) / si;
	ss_y = (s_y - (y << r_shift)) / si;	
	f.z = poly.v[vert].x[2];
	f.c[0] = poly.v[vert].c[0];
	f.c[1] = poly.v[vert].c[1];
	f.c[2] = poly.v[vert].c[2];
	f.c[3] = poly.v[vert].c[3];
	z.process_Fragment( x , y , ss_x , ss_y ,  
			    f.z , f.c[0] , f.c[1] , 
			    f.c[2] , f.c[3] );
      }
    }
  }
Пример #2
0
/*

   Test Rast
     This is a test function with a 
     few cases with known results.

     These tests should act as a rough
     test of whether the bounding box
     and sample test operation have 
     been configured correctly.

     This function also demonstrates
     how some of the primitives are defined.
*/
bool testRast()
{

  /* Lets Describe the Screen Space */
  long r_shift = 10 ;   //This is the number of fractional bits
  long r_val   = 1024 ; //This is the value of 1 << r_shift

  long screen_w = 1024 << r_shift ; // 1024 pixels wide (on x axis)
  long screen_h = 1024 << r_shift ; // 1024 pixels tall (on y axit)

  int ss_w_lg2 = 2 ; // This is the log_2 ( sqrt( MSAA ) )  

  u_Poly< long , ushort > poly; //This is a micropolygon
  poly.v[0].x[0] = 556 << ( r_shift - ss_w_lg2 ); //v0.x
  poly.v[0].x[1] = 679 << ( r_shift - ss_w_lg2 ); //v0.y

  poly.v[1].x[0] = 562 << ( r_shift - ss_w_lg2 ); //v1.x
  poly.v[1].x[1] = 660 << ( r_shift - ss_w_lg2 ); //v1.y

  poly.v[2].x[0] = 557 << ( r_shift - ss_w_lg2 ); //v2.x
  poly.v[2].x[1] = 661 << ( r_shift - ss_w_lg2 ); //v2.y

  poly.v[3].x[0] = 561 << ( r_shift - ss_w_lg2 ); //v3.x
  poly.v[3].x[1] = 680 << ( r_shift - ss_w_lg2 ); //v.y

  poly.vertices = 3; //The number of vertices
                     // Three is a triangle
                     // Four is a quadrilateral
  // Note that there are other parameters in
  // a micropolygon, but they are more or less
  // irrelevant for this portion of the algorithm

  long ll_x;
  long ll_y;
  long ur_x;
  long ur_y;
  bool valid;

  long s_x , s_y ;
  int hit ;

  printf( "Test 1: Bounding Box Test\n" );
  poly.vertices = 3;

  rastBBox_bbox_fix(  poly, ll_x, ll_y, ur_x, ur_y, ss_w_lg2, 
		      screen_w, screen_h, valid, r_shift, r_val);

  if( ! valid ){
    abort_("Fail Test 1"); 
  }
  if( ll_x != (556 << ( r_shift - ss_w_lg2 )) ){
    abort_("Fail Test 1"); 
  }
  if( ll_y != (660 << ( r_shift - ss_w_lg2 )) ){
    abort_("Fail Test 1"); 
  }
  if( ur_x != (562 << ( r_shift - ss_w_lg2 )) ){
    abort_("Fail Test 1"); 
  }
  if( ur_y != (679 << ( r_shift - ss_w_lg2 )) ){
    abort_("Fail Test 1"); 
  }

  // check some more conditions
  poly.v[0].x[0] = (556 << ( r_shift - ss_w_lg2 )) - 1;
  poly.v[0].x[1] = (679 << ( r_shift - ss_w_lg2 )) + 1;
  poly.v[1].x[1] = (660 << ( r_shift - ss_w_lg2 )) + 1;
  poly.v[1].x[0] = (562 << ( r_shift - ss_w_lg2 )) - 1;
  rastBBox_bbox_fix(  poly, ll_x, ll_y, ur_x, ur_y, ss_w_lg2, 
                      screen_w, screen_h, valid, r_shift, r_val);

  if ( ll_x != (555 << ( r_shift - ss_w_lg2 )) ){
    abort_("Fail Test 1: did not round down correctly");
  }
  if ( ur_y != (680 << ( r_shift - ss_w_lg2 )) ){
    abort_("Fail Test 1: did not round up correctly");
  }
  if( ll_y != (660 << ( r_shift - ss_w_lg2 )) ){
    abort_("Fail Test 1: did not round down correctly"); 
  }
  if( ur_x != (562 << ( r_shift - ss_w_lg2 )) ){
    abort_("Fail Test 1: did not round up correctly"); 
  }
 
  // reset the values for later use
  poly.v[0].x[0] = (556 << ( r_shift - ss_w_lg2 ));
  poly.v[0].x[1] = (679 << ( r_shift - ss_w_lg2 ));
  poly.v[1].x[1] = (660 << ( r_shift - ss_w_lg2 ));
  poly.v[1].x[0] = (562 << ( r_shift - ss_w_lg2 ));

  printf( "\t\tPass Test 1\n");


  /* 
     If you are having trouble determining if your bounding
     box function is correct, you can add more test cases
     here.
  */

  printf( "Test 2: SampleTest Test\n" );
  poly.vertices = 3;

  s_x = 559 << ( r_shift - 2 );
  s_y = 662 << ( r_shift - 2 );
  hit = rastBBox_stest_fix( poly, s_x , s_y);

  if( hit == -1 ) { //If a miss
    abort_("Failed Test 2");
  }

  printf( "\t\tPass Test 2\n");


  printf( "Test 3: SampleTest Test\n" );
  poly.vertices = 3;

  s_x = 560 << ( r_shift - 2 );
  s_y = 678 << ( r_shift - 2 );
  hit = rastBBox_stest_fix( poly, s_x , s_y);

  if( hit!=-1 ) { //If a hit
    abort_("Failed Test 3");
  }

  printf( "\t\tPass Test 3\n");

  /* 
     If you are having trouble determining if your sample test
     function is correct, you can add more test cases
     here.
  */

  return true ;
}