filename | src/pvr2/rendsort.c |
changeset | 318:363935d31859 |
prev | 276:1e594c2804f8 |
next | 319:5392aed6a982 |
author | nkeynes |
date | Tue Jan 23 12:03:57 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Add initial offset color support Honor the "enable fragment alpha" bit |
file | annotate | diff | log | raw |
1.1 --- a/src/pvr2/rendsort.c Fri Jan 12 10:15:06 2007 +00001.2 +++ b/src/pvr2/rendsort.c Tue Jan 23 12:03:57 2007 +00001.3 @@ -1,5 +1,5 @@1.4 /**1.5 - * $Id: rendsort.c,v 1.2 2007-01-12 10:15:06 nkeynes Exp $1.6 + * $Id: rendsort.c,v 1.3 2007-01-23 12:03:57 nkeynes Exp $1.7 *1.8 * PVR2 renderer routines for depth sorted polygons1.9 *1.10 @@ -20,6 +20,7 @@1.11 #include "asic.h"1.13 extern char *video_base;1.14 +extern gboolean pvr2_force_fragment_alpha;1.16 #define MIN3( a,b,c ) ((a) < (b) ? ( (a) < (c) ? (a) : (c) ) : ((b) < (c) ? (b) : (c)) )1.17 #define MAX3( a,b,c ) ((a) > (b) ? ( (a) > (c) ? (a) : (c) ) : ((b) > (c) ? (b) : (c)) )1.18 @@ -37,6 +38,8 @@1.19 float *vertexes[3];1.20 };1.22 +#define SENTINEL 0xDEADBEEF1.23 +1.24 /**1.25 * Count the number of triangles in the list starting at the given1.26 * pvr memory address.1.27 @@ -80,7 +83,7 @@1.28 }1.30 void render_extract_triangles( pvraddr_t tile_entry, gboolean cheap_modifier_mode,1.31 - struct render_triangle *triangles )1.32 + struct render_triangle *triangles, int num_triangles )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 @@ -167,12 +170,15 @@1.37 }1.38 }1.39 }1.40 + if( count != num_triangles ) {1.41 + ERROR( "Extracted triangles do not match expected count!" );1.42 + }1.43 }1.45 void render_triangles( struct render_triangle *triangles, int num_triangles,1.46 int render_mode )1.47 {1.48 - int i,j, m = 0;1.49 + int i,j, k, m = 0;1.50 for( i=0; i<num_triangles; i++ ) {1.51 render_set_context( triangles[i].polygon, render_mode );1.52 if( render_mode == RENDER_FULLMOD ) {1.53 @@ -185,21 +191,31 @@1.54 uint32_t *vertexes = (uint32_t *)triangles[i].vertexes[j];1.55 float *vertexf = (float *)vertexes;1.56 uint32_t argb;1.57 + k = m + 3;1.58 if( POLY1_TEXTURED(*triangles[i].polygon) ) {1.59 if( POLY1_UV16(*triangles[i].polygon) ) {1.60 - glTexCoord2f( halftofloat(vertexes[m+3]>>16),1.61 - halftofloat(vertexes[m+3]) );1.62 - argb = vertexes[m+4];1.63 + glTexCoord2f( halftofloat(vertexes[k]>>16),1.64 + halftofloat(vertexes[k]) );1.65 + k++;1.66 } else {1.67 - glTexCoord2f( vertexf[m+3], vertexf[m+4] );1.68 - argb = vertexes[m+5];1.69 + glTexCoord2f( vertexf[k], vertexf[k+1] );1.70 + k+=2;1.71 }1.72 + }1.73 + argb = vertexes[k++];1.74 + if( pvr2_force_fragment_alpha ) {1.75 + glColor4ub( (GLubyte)(argb >> 16), (GLubyte)(argb >> 8),1.76 + (GLubyte)argb, 0xFF );1.77 } else {1.78 - argb = vertexes[m+3];1.79 + glColor4ub( (GLubyte)(argb >> 16), (GLubyte)(argb >> 8),1.80 + (GLubyte)argb, (GLubyte)(argb >> 24) );1.81 }1.82 -1.83 - glColor4ub( (GLubyte)(argb >> 16), (GLubyte)(argb >> 8),1.84 - (GLubyte)argb, (GLubyte)(argb >> 24) );1.85 +1.86 + if( POLY1_SPECULAR(*triangles[i].polygon) ) {1.87 + uint32_t spec = vertexes[k];1.88 + glSecondaryColor3ubEXT( (GLubyte)(spec >> 16), (GLubyte)(spec >> 8),1.89 + (GLubyte)spec );1.90 + }1.91 glVertex3f( vertexf[0], vertexf[1], vertexf[2] );1.92 }1.93 glEnd();1.94 @@ -234,10 +250,14 @@1.95 } else if( num_triangles == 1 ) { /* Triangle can hardly overlap with itself */1.96 render_tile( tile_entry, render_mode, cheap_modifier_mode );1.97 } else { /* Ooh boy here we go... */1.98 - struct render_triangle triangles[num_triangles];1.99 - render_extract_triangles(tile_entry, cheap_modifier_mode, triangles);1.100 + struct render_triangle triangles[num_triangles+1];1.101 + triangles[num_triangles].polygon = (void *)SENTINEL;1.102 + render_extract_triangles(tile_entry, cheap_modifier_mode, triangles, num_triangles);1.103 compute_triangle_boxes(triangles, num_triangles);1.104 sort_triangles( triangles, num_triangles );1.105 render_triangles(triangles, num_triangles, render_mode);1.106 + if( triangles[num_triangles].polygon != (void *)SENTINEL ) {1.107 + fprintf( stderr, "Triangle overflow in render_autosort_tile!" );1.108 + }1.109 }1.110 }
.