model2.cpp: stateize float_to_zval, fix z code (nw)

This commit is contained in:
angelosa 2018-03-03 22:31:48 +01:00
parent 6047d3a629
commit 45a09141c8
2 changed files with 32 additions and 25 deletions

View File

@ -318,6 +318,8 @@ private:
// inliners // inliners
inline void model2_3d_project( triangle *tri ); inline void model2_3d_project( triangle *tri );
inline uint16_t float_to_zval( float floatval );
}; };
/***************************** /*****************************

View File

@ -157,7 +157,7 @@ static inline void vector_cross3( poly_vertex *dst, poly_vertex *v0, poly_vertex
} }
/* 1.8.23 float to 4.12 float converter, courtesy of Aaron Giles */ /* 1.8.23 float to 4.12 float converter, courtesy of Aaron Giles */
static uint16_t float_to_zval( float floatval ) inline uint16_t model2_state::float_to_zval( float floatval )
{ {
int32_t fpint = f2u(floatval); int32_t fpint = f2u(floatval);
int32_t exponent = ((fpint >> 23) & 0xff) - 127; int32_t exponent = ((fpint >> 23) & 0xff) - 127;
@ -327,7 +327,7 @@ READ32_MEMBER(model2_state::polygon_count_r)
* Hardware 3D Rasterizer Processing * Hardware 3D Rasterizer Processing
* *
*******************************************/ *******************************************/
void model2_state::model2_3d_process_quad( raster_state *raster, uint32_t attr ) void model2_state::model2_3d_process_quad( raster_state *raster, uint32_t attr )
{ {
quad_m2 object; quad_m2 object;
@ -438,21 +438,25 @@ void model2_state::model2_3d_process_quad( raster_state *raster, uint32_t attr )
/* set the object's z value */ /* set the object's z value */
zvalue = raster->triangle_z; zvalue = raster->triangle_z;
/* see if we need to recompute min/max z */ /* set the object's z value */
if ( (attr >> 10) & 3 ) switch((attr >> 10) & 3)
{ {
if ( (attr >> 10) & 1 ) /* min value */ case 0: // old value
{ zvalue = raster->triangle_z;
break;
case 1: // min z
zvalue = min_z; zvalue = min_z;
} break;
else if ( (attr >> 10) & 2 ) /* max value */ case 2: // max z
{
zvalue = max_z; zvalue = max_z;
} break;
case 3: // error
raster->triangle_z = zvalue; zvalue = 0.0f;
break;
} }
raster->triangle_z = zvalue;
if ( cull == 0 ) if ( cull == 0 )
{ {
int32_t clipped_verts; int32_t clipped_verts;
@ -672,23 +676,24 @@ void model2_state::model2_3d_process_triangle( raster_state *raster, uint32_t at
cull = 1; cull = 1;
/* set the object's z value */ /* set the object's z value */
zvalue = raster->triangle_z; switch((attr >> 10) & 3)
/* see if we need to recompute min/max z */
if ( (attr >> 10) & 3 )
{ {
if ( (attr >> 10) & 1 ) /* min value */ case 0: // old value
{ zvalue = raster->triangle_z;
break;
case 1: // min z
zvalue = min_z; zvalue = min_z;
} break;
else if ( (attr >> 10) & 2 ) /* max value */ case 2: // max z
{
zvalue = max_z; zvalue = max_z;
} break;
case 3: // error
raster->triangle_z = zvalue; zvalue = 0.0f;
break;
} }
raster->triangle_z = zvalue;
/* if we're not culling, do z-clip and add to out triangle list */ /* if we're not culling, do z-clip and add to out triangle list */
if ( cull == 0 ) if ( cull == 0 )
{ {
@ -1160,7 +1165,7 @@ void model2_state::model2_3d_push( raster_state *raster, uint32_t input )
raster->center_sel = ( input >> 6 ) & 3; raster->center_sel = ( input >> 6 ) & 3;
/* reset the triangle z value */ /* reset the triangle z value */
raster->triangle_z = 0; raster->triangle_z = 0.0f;
} }
} }
} }