Search
lxdream.org :: lxdream/src/pvr2/rendcore.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/rendcore.c
changeset 319:5392aed6a982
prev318:363935d31859
next322:354407942957
author nkeynes
date Wed Jan 24 08:11:14 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add support for quads (auto-calculated 4th vertex)
file annotate diff log raw
1.1 --- a/src/pvr2/rendcore.c Tue Jan 23 12:03:57 2007 +0000
1.2 +++ b/src/pvr2/rendcore.c Wed Jan 24 08:11:14 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: rendcore.c,v 1.11 2007-01-23 12:03:57 nkeynes Exp $
1.6 + * $Id: rendcore.c,v 1.12 2007-01-24 08:11:14 nkeynes Exp $
1.7 *
1.8 * PVR2 renderer core.
1.9 *
1.10 @@ -158,8 +158,151 @@
1.11
1.12 }
1.13
1.14 -void render_vertexes( uint32_t poly1, uint32_t *vertexes, int num_vertexes, int vertex_size,
1.15 - int render_mode )
1.16 +#define FARGB_A(x) (((float)(((x)>>24)+1))/256.0)
1.17 +#define FARGB_R(x) (((float)((((x)>>16)&0xFF)+1))/256.0)
1.18 +#define FARGB_G(x) (((float)((((x)>>8)&0xFF)+1))/256.0)
1.19 +#define FARGB_B(x) (((float)(((x)&0xFF)+1))/256.0)
1.20 +
1.21 +void render_unpack_vertexes( struct vertex_unpacked *out, uint32_t poly1,
1.22 + uint32_t *vertexes, int num_vertexes,
1.23 + int vertex_size, int render_mode )
1.24 +{
1.25 + int m = 0, i;
1.26 + if( render_mode == RENDER_FULLMOD ) {
1.27 + m = (vertex_size - 3)/2;
1.28 + }
1.29 +
1.30 + for( i=0; i<num_vertexes; i++ ) {
1.31 + float *vertexf = (float *)vertexes;
1.32 + int k = m + 3;
1.33 + out[i].x = vertexf[0];
1.34 + out[i].y = vertexf[1];
1.35 + out[i].z = vertexf[2];
1.36 + if( POLY1_TEXTURED(poly1) ) {
1.37 + if( POLY1_UV16(poly1) ) {
1.38 + out[i].u = halftofloat(vertexes[k]>>16);
1.39 + out[i].v = halftofloat(vertexes[k]);
1.40 + k++;
1.41 + } else {
1.42 + out[i].u = vertexf[k];
1.43 + out[i].v = vertexf[k+1];
1.44 + k+=2;
1.45 + }
1.46 + } else {
1.47 + out[i].u = 0;
1.48 + out[i].v = 0;
1.49 + }
1.50 + uint32_t argb = vertexes[k++];
1.51 + out[i].rgba[0] = FARGB_R(argb);
1.52 + out[i].rgba[1] = FARGB_G(argb);
1.53 + out[i].rgba[2] = FARGB_B(argb);
1.54 + out[i].rgba[3] = FARGB_A(argb);
1.55 + if( POLY1_SPECULAR(poly1) ) {
1.56 + uint32_t offset = vertexes[k++];
1.57 + out[i].offset_rgba[0] = FARGB_R(argb);
1.58 + out[i].offset_rgba[1] = FARGB_G(argb);
1.59 + out[i].offset_rgba[2] = FARGB_B(argb);
1.60 + out[i].offset_rgba[3] = FARGB_A(argb);
1.61 + }
1.62 + vertexes += vertex_size;
1.63 + }
1.64 +}
1.65 +
1.66 +/**
1.67 + * Unpack the vertexes for a quad, calculating the values for the last
1.68 + * vertex.
1.69 + * FIXME: Integrate this with rendbkg somehow
1.70 + */
1.71 +void render_unpack_quad( struct vertex_unpacked *unpacked, uint32_t poly1,
1.72 + uint32_t *vertexes, int vertex_size,
1.73 + int render_mode )
1.74 +{
1.75 + int i;
1.76 + struct vertex_unpacked diff0, diff1;
1.77 +
1.78 + render_unpack_vertexes( unpacked, poly1, vertexes, 3, vertex_size, render_mode );
1.79 +
1.80 + diff0.x = unpacked[0].x - unpacked[1].x;
1.81 + diff0.y = unpacked[0].y - unpacked[1].y;
1.82 + diff1.x = unpacked[2].x - unpacked[1].x;
1.83 + diff1.y = unpacked[2].y - unpacked[1].y;
1.84 +
1.85 + float detxy = ((diff1.y) * (diff0.x)) - ((diff0.y) * (diff1.x));
1.86 + float *vertexf = (float *)(vertexes+(vertex_size*3));
1.87 + if( detxy == 0 ) {
1.88 + memcpy( &unpacked[3], &unpacked[2], sizeof(struct vertex_unpacked) );
1.89 + unpacked[3].x = vertexf[0];
1.90 + unpacked[3].y = vertexf[1];
1.91 + return;
1.92 + }
1.93 +
1.94 + unpacked[3].x = vertexf[0];
1.95 + unpacked[3].y = vertexf[1];
1.96 + float t = ((unpacked[3].x - unpacked[1].x) * diff1.y -
1.97 + (unpacked[3].y - unpacked[1].y) * diff1.x) / detxy;
1.98 + float s = ((unpacked[3].y - unpacked[1].y) * diff0.x -
1.99 + (unpacked[3].x - unpacked[1].x) * diff0.y) / detxy;
1.100 + diff0.z = unpacked[0].z - unpacked[1].z;
1.101 + diff1.z = unpacked[2].z - unpacked[1].z;
1.102 + unpacked[3].z = unpacked[1].z + (t*diff0.z) + (s*diff1.z);
1.103 +
1.104 + diff0.u = unpacked[0].u - unpacked[1].u;
1.105 + diff0.v = unpacked[0].v - unpacked[1].v;
1.106 + diff1.u = unpacked[2].u - unpacked[1].u;
1.107 + diff1.v = unpacked[2].v - unpacked[1].v;
1.108 + unpacked[3].u = unpacked[1].u + (t*diff0.u) + (s*diff1.u);
1.109 + unpacked[3].v = unpacked[1].v + (t*diff0.v) + (s*diff1.v);
1.110 +
1.111 + if( !POLY1_GOURAUD_SHADED(poly1) ) {
1.112 + memcpy( unpacked[3].rgba, unpacked[2].rgba, sizeof(unpacked[2].rgba) );
1.113 + memcpy( unpacked[3].offset_rgba, unpacked[2].offset_rgba, sizeof(unpacked[2].offset_rgba) );
1.114 + } else {
1.115 + for( i=0; i<4; i++ ) {
1.116 + float d0 = unpacked[0].rgba[i] - unpacked[1].rgba[i];
1.117 + float d1 = unpacked[2].rgba[i] - unpacked[1].rgba[i];
1.118 + unpacked[3].rgba[i] = unpacked[1].rgba[i] + (t*d0) + (s*d1);
1.119 + d0 = unpacked[0].offset_rgba[i] - unpacked[1].offset_rgba[i];
1.120 + d1 = unpacked[2].offset_rgba[i] - unpacked[1].offset_rgba[i];
1.121 + unpacked[3].offset_rgba[i] = unpacked[1].offset_rgba[i] + (t*d0) + (s*d1);
1.122 + }
1.123 + }
1.124 +}
1.125 +
1.126 +void render_unpacked_vertex_array( uint32_t poly1, struct vertex_unpacked *vertexes[],
1.127 + int num_vertexes ) {
1.128 + int i;
1.129 +
1.130 + glBegin( GL_TRIANGLE_STRIP );
1.131 +
1.132 + for( i=0; i<num_vertexes; i++ ) {
1.133 + if( POLY1_TEXTURED(poly1) ) {
1.134 + glTexCoord2f( vertexes[i]->u, vertexes[i]->v );
1.135 + }
1.136 +
1.137 + glColor4f( vertexes[i]->rgba[0], vertexes[i]->rgba[1], vertexes[i]->rgba[2],
1.138 + (pvr2_force_fragment_alpha ? 1.0 : vertexes[i]->rgba[3]) );
1.139 +
1.140 + if( POLY1_SPECULAR(poly1) ) {
1.141 + glSecondaryColor3fEXT( vertexes[i]->offset_rgba[0],
1.142 + vertexes[i]->offset_rgba[1],
1.143 + vertexes[i]->offset_rgba[2] );
1.144 + }
1.145 + glVertex3f( vertexes[i]->x, vertexes[i]->y, vertexes[i]->z );
1.146 + }
1.147 +
1.148 + glEnd();
1.149 +}
1.150 +
1.151 +void render_quad_vertexes( uint32_t poly1, uint32_t *vertexes, int vertex_size, int render_mode )
1.152 +{
1.153 + struct vertex_unpacked unpacked[4];
1.154 + struct vertex_unpacked *pt[4] = {&unpacked[0], &unpacked[1], &unpacked[3], &unpacked[2]};
1.155 + render_unpack_quad( unpacked, poly1, vertexes, vertex_size, render_mode );
1.156 + render_unpacked_vertex_array( poly1, pt, 4 );
1.157 +}
1.158 +
1.159 +void render_vertex_array( uint32_t poly1, uint32_t *vert_array[], int num_vertexes, int vertex_size,
1.160 + int render_mode )
1.161 {
1.162 int i, m=0;
1.163
1.164 @@ -170,7 +313,8 @@
1.165 glBegin( GL_TRIANGLE_STRIP );
1.166
1.167 for( i=0; i<num_vertexes; i++ ) {
1.168 - float *vertexf = (float *)vertexes;
1.169 + uint32_t *vertexes = vert_array[i];
1.170 + float *vertexf = (float *)vert_array[i];
1.171 uint32_t argb;
1.172 int k = m + 3;
1.173 if( POLY1_TEXTURED(poly1) ) {
1.174 @@ -205,6 +349,18 @@
1.175 glEnd();
1.176 }
1.177
1.178 +void render_vertexes( uint32_t poly1, uint32_t *vertexes, int num_vertexes, int vertex_size,
1.179 + int render_mode )
1.180 +{
1.181 + uint32_t *vert_array[num_vertexes];
1.182 + int i;
1.183 + for( i=0; i<num_vertexes; i++ ) {
1.184 + vert_array[i] = vertexes;
1.185 + vertexes += vertex_size;
1.186 + }
1.187 + render_vertex_array( poly1, vert_array, num_vertexes, vertex_size, render_mode );
1.188 +}
1.189 +
1.190 /**
1.191 * Render a simple (not auto-sorted) tile
1.192 */
1.193 @@ -241,13 +397,13 @@
1.194 }
1.195 } else if( (entry & 0xE0000000) == 0xA0000000 ) {
1.196 /* Sprite(s) */
1.197 - int strip_count = (entry >> 25) & 0x0F;
1.198 + int strip_count = ((entry >> 25) & 0x0F)+1;
1.199 int polygon_length = 4 * vertex_length + context_length;
1.200 int i;
1.201 for( i=0; i<strip_count; i++ ) {
1.202 render_set_context( polygon, render_mode );
1.203 - render_vertexes( *polygon, polygon+context_length, 4, vertex_length,
1.204 - render_mode );
1.205 + render_quad_vertexes( *polygon, polygon+context_length, vertex_length,
1.206 + render_mode );
1.207 polygon += polygon_length;
1.208 }
1.209 } else {
.