Search
lxdream.org :: lxdream :: r331:a6048d3a9a79
lxdream 0.9.1
released Jun 29
Download Now
changeset331:a6048d3a9a79
parent330:ae85a338b954
child332:4c1b31e646ef
authornkeynes
dateFri Jan 26 01:37:39 2007 +0000 (13 years ago)
Z should be rendered as 1/Z - fixes a host of depth issues
src/pvr2/rendbkg.c
src/pvr2/rendcore.c
src/pvr2/render.c
src/pvr2/rendsort.c
1.1 --- a/src/pvr2/rendbkg.c Fri Jan 26 01:17:49 2007 +0000
1.2 +++ b/src/pvr2/rendbkg.c Fri Jan 26 01:37:39 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: rendbkg.c,v 1.4 2006-12-15 10:17:30 nkeynes Exp $
1.6 + * $Id: rendbkg.c,v 1.5 2007-01-26 01:37:39 nkeynes Exp $
1.7 *
1.8 * PVR2 background renderer.
1.9 *
1.10 @@ -163,7 +163,7 @@
1.11 float *vertexf = (float *)vertexes;
1.12 result[i].x = vertexf[0];
1.13 result[i].y = vertexf[1];
1.14 - result[i].z = vertexf[2];
1.15 + result[i].z = 1/vertexf[2];
1.16 uint32_t argb;
1.17 if( POLY1_TEXTURED(*polygon) ) {
1.18 if( POLY1_UV16(*polygon) ) {
2.1 --- a/src/pvr2/rendcore.c Fri Jan 26 01:17:49 2007 +0000
2.2 +++ b/src/pvr2/rendcore.c Fri Jan 26 01:37:39 2007 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: rendcore.c,v 1.13 2007-01-25 08:18:03 nkeynes Exp $
2.6 + * $Id: rendcore.c,v 1.14 2007-01-26 01:37:39 nkeynes Exp $
2.7 *
2.8 * PVR2 renderer core.
2.9 *
2.10 @@ -250,9 +250,9 @@
2.11 (unpacked[3].y - unpacked[1].y) * diff1.x) / detxy;
2.12 float s = ((unpacked[3].y - unpacked[1].y) * diff0.x -
2.13 (unpacked[3].x - unpacked[1].x) * diff0.y) / detxy;
2.14 - diff0.z = unpacked[0].z - unpacked[1].z;
2.15 - diff1.z = unpacked[2].z - unpacked[1].z;
2.16 - unpacked[3].z = unpacked[1].z + (t*diff0.z) + (s*diff1.z);
2.17 + diff0.z = (1/unpacked[0].z) - (1/unpacked[1].z);
2.18 + diff1.z = (1/unpacked[2].z) - (1/unpacked[1].z);
2.19 + unpacked[3].z = 1/((1/unpacked[1].z) + (t*diff0.z) + (s*diff1.z));
2.20
2.21 diff0.u = unpacked[0].u - unpacked[1].u;
2.22 diff0.v = unpacked[0].v - unpacked[1].v;
2.23 @@ -298,7 +298,7 @@
2.24 vertexes[i]->offset_rgba[1],
2.25 vertexes[i]->offset_rgba[2] );
2.26 }
2.27 - glVertex3f( vertexes[i]->x, vertexes[i]->y, vertexes[i]->z );
2.28 + glVertex3f( vertexes[i]->x, vertexes[i]->y, 1/vertexes[i]->z );
2.29 }
2.30
2.31 glEnd();
2.32 @@ -353,7 +353,7 @@
2.33 glSecondaryColor3ubEXT( (GLubyte)(spec >> 16), (GLubyte)(spec >> 8),
2.34 (GLubyte)spec );
2.35 }
2.36 - glVertex3f( vertexf[0], vertexf[1], vertexf[2] );
2.37 + glVertex3f( vertexf[0], vertexf[1], 1/vertexf[2] );
2.38 vertexes += vertex_size;
2.39 }
2.40
2.41 @@ -613,5 +613,5 @@
2.42
2.43 } while( ((segment++)->control & SEGMENT_END) == 0 );
2.44
2.45 - return maximumz;
2.46 + return 1/maximumz;
2.47 }
3.1 --- a/src/pvr2/render.c Fri Jan 26 01:17:49 2007 +0000
3.2 +++ b/src/pvr2/render.c Fri Jan 26 01:37:39 2007 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: render.c,v 1.19 2007-01-25 08:18:03 nkeynes Exp $
3.6 + * $Id: render.c,v 1.20 2007-01-26 01:37:39 nkeynes Exp $
3.7 *
3.8 * PVR2 Renderer support. This part is primarily
3.9 *
3.10 @@ -186,7 +186,7 @@
3.11 glViewport( 0, 0, width, height );
3.12 glMatrixMode(GL_PROJECTION);
3.13 glLoadIdentity();
3.14 - glOrtho( 0, width, height, 0, bgplanez, -(nearz+1) );
3.15 + glOrtho( 0, width, height, 0, -bgplanez, -nearz );
3.16 glMatrixMode(GL_MODELVIEW);
3.17 glLoadIdentity();
3.18 glCullFace( GL_BACK );
3.19 @@ -225,7 +225,7 @@
3.20 render_to_tex = FALSE;
3.21 }
3.22
3.23 - float bgplanez = MMIO_READF( PVR2, RENDER_FARCLIP );
3.24 + float bgplanez = 1/MMIO_READF( PVR2, RENDER_FARCLIP );
3.25 uint32_t render_mode = MMIO_READ( PVR2, RENDER_MODE );
3.26 int width = 640; /* FIXME - get this from the tile buffer */
3.27 int height = 480;
4.1 --- a/src/pvr2/rendsort.c Fri Jan 26 01:17:49 2007 +0000
4.2 +++ b/src/pvr2/rendsort.c Fri Jan 26 01:37:39 2007 +0000
4.3 @@ -1,5 +1,5 @@
4.4 /**
4.5 - * $Id: rendsort.c,v 1.4 2007-01-24 08:11:14 nkeynes Exp $
4.6 + * $Id: rendsort.c,v 1.5 2007-01-26 01:37:39 nkeynes Exp $
4.7 *
4.8 * PVR2 renderer routines for depth sorted polygons
4.9 *
4.10 @@ -72,8 +72,11 @@
4.11 triangle[i].maxx = MAX3(triangle[i].vertexes[0][0],triangle[i].vertexes[1][0],triangle[i].vertexes[2][0]);
4.12 triangle[i].miny = MIN3(triangle[i].vertexes[0][1],triangle[i].vertexes[1][1],triangle[i].vertexes[2][1]);
4.13 triangle[i].maxy = MAX3(triangle[i].vertexes[0][1],triangle[i].vertexes[1][1],triangle[i].vertexes[2][1]);
4.14 - triangle[i].minz = MIN3(triangle[i].vertexes[0][2],triangle[i].vertexes[1][2],triangle[i].vertexes[2][2]);
4.15 - triangle[i].maxz = MAX3(triangle[i].vertexes[0][2],triangle[i].vertexes[1][2],triangle[i].vertexes[2][2]);
4.16 + float az = 1/triangle[i].vertexes[0][2];
4.17 + float bz = 1/triangle[i].vertexes[1][2];
4.18 + float cz = 1/triangle[i].vertexes[2][2];
4.19 + triangle[i].minz = MIN3(az,bz,cz);
4.20 + triangle[i].maxz = MAX3(az,bz,cz);
4.21 }
4.22 }
4.23
4.24 @@ -178,6 +181,8 @@
4.25 int i,j, k, m = 0;
4.26 for( i=0; i<num_triangles; i++ ) {
4.27 render_set_context( triangles[i].polygon, render_mode );
4.28 + glEnable(GL_DEPTH_TEST);
4.29 + glDepthFunc(GL_GEQUAL);
4.30 if( triangles[i].vertex_length == 0 ) {
4.31 render_unpacked_vertex_array( *triangles[i].polygon, (struct vertex_unpacked **)triangles[i].vertexes, 3 );
4.32 } else {
4.33 @@ -193,10 +198,10 @@
4.34 {
4.35 struct render_triangle *tri1 = a;
4.36 struct render_triangle *tri2 = b;
4.37 - if( tri1->minz < tri2->minz ) {
4.38 + if( tri1->minz < tri2->minz ) {
4.39 + return 1; // No these _aren't_ back to front...
4.40 + } else if( tri1->minz > tri2->minz ) {
4.41 return -1;
4.42 - } else if( tri1->minz > tri2->minz ) {
4.43 - return 1;
4.44 } else {
4.45 return 0;
4.46 }
.