trunk/src/emu/video/psx.c
| r22543 | r22544 | |
| 75 | 75 | |
| 76 | 76 | static const UINT16 m_p_n_nextpointlist4[] = { 1, 3, 0, 2 }; |
| 77 | 77 | static const UINT16 m_p_n_prevpointlist4[] = { 2, 0, 3, 1 }; |
| 78 | static const UINT16 m_p_n_nextpointlist4b[] = { 0, 3, 1, 2 }; |
| 79 | static const UINT16 m_p_n_prevpointlist4b[] = { 0, 2, 3, 1 }; |
| 78 | 80 | static const UINT16 m_p_n_nextpointlist3[] = { 1, 2, 0 }; |
| 79 | 81 | static const UINT16 m_p_n_prevpointlist3[] = { 2, 0, 1 }; |
| 80 | 82 | |
| r22543 | r22544 | |
| 1272 | 1274 | } \ |
| 1273 | 1275 | } |
| 1274 | 1276 | |
| 1277 | INLINE int CullVertex( int a, int b ) |
| 1278 | { |
| 1279 | int d = a - b; |
| 1280 | if( d < -1023 || d > 1023 ) |
| 1281 | { |
| 1282 | return 1; |
| 1283 | } |
| 1284 | |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
| 1288 | #define CULLTRIANGLE( PacketType, start ) \ |
| 1289 | ( \ |
| 1290 | CULLPOINT( PacketType, start, start + 1 ) || CULLPOINT( PacketType, start + 1, start + 2 ) || CULLPOINT( PacketType, start + 2, start ) \ |
| 1291 | ) |
| 1292 | |
| 1293 | #define CULLPOINT( PacketType, p1, p2 ) \ |
| 1294 | ( \ |
| 1295 | CullVertex( COORD_Y( m_packet.PacketType.vertex[ p1 ].n_coord ), COORD_Y( m_packet.PacketType.vertex[ p2 ].n_coord ) ) || \ |
| 1296 | CullVertex( COORD_X( m_packet.PacketType.vertex[ p1 ].n_coord ), COORD_X( m_packet.PacketType.vertex[ p2 ].n_coord ) ) \ |
| 1297 | ) |
| 1298 | |
| 1299 | #define FINDTOPLEFT( PacketType ) \ |
| 1300 | for( n_point = 0; n_point < n_points; n_point++ ) \ |
| 1301 | { \ |
| 1302 | ADJUST_COORD( m_packet.PacketType.vertex[ n_point ].n_coord ); \ |
| 1303 | } \ |
| 1304 | \ |
| 1305 | n_leftpoint = 0; \ |
| 1306 | if( n_points == 4 ) \ |
| 1307 | { \ |
| 1308 | if( CULLTRIANGLE( PacketType, 0 ) ) \ |
| 1309 | { \ |
| 1310 | if( CULLTRIANGLE( PacketType, 1 ) ) \ |
| 1311 | { \ |
| 1312 | return; \ |
| 1313 | } \ |
| 1314 | \ |
| 1315 | p_n_rightpointlist = m_p_n_nextpointlist4b; \ |
| 1316 | p_n_leftpointlist = m_p_n_prevpointlist4b; \ |
| 1317 | n_leftpoint++; \ |
| 1318 | } \ |
| 1319 | else if( CULLTRIANGLE( PacketType, 1 ) ) \ |
| 1320 | { \ |
| 1321 | p_n_rightpointlist = m_p_n_nextpointlist3; \ |
| 1322 | p_n_leftpointlist = m_p_n_prevpointlist3; \ |
| 1323 | n_points--; \ |
| 1324 | } \ |
| 1325 | else \ |
| 1326 | { \ |
| 1327 | p_n_rightpointlist = m_p_n_nextpointlist4; \ |
| 1328 | p_n_leftpointlist = m_p_n_prevpointlist4; \ |
| 1329 | } \ |
| 1330 | } \ |
| 1331 | else if( CULLTRIANGLE( PacketType, 0 ) ) \ |
| 1332 | { \ |
| 1333 | return; \ |
| 1334 | } \ |
| 1335 | else \ |
| 1336 | { \ |
| 1337 | p_n_rightpointlist = m_p_n_nextpointlist3; \ |
| 1338 | p_n_leftpointlist = m_p_n_prevpointlist3; \ |
| 1339 | } \ |
| 1340 | \ |
| 1341 | for( n_point = n_leftpoint + 1; n_point < n_points; n_point++ ) \ |
| 1342 | { \ |
| 1343 | if( COORD_Y( m_packet.PacketType.vertex[ n_point ].n_coord ) < COORD_Y( m_packet.PacketType.vertex[ n_leftpoint ].n_coord ) || \ |
| 1344 | ( COORD_Y( m_packet.PacketType.vertex[ n_point ].n_coord ) == COORD_Y( m_packet.PacketType.vertex[ n_leftpoint ].n_coord ) && \ |
| 1345 | COORD_X( m_packet.PacketType.vertex[ n_point ].n_coord ) < COORD_X( m_packet.PacketType.vertex[ n_leftpoint ].n_coord ) ) ) \ |
| 1346 | { \ |
| 1347 | n_leftpoint = n_point; \ |
| 1348 | } \ |
| 1349 | } \ |
| 1350 | n_rightpoint = n_leftpoint; \ |
| 1351 | |
| 1275 | 1352 | void psxgpu_device::FlatPolygon( int n_points ) |
| 1276 | 1353 | { |
| 1277 | 1354 | INT16 n_y; |
| r22543 | r22544 | |
| 1328 | 1405 | n_g.w.h = BGR_G( m_packet.FlatPolygon.n_bgr ); n_g.w.l = 0; |
| 1329 | 1406 | n_b.w.h = BGR_B( m_packet.FlatPolygon.n_bgr ); n_b.w.l = 0; |
| 1330 | 1407 | |
| 1331 | | if( n_points == 4 ) |
| 1332 | | { |
| 1333 | | p_n_rightpointlist = m_p_n_nextpointlist4; |
| 1334 | | p_n_leftpointlist = m_p_n_prevpointlist4; |
| 1335 | | } |
| 1336 | | else |
| 1337 | | { |
| 1338 | | p_n_rightpointlist = m_p_n_nextpointlist3; |
| 1339 | | p_n_leftpointlist = m_p_n_prevpointlist3; |
| 1340 | | } |
| 1408 | FINDTOPLEFT( FlatPolygon ) |
| 1341 | 1409 | |
| 1342 | | for( n_point = 0; n_point < n_points; n_point++ ) |
| 1343 | | { |
| 1344 | | ADJUST_COORD( m_packet.FlatPolygon.vertex[ n_point ].n_coord ); |
| 1345 | | } |
| 1346 | | |
| 1347 | | n_leftpoint = 0; |
| 1348 | | for( n_point = 1; n_point < n_points; n_point++ ) |
| 1349 | | { |
| 1350 | | if( COORD_Y( m_packet.FlatPolygon.vertex[ n_point ].n_coord ) < COORD_Y( m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) || |
| 1351 | | ( COORD_Y( m_packet.FlatPolygon.vertex[ n_point ].n_coord ) == COORD_Y( m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) && |
| 1352 | | COORD_X( m_packet.FlatPolygon.vertex[ n_point ].n_coord ) < COORD_X( m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) ) ) |
| 1353 | | { |
| 1354 | | n_leftpoint = n_point; |
| 1355 | | } |
| 1356 | | } |
| 1357 | | n_rightpoint = n_leftpoint; |
| 1358 | | |
| 1359 | 1410 | n_dx1 = 0; |
| 1360 | 1411 | n_dx2 = 0; |
| 1361 | 1412 | |
| r22543 | r22544 | |
| 1528 | 1579 | break; |
| 1529 | 1580 | } |
| 1530 | 1581 | |
| 1531 | | if( n_points == 4 ) |
| 1532 | | { |
| 1533 | | p_n_rightpointlist = m_p_n_nextpointlist4; |
| 1534 | | p_n_leftpointlist = m_p_n_prevpointlist4; |
| 1535 | | } |
| 1536 | | else |
| 1537 | | { |
| 1538 | | p_n_rightpointlist = m_p_n_nextpointlist3; |
| 1539 | | p_n_leftpointlist = m_p_n_prevpointlist3; |
| 1540 | | } |
| 1582 | FINDTOPLEFT( FlatTexturedPolygon ) |
| 1541 | 1583 | |
| 1542 | | for( n_point = 0; n_point < n_points; n_point++ ) |
| 1543 | | { |
| 1544 | | ADJUST_COORD( m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ); |
| 1545 | | } |
| 1546 | | |
| 1547 | | n_leftpoint = 0; |
| 1548 | | for( n_point = 1; n_point < n_points; n_point++ ) |
| 1549 | | { |
| 1550 | | if( COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) < COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) || |
| 1551 | | ( COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) == COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) && |
| 1552 | | COORD_X( m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) < COORD_X( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) ) ) |
| 1553 | | { |
| 1554 | | n_leftpoint = n_point; |
| 1555 | | } |
| 1556 | | } |
| 1557 | | n_rightpoint = n_leftpoint; |
| 1558 | | |
| 1559 | 1584 | n_dx1 = 0; |
| 1560 | 1585 | n_dx2 = 0; |
| 1561 | 1586 | n_du1 = 0; |
| r22543 | r22544 | |
| 1734 | 1759 | |
| 1735 | 1760 | SOLIDSETUP |
| 1736 | 1761 | |
| 1737 | | if( n_points == 4 ) |
| 1738 | | { |
| 1739 | | p_n_rightpointlist = m_p_n_nextpointlist4; |
| 1740 | | p_n_leftpointlist = m_p_n_prevpointlist4; |
| 1741 | | } |
| 1742 | | else |
| 1743 | | { |
| 1744 | | p_n_rightpointlist = m_p_n_nextpointlist3; |
| 1745 | | p_n_leftpointlist = m_p_n_prevpointlist3; |
| 1746 | | } |
| 1762 | FINDTOPLEFT( GouraudPolygon ) |
| 1747 | 1763 | |
| 1748 | | for( n_point = 0; n_point < n_points; n_point++ ) |
| 1749 | | { |
| 1750 | | ADJUST_COORD( m_packet.GouraudPolygon.vertex[ n_point ].n_coord ); |
| 1751 | | } |
| 1752 | | |
| 1753 | | n_leftpoint = 0; |
| 1754 | | for( n_point = 1; n_point < n_points; n_point++ ) |
| 1755 | | { |
| 1756 | | if( COORD_Y( m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) < COORD_Y( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) || |
| 1757 | | ( COORD_Y( m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) == COORD_Y( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) && |
| 1758 | | COORD_X( m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) < COORD_X( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) ) ) |
| 1759 | | { |
| 1760 | | n_leftpoint = n_point; |
| 1761 | | } |
| 1762 | | } |
| 1763 | | n_rightpoint = n_leftpoint; |
| 1764 | | |
| 1765 | 1764 | n_dx1 = 0; |
| 1766 | 1765 | n_dx2 = 0; |
| 1767 | 1766 | n_dr1 = 0; |
| r22543 | r22544 | |
| 1979 | 1978 | decode_tpage( m_packet.GouraudTexturedPolygon.vertex[ 1 ].n_texture.w.h ); |
| 1980 | 1979 | TEXTURESETUP |
| 1981 | 1980 | |
| 1982 | | if( n_points == 4 ) |
| 1983 | | { |
| 1984 | | p_n_rightpointlist = m_p_n_nextpointlist4; |
| 1985 | | p_n_leftpointlist = m_p_n_prevpointlist4; |
| 1986 | | } |
| 1987 | | else |
| 1988 | | { |
| 1989 | | p_n_rightpointlist = m_p_n_nextpointlist3; |
| 1990 | | p_n_leftpointlist = m_p_n_prevpointlist3; |
| 1991 | | } |
| 1981 | FINDTOPLEFT( GouraudTexturedPolygon ) |
| 1992 | 1982 | |
| 1993 | | for( n_point = 0; n_point < n_points; n_point++ ) |
| 1994 | | { |
| 1995 | | ADJUST_COORD( m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ); |
| 1996 | | } |
| 1997 | | |
| 1998 | | n_leftpoint = 0; |
| 1999 | | for( n_point = 1; n_point < n_points; n_point++ ) |
| 2000 | | { |
| 2001 | | if( COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) < COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) || |
| 2002 | | ( COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) == COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) && |
| 2003 | | COORD_X( m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) < COORD_X( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) ) ) |
| 2004 | | { |
| 2005 | | n_leftpoint = n_point; |
| 2006 | | } |
| 2007 | | } |
| 2008 | | n_rightpoint = n_leftpoint; |
| 2009 | | |
| 2010 | 1983 | n_dx1 = 0; |
| 2011 | 1984 | n_dx2 = 0; |
| 2012 | 1985 | n_du1 = 0; |