summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatarGravatar angelosa <salese_corp_ltd@email.it>2018-03-07 20:26:58 +0100
committerGravatarGravatar angelosa <salese_corp_ltd@email.it>2018-03-07 23:33:01 +0100
commit2731786d612559d7517a016d764d051f965469d6 (patch) (github)
tree21feafa63f355358e30653e2df02ac0bede25993
parenta06b6616d6cea2d185c130f0453ebe6302ecaa07 (diff)
downloadmame-2731786d612559d7517a016d764d051f965469d6.tar.bz2
mame-2731786d612559d7517a016d764d051f965469d6.zip
model2.cpp: cleanup culling (nw)
-rw-r--r--src/mame/includes/model2.h2
-rw-r--r--src/mame/video/model2.cpp173
2 files changed, 81 insertions, 94 deletions
diff --git a/src/mame/includes/model2.h b/src/mame/includes/model2.h
index c290485b182..3b95f3c19fe 100644
--- a/src/mame/includes/model2.h
+++ b/src/mame/includes/model2.h
@@ -319,7 +319,7 @@ private:
// inliners
inline void model2_3d_project( triangle *tri );
inline uint16_t float_to_zval( float floatval );
-
+ inline bool check_culling( raster_state *raster, uint32_t attr, float min_z, float max_z );
};
/*****************************
diff --git a/src/mame/video/model2.cpp b/src/mame/video/model2.cpp
index 18027ff7ed7..56dfb301a6e 100644
--- a/src/mame/video/model2.cpp
+++ b/src/mame/video/model2.cpp
@@ -98,6 +98,41 @@
#define pv p[2]
+
+/*******************************************
+ *
+ * Hardware 3D Rasterizer Internal State
+ *
+ *******************************************/
+
+#define MAX_TRIANGLES 32768
+
+struct raster_state
+{
+// uint32_t mode; /* bit 0 = Test Mode, bit 2 = Switch 60Hz(1)/30Hz(0) operation */
+ uint16_t *texture_rom; /* Texture ROM pointer */
+ uint32_t texture_rom_mask; /* Texture ROM mask */
+ int16_t viewport[4]; /* View port (startx,starty,endx,endy) */
+ int16_t center[4][2]; /* Centers (eye 0[x,y],1[x,y],2[x,y],3[x,y]) */
+ uint16_t center_sel; /* Selected center */
+ uint32_t reverse; /* Left/Right Reverse */
+ float z_adjust; /* ZSort Mode */
+ float triangle_z; /* Current Triangle z value */
+ uint8_t master_z_clip; /* Master Z-Clip value */
+ uint32_t cur_command; /* Current command */
+ uint32_t command_buffer[32]; /* Command buffer */
+ uint32_t command_index; /* Command buffer index */
+ triangle tri_list[MAX_TRIANGLES]; /* Triangle list */
+ uint32_t tri_list_index; /* Triangle list index */
+ triangle *tri_sorted_list[0x10000]; /* Sorted Triangle list */
+ uint16_t min_z; /* Minimum sortable Z value */
+ uint16_t max_z; /* Maximum sortable Z value */
+ uint16_t texture_ram[0x10000]; /* Texture RAM pointer */
+ uint8_t log_ram[0x40000]; /* Log RAM pointer */
+};
+
+
+
/*******************************************
*
* Generic 3D Math Functions
@@ -178,11 +213,11 @@ inline uint16_t model2_state::float_to_zval( float floatval )
return 0x0000;
/* between -12 and 0 create a denormal with exponent of 0 */
- else if ( exponent < 0 )
+ if ( exponent < 0 )
return (mantissa | 0x1000) >> -exponent;
/* between 0 and 14 create a FP value with exponent + 1 */
- else if ( exponent < 15 )
+ if ( exponent < 15 )
return (( exponent + 1 ) << 12) | mantissa;
/* above 14 is too large */
@@ -237,40 +272,32 @@ static int32_t clip_polygon(poly_vertex *v, int32_t num_vertices, plane *cp, pol
return outcount;
}
-/***********************************************************************************************/
+inline bool model2_state::check_culling( raster_state *raster, uint32_t attr, float min_z, float max_z )
+{
+ /* if doubleside is disabled */
+ if ( ((attr >> 17) & 1) == 0 )
+ {
+ /* if it's the backface, cull it */
+ if ( raster->command_buffer[9] & 0x00800000 )
+ return true;
+ }
-/*******************************************
- *
- * Hardware 3D Rasterizer Internal State
- *
- *******************************************/
+ /* if the linktype is 0, then we can also cull it */
+ if ( ((attr >> 8) & 3) == 0 )
+ return true;
-#define MAX_TRIANGLES 32768
+ /* if the minimum z value is bigger than the master z clip value, don't render */
+ if ( (int32_t)(1.0/min_z) > raster->master_z_clip )
+ return true;
-struct raster_state
-{
-// uint32_t mode; /* bit 0 = Test Mode, bit 2 = Switch 60Hz(1)/30Hz(0) operation */
- uint16_t * texture_rom; /* Texture ROM pointer */
- uint32_t texture_rom_mask; /* Texture ROM mask */
- int16_t viewport[4]; /* View port (startx,starty,endx,endy) */
- int16_t center[4][2]; /* Centers (eye 0[x,y],1[x,y],2[x,y],3[x,y]) */
- uint16_t center_sel; /* Selected center */
- uint32_t reverse; /* Left/Right Reverse */
- float z_adjust; /* ZSort Mode */
- float triangle_z; /* Current Triangle z value */
- uint8_t master_z_clip; /* Master Z-Clip value */
- uint32_t cur_command; /* Current command */
- uint32_t command_buffer[32]; /* Command buffer */
- uint32_t command_index; /* Command buffer index */
- triangle tri_list[MAX_TRIANGLES]; /* Triangle list */
- uint32_t tri_list_index; /* Triangle list index */
- triangle * tri_sorted_list[0x10000]; /* Sorted Triangle list */
- uint16_t min_z; /* Minimum sortable Z value */
- uint16_t max_z; /* Maximum sortable Z value */
- uint16_t texture_ram[0x10000]; /* Texture RAM pointer */
- uint8_t log_ram[0x40000]; /* Log RAM pointer */
-};
+ /* if the maximum z value is < 0 then we can safely clip the entire polygon */
+ if ( max_z < 0 )
+ return true;
+
+ return false;
+}
+/***********************************************************************************************/
/*******************************************
*
@@ -330,12 +357,13 @@ READ32_MEMBER(model2_state::polygon_count_r)
void model2_state::model2_3d_process_quad( raster_state *raster, uint32_t attr )
{
- quad_m2 object;
- uint16_t *th, *tp;
- int32_t tho;
- uint32_t cull, i;
- float zvalue;
- float min_z, max_z;
+ quad_m2 object;
+ uint16_t *th, *tp;
+ int32_t tho;
+ uint32_t i;
+ bool cull;
+ float zvalue;
+ float min_z, max_z;
/* extract P0(n-1) */
object.v[1].x = u2f( raster->command_buffer[2] << 8 );
@@ -413,30 +441,7 @@ void model2_state::model2_3d_process_quad( raster_state *raster, uint32_t attr )
object.luma = (raster->command_buffer[9] >> 15) & 0xFF;
/* determine whether we can cull this quad */
- cull = 0;
-
- /* if doubleside is disabled */
- if ( ((attr >> 17) & 1) == 0 )
- {
- /* if it's the backface, cull it */
- if ( raster->command_buffer[9] & 0x00800000 )
- cull = 1;
- }
-
- /* if the linktype is 0, then we can also cull it */
- if ( ((attr >> 8) & 3) == 0 )
- cull = 1;
-
- /* if the minimum z value is bigger than the master z clip value, don't render */
- if ( (int32_t)(1.0/min_z) > raster->master_z_clip )
- cull = 1;
-
- /* if the maximum z value is < 0 then we can safely clip the entire polygon */
- if ( max_z < 0 )
- cull = 1;
-
- /* set the object's z value */
- zvalue = raster->triangle_z;
+ cull = check_culling(raster,attr,min_z,max_z);
/* set the object's z value */
switch((attr >> 10) & 3)
@@ -451,17 +456,18 @@ void model2_state::model2_3d_process_quad( raster_state *raster, uint32_t attr )
zvalue = max_z;
break;
case 3: // error
+ default:
zvalue = 0.0f;
break;
}
raster->triangle_z = zvalue;
- if ( cull == 0 )
+ if ( cull == false )
{
- int32_t clipped_verts;
+ int32_t clipped_verts;
poly_vertex verts[10];
- plane clip_plane;
+ plane clip_plane;
clip_plane.normal.x = 0;
clip_plane.normal.y = 0;
@@ -574,12 +580,13 @@ void model2_state::model2_3d_process_quad( raster_state *raster, uint32_t attr )
void model2_state::model2_3d_process_triangle( raster_state *raster, uint32_t attr )
{
- triangle object;
- uint16_t *th, *tp;
- int32_t tho;
- uint32_t cull, i;
- float zvalue;
- float min_z, max_z;
+ triangle object;
+ uint16_t *th, *tp;
+ int32_t tho;
+ uint32_t i;
+ bool cull;
+ float zvalue;
+ float min_z, max_z;
/* extract P0(n-1) */
object.v[1].x = u2f( raster->command_buffer[2] << 8 );
@@ -653,27 +660,7 @@ void model2_state::model2_3d_process_triangle( raster_state *raster, uint32_t at
object.luma = (raster->command_buffer[9] >> 15) & 0xFF;
/* determine whether we can cull this quad */
- cull = 0;
-
- /* if doubleside is disabled */
- if ( ((attr >> 17) & 1) == 0 )
- {
- /* if it's the backface, cull it */
- if ( raster->command_buffer[9] & 0x00800000 )
- cull = 1;
- }
-
- /* if the linktype is 0, then we can also cull it */
- if ( ((attr >> 8) & 3) == 0 )
- cull = 1;
-
- /* if the minimum z value is bigger than the master z clip value, don't render */
- if ( (int32_t)(1.0/min_z) > raster->master_z_clip )
- cull = 1;
-
- /* if the maximum z value is < 0 then we can safely clip the entire polygon */
- if ( max_z < 0 )
- cull = 1;
+ cull = check_culling(raster,attr,min_z,max_z);
/* set the object's z value */
switch((attr >> 10) & 3)
@@ -696,7 +683,7 @@ void model2_state::model2_3d_process_triangle( raster_state *raster, uint32_t at
raster->triangle_z = zvalue;
/* if we're not culling, do z-clip and add to out triangle list */
- if ( cull == 0 )
+ if ( cull == false )
{
int32_t clipped_verts;
poly_vertex verts[10];