Search
lxdream.org :: lxdream/src/pvr2/scene.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/scene.c
changeset 827:d333f4248727
prev784:0417e1c488b3
next847:2089244671d2
author nkeynes
date Sun Aug 24 02:57:15 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Adjust the hclip when the horizontal scaler is active
file annotate diff log raw
1.1 --- a/src/pvr2/scene.c Tue Jul 29 08:43:16 2008 +0000
1.2 +++ b/src/pvr2/scene.c Sun Aug 24 02:57:15 2008 +0000
1.3 @@ -1,7 +1,7 @@
1.4 /**
1.5 * $Id$
1.6 *
1.7 - * Manage the internal vertex/polygon buffers and scene data structure.
1.8 + * Manage the internal vertex/polygon buffers and scene data structure.
1.9 * Where possible this uses VBOs for the vertex + index data.
1.10 *
1.11 * Copyright (c) 2005 Nathan Keynes.
1.12 @@ -166,7 +166,7 @@
1.13 }
1.14
1.15 static struct polygon_struct *scene_add_polygon( pvraddr_t poly_idx, int vertex_count,
1.16 - gboolean is_modified )
1.17 + gboolean is_modified )
1.18 {
1.19 int vert_mul = is_modified ? 2 : 1;
1.20
1.21 @@ -199,8 +199,8 @@
1.22 * @param modify_offset Offset in 32-bit words to the tex/color data. 0 for
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 +static void pvr2_decode_render_vertex( struct vertex_struct *vert, uint32_t poly1,
1.28 + uint32_t poly2, uint32_t *pvr2_data,
1.29 int modify_offset )
1.30 {
1.31 gboolean force_alpha = !POLY2_ALPHA_ENABLE(poly2);
1.32 @@ -250,7 +250,7 @@
1.33 vert->offset_rgba[0] = 0.0;
1.34 vert->offset_rgba[1] = 0.0;
1.35 vert->offset_rgba[2] = 0.0;
1.36 - vert->offset_rgba[3] = 0.0;
1.37 + vert->offset_rgba[3] = 0.0;
1.38 }
1.39
1.40 if( force_alpha ) {
1.41 @@ -263,7 +263,7 @@
1.42 * Compute texture, colour, and z values for 1 or more result points by interpolating from
1.43 * a set of 3 input points. The result point(s) must define their x,y.
1.44 */
1.45 -static void scene_compute_vertexes( struct vertex_struct *result,
1.46 +static void scene_compute_vertexes( struct vertex_struct *result,
1.47 int result_count,
1.48 struct vertex_struct *input,
1.49 gboolean is_solid_shaded )
1.50 @@ -276,7 +276,7 @@
1.51
1.52 float detxy = ((sy) * (tx)) - ((ty) * (sx));
1.53 if( detxy == 0 ) {
1.54 - // If the input points fall on a line, they don't define a usable
1.55 + // If the input points fall on a line, they don't define a usable
1.56 // polygon - the PVR2 takes the last input point as the result in
1.57 // this case.
1.58 for( i=0; i<result_count; i++ ) {
1.59 @@ -305,7 +305,7 @@
1.60 if( rz > pvr2_scene.bounds[5] ) {
1.61 pvr2_scene.bounds[5] = rz;
1.62 } else if( rz < pvr2_scene.bounds[4] ) {
1.63 - pvr2_scene.bounds[4] = rz;
1.64 + pvr2_scene.bounds[4] = rz;
1.65 }
1.66 result[i].z = rz;
1.67 result[i].u = input[1].u + (t*tu) + (s*su);
1.68 @@ -360,7 +360,7 @@
1.69 }
1.70 }
1.71
1.72 -static void scene_add_quad_vertexes( pvraddr_t poly_idx, int vertex_length,
1.73 +static void scene_add_quad_vertexes( pvraddr_t poly_idx, int vertex_length,
1.74 gboolean is_modified )
1.75 {
1.76 struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_idx];
1.77 @@ -369,7 +369,7 @@
1.78 unsigned int i;
1.79
1.80 if( poly->vertex_index == -1 ) {
1.81 - // Construct it locally and copy to the vertex buffer, as the VBO is
1.82 + // Construct it locally and copy to the vertex buffer, as the VBO is
1.83 // allowed to be horribly slow for reads (ie it could be direct-mapped
1.84 // vram).
1.85 struct vertex_struct quad[4];
1.86 @@ -524,7 +524,7 @@
1.87 }
1.88 }
1.89 }
1.90 - } while( 1 );
1.91 + } while( 1 );
1.92 }
1.93
1.94 static void scene_extract_background( void )
1.95 @@ -543,7 +543,7 @@
1.96 context_length = 5;
1.97 vertex_length <<= 1;
1.98 poly->mod_vertex_index = pvr2_scene.vertex_count + 4;
1.99 - pvr2_scene.vertex_count += 8;
1.100 + pvr2_scene.vertex_count += 8;
1.101 } else {
1.102 poly->mod_vertex_index = -1;
1.103 pvr2_scene.vertex_count += 4;
1.104 @@ -555,7 +555,7 @@
1.105 pvr2_scene.bkgnd_poly = poly;
1.106
1.107 struct vertex_struct base_vertexes[3];
1.108 - uint32_t *ptr = context + context_length;
1.109 + uint32_t *ptr = context + context_length;
1.110 for( i=0; i<3; i++ ) {
1.111 pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[1],
1.112 ptr, 0 );
1.113 @@ -599,10 +599,10 @@
1.114
1.115 /**
1.116 * Extract the current scene into the rendering structures. We run two passes
1.117 - * - first pass extracts the polygons into pvr2_scene.poly_array (finding vertex counts),
1.118 + * - first pass extracts the polygons into pvr2_scene.poly_array (finding vertex counts),
1.119 * second pass extracts the vertex data into the VBO/vertex array.
1.120 *
1.121 - * Difficult to do in single pass as we don't generally know the size of a
1.122 + * Difficult to do in single pass as we don't generally know the size of a
1.123 * polygon for certain until we've seen all tiles containing it. It also means we
1.124 * can count the vertexes and allocate the appropriate size VBO.
1.125 *
1.126 @@ -619,6 +619,15 @@
1.127 pvr2_scene.bounds[3] = ((MMIO_READ( PVR2, RENDER_VCLIP ) >> 16) & 0x03FF) + 1;
1.128 pvr2_scene.bounds[4] = pvr2_scene.bounds[5] = MMIO_READF( PVR2, RENDER_FARCLIP );
1.129
1.130 + uint32_t scaler = MMIO_READ( PVR2, RENDER_SCALER );
1.131 + if( scaler & SCALER_HSCALE ) {
1.132 + /* If the horizontal scaler is in use, we're (in principle) supposed to
1.133 + * divide everything by 2. However in the interests of display quality,
1.134 + * instead we want to render to the unscaled resolution and downsample
1.135 + * only if/when required.
1.136 + */
1.137 + pvr2_scene.bounds[1] *= 2;
1.138 + }
1.139 uint32_t *tilebuffer = (uint32_t *)(video_base + MMIO_READ( PVR2, RENDER_TILEBASE ));
1.140 uint32_t *segment = tilebuffer;
1.141 pvr2_scene.segment_list = (struct tile_segment *)tilebuffer;
1.142 @@ -640,7 +649,7 @@
1.143 pvr2_scene.sort_mode = SORT_TILEFLAG;
1.144 }
1.145
1.146 - // Pass 1: Extract polygon list
1.147 + // Pass 1: Extract polygon list
1.148 uint32_t control;
1.149 int i;
1.150 do {
1.151 @@ -649,7 +658,7 @@
1.152 int tile_y = SEGMENT_Y(control);
1.153 if( tile_x > max_tile_x ) {
1.154 max_tile_x = tile_x;
1.155 - }
1.156 + }
1.157 if( tile_y > max_tile_y ) {
1.158 max_tile_y = tile_y;
1.159 }
1.160 @@ -709,7 +718,7 @@
1.161 for( j=0; j<poly->vertex_count; j++ ) {
1.162 struct vertex_struct *v = &pvr2_scene.vertex_array[poly->vertex_index+j];
1.163 fprintf( f, " %.5f %.5f %.5f, (%.5f,%.5f) %.5f,%.5f,%.5f,%.5f %.5f %.5f %.5f %.5f\n", v->x, v->y, v->z, v->u, v->v,
1.164 - v->rgba[0], v->rgba[1], v->rgba[2], v->rgba[3],
1.165 + v->rgba[0], v->rgba[1], v->rgba[2], v->rgba[3],
1.166 v->offset_rgba[0], v->offset_rgba[1], v->offset_rgba[2], v->offset_rgba[3] );
1.167 }
1.168 if( poly->mod_vertex_index != -1 ) {
1.169 @@ -717,7 +726,7 @@
1.170 for( j=0; j<poly->vertex_count; j++ ) {
1.171 struct vertex_struct *v = &pvr2_scene.vertex_array[poly->mod_vertex_index+j];
1.172 fprintf( f, " %.5f %.5f %.5f, (%.5f,%.5f) %.5f,%.5f,%.5f,%.5f %.5f %.5f %.5f %.5f\n", v->x, v->y, v->z, v->u, v->v,
1.173 - v->rgba[0], v->rgba[1], v->rgba[2], v->rgba[3],
1.174 + v->rgba[0], v->rgba[1], v->rgba[2], v->rgba[3],
1.175 v->offset_rgba[0], v->offset_rgba[1], v->offset_rgba[2], v->offset_rgba[3] );
1.176 }
1.177 }
.