Search
lxdream.org :: lxdream/src/pvr2/scene.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/scene.c
changeset 1140:7dc1c71ece76
prev1139:9af81878480b
next1142:fd82bfba61c4
author nkeynes
date Tue Oct 26 08:39:02 2010 +1000 (10 years ago)
permissions -rw-r--r--
last change Implement fragment shader to support palette textures 'directly', and
therefore avoid having to reload all palette textures whenever the palette
changes.
file annotate diff log raw
1.1 --- a/src/pvr2/scene.c Sun Oct 24 15:22:59 2010 +1000
1.2 +++ b/src/pvr2/scene.c Tue Oct 26 08:39:02 2010 +1000
1.3 @@ -226,6 +226,18 @@
1.4 return poly;
1.5 }
1.6
1.7 +static float scene_get_palette_offset( uint32_t tex )
1.8 +{
1.9 + uint32_t fmt = (tex & PVR2_TEX_FORMAT_MASK);
1.10 + if( fmt == PVR2_TEX_FORMAT_IDX4 ) {
1.11 + return ((float)((tex & 0x07E00000) >> 17))/1024.0 + 0.0002;
1.12 + } else if( fmt == PVR2_TEX_FORMAT_IDX8 ) {
1.13 + return ((float)((tex & 0x06000000) >> 17))/1024.0 + 0.0002;
1.14 + } else {
1.15 + return -1.0;
1.16 + }
1.17 +}
1.18 +
1.19 /**
1.20 * Decode a single PVR2 renderable vertex (opaque/trans/punch-out, but not shadow
1.21 * volume)
1.22 @@ -237,7 +249,7 @@
1.23 * the normal vertex, half the vertex length for the modified vertex.
1.24 */
1.25 static void pvr2_decode_render_vertex( struct vertex_struct *vert, uint32_t poly1,
1.26 - uint32_t poly2, uint32_t *pvr2_data,
1.27 + uint32_t poly2, uint32_t tex, uint32_t *pvr2_data,
1.28 int modify_offset )
1.29 {
1.30 gboolean force_alpha = !POLY2_ALPHA_ENABLE(poly2);
1.31 @@ -279,16 +291,25 @@
1.32 switch( POLY2_TEX_BLEND(poly2) ) {
1.33 case 0:/* Convert replace => modulate by setting colour values to 1.0 */
1.34 vert->rgba[0] = vert->rgba[1] = vert->rgba[2] = vert->rgba[3] = 1.0;
1.35 + vert->tex_mode = 0.0;
1.36 data.ival++; /* Skip the colour word */
1.37 break;
1.38 + case 2: /* Decal */
1.39 + vert->tex_mode = 1.0;
1.40 + unpack_bgra(*data.ival++, vert->rgba);
1.41 + break;
1.42 case 1:
1.43 force_alpha = TRUE;
1.44 /* fall-through */
1.45 - default: /* Can't handle decal this way */
1.46 + default:
1.47 + vert->tex_mode = 0.0;
1.48 unpack_bgra(*data.ival++, vert->rgba);
1.49 break;
1.50 }
1.51 + vert->r = scene_get_palette_offset(tex);
1.52 } else {
1.53 + vert->tex_mode = 2.0;
1.54 + vert->r = -1.0;
1.55 unpack_bgra(*data.ival++, vert->rgba);
1.56 }
1.57
1.58 @@ -357,6 +378,8 @@
1.59 result[i].z = rz;
1.60 result[i].u = input[1].u + (t*tu) + (s*su);
1.61 result[i].v = input[1].v + (t*tv) + (s*sv);
1.62 + result[i].r = input[1].r; /* Last two components are flat */
1.63 + result[i].tex_mode = input[1].tex_mode;
1.64
1.65 if( is_solid_shaded ) {
1.66 memcpy( result->rgba, input[2].rgba, sizeof(result->rgba) );
1.67 @@ -503,6 +526,8 @@
1.68 dest->z = src->z;
1.69 dest->u = src->u;
1.70 dest->v = src->v;
1.71 + dest->r = src->r;
1.72 + dest->tex_mode = src->tex_mode;
1.73 dest->rgba[0] = src->rgba[0] * scene_shadow_intensity;
1.74 dest->rgba[1] = src->rgba[1] * scene_shadow_intensity;
1.75 dest->rgba[2] = src->rgba[2] * scene_shadow_intensity;
1.76 @@ -531,7 +556,7 @@
1.77 assert( poly != NULL );
1.78 assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );
1.79 for( i=0; i<poly->vertex_count; i++ ) {
1.80 - pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[1], ptr, 0 );
1.81 + pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[1], context[2], ptr, 0 );
1.82 ptr += vertex_length;
1.83 }
1.84 if( is_modified ) {
1.85 @@ -541,7 +566,7 @@
1.86 int mod_offset = (vertex_length - 3)>>1;
1.87 ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;
1.88 for( i=0; i<poly->vertex_count; i++ ) {
1.89 - pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[3], ptr, mod_offset );
1.90 + pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[3], context[4], ptr, mod_offset );
1.91 ptr += vertex_length;
1.92 }
1.93 } else {
1.94 @@ -572,7 +597,7 @@
1.95 ptr += (is_modified == SHADOW_FULL ? 5 : 3 );
1.96 poly->vertex_index = pvr2_scene.vertex_index;
1.97 for( i=0; i<4; i++ ) {
1.98 - pvr2_decode_render_vertex( &quad[i], context[0], context[1], ptr, 0 );
1.99 + pvr2_decode_render_vertex( &quad[i], context[0], context[1], context[2], ptr, 0 );
1.100 ptr += vertex_length;
1.101 }
1.102 scene_compute_vertexes( &quad[3], 1, &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
1.103 @@ -589,7 +614,7 @@
1.104 int mod_offset = (vertex_length - 3)>>1;
1.105 ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;
1.106 for( i=0; i<4; i++ ) {
1.107 - pvr2_decode_render_vertex( &quad[4], context[0], context[3], ptr, mod_offset );
1.108 + pvr2_decode_render_vertex( &quad[4], context[0], context[3], context[4], ptr, mod_offset );
1.109 ptr += vertex_length;
1.110 }
1.111 scene_compute_vertexes( &quad[3], 1, &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
1.112 @@ -759,7 +784,7 @@
1.113 struct vertex_struct base_vertexes[3];
1.114 uint32_t *ptr = context + context_length;
1.115 for( i=0; i<3; i++ ) {
1.116 - pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[1],
1.117 + pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[1], context[2],
1.118 ptr, 0 );
1.119 ptr += vertex_length;
1.120 }
1.121 @@ -774,7 +799,7 @@
1.122 int mod_offset = (vertex_length - 3)>>1;
1.123 ptr = context + context_length;
1.124 for( i=0; i<3; i++ ) {
1.125 - pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[3],
1.126 + pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[3], context[4],
1.127 ptr, mod_offset );
1.128 ptr += vertex_length;
1.129 }
.