Search
lxdream.org :: lxdream/src/pvr2/rendsort.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/rendsort.c
changeset 319:5392aed6a982
prev318:363935d31859
next331:a6048d3a9a79
author nkeynes
date Wed Jan 24 08:11:14 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add support for quads (auto-calculated 4th vertex)
file annotate diff log raw
1.1 --- a/src/pvr2/rendsort.c Tue Jan 23 12:03:57 2007 +0000
1.2 +++ b/src/pvr2/rendsort.c Wed Jan 24 08:11:14 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: rendsort.c,v 1.3 2007-01-23 12:03:57 nkeynes Exp $
1.6 + * $Id: rendsort.c,v 1.4 2007-01-24 08:11:14 nkeynes Exp $
1.7 *
1.8 * PVR2 renderer routines for depth sorted polygons
1.9 *
1.10 @@ -25,14 +25,9 @@
1.11 #define MIN3( a,b,c ) ((a) < (b) ? ( (a) < (c) ? (a) : (c) ) : ((b) < (c) ? (b) : (c)) )
1.12 #define MAX3( a,b,c ) ((a) > (b) ? ( (a) > (c) ? (a) : (c) ) : ((b) > (c) ? (b) : (c)) )
1.13
1.14 -struct pvr_vertex {
1.15 - float x,y,z;
1.16 - uint32_t detail[1];
1.17 -};
1.18 -
1.19 struct render_triangle {
1.20 uint32_t *polygon;
1.21 - int vertex_length;
1.22 + int vertex_length; /* Number of 32-bit words in vertex, or 0 for an unpacked vertex */
1.23 float minx,miny,minz;
1.24 float maxx,maxy,maxz;
1.25 float *vertexes[3];
1.26 @@ -83,7 +78,8 @@
1.27 }
1.28
1.29 void render_extract_triangles( pvraddr_t tile_entry, gboolean cheap_modifier_mode,
1.30 - struct render_triangle *triangles, int num_triangles )
1.31 + struct render_triangle *triangles, int num_triangles,
1.32 + struct vertex_unpacked *vertex_space, int render_mode )
1.33 {
1.34 uint32_t poly_bank = MMIO_READ(PVR2,RENDER_POLYBASE);
1.35 uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
1.36 @@ -123,27 +119,28 @@
1.37 count++;
1.38 }
1.39 } else if( (entry & 0xE0000000) == 0xA0000000 ) {
1.40 - /* Sprite(s) */
1.41 + /* Quad(s) */
1.42 int strip_count = ((entry >> 25) & 0x0F)+1;
1.43 int polygon_length = 4 * vertex_length + context_length;
1.44 +
1.45 int i;
1.46 for( i=0; i<strip_count; i++ ) {
1.47 - float *vertex = (float *)(polygon+context_length);
1.48 + render_unpack_quad( vertex_space, *polygon, (polygon+context_length),
1.49 + vertex_length, render_mode );
1.50 triangles[count].polygon = polygon;
1.51 - triangles[count].vertex_length = vertex_length;
1.52 - triangles[count].vertexes[0] = vertex;
1.53 - vertex+=vertex_length;
1.54 - triangles[count].vertexes[1] = vertex;
1.55 - vertex+=vertex_length;
1.56 - triangles[count].vertexes[2] = vertex;
1.57 + triangles[count].vertex_length = 0;
1.58 + triangles[count].vertexes[0] = (float *)vertex_space;
1.59 + triangles[count].vertexes[1] = (float *)(vertex_space + 1);
1.60 + triangles[count].vertexes[2] = (float *)(vertex_space + 3);
1.61 count++;
1.62 /* Preserve face direction */
1.63 triangles[count].polygon = polygon;
1.64 - triangles[count].vertex_length = vertex_length;
1.65 - triangles[count].vertexes[0] = vertex;
1.66 - triangles[count].vertexes[1] = vertex - vertex_length;
1.67 - triangles[count].vertexes[2] = vertex + vertex_length;
1.68 + triangles[count].vertex_length = 0;
1.69 + triangles[count].vertexes[0] = (float *)(vertex_space + 1);
1.70 + triangles[count].vertexes[1] = (float *)(vertex_space + 2);
1.71 + triangles[count].vertexes[2] = (float *)(vertex_space + 3);
1.72 count++;
1.73 + vertex_space += 4;
1.74 polygon += polygon_length;
1.75 }
1.76 } else {
1.77 @@ -181,44 +178,12 @@
1.78 int i,j, k, m = 0;
1.79 for( i=0; i<num_triangles; i++ ) {
1.80 render_set_context( triangles[i].polygon, render_mode );
1.81 - if( render_mode == RENDER_FULLMOD ) {
1.82 - m = (triangles[i].vertex_length - 3)/2;
1.83 + if( triangles[i].vertex_length == 0 ) {
1.84 + render_unpacked_vertex_array( *triangles[i].polygon, (struct vertex_unpacked **)triangles[i].vertexes, 3 );
1.85 + } else {
1.86 + render_vertex_array( *triangles[i].polygon, (uint32_t **)triangles[i].vertexes, 3,
1.87 + triangles[i].vertex_length, render_mode );
1.88 }
1.89 -
1.90 - glBegin( GL_TRIANGLE_STRIP );
1.91 -
1.92 - for( j=0; j<3; j++ ) {
1.93 - uint32_t *vertexes = (uint32_t *)triangles[i].vertexes[j];
1.94 - float *vertexf = (float *)vertexes;
1.95 - uint32_t argb;
1.96 - k = m + 3;
1.97 - if( POLY1_TEXTURED(*triangles[i].polygon) ) {
1.98 - if( POLY1_UV16(*triangles[i].polygon) ) {
1.99 - glTexCoord2f( halftofloat(vertexes[k]>>16),
1.100 - halftofloat(vertexes[k]) );
1.101 - k++;
1.102 - } else {
1.103 - glTexCoord2f( vertexf[k], vertexf[k+1] );
1.104 - k+=2;
1.105 - }
1.106 - }
1.107 - argb = vertexes[k++];
1.108 - if( pvr2_force_fragment_alpha ) {
1.109 - glColor4ub( (GLubyte)(argb >> 16), (GLubyte)(argb >> 8),
1.110 - (GLubyte)argb, 0xFF );
1.111 - } else {
1.112 - glColor4ub( (GLubyte)(argb >> 16), (GLubyte)(argb >> 8),
1.113 - (GLubyte)argb, (GLubyte)(argb >> 24) );
1.114 - }
1.115 -
1.116 - if( POLY1_SPECULAR(*triangles[i].polygon) ) {
1.117 - uint32_t spec = vertexes[k];
1.118 - glSecondaryColor3ubEXT( (GLubyte)(spec >> 16), (GLubyte)(spec >> 8),
1.119 - (GLubyte)spec );
1.120 - }
1.121 - glVertex3f( vertexf[0], vertexf[1], vertexf[2] );
1.122 - }
1.123 - glEnd();
1.124 }
1.125
1.126
1.127 @@ -251,8 +216,11 @@
1.128 render_tile( tile_entry, render_mode, cheap_modifier_mode );
1.129 } else { /* Ooh boy here we go... */
1.130 struct render_triangle triangles[num_triangles+1];
1.131 + struct vertex_unpacked vertex_space[num_triangles << 1];
1.132 + // Reserve space for num_triangles / 2 * 4 vertexes (maximum possible number of
1.133 + // quad vertices)
1.134 triangles[num_triangles].polygon = (void *)SENTINEL;
1.135 - render_extract_triangles(tile_entry, cheap_modifier_mode, triangles, num_triangles);
1.136 + render_extract_triangles(tile_entry, cheap_modifier_mode, triangles, num_triangles, vertex_space, render_mode);
1.137 compute_triangle_boxes(triangles, num_triangles);
1.138 sort_triangles( triangles, num_triangles );
1.139 render_triangles(triangles, num_triangles, render_mode);
.