Search
lxdream.org :: lxdream/src/pvr2/rendcore.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/rendcore.c
changeset 635:76c63aac3590
prev561:533f6b478071
author nkeynes
date Thu Feb 14 13:54:11 2008 +0000 (13 years ago)
branchlxdream-render
permissions -rw-r--r--
last change Commit render work in progress. Main changes:
* Preliminary OSMesa support
* Move the generic gl code out to pvr2/
* Implement scene data structure + reader
* Remove the 1/z adjustments
file annotate diff log raw
1.1 --- a/src/pvr2/rendcore.c Tue Jan 01 05:08:38 2008 +0000
1.2 +++ b/src/pvr2/rendcore.c Thu Feb 14 13:54:11 2008 +0000
1.3 @@ -16,6 +16,8 @@
1.4 * GNU General Public License for more details.
1.5 */
1.6 #include <sys/time.h>
1.7 +#include <assert.h>
1.8 +#include <string.h>
1.9 #include "pvr2/pvr2.h"
1.10 #include "asic.h"
1.11 #include "display.h"
1.12 @@ -41,33 +43,11 @@
1.13 COLFMT_BGRA1555, COLFMT_RGB565, COLFMT_BGRA4444, COLFMT_BGRA1555,
1.14 COLFMT_BGR888, COLFMT_BGRA8888, COLFMT_BGRA8888, COLFMT_BGRA4444 };
1.15
1.16 -
1.17 -#define CULL_NONE 0
1.18 -#define CULL_SMALL 1
1.19 -#define CULL_CCW 2
1.20 -#define CULL_CW 3
1.21 -
1.22 -#define SEGMENT_END 0x80000000
1.23 -#define SEGMENT_ZCLEAR 0x40000000
1.24 -#define SEGMENT_SORT_TRANS 0x20000000
1.25 -#define SEGMENT_START 0x10000000
1.26 -#define SEGMENT_X(c) (((c) >> 2) & 0x3F)
1.27 -#define SEGMENT_Y(c) (((c) >> 8) & 0x3F)
1.28 -#define NO_POINTER 0x80000000
1.29 -
1.30 extern char *video_base;
1.31
1.32 gboolean pvr2_force_fragment_alpha = FALSE;
1.33 gboolean pvr2_debug_render = FALSE;
1.34
1.35 -struct tile_segment {
1.36 - uint32_t control;
1.37 - pvraddr_t opaque_ptr;
1.38 - pvraddr_t opaquemod_ptr;
1.39 - pvraddr_t trans_ptr;
1.40 - pvraddr_t transmod_ptr;
1.41 - pvraddr_t punchout_ptr;
1.42 -};
1.43
1.44 void render_print_tilelist( FILE *f, uint32_t tile_entry );
1.45
1.46 @@ -272,9 +252,9 @@
1.47 (unpacked[3].y - unpacked[1].y) * diff1.x) / detxy;
1.48 float s = ((unpacked[3].y - unpacked[1].y) * diff0.x -
1.49 (unpacked[3].x - unpacked[1].x) * diff0.y) / detxy;
1.50 - diff0.z = (1/unpacked[0].z) - (1/unpacked[1].z);
1.51 - diff1.z = (1/unpacked[2].z) - (1/unpacked[1].z);
1.52 - unpacked[3].z = 1/((1/unpacked[1].z) + (t*diff0.z) + (s*diff1.z));
1.53 + diff0.z = unpacked[0].z - unpacked[1].z;
1.54 + diff1.z = unpacked[2].z - unpacked[1].z;
1.55 + unpacked[3].z = unpacked[1].z + (t*diff0.z) + (s*diff1.z);
1.56
1.57 diff0.u = unpacked[0].u - unpacked[1].u;
1.58 diff0.v = unpacked[0].v - unpacked[1].v;
1.59 @@ -320,7 +300,8 @@
1.60 vertexes[i]->offset_rgba[1],
1.61 vertexes[i]->offset_rgba[2] );
1.62 }
1.63 - glVertex3f( vertexes[i]->x, vertexes[i]->y, 1/vertexes[i]->z );
1.64 + assert( vertexes[i]->z > 0 && !isinf(vertexes[i]->z) );
1.65 + glVertex3f( vertexes[i]->x, vertexes[i]->y, vertexes[i]->z );
1.66 }
1.67
1.68 glEnd();
1.69 @@ -375,7 +356,8 @@
1.70 glSecondaryColor3ubEXT( (GLubyte)(spec >> 16), (GLubyte)(spec >> 8),
1.71 (GLubyte)spec );
1.72 }
1.73 - glVertex3f( vertexf[0], vertexf[1], 1/vertexf[2] );
1.74 + // assert( vertexf[2] > 0 && !isinf(vertexf[2]) );
1.75 + glVertex3f( vertexf[0], vertexf[1], vertexf[2] );
1.76 vertexes += vertex_size;
1.77 }
1.78
1.79 @@ -545,13 +527,12 @@
1.80 glDisable( GL_SCISSOR_TEST );
1.81 }
1.82
1.83 -static float render_find_maximum_tile_z( pvraddr_t tile_entry, float inputz )
1.84 +static void render_find_maximum_tile_z( pvraddr_t tile_entry, float *minimumz, float *maximumz )
1.85 {
1.86 uint32_t poly_bank = MMIO_READ(PVR2,RENDER_POLYBASE);
1.87 uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
1.88 int shadow_cfg = MMIO_READ( PVR2, RENDER_SHADOW ) & 0x100;
1.89 int i, j;
1.90 - float z = inputz;
1.91 do {
1.92 uint32_t entry = *tile_list++;
1.93 if( entry >> 28 == 0x0F ) {
1.94 @@ -573,8 +554,10 @@
1.95 float *vertexz = (float *)(polygon+context_length+2);
1.96 for( i=0; i<strip_count; i++ ) {
1.97 for( j=0; j<3; j++ ) {
1.98 - if( *vertexz > z ) {
1.99 - z = *vertexz;
1.100 + if( *vertexz > *maximumz ) {
1.101 + *maximumz = *vertexz;
1.102 + } else if( *vertexz < *minimumz ) {
1.103 + *minimumz = *vertexz;
1.104 }
1.105 vertexz += vertex_length;
1.106 }
1.107 @@ -587,8 +570,10 @@
1.108 float *vertexz = (float *)(polygon+context_length+2);
1.109 for( i=0; i<strip_count; i++ ) {
1.110 for( j=0; j<4; j++ ) {
1.111 - if( *vertexz > z ) {
1.112 - z = *vertexz;
1.113 + if( *vertexz > *maximumz ) {
1.114 + *maximumz = *vertexz;
1.115 + } else if( *vertexz < *minimumz ) {
1.116 + *minimumz = *vertexz;
1.117 }
1.118 vertexz += vertex_length;
1.119 }
1.120 @@ -599,48 +584,50 @@
1.121 int i;
1.122 float *vertexz = (float *)polygon+context_length+2;
1.123 for( i=0; i<6; i++ ) {
1.124 - if( (entry & (0x40000000>>i)) && *vertexz > z ) {
1.125 - z = *vertexz;
1.126 + if( (entry & (0x40000000>>i)) ) {
1.127 + if( *vertexz > *maximumz ) {
1.128 + *maximumz = *vertexz;
1.129 + } else if( *vertexz < *minimumz ) {
1.130 + *minimumz = *vertexz;
1.131 + }
1.132 }
1.133 vertexz += vertex_length;
1.134 }
1.135 }
1.136 }
1.137 } while(1);
1.138 - return z;
1.139 }
1.140
1.141 /**
1.142 * Scan through the scene to determine the largest z value (in order to set up
1.143 * an appropriate near clip plane).
1.144 */
1.145 -float pvr2_render_find_maximum_z( )
1.146 +void pvr2_render_find_z_range( float *minimumz, float *maximumz )
1.147 {
1.148 pvraddr_t segmentbase = MMIO_READ( PVR2, RENDER_TILEBASE );
1.149 - float maximumz = MMIO_READF( PVR2, RENDER_FARCLIP ); /* Initialize to the far clip plane */
1.150 + *minimumz = MMIO_READF( PVR2, RENDER_FARCLIP ); /* Initialize to the far clip plane */
1.151 + *maximumz = *minimumz;
1.152
1.153 struct tile_segment *segment = (struct tile_segment *)(video_base + segmentbase);
1.154 do {
1.155
1.156 if( (segment->opaque_ptr & NO_POINTER) == 0 ) {
1.157 - maximumz = render_find_maximum_tile_z(segment->opaque_ptr, maximumz);
1.158 + render_find_maximum_tile_z(segment->opaque_ptr, minimumz, maximumz);
1.159 }
1.160 if( (segment->opaquemod_ptr & NO_POINTER) == 0 ) {
1.161 - maximumz = render_find_maximum_tile_z(segment->opaquemod_ptr, maximumz);
1.162 + render_find_maximum_tile_z(segment->opaquemod_ptr, minimumz, maximumz);
1.163 }
1.164 if( (segment->trans_ptr & NO_POINTER) == 0 ) {
1.165 - maximumz = render_find_maximum_tile_z(segment->trans_ptr, maximumz);
1.166 + render_find_maximum_tile_z(segment->trans_ptr, minimumz, maximumz);
1.167 }
1.168 if( (segment->transmod_ptr & NO_POINTER) == 0 ) {
1.169 - maximumz = render_find_maximum_tile_z(segment->transmod_ptr, maximumz);
1.170 + render_find_maximum_tile_z(segment->transmod_ptr, minimumz, maximumz);
1.171 }
1.172 if( (segment->punchout_ptr & NO_POINTER) == 0 ) {
1.173 - maximumz = render_find_maximum_tile_z(segment->punchout_ptr, maximumz);
1.174 + render_find_maximum_tile_z(segment->punchout_ptr, minimumz, maximumz);
1.175 }
1.176
1.177 } while( ((segment++)->control & SEGMENT_END) == 0 );
1.178 -
1.179 - return 1/maximumz;
1.180 }
1.181
1.182 /**
.