Search
lxdream.org :: lxdream :: r341:924029ff95ea
lxdream 0.9.1
released Jun 29
Download Now
changeset341:924029ff95ea
parent340:5ae1c80a68fb
child342:850502f0e8de
authornkeynes
dateWed Jan 31 10:32:25 2007 +0000 (12 years ago)
Add better (ie fancier) debug-print functions
src/pvr2/rendcore.c
1.1 --- a/src/pvr2/rendcore.c Wed Jan 31 10:31:53 2007 +0000
1.2 +++ b/src/pvr2/rendcore.c Wed Jan 31 10:32:25 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: rendcore.c,v 1.15 2007-01-29 11:24:44 nkeynes Exp $
1.6 + * $Id: rendcore.c,v 1.16 2007-01-31 10:32:25 nkeynes Exp $
1.7 *
1.8 * PVR2 renderer core.
1.9 *
1.10 @@ -68,6 +68,8 @@
1.11 pvraddr_t punchout_ptr;
1.12 };
1.13
1.14 +void render_print_tilelist( FILE *f, uint32_t tile_entry );
1.15 +
1.16 /**
1.17 * Convert a half-float (16-bit) FP number to a regular 32-bit float.
1.18 * Source is 1-bit sign, 5-bit exponent, 10-bit mantissa.
1.19 @@ -105,10 +107,6 @@
1.20 texture = context[2];
1.21 }
1.22
1.23 - if( pvr2_debug_render ) {
1.24 - fprintf( stderr, "Poly %08X %08X %08X\n", poly1, poly2, texture );
1.25 - }
1.26 -
1.27 if( POLY1_DEPTH_ENABLE(poly1) ) {
1.28 glEnable( GL_DEPTH_TEST );
1.29 glDepthFunc( POLY1_DEPTH_MODE(poly1) );
1.30 @@ -513,6 +511,7 @@
1.31 if( (segment->opaque_ptr & NO_POINTER) == 0 ) {
1.32 if( pvr2_debug_render ) {
1.33 fprintf( stderr, "Tile %d,%d Opaque\n", tilex, tiley );
1.34 + render_print_tilelist( stderr, segment->opaque_ptr );
1.35 }
1.36 if( (segment->opaquemod_ptr & NO_POINTER) == 0 ) {
1.37 /* TODO */
1.38 @@ -523,6 +522,7 @@
1.39 if( (segment->trans_ptr & NO_POINTER) == 0 ) {
1.40 if( pvr2_debug_render ) {
1.41 fprintf( stderr, "Tile %d,%d Trans\n", tilex, tiley );
1.42 + render_print_tilelist( stderr, segment->trans_ptr );
1.43 }
1.44 if( (segment->transmod_ptr & NO_POINTER) == 0 ) {
1.45 /* TODO */
1.46 @@ -538,6 +538,7 @@
1.47 if( (segment->punchout_ptr & NO_POINTER) == 0 ) {
1.48 if( pvr2_debug_render ) {
1.49 fprintf( stderr, "Tile %d,%d Punchout\n", tilex, tiley );
1.50 + render_print_tilelist( stderr, segment->punchout_ptr );
1.51 }
1.52 render_tile( segment->punchout_ptr, RENDER_NORMAL, cheap_shadow );
1.53 }
1.54 @@ -673,3 +674,115 @@
1.55 *x = (maxx+1)<<5;
1.56 *y = (maxy+1)<<5;
1.57 }
1.58 +
1.59 +void render_print_vertexes( FILE *f, uint32_t poly1, uint32_t *vert_array[],
1.60 + int num_vertexes, int vertex_size )
1.61 +{
1.62 + char buf[256], *p;
1.63 + int i,j, k;
1.64 + for( i=0; i<num_vertexes; i++ ) {
1.65 + p = buf;
1.66 + float *vertf = (float *)vert_array[i];
1.67 + uint32_t *verti = (uint32_t *)vert_array[i];
1.68 + p += sprintf( p, " V %9.5f,%9.5f,%9.5f ", vertf[0], vertf[1], vertf[2] );
1.69 + k = 3;
1.70 + if( POLY1_TEXTURED(poly1) ) {
1.71 + if( POLY1_UV16(poly1) ) {
1.72 + p += sprintf( p, "uv=%9.5f,%9.5f ",
1.73 + halftofloat(verti[k]>>16),
1.74 + halftofloat(verti[k]) );
1.75 + k++;
1.76 + } else {
1.77 + p += sprintf( p, "uv=%9.5f,%9.5f ", vertf[k], vertf[k+1] );
1.78 + k+=2;
1.79 + }
1.80 + }
1.81 +
1.82 + p += sprintf( p, "%08X ", verti[k++] );
1.83 + if( POLY1_SPECULAR(poly1) ) {
1.84 + p += sprintf( p, "%08X", verti[k++] );
1.85 + }
1.86 + p += sprintf( p, "\n" );
1.87 + fprintf( f, buf );
1.88 + }
1.89 +}
1.90 +
1.91 +void render_print_polygon( FILE *f, uint32_t entry )
1.92 +{
1.93 + uint32_t poly_bank = MMIO_READ(PVR2,RENDER_POLYBASE);
1.94 + int shadow_cfg = MMIO_READ( PVR2, RENDER_SHADOW ) & 0x100;
1.95 + int i, j;
1.96 +
1.97 + if( entry >> 28 == 0x0F ) {
1.98 + fprintf( f, "EOT\n" );
1.99 + } else if( entry >> 28 == 0x0E ) {
1.100 + fprintf( f, "LINK %08X\n", entry &0x7FFFFF );
1.101 + } else {
1.102 + uint32_t *polygon = (uint32_t *)(video_base + poly_bank + ((entry & 0x000FFFFF) << 2));
1.103 + int is_modified = entry & 0x01000000;
1.104 + int vertex_length = (entry >> 21) & 0x07;
1.105 + int context_length = 3;
1.106 + if( (entry & 0x01000000) && shadow_cfg ) {
1.107 + context_length = 5;
1.108 + vertex_length *= 2 ;
1.109 + }
1.110 + vertex_length += 3;
1.111 + if( (entry & 0xE0000000) == 0x80000000 ) {
1.112 + /* Triangle(s) */
1.113 + int strip_count = ((entry >> 25) & 0x0F)+1;
1.114 + for( i=0; i<strip_count; i++ ) {
1.115 + fprintf( f, "TRI %08X %08X %08X\n", polygon[0], polygon[1], polygon[2] );
1.116 + uint32_t *array[3];
1.117 + array[0] = polygon + context_length;
1.118 + array[1] = array[0] + vertex_length;
1.119 + array[2] = array[1] + vertex_length;
1.120 + render_print_vertexes( f, *polygon, array, 3, vertex_length );
1.121 + polygon = array[2] + vertex_length;
1.122 + }
1.123 + } else if( (entry & 0xE0000000) == 0xA0000000 ) {
1.124 + /* Sprite(s) */
1.125 + int strip_count = ((entry >> 25) & 0x0F)+1;
1.126 + for( i=0; i<strip_count; i++ ) {
1.127 + fprintf( f, "QUAD %08X %08X %08X\n", polygon[0], polygon[1], polygon[2] );
1.128 + uint32_t *array[4];
1.129 + array[0] = polygon + context_length;
1.130 + array[1] = array[0] + vertex_length;
1.131 + array[2] = array[1] + vertex_length;
1.132 + array[3] = array[2] + vertex_length;
1.133 + render_print_vertexes( f, *polygon, array, 4, vertex_length );
1.134 + polygon = array[3] + vertex_length;
1.135 + }
1.136 + } else {
1.137 + /* Polygon */
1.138 + int last = -1;
1.139 + float *vertexz = (float *)polygon+context_length+2;
1.140 + uint32_t *array[8];
1.141 + for( i=0; i<6; i++ ) {
1.142 + if( entry & (0x40000000>>i) ) {
1.143 + last = i;
1.144 + }
1.145 + }
1.146 + fprintf( f, "POLY %08X %08X %08X\n", polygon[0], polygon[1], polygon[2] );
1.147 + for( i=0; i<last+2; i++ ) {
1.148 + array[i] = polygon + context_length + vertex_length*i;
1.149 + }
1.150 + render_print_vertexes( f, *polygon, array, last+2, vertex_length );
1.151 + }
1.152 + }
1.153 +}
1.154 +
1.155 +void render_print_tilelist( FILE *f, uint32_t tile_entry )
1.156 +{
1.157 + uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
1.158 + do {
1.159 + uint32_t entry = *tile_list++;
1.160 + if( entry >> 28 == 0x0F ) {
1.161 + break;
1.162 + } else if( entry >> 28 == 0x0E ) {
1.163 + tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
1.164 + } else {
1.165 + render_print_polygon(f, entry);
1.166 + }
1.167 + } while( 1 );
1.168 +}
1.169 +
.