Search
lxdream.org :: lxdream/src/pvr2/rendcore.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/rendcore.c
changeset 322:354407942957
prev319:5392aed6a982
next331:a6048d3a9a79
author nkeynes
date Thu Jan 25 08:18:03 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add method to determine maximum z-coord in scene, use for near-clip value
file annotate diff log raw
1.1 --- a/src/pvr2/rendcore.c Wed Jan 24 08:11:14 2007 +0000
1.2 +++ b/src/pvr2/rendcore.c Thu Jan 25 08:18:03 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: rendcore.c,v 1.12 2007-01-24 08:11:14 nkeynes Exp $
1.6 + * $Id: rendcore.c,v 1.13 2007-01-25 08:18:03 nkeynes Exp $
1.7 *
1.8 * PVR2 renderer core.
1.9 *
1.10 @@ -31,7 +31,11 @@
1.11 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
1.12 GL_ONE_MINUS_DST_ALPHA };
1.13 int pvr2_poly_texblend[4] = {
1.14 - GL_REPLACE, GL_MODULATE, GL_DECAL, GL_MODULATE };
1.15 + GL_REPLACE,
1.16 + GL_MODULATE,
1.17 + GL_DECAL,
1.18 + GL_MODULATE
1.19 +};
1.20 int pvr2_render_colour_format[8] = {
1.21 COLFMT_ARGB1555, COLFMT_RGB565, COLFMT_ARGB4444, COLFMT_ARGB1555,
1.22 COLFMT_RGB888, COLFMT_ARGB8888, COLFMT_ARGB8888, COLFMT_ARGB4444 };
1.23 @@ -52,7 +56,7 @@
1.24
1.25 extern char *video_base;
1.26
1.27 -gboolean pvr2_force_fragment_alpha;
1.28 +gboolean pvr2_force_fragment_alpha = FALSE;
1.29
1.30 struct tile_segment {
1.31 uint32_t control;
1.32 @@ -154,6 +158,10 @@
1.33 int destblend = POLY2_DEST_BLEND(poly2);
1.34 glBlendFunc( srcblend, destblend );
1.35
1.36 + if( POLY2_SRC_BLEND_TARGET(poly2) || POLY2_DEST_BLEND_TARGET(poly2) ) {
1.37 + ERROR( "Accumulation buffer not supported" );
1.38 + }
1.39 +
1.40 pvr2_force_fragment_alpha = POLY2_ALPHA_ENABLE(poly2) ? FALSE : TRUE;
1.41
1.42 }
1.43 @@ -279,9 +287,12 @@
1.44 glTexCoord2f( vertexes[i]->u, vertexes[i]->v );
1.45 }
1.46
1.47 - glColor4f( vertexes[i]->rgba[0], vertexes[i]->rgba[1], vertexes[i]->rgba[2],
1.48 - (pvr2_force_fragment_alpha ? 1.0 : vertexes[i]->rgba[3]) );
1.49 -
1.50 + if( pvr2_force_fragment_alpha ) {
1.51 + glColor4f( vertexes[i]->rgba[0], vertexes[i]->rgba[1], vertexes[i]->rgba[2], 1.0 );
1.52 + } else {
1.53 + glColor4f( vertexes[i]->rgba[0], vertexes[i]->rgba[1], vertexes[i]->rgba[2],
1.54 + vertexes[i]->rgba[3] );
1.55 + }
1.56 if( POLY1_SPECULAR(poly1) ) {
1.57 glSecondaryColor3fEXT( vertexes[i]->offset_rgba[0],
1.58 vertexes[i]->offset_rgba[1],
1.59 @@ -504,3 +515,103 @@
1.60 gettimeofday(&tv_end, NULL);
1.61 timersub(&tv_end,&tv_start, &tv_start);
1.62 }
1.63 +
1.64 +static float render_find_maximum_tile_z( pvraddr_t tile_entry, float inputz )
1.65 +{
1.66 + uint32_t poly_bank = MMIO_READ(PVR2,RENDER_POLYBASE);
1.67 + uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
1.68 + int shadow_cfg = MMIO_READ( PVR2, RENDER_SHADOW ) & 0x100;
1.69 + int i, j;
1.70 + float z = inputz;
1.71 + do {
1.72 + uint32_t entry = *tile_list++;
1.73 + if( entry >> 28 == 0x0F ) {
1.74 + break;
1.75 + } else if( entry >> 28 == 0x0E ) {
1.76 + tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
1.77 + } else {
1.78 + uint32_t *polygon = (uint32_t *)(video_base + poly_bank + ((entry & 0x000FFFFF) << 2));
1.79 + int is_modified = entry & 0x01000000;
1.80 + int vertex_length = (entry >> 21) & 0x07;
1.81 + int context_length = 3;
1.82 + if( (entry & 0x01000000) && shadow_cfg ) {
1.83 + context_length = 5;
1.84 + vertex_length *= 2 ;
1.85 + }
1.86 + vertex_length += 3;
1.87 + if( (entry & 0xE0000000) == 0x80000000 ) {
1.88 + /* Triangle(s) */
1.89 + int strip_count = ((entry >> 25) & 0x0F)+1;
1.90 + float *vertexz = (float *)(polygon+context_length+2);
1.91 + for( i=0; i<strip_count; i++ ) {
1.92 + for( j=0; j<3; j++ ) {
1.93 + if( *vertexz > z ) {
1.94 + z = *vertexz;
1.95 + }
1.96 + vertexz += vertex_length;
1.97 + }
1.98 + vertexz += context_length;
1.99 + }
1.100 + } else if( (entry & 0xE0000000) == 0xA0000000 ) {
1.101 + /* Sprite(s) */
1.102 + int strip_count = ((entry >> 25) & 0x0F)+1;
1.103 + int polygon_length = 4 * vertex_length + context_length;
1.104 + int i;
1.105 + float *vertexz = (float *)(polygon+context_length+2);
1.106 + for( i=0; i<strip_count; i++ ) {
1.107 + for( j=0; j<4; j++ ) {
1.108 + if( *vertexz > z ) {
1.109 + z = *vertexz;
1.110 + }
1.111 + vertexz += vertex_length;
1.112 + }
1.113 + vertexz+=context_length;
1.114 + }
1.115 + } else {
1.116 + /* Polygon */
1.117 + int i, first=-1, last = -1;
1.118 + float *vertexz = (float *)polygon+context_length+2;
1.119 + for( i=0; i<6; i++ ) {
1.120 + if( (entry & (0x40000000>>i)) && *vertexz > z ) {
1.121 + z = *vertexz;
1.122 + }
1.123 + vertexz += vertex_length;
1.124 + }
1.125 + }
1.126 + }
1.127 + } while(1);
1.128 + return z;
1.129 +}
1.130 +
1.131 +/**
1.132 + * Scan through the scene to determine the largest z value (in order to set up
1.133 + * an appropriate near clip plane).
1.134 + */
1.135 +float pvr2_render_find_maximum_z( )
1.136 +{
1.137 + pvraddr_t segmentbase = MMIO_READ( PVR2, RENDER_TILEBASE );
1.138 + float maximumz = MMIO_READF( PVR2, RENDER_FARCLIP ); /* Initialize to the far clip plane */
1.139 +
1.140 + struct tile_segment *segment = (struct tile_segment *)(video_base + segmentbase);
1.141 + do {
1.142 +
1.143 + if( (segment->opaque_ptr & NO_POINTER) == 0 ) {
1.144 + maximumz = render_find_maximum_tile_z(segment->opaque_ptr, maximumz);
1.145 + }
1.146 + if( (segment->opaquemod_ptr & NO_POINTER) == 0 ) {
1.147 + maximumz = render_find_maximum_tile_z(segment->opaquemod_ptr, maximumz);
1.148 + }
1.149 + if( (segment->trans_ptr & NO_POINTER) == 0 ) {
1.150 + maximumz = render_find_maximum_tile_z(segment->trans_ptr, maximumz);
1.151 + }
1.152 + if( (segment->transmod_ptr & NO_POINTER) == 0 ) {
1.153 + maximumz = render_find_maximum_tile_z(segment->transmod_ptr, maximumz);
1.154 + }
1.155 + if( (segment->punchout_ptr & NO_POINTER) == 0 ) {
1.156 + maximumz = render_find_maximum_tile_z(segment->punchout_ptr, maximumz);
1.157 + }
1.158 +
1.159 + } while( ((segment++)->control & SEGMENT_END) == 0 );
1.160 +
1.161 + return maximumz;
1.162 +}
.