Search
lxdream.org :: lxdream :: r322:354407942957
lxdream 0.9.1
released Jun 29
Download Now
changeset322:354407942957
parent321:7036e3692165
child323:067583c1a704
authornkeynes
dateThu Jan 25 08:18:03 2007 +0000 (12 years ago)
Add method to determine maximum z-coord in scene, use for near-clip value
src/pvr2/pvr2.h
src/pvr2/rendcore.c
src/pvr2/render.c
1.1 --- a/src/pvr2/pvr2.h Thu Jan 25 08:16:02 2007 +0000
1.2 +++ b/src/pvr2/pvr2.h Thu Jan 25 08:18:03 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: pvr2.h,v 1.26 2007-01-24 08:11:14 nkeynes Exp $
1.6 + * $Id: pvr2.h,v 1.27 2007-01-25 08:18:03 nkeynes Exp $
1.7 *
1.8 * PVR2 (video chip) functions and macros.
1.9 *
1.10 @@ -265,7 +265,7 @@
1.11 void pvr2_render_tilebuffer( int width, int height, int clipx1, int clipy1,
1.12 int clipx2, int clipy2 );
1.13
1.14 -
1.15 +float pvr2_render_find_maximum_z();
1.16 /**
1.17 * Structure to hold a complete unpacked vertex (excluding modifier
1.18 * volume parameters - generate separate vertexes in that case).
1.19 @@ -333,13 +333,13 @@
1.20
1.21 #define POLY2_SRC_BLEND(poly2) ( pvr2_poly_srcblend[(poly2) >> 29] )
1.22 #define POLY2_DEST_BLEND(poly2) ( pvr2_poly_dstblend[((poly2)>>26)&0x07] )
1.23 -#define POLY2_SRC_BLEND_TARGET(poly2) ((poly2)&0x02000000)
1.24 -#define POLY2_DEST_BLEND_TARGET(poly2) ((poly2)&0x01000000)
1.25 +#define POLY2_SRC_BLEND_TARGET(poly2) ((poly2)&0x02000000)
1.26 +#define POLY2_DEST_BLEND_TARGET(poly2) ((poly2)&0x01000000)
1.27 #define POLY2_COLOUR_CLAMP_ENABLE(poly2) ((poly2)&0x00200000)
1.28 -#define POLY2_ALPHA_ENABLE(poly2) ((poly2)&0x001000000)
1.29 -#define POLY2_TEX_ALPHA_ENABLE(poly2) (((poly2)&0x00080000) == 0 )
1.30 -#define POLY2_TEX_CLAMP_U(poly2) ((poly2)&0x00010000)
1.31 -#define POLY2_TEX_CLAMP_V(poly2) ((poly2)&0x00008000)
1.32 +#define POLY2_ALPHA_ENABLE(poly2) ((poly2)&0x00100000)
1.33 +#define POLY2_TEX_ALPHA_ENABLE(poly2) (((poly2)&0x00080000) == 0 )
1.34 +#define POLY2_TEX_CLAMP_U(poly2) ((poly2)&0x00010000)
1.35 +#define POLY2_TEX_CLAMP_V(poly2) ((poly2)&0x00008000)
1.36 #define POLY2_TEX_WIDTH(poly2) ( 1<< ((((poly2) >> 3) & 0x07 ) + 3) )
1.37 #define POLY2_TEX_HEIGHT(poly2) ( 1<< (((poly2) & 0x07 ) + 3) )
1.38 #define POLY2_TEX_BLEND(poly2) ( pvr2_poly_texblend[((poly2) >> 6)&0x03] )
2.1 --- a/src/pvr2/rendcore.c Thu Jan 25 08:16:02 2007 +0000
2.2 +++ b/src/pvr2/rendcore.c Thu Jan 25 08:18:03 2007 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: rendcore.c,v 1.12 2007-01-24 08:11:14 nkeynes Exp $
2.6 + * $Id: rendcore.c,v 1.13 2007-01-25 08:18:03 nkeynes Exp $
2.7 *
2.8 * PVR2 renderer core.
2.9 *
2.10 @@ -31,7 +31,11 @@
2.11 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
2.12 GL_ONE_MINUS_DST_ALPHA };
2.13 int pvr2_poly_texblend[4] = {
2.14 - GL_REPLACE, GL_MODULATE, GL_DECAL, GL_MODULATE };
2.15 + GL_REPLACE,
2.16 + GL_MODULATE,
2.17 + GL_DECAL,
2.18 + GL_MODULATE
2.19 +};
2.20 int pvr2_render_colour_format[8] = {
2.21 COLFMT_ARGB1555, COLFMT_RGB565, COLFMT_ARGB4444, COLFMT_ARGB1555,
2.22 COLFMT_RGB888, COLFMT_ARGB8888, COLFMT_ARGB8888, COLFMT_ARGB4444 };
2.23 @@ -52,7 +56,7 @@
2.24
2.25 extern char *video_base;
2.26
2.27 -gboolean pvr2_force_fragment_alpha;
2.28 +gboolean pvr2_force_fragment_alpha = FALSE;
2.29
2.30 struct tile_segment {
2.31 uint32_t control;
2.32 @@ -154,6 +158,10 @@
2.33 int destblend = POLY2_DEST_BLEND(poly2);
2.34 glBlendFunc( srcblend, destblend );
2.35
2.36 + if( POLY2_SRC_BLEND_TARGET(poly2) || POLY2_DEST_BLEND_TARGET(poly2) ) {
2.37 + ERROR( "Accumulation buffer not supported" );
2.38 + }
2.39 +
2.40 pvr2_force_fragment_alpha = POLY2_ALPHA_ENABLE(poly2) ? FALSE : TRUE;
2.41
2.42 }
2.43 @@ -279,9 +287,12 @@
2.44 glTexCoord2f( vertexes[i]->u, vertexes[i]->v );
2.45 }
2.46
2.47 - glColor4f( vertexes[i]->rgba[0], vertexes[i]->rgba[1], vertexes[i]->rgba[2],
2.48 - (pvr2_force_fragment_alpha ? 1.0 : vertexes[i]->rgba[3]) );
2.49 -
2.50 + if( pvr2_force_fragment_alpha ) {
2.51 + glColor4f( vertexes[i]->rgba[0], vertexes[i]->rgba[1], vertexes[i]->rgba[2], 1.0 );
2.52 + } else {
2.53 + glColor4f( vertexes[i]->rgba[0], vertexes[i]->rgba[1], vertexes[i]->rgba[2],
2.54 + vertexes[i]->rgba[3] );
2.55 + }
2.56 if( POLY1_SPECULAR(poly1) ) {
2.57 glSecondaryColor3fEXT( vertexes[i]->offset_rgba[0],
2.58 vertexes[i]->offset_rgba[1],
2.59 @@ -504,3 +515,103 @@
2.60 gettimeofday(&tv_end, NULL);
2.61 timersub(&tv_end,&tv_start, &tv_start);
2.62 }
2.63 +
2.64 +static float render_find_maximum_tile_z( pvraddr_t tile_entry, float inputz )
2.65 +{
2.66 + uint32_t poly_bank = MMIO_READ(PVR2,RENDER_POLYBASE);
2.67 + uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
2.68 + int shadow_cfg = MMIO_READ( PVR2, RENDER_SHADOW ) & 0x100;
2.69 + int i, j;
2.70 + float z = inputz;
2.71 + do {
2.72 + uint32_t entry = *tile_list++;
2.73 + if( entry >> 28 == 0x0F ) {
2.74 + break;
2.75 + } else if( entry >> 28 == 0x0E ) {
2.76 + tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
2.77 + } else {
2.78 + uint32_t *polygon = (uint32_t *)(video_base + poly_bank + ((entry & 0x000FFFFF) << 2));
2.79 + int is_modified = entry & 0x01000000;
2.80 + int vertex_length = (entry >> 21) & 0x07;
2.81 + int context_length = 3;
2.82 + if( (entry & 0x01000000) && shadow_cfg ) {
2.83 + context_length = 5;
2.84 + vertex_length *= 2 ;
2.85 + }
2.86 + vertex_length += 3;
2.87 + if( (entry & 0xE0000000) == 0x80000000 ) {
2.88 + /* Triangle(s) */
2.89 + int strip_count = ((entry >> 25) & 0x0F)+1;
2.90 + float *vertexz = (float *)(polygon+context_length+2);
2.91 + for( i=0; i<strip_count; i++ ) {
2.92 + for( j=0; j<3; j++ ) {
2.93 + if( *vertexz > z ) {
2.94 + z = *vertexz;
2.95 + }
2.96 + vertexz += vertex_length;
2.97 + }
2.98 + vertexz += context_length;
2.99 + }
2.100 + } else if( (entry & 0xE0000000) == 0xA0000000 ) {
2.101 + /* Sprite(s) */
2.102 + int strip_count = ((entry >> 25) & 0x0F)+1;
2.103 + int polygon_length = 4 * vertex_length + context_length;
2.104 + int i;
2.105 + float *vertexz = (float *)(polygon+context_length+2);
2.106 + for( i=0; i<strip_count; i++ ) {
2.107 + for( j=0; j<4; j++ ) {
2.108 + if( *vertexz > z ) {
2.109 + z = *vertexz;
2.110 + }
2.111 + vertexz += vertex_length;
2.112 + }
2.113 + vertexz+=context_length;
2.114 + }
2.115 + } else {
2.116 + /* Polygon */
2.117 + int i, first=-1, last = -1;
2.118 + float *vertexz = (float *)polygon+context_length+2;
2.119 + for( i=0; i<6; i++ ) {
2.120 + if( (entry & (0x40000000>>i)) && *vertexz > z ) {
2.121 + z = *vertexz;
2.122 + }
2.123 + vertexz += vertex_length;
2.124 + }
2.125 + }
2.126 + }
2.127 + } while(1);
2.128 + return z;
2.129 +}
2.130 +
2.131 +/**
2.132 + * Scan through the scene to determine the largest z value (in order to set up
2.133 + * an appropriate near clip plane).
2.134 + */
2.135 +float pvr2_render_find_maximum_z( )
2.136 +{
2.137 + pvraddr_t segmentbase = MMIO_READ( PVR2, RENDER_TILEBASE );
2.138 + float maximumz = MMIO_READF( PVR2, RENDER_FARCLIP ); /* Initialize to the far clip plane */
2.139 +
2.140 + struct tile_segment *segment = (struct tile_segment *)(video_base + segmentbase);
2.141 + do {
2.142 +
2.143 + if( (segment->opaque_ptr & NO_POINTER) == 0 ) {
2.144 + maximumz = render_find_maximum_tile_z(segment->opaque_ptr, maximumz);
2.145 + }
2.146 + if( (segment->opaquemod_ptr & NO_POINTER) == 0 ) {
2.147 + maximumz = render_find_maximum_tile_z(segment->opaquemod_ptr, maximumz);
2.148 + }
2.149 + if( (segment->trans_ptr & NO_POINTER) == 0 ) {
2.150 + maximumz = render_find_maximum_tile_z(segment->trans_ptr, maximumz);
2.151 + }
2.152 + if( (segment->transmod_ptr & NO_POINTER) == 0 ) {
2.153 + maximumz = render_find_maximum_tile_z(segment->transmod_ptr, maximumz);
2.154 + }
2.155 + if( (segment->punchout_ptr & NO_POINTER) == 0 ) {
2.156 + maximumz = render_find_maximum_tile_z(segment->punchout_ptr, maximumz);
2.157 + }
2.158 +
2.159 + } while( ((segment++)->control & SEGMENT_END) == 0 );
2.160 +
2.161 + return maximumz;
2.162 +}
3.1 --- a/src/pvr2/render.c Thu Jan 25 08:16:02 2007 +0000
3.2 +++ b/src/pvr2/render.c Thu Jan 25 08:18:03 2007 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: render.c,v 1.18 2007-01-23 11:19:32 nkeynes Exp $
3.6 + * $Id: render.c,v 1.19 2007-01-25 08:18:03 nkeynes Exp $
3.7 *
3.8 * PVR2 Renderer support. This part is primarily
3.9 *
3.10 @@ -148,7 +148,7 @@
3.11 static void pvr2_render_prepare_context( sh4addr_t render_addr,
3.12 uint32_t width, uint32_t height,
3.13 uint32_t colour_format,
3.14 - float bgplanez,
3.15 + float bgplanez, float nearz,
3.16 gboolean texture_target )
3.17 {
3.18 /* Select and initialize the render context */
3.19 @@ -186,7 +186,7 @@
3.20 glViewport( 0, 0, width, height );
3.21 glMatrixMode(GL_PROJECTION);
3.22 glLoadIdentity();
3.23 - glOrtho( 0, width, height, 0, bgplanez, -4 );
3.24 + glOrtho( 0, width, height, 0, bgplanez, -(nearz+1) );
3.25 glMatrixMode(GL_MODELVIEW);
3.26 glLoadIdentity();
3.27 glCullFace( GL_BACK );
3.28 @@ -230,8 +230,9 @@
3.29 int width = 640; /* FIXME - get this from the tile buffer */
3.30 int height = 480;
3.31 int colour_format = pvr2_render_colour_format[render_mode&0x07];
3.32 + float maxz = pvr2_render_find_maximum_z();
3.33 pvr2_render_prepare_context( render_addr, width, height, colour_format,
3.34 - bgplanez, render_to_tex );
3.35 + bgplanez, maxz, render_to_tex );
3.36
3.37 int clip_x = MMIO_READ( PVR2, RENDER_HCLIP ) & 0x03FF;
3.38 int clip_y = MMIO_READ( PVR2, RENDER_VCLIP ) & 0x03FF;
.