Search
lxdream.org :: lxdream/src/pvr2/rendsort.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/rendsort.c
changeset 736:a02d1475ccfd
prev669:ab344e42bca9
next862:d3b2066d5daa
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
1.1 --- a/src/pvr2/rendsort.c Mon May 12 10:00:13 2008 +0000
1.2 +++ b/src/pvr2/rendsort.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -41,23 +41,23 @@
1.4 uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
1.5 int count = 0;
1.6 while(1) {
1.7 - uint32_t entry = *tile_list++;
1.8 - if( entry >> 28 == 0x0F ) {
1.9 - break;
1.10 - } else if( entry >> 28 == 0x0E ) {
1.11 - tile_list = (uint32_t *)(video_base+(entry&0x007FFFFF));
1.12 - } else if( entry >> 29 == 0x04 ) { /* Triangle array */
1.13 - count += ((entry >> 25) & 0x0F)+1;
1.14 - } else if( entry >> 29 == 0x05 ) { /* Quad array */
1.15 - count += ((((entry >> 25) & 0x0F)+1)<<1);
1.16 - } else { /* Polygon */
1.17 - int i;
1.18 - for( i=0; i<6; i++ ) {
1.19 - if( entry & (0x40000000>>i) ) {
1.20 - count++;
1.21 - }
1.22 - }
1.23 - }
1.24 + uint32_t entry = *tile_list++;
1.25 + if( entry >> 28 == 0x0F ) {
1.26 + break;
1.27 + } else if( entry >> 28 == 0x0E ) {
1.28 + tile_list = (uint32_t *)(video_base+(entry&0x007FFFFF));
1.29 + } else if( entry >> 29 == 0x04 ) { /* Triangle array */
1.30 + count += ((entry >> 25) & 0x0F)+1;
1.31 + } else if( entry >> 29 == 0x05 ) { /* Quad array */
1.32 + count += ((((entry >> 25) & 0x0F)+1)<<1);
1.33 + } else { /* Polygon */
1.34 + int i;
1.35 + for( i=0; i<6; i++ ) {
1.36 + if( entry & (0x40000000>>i) ) {
1.37 + count++;
1.38 + }
1.39 + }
1.40 + }
1.41 }
1.42 return count;
1.43 }
1.44 @@ -71,98 +71,98 @@
1.45 uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
1.46 int count = 0;
1.47 while(1) {
1.48 - uint32_t entry = *tile_list++;
1.49 - if( entry >> 28 == 0x0F ) {
1.50 - break;
1.51 - } else if( entry >> 28 == 0x0E ) {
1.52 - tile_list = (uint32_t *)(video_base+(entry&0x007FFFFF));
1.53 - } else {
1.54 - uint32_t poly_addr = entry & 0x000FFFFF;
1.55 - int is_modified = entry & 0x01000000;
1.56 - int vertex_length = (entry >> 21) & 0x07;
1.57 - int context_length = 3;
1.58 - if( is_modified && pvr2_scene.full_shadow ) {
1.59 - context_length = 5;
1.60 - vertex_length *= 2 ;
1.61 - }
1.62 - vertex_length += 3;
1.63 + uint32_t entry = *tile_list++;
1.64 + if( entry >> 28 == 0x0F ) {
1.65 + break;
1.66 + } else if( entry >> 28 == 0x0E ) {
1.67 + tile_list = (uint32_t *)(video_base+(entry&0x007FFFFF));
1.68 + } else {
1.69 + uint32_t poly_addr = entry & 0x000FFFFF;
1.70 + int is_modified = entry & 0x01000000;
1.71 + int vertex_length = (entry >> 21) & 0x07;
1.72 + int context_length = 3;
1.73 + if( is_modified && pvr2_scene.full_shadow ) {
1.74 + context_length = 5;
1.75 + vertex_length *= 2 ;
1.76 + }
1.77 + vertex_length += 3;
1.78
1.79 - if( (entry & 0xE0000000) == 0x80000000 ) {
1.80 - /* Triangle(s) */
1.81 - int strip_count = ((entry >> 25) & 0x0F)+1;
1.82 - int polygon_length = 3 * vertex_length + context_length;
1.83 - int i;
1.84 - for( i=0; i<strip_count; i++ ) {
1.85 - struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_addr];
1.86 - triangles[count].poly = poly;
1.87 - triangles[count].triangle_num = 0;
1.88 - triangles[count].maxz = MAX3( pvr2_scene.vertex_array[poly->vertex_index].z,
1.89 - pvr2_scene.vertex_array[poly->vertex_index+1].z,
1.90 - pvr2_scene.vertex_array[poly->vertex_index+2].z );
1.91 - poly_addr += polygon_length;
1.92 - count++;
1.93 - }
1.94 - } else if( (entry & 0xE0000000) == 0xA0000000 ) {
1.95 - /* Quad(s) */
1.96 - int strip_count = ((entry >> 25) & 0x0F)+1;
1.97 - int polygon_length = 4 * vertex_length + context_length;
1.98 - int i;
1.99 - for( i=0; i<strip_count; i++ ) {
1.100 - struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_addr];
1.101 - triangles[count].poly = poly;
1.102 - triangles[count].triangle_num = 0;
1.103 - triangles[count].maxz = MAX3( pvr2_scene.vertex_array[poly->vertex_index].z,
1.104 - pvr2_scene.vertex_array[poly->vertex_index+1].z,
1.105 - pvr2_scene.vertex_array[poly->vertex_index+2].z );
1.106 - count++;
1.107 - triangles[count].poly = poly;
1.108 - triangles[count].triangle_num = 1;
1.109 - triangles[count].maxz = MAX3( pvr2_scene.vertex_array[poly->vertex_index+1].z,
1.110 - pvr2_scene.vertex_array[poly->vertex_index+2].z,
1.111 - pvr2_scene.vertex_array[poly->vertex_index+3].z );
1.112 - count++;
1.113 - poly_addr += polygon_length;
1.114 - }
1.115 - } else {
1.116 - /* Polygon */
1.117 - int i;
1.118 - struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_addr];
1.119 - for( i=0; i<6; i++ ) {
1.120 - if( entry & (0x40000000>>i) ) {
1.121 - triangles[count].poly = poly;
1.122 - triangles[count].triangle_num = i;
1.123 - triangles[count].maxz = MAX3( pvr2_scene.vertex_array[poly->vertex_index+i].z,
1.124 - pvr2_scene.vertex_array[poly->vertex_index+i+1].z,
1.125 - pvr2_scene.vertex_array[poly->vertex_index+i+2].z );
1.126 - count++;
1.127 - }
1.128 - }
1.129 - }
1.130 - }
1.131 + if( (entry & 0xE0000000) == 0x80000000 ) {
1.132 + /* Triangle(s) */
1.133 + int strip_count = ((entry >> 25) & 0x0F)+1;
1.134 + int polygon_length = 3 * vertex_length + context_length;
1.135 + int i;
1.136 + for( i=0; i<strip_count; i++ ) {
1.137 + struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_addr];
1.138 + triangles[count].poly = poly;
1.139 + triangles[count].triangle_num = 0;
1.140 + triangles[count].maxz = MAX3( pvr2_scene.vertex_array[poly->vertex_index].z,
1.141 + pvr2_scene.vertex_array[poly->vertex_index+1].z,
1.142 + pvr2_scene.vertex_array[poly->vertex_index+2].z );
1.143 + poly_addr += polygon_length;
1.144 + count++;
1.145 + }
1.146 + } else if( (entry & 0xE0000000) == 0xA0000000 ) {
1.147 + /* Quad(s) */
1.148 + int strip_count = ((entry >> 25) & 0x0F)+1;
1.149 + int polygon_length = 4 * vertex_length + context_length;
1.150 + int i;
1.151 + for( i=0; i<strip_count; i++ ) {
1.152 + struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_addr];
1.153 + triangles[count].poly = poly;
1.154 + triangles[count].triangle_num = 0;
1.155 + triangles[count].maxz = MAX3( pvr2_scene.vertex_array[poly->vertex_index].z,
1.156 + pvr2_scene.vertex_array[poly->vertex_index+1].z,
1.157 + pvr2_scene.vertex_array[poly->vertex_index+2].z );
1.158 + count++;
1.159 + triangles[count].poly = poly;
1.160 + triangles[count].triangle_num = 1;
1.161 + triangles[count].maxz = MAX3( pvr2_scene.vertex_array[poly->vertex_index+1].z,
1.162 + pvr2_scene.vertex_array[poly->vertex_index+2].z,
1.163 + pvr2_scene.vertex_array[poly->vertex_index+3].z );
1.164 + count++;
1.165 + poly_addr += polygon_length;
1.166 + }
1.167 + } else {
1.168 + /* Polygon */
1.169 + int i;
1.170 + struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_addr];
1.171 + for( i=0; i<6; i++ ) {
1.172 + if( entry & (0x40000000>>i) ) {
1.173 + triangles[count].poly = poly;
1.174 + triangles[count].triangle_num = i;
1.175 + triangles[count].maxz = MAX3( pvr2_scene.vertex_array[poly->vertex_index+i].z,
1.176 + pvr2_scene.vertex_array[poly->vertex_index+i+1].z,
1.177 + pvr2_scene.vertex_array[poly->vertex_index+i+2].z );
1.178 + count++;
1.179 + }
1.180 + }
1.181 + }
1.182 + }
1.183 }
1.184 return count;
1.185 }
1.186
1.187 void sort_render_triangles( struct sort_triangle *triangles, int num_triangles,
1.188 - int render_mode )
1.189 + int render_mode )
1.190 {
1.191 int i;
1.192 for( i=0; i<num_triangles; i++ ) {
1.193 - struct polygon_struct *poly = triangles[i].poly;
1.194 - if( poly->tex_id != -1 ) {
1.195 - glBindTexture(GL_TEXTURE_2D, poly->tex_id);
1.196 - }
1.197 - render_set_context( poly->context, RENDER_NORMAL );
1.198 - glDepthMask(GL_FALSE);
1.199 - glDepthFunc(GL_GEQUAL);
1.200 - /* Fix cull direction */
1.201 - if( triangles[i].triangle_num & 1 ) {
1.202 - glCullFace(GL_FRONT);
1.203 - } else {
1.204 - glCullFace(GL_BACK);
1.205 - }
1.206 -
1.207 - glDrawArrays(GL_TRIANGLE_STRIP, poly->vertex_index + triangles[i].triangle_num, 3 );
1.208 + struct polygon_struct *poly = triangles[i].poly;
1.209 + if( poly->tex_id != -1 ) {
1.210 + glBindTexture(GL_TEXTURE_2D, poly->tex_id);
1.211 + }
1.212 + render_set_context( poly->context, RENDER_NORMAL );
1.213 + glDepthMask(GL_FALSE);
1.214 + glDepthFunc(GL_GEQUAL);
1.215 + /* Fix cull direction */
1.216 + if( triangles[i].triangle_num & 1 ) {
1.217 + glCullFace(GL_FRONT);
1.218 + } else {
1.219 + glCullFace(GL_BACK);
1.220 + }
1.221 +
1.222 + glDrawArrays(GL_TRIANGLE_STRIP, poly->vertex_index + triangles[i].triangle_num, 3 );
1.223 }
1.224 }
1.225
1.226 @@ -177,24 +177,24 @@
1.227 {
1.228 qsort( triangles, num_triangles, sizeof(struct sort_triangle), compare_triangles );
1.229 }
1.230 -
1.231 +
1.232 void render_autosort_tile( pvraddr_t tile_entry, int render_mode )
1.233 {
1.234 int num_triangles = sort_count_triangles(tile_entry);
1.235 if( num_triangles == 0 ) {
1.236 - return; /* nothing to do */
1.237 + return; /* nothing to do */
1.238 } else if( num_triangles == 1 ) { /* Triangle can hardly overlap with itself */
1.239 - gl_render_tilelist(tile_entry);
1.240 + gl_render_tilelist(tile_entry);
1.241 } else { /* Ooh boy here we go... */
1.242 - struct sort_triangle triangles[num_triangles+1];
1.243 - // Reserve space for num_triangles / 2 * 4 vertexes (maximum possible number of
1.244 - // quad vertices)
1.245 - triangles[num_triangles].poly = (void *)SENTINEL;
1.246 - int extracted_triangles = sort_extract_triangles(tile_entry, triangles);
1.247 - assert( extracted_triangles == num_triangles );
1.248 - sort_triangles( triangles, num_triangles );
1.249 - sort_render_triangles(triangles, num_triangles, render_mode);
1.250 - glCullFace(GL_BACK);
1.251 - assert( triangles[num_triangles].poly == (void *)SENTINEL );
1.252 + struct sort_triangle triangles[num_triangles+1];
1.253 + // Reserve space for num_triangles / 2 * 4 vertexes (maximum possible number of
1.254 + // quad vertices)
1.255 + triangles[num_triangles].poly = (void *)SENTINEL;
1.256 + int extracted_triangles = sort_extract_triangles(tile_entry, triangles);
1.257 + assert( extracted_triangles == num_triangles );
1.258 + sort_triangles( triangles, num_triangles );
1.259 + sort_render_triangles(triangles, num_triangles, render_mode);
1.260 + glCullFace(GL_BACK);
1.261 + assert( triangles[num_triangles].poly == (void *)SENTINEL );
1.262 }
1.263 }
.