Search
lxdream.org :: lxdream/src/pvr2/scene.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/scene.c
changeset 736:a02d1475ccfd
prev690:1e8fd13a67ef
next784:0417e1c488b3
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (15 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/scene.c Mon Jun 16 11:00:40 2008 +0000
1.2 +++ b/src/pvr2/scene.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -76,16 +76,16 @@
1.4 {
1.5 if( !vbo_init ) {
1.6 #ifdef ENABLE_VERTEX_BUFFER
1.7 - if( isGLVertexBufferSupported() ) {
1.8 - vbo_supported = TRUE;
1.9 - pvr2_scene.vbo_id = 1;
1.10 - }
1.11 + if( isGLVertexBufferSupported() ) {
1.12 + vbo_supported = TRUE;
1.13 + pvr2_scene.vbo_id = 1;
1.14 + }
1.15 #endif
1.16 - pvr2_scene.vertex_array = NULL;
1.17 - pvr2_scene.vertex_array_size = 0;
1.18 - pvr2_scene.poly_array = g_malloc( MAX_POLY_BUFFER_SIZE );
1.19 - pvr2_scene.buf_to_poly_map = g_malloc0( BUF_POLY_MAP_SIZE );
1.20 - vbo_init = TRUE;
1.21 + pvr2_scene.vertex_array = NULL;
1.22 + pvr2_scene.vertex_array_size = 0;
1.23 + pvr2_scene.poly_array = g_malloc( MAX_POLY_BUFFER_SIZE );
1.24 + pvr2_scene.buf_to_poly_map = g_malloc0( BUF_POLY_MAP_SIZE );
1.25 + vbo_init = TRUE;
1.26 }
1.27 }
1.28
1.29 @@ -103,13 +103,13 @@
1.30 {
1.31 #ifdef ENABLE_VERTEX_BUFFER
1.32 if( vbo_supported ) {
1.33 - glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
1.34 - glDeleteBuffersARB( 1, &pvr2_scene.vbo_id );
1.35 - pvr2_scene.vbo_id = 0;
1.36 + glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
1.37 + glDeleteBuffersARB( 1, &pvr2_scene.vbo_id );
1.38 + pvr2_scene.vbo_id = 0;
1.39 } else {
1.40 #endif
1.41 - g_free( pvr2_scene.vertex_array );
1.42 - pvr2_scene.vertex_array = NULL;
1.43 + g_free( pvr2_scene.vertex_array );
1.44 + pvr2_scene.vertex_array = NULL;
1.45 #ifdef ENABLE_VERTEX_BUFFER
1.46 }
1.47 #endif
1.48 @@ -128,23 +128,23 @@
1.49 #ifdef ENABLE_VERTEX_BUFFER
1.50 if( vbo_supported ) {
1.51 glGetError();
1.52 - glBindBufferARB( GL_ARRAY_BUFFER_ARB, pvr2_scene.vbo_id );
1.53 - if( size > pvr2_scene.vertex_array_size ) {
1.54 - glBufferDataARB( GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB );
1.55 - int status = glGetError();
1.56 - if( status != 0 ) {
1.57 - fprintf( stderr, "Error %08X allocating vertex buffer\n", status );
1.58 - abort();
1.59 - }
1.60 - pvr2_scene.vertex_array_size = size;
1.61 - }
1.62 - pvr2_scene.vertex_array = glMapBufferARB( GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB );
1.63 - assert(pvr2_scene.vertex_array != NULL );
1.64 + glBindBufferARB( GL_ARRAY_BUFFER_ARB, pvr2_scene.vbo_id );
1.65 + if( size > pvr2_scene.vertex_array_size ) {
1.66 + glBufferDataARB( GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB );
1.67 + int status = glGetError();
1.68 + if( status != 0 ) {
1.69 + fprintf( stderr, "Error %08X allocating vertex buffer\n", status );
1.70 + abort();
1.71 + }
1.72 + pvr2_scene.vertex_array_size = size;
1.73 + }
1.74 + pvr2_scene.vertex_array = glMapBufferARB( GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB );
1.75 + assert(pvr2_scene.vertex_array != NULL );
1.76 } else {
1.77 #endif
1.78 - if( size > pvr2_scene.vertex_array_size ) {
1.79 - pvr2_scene.vertex_array = g_realloc( pvr2_scene.vertex_array, size );
1.80 - }
1.81 + if( size > pvr2_scene.vertex_array_size ) {
1.82 + pvr2_scene.vertex_array = g_realloc( pvr2_scene.vertex_array, size );
1.83 + }
1.84 #ifdef ENABLE_VERTEX_BUFFER
1.85 }
1.86 #endif
1.87 @@ -155,10 +155,10 @@
1.88 {
1.89 #ifdef ENABLE_VERTEX_BUFFER
1.90 if( vbo_supported ) {
1.91 - pvr2_scene.vertex_array = NULL;
1.92 - return glUnmapBufferARB( GL_ARRAY_BUFFER_ARB );
1.93 + pvr2_scene.vertex_array = NULL;
1.94 + return glUnmapBufferARB( GL_ARRAY_BUFFER_ARB );
1.95 } else {
1.96 - return TRUE;
1.97 + return TRUE;
1.98 }
1.99 #else
1.100 return TRUE;
1.101 @@ -200,8 +200,8 @@
1.102 * the normal vertex, half the vertex length for the modified vertex.
1.103 */
1.104 static void pvr2_decode_render_vertex( struct vertex_struct *vert, uint32_t poly1,
1.105 - uint32_t poly2, uint32_t *pvr2_data,
1.106 - int modify_offset )
1.107 + uint32_t poly2, uint32_t *pvr2_data,
1.108 + int modify_offset )
1.109 {
1.110 gboolean force_alpha = !POLY2_ALPHA_ENABLE(poly2);
1.111 union pvr2_data_type {
1.112 @@ -265,8 +265,8 @@
1.113 */
1.114 static void scene_compute_vertexes( struct vertex_struct *result,
1.115 int result_count,
1.116 - struct vertex_struct *input,
1.117 - gboolean is_solid_shaded )
1.118 + struct vertex_struct *input,
1.119 + gboolean is_solid_shaded )
1.120 {
1.121 int i,j;
1.122 float sx = input[2].x - input[1].x;
1.123 @@ -330,7 +330,7 @@
1.124 }
1.125
1.126 static void scene_add_vertexes( pvraddr_t poly_idx, int vertex_length,
1.127 - gboolean is_modified )
1.128 + gboolean is_modified )
1.129 {
1.130 struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_idx];
1.131 uint32_t *ptr = &pvr2_scene.pvr2_pbuf[poly_idx];
1.132 @@ -361,7 +361,7 @@
1.133 }
1.134
1.135 static void scene_add_quad_vertexes( pvraddr_t poly_idx, int vertex_length,
1.136 - gboolean is_modified )
1.137 + gboolean is_modified )
1.138 {
1.139 struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_idx];
1.140 uint32_t *ptr = &pvr2_scene.pvr2_pbuf[poly_idx];
1.141 @@ -369,41 +369,41 @@
1.142 unsigned int i;
1.143
1.144 if( poly->vertex_index == -1 ) {
1.145 - // Construct it locally and copy to the vertex buffer, as the VBO is
1.146 - // allowed to be horribly slow for reads (ie it could be direct-mapped
1.147 - // vram).
1.148 - struct vertex_struct quad[4];
1.149 -
1.150 - assert( poly != NULL );
1.151 - assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );
1.152 - ptr += (is_modified ? 5 : 3 );
1.153 - poly->vertex_index = pvr2_scene.vertex_index;
1.154 - for( i=0; i<4; i++ ) {
1.155 - pvr2_decode_render_vertex( &quad[i], context[0], context[1], ptr, 0 );
1.156 - ptr += vertex_length;
1.157 - }
1.158 - scene_compute_vertexes( &quad[3], 1, &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
1.159 - // Swap last two vertexes (quad arrangement => tri strip arrangement)
1.160 - memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index], quad, sizeof(struct vertex_struct)*2 );
1.161 - memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+2], &quad[3], sizeof(struct vertex_struct) );
1.162 - memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3], &quad[2], sizeof(struct vertex_struct) );
1.163 - pvr2_scene.vertex_index += 4;
1.164 -
1.165 - if( is_modified ) {
1.166 - int mod_offset = (vertex_length - 3)>>1;
1.167 - assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );
1.168 - ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;
1.169 - poly->mod_vertex_index = pvr2_scene.vertex_index;
1.170 - for( i=0; i<4; i++ ) {
1.171 - pvr2_decode_render_vertex( &quad[4], context[0], context[3], ptr, mod_offset );
1.172 - ptr += vertex_length;
1.173 - }
1.174 + // Construct it locally and copy to the vertex buffer, as the VBO is
1.175 + // allowed to be horribly slow for reads (ie it could be direct-mapped
1.176 + // vram).
1.177 + struct vertex_struct quad[4];
1.178 +
1.179 + assert( poly != NULL );
1.180 + assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );
1.181 + ptr += (is_modified ? 5 : 3 );
1.182 + poly->vertex_index = pvr2_scene.vertex_index;
1.183 + for( i=0; i<4; i++ ) {
1.184 + pvr2_decode_render_vertex( &quad[i], context[0], context[1], ptr, 0 );
1.185 + ptr += vertex_length;
1.186 + }
1.187 scene_compute_vertexes( &quad[3], 1, &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
1.188 - memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index], quad, sizeof(struct vertex_struct)*2 );
1.189 - memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+2], &quad[3], sizeof(struct vertex_struct) );
1.190 - memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3], &quad[2], sizeof(struct vertex_struct) );
1.191 - pvr2_scene.vertex_index += 4;
1.192 - }
1.193 + // Swap last two vertexes (quad arrangement => tri strip arrangement)
1.194 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index], quad, sizeof(struct vertex_struct)*2 );
1.195 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+2], &quad[3], sizeof(struct vertex_struct) );
1.196 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3], &quad[2], sizeof(struct vertex_struct) );
1.197 + pvr2_scene.vertex_index += 4;
1.198 +
1.199 + if( is_modified ) {
1.200 + int mod_offset = (vertex_length - 3)>>1;
1.201 + assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );
1.202 + ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;
1.203 + poly->mod_vertex_index = pvr2_scene.vertex_index;
1.204 + for( i=0; i<4; i++ ) {
1.205 + pvr2_decode_render_vertex( &quad[4], context[0], context[3], ptr, mod_offset );
1.206 + ptr += vertex_length;
1.207 + }
1.208 + scene_compute_vertexes( &quad[3], 1, &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
1.209 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index], quad, sizeof(struct vertex_struct)*2 );
1.210 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+2], &quad[3], sizeof(struct vertex_struct) );
1.211 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3], &quad[2], sizeof(struct vertex_struct) );
1.212 + pvr2_scene.vertex_index += 4;
1.213 + }
1.214 }
1.215 }
1.216
1.217 @@ -476,54 +476,54 @@
1.218 {
1.219 uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
1.220 do {
1.221 - uint32_t entry = *tile_list++;
1.222 - if( entry >> 28 == 0x0F ) {
1.223 - break;
1.224 - } else if( entry >> 28 == 0x0E ) {
1.225 - tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
1.226 - } else {
1.227 - pvraddr_t polyaddr = entry&0x000FFFFF;
1.228 - int is_modified = (entry & 0x01000000) && pvr2_scene.full_shadow;
1.229 - int vertex_length = (entry >> 21) & 0x07;
1.230 - int context_length = 3;
1.231 - if( is_modified ) {
1.232 - context_length = 5;
1.233 - vertex_length <<=1 ;
1.234 - }
1.235 - vertex_length += 3;
1.236 -
1.237 - if( (entry & 0xE0000000) == 0x80000000 ) {
1.238 - /* Triangle(s) */
1.239 - int strip_count = ((entry >> 25) & 0x0F)+1;
1.240 - int polygon_length = 3 * vertex_length + context_length;
1.241 - int i;
1.242 - for( i=0; i<strip_count; i++ ) {
1.243 - scene_add_vertexes( polyaddr, vertex_length, is_modified );
1.244 - polyaddr += polygon_length;
1.245 - }
1.246 - } else if( (entry & 0xE0000000) == 0xA0000000 ) {
1.247 - /* Sprite(s) */
1.248 - int strip_count = ((entry >> 25) & 0x0F)+1;
1.249 - int polygon_length = 4 * vertex_length + context_length;
1.250 - int i;
1.251 - for( i=0; i<strip_count; i++ ) {
1.252 - scene_add_quad_vertexes( polyaddr, vertex_length, is_modified );
1.253 - polyaddr += polygon_length;
1.254 - }
1.255 - } else {
1.256 - /* Polygon */
1.257 - int i, last = -1;
1.258 - for( i=5; i>=0; i-- ) {
1.259 - if( entry & (0x40000000>>i) ) {
1.260 - last = i;
1.261 - break;
1.262 - }
1.263 - }
1.264 - if( last != -1 ) {
1.265 - scene_add_vertexes( polyaddr, vertex_length, is_modified );
1.266 - }
1.267 - }
1.268 - }
1.269 + uint32_t entry = *tile_list++;
1.270 + if( entry >> 28 == 0x0F ) {
1.271 + break;
1.272 + } else if( entry >> 28 == 0x0E ) {
1.273 + tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
1.274 + } else {
1.275 + pvraddr_t polyaddr = entry&0x000FFFFF;
1.276 + int is_modified = (entry & 0x01000000) && pvr2_scene.full_shadow;
1.277 + int vertex_length = (entry >> 21) & 0x07;
1.278 + int context_length = 3;
1.279 + if( is_modified ) {
1.280 + context_length = 5;
1.281 + vertex_length <<=1 ;
1.282 + }
1.283 + vertex_length += 3;
1.284 +
1.285 + if( (entry & 0xE0000000) == 0x80000000 ) {
1.286 + /* Triangle(s) */
1.287 + int strip_count = ((entry >> 25) & 0x0F)+1;
1.288 + int polygon_length = 3 * vertex_length + context_length;
1.289 + int i;
1.290 + for( i=0; i<strip_count; i++ ) {
1.291 + scene_add_vertexes( polyaddr, vertex_length, is_modified );
1.292 + polyaddr += polygon_length;
1.293 + }
1.294 + } else if( (entry & 0xE0000000) == 0xA0000000 ) {
1.295 + /* Sprite(s) */
1.296 + int strip_count = ((entry >> 25) & 0x0F)+1;
1.297 + int polygon_length = 4 * vertex_length + context_length;
1.298 + int i;
1.299 + for( i=0; i<strip_count; i++ ) {
1.300 + scene_add_quad_vertexes( polyaddr, vertex_length, is_modified );
1.301 + polyaddr += polygon_length;
1.302 + }
1.303 + } else {
1.304 + /* Polygon */
1.305 + int i, last = -1;
1.306 + for( i=5; i>=0; i-- ) {
1.307 + if( entry & (0x40000000>>i) ) {
1.308 + last = i;
1.309 + break;
1.310 + }
1.311 + }
1.312 + if( last != -1 ) {
1.313 + scene_add_vertexes( polyaddr, vertex_length, is_modified );
1.314 + }
1.315 + }
1.316 + }
1.317 } while( 1 );
1.318 }
1.319
1.320 @@ -553,12 +553,12 @@
1.321
1.322 poly->next = NULL;
1.323 pvr2_scene.bkgnd_poly = poly;
1.324 -
1.325 +
1.326 struct vertex_struct base_vertexes[3];
1.327 uint32_t *ptr = context + context_length;
1.328 for( i=0; i<3; i++ ) {
1.329 pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[1],
1.330 - ptr, 0 );
1.331 + ptr, 0 );
1.332 ptr += vertex_length;
1.333 }
1.334 struct vertex_struct *result_vertexes = &pvr2_scene.vertex_array[poly->vertex_index];
1.335 @@ -573,7 +573,7 @@
1.336 ptr = context + context_length;
1.337 for( i=0; i<3; i++ ) {
1.338 pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[3],
1.339 - ptr, mod_offset );
1.340 + ptr, mod_offset );
1.341 ptr += vertex_length;
1.342 }
1.343 result_vertexes = &pvr2_scene.vertex_array[poly->mod_vertex_index];
1.344 @@ -583,7 +583,7 @@
1.345 result_vertexes[2].y = result_vertexes[3].y = pvr2_scene.buffer_height;
1.346 scene_compute_vertexes( result_vertexes, 4, base_vertexes, !POLY1_GOURAUD_SHADED(context[0]) );
1.347 }
1.348 -
1.349 +
1.350 }
1.351
1.352
1.353 @@ -677,9 +677,9 @@
1.354 segment++;
1.355 }
1.356 } while( (control & SEGMENT_END) == 0 );
1.357 -
1.358 +
1.359 scene_extract_background();
1.360 -
1.361 +
1.362 vertex_buffer_unmap();
1.363 }
1.364
1.365 @@ -692,33 +692,33 @@
1.366
1.367 fprintf( f, "Polygons: %d\n", pvr2_scene.poly_count );
1.368 for( i=0; i<pvr2_scene.poly_count; i++ ) {
1.369 - struct polygon_struct *poly = &pvr2_scene.poly_array[i];
1.370 - fprintf( f, " %08X ", ((unsigned char *)poly->context) - video_base );
1.371 - switch( poly->vertex_count ) {
1.372 - case 3: fprintf( f, "Tri " ); break;
1.373 - case 4: fprintf( f, "Quad " ); break;
1.374 - default: fprintf( f,"%d-Strip ", poly->vertex_count-2 ); break;
1.375 - }
1.376 - fprintf( f, "%08X %08X %08X ", poly->context[0], poly->context[1], poly->context[2] );
1.377 - if( poly->mod_vertex_index != -1 ) {
1.378 - fprintf( f, "%08X %08X\n", poly->context[3], poly->context[5] );
1.379 - } else {
1.380 - fprintf( f, "\n" );
1.381 - }
1.382 -
1.383 - for( j=0; j<poly->vertex_count; j++ ) {
1.384 - struct vertex_struct *v = &pvr2_scene.vertex_array[poly->vertex_index+j];
1.385 - fprintf( f, " %.5f %.5f %.5f, (%.5f,%.5f) %08X %08X\n", v->x, v->y, v->z, v->u, v->v,
1.386 - v->rgba, v->offset_rgba );
1.387 - }
1.388 - if( poly->mod_vertex_index != -1 ) {
1.389 - fprintf( f, " ---\n" );
1.390 - for( j=0; j<poly->vertex_count; j++ ) {
1.391 - struct vertex_struct *v = &pvr2_scene.vertex_array[poly->mod_vertex_index+j];
1.392 - fprintf( f, " %.5f %.5f %.5f, (%.5f,%.5f) %08X %08X\n", v->x, v->y, v->z, v->u, v->v,
1.393 - v->rgba, v->offset_rgba );
1.394 - }
1.395 - }
1.396 + struct polygon_struct *poly = &pvr2_scene.poly_array[i];
1.397 + fprintf( f, " %08X ", ((unsigned char *)poly->context) - video_base );
1.398 + switch( poly->vertex_count ) {
1.399 + case 3: fprintf( f, "Tri " ); break;
1.400 + case 4: fprintf( f, "Quad " ); break;
1.401 + default: fprintf( f,"%d-Strip ", poly->vertex_count-2 ); break;
1.402 + }
1.403 + fprintf( f, "%08X %08X %08X ", poly->context[0], poly->context[1], poly->context[2] );
1.404 + if( poly->mod_vertex_index != -1 ) {
1.405 + fprintf( f, "%08X %08X\n", poly->context[3], poly->context[5] );
1.406 + } else {
1.407 + fprintf( f, "\n" );
1.408 + }
1.409 +
1.410 + for( j=0; j<poly->vertex_count; j++ ) {
1.411 + struct vertex_struct *v = &pvr2_scene.vertex_array[poly->vertex_index+j];
1.412 + fprintf( f, " %.5f %.5f %.5f, (%.5f,%.5f) %08X %08X\n", v->x, v->y, v->z, v->u, v->v,
1.413 + v->rgba, v->offset_rgba );
1.414 + }
1.415 + if( poly->mod_vertex_index != -1 ) {
1.416 + fprintf( f, " ---\n" );
1.417 + for( j=0; j<poly->vertex_count; j++ ) {
1.418 + struct vertex_struct *v = &pvr2_scene.vertex_array[poly->mod_vertex_index+j];
1.419 + fprintf( f, " %.5f %.5f %.5f, (%.5f,%.5f) %08X %08X\n", v->x, v->y, v->z, v->u, v->v,
1.420 + v->rgba, v->offset_rgba );
1.421 + }
1.422 + }
1.423 }
1.424
1.425 }
.