Search
lxdream.org :: lxdream/src/pvr2/rendbkg.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/rendbkg.c
changeset 645:a7392098299c
prev635:76c63aac3590
next649:620c5c6496b5
author nkeynes
date Thu Mar 06 08:22:00 2008 +0000 (12 years ago)
branchlxdream-render
permissions -rw-r--r--
last change More refactor work in progress - nearly done now
file annotate diff log raw
1.1 --- a/src/pvr2/rendbkg.c Thu Feb 14 13:54:11 2008 +0000
1.2 +++ b/src/pvr2/rendbkg.c Thu Mar 06 08:22:00 2008 +0000
1.3 @@ -49,6 +49,70 @@
1.4 #define FARGB_B(x) (((float)(((x)&0xFF)+1))/256.0)
1.5
1.6 /**
1.7 + * Convert a half-float (16-bit) FP number to a regular 32-bit float.
1.8 + * Source is 1-bit sign, 5-bit exponent, 10-bit mantissa.
1.9 + * TODO: Check the correctness of this.
1.10 + */
1.11 +static float halftofloat( uint16_t half )
1.12 +{
1.13 + union {
1.14 + float f;
1.15 + uint32_t i;
1.16 + } temp;
1.17 + /* int e = ((half & 0x7C00) >> 10) - 15 + 127;
1.18 +
1.19 + temp.i = ((half & 0x8000) << 16) | (e << 23) |
1.20 + ((half & 0x03FF) << 13); */
1.21 + temp.i = ((uint32_t)half)<<16;
1.22 + return temp.f;
1.23 +}
1.24 +
1.25 +void render_unpack_vertexes( struct vertex_unpacked *out, uint32_t poly1,
1.26 + uint32_t *vertexes, int num_vertexes,
1.27 + int vertex_size, int render_mode )
1.28 +{
1.29 + int m = 0, i;
1.30 + if( render_mode == RENDER_FULLMOD ) {
1.31 + m = (vertex_size - 3)/2;
1.32 + }
1.33 +
1.34 + for( i=0; i<num_vertexes; i++ ) {
1.35 + float *vertexf = (float *)vertexes;
1.36 + int k = m + 3;
1.37 + out[i].x = vertexf[0];
1.38 + out[i].y = vertexf[1];
1.39 + out[i].z = vertexf[2];
1.40 + if( POLY1_TEXTURED(poly1) ) {
1.41 + if( POLY1_UV16(poly1) ) {
1.42 + out[i].u = halftofloat(vertexes[k]>>16);
1.43 + out[i].v = halftofloat(vertexes[k]);
1.44 + k++;
1.45 + } else {
1.46 + out[i].u = vertexf[k];
1.47 + out[i].v = vertexf[k+1];
1.48 + k+=2;
1.49 + }
1.50 + } else {
1.51 + out[i].u = 0;
1.52 + out[i].v = 0;
1.53 + }
1.54 + uint32_t argb = vertexes[k++];
1.55 + out[i].rgba[0] = FARGB_R(argb);
1.56 + out[i].rgba[1] = FARGB_G(argb);
1.57 + out[i].rgba[2] = FARGB_B(argb);
1.58 + out[i].rgba[3] = FARGB_A(argb);
1.59 + if( POLY1_SPECULAR(poly1) ) {
1.60 + uint32_t offset = vertexes[k++];
1.61 + out[i].offset_rgba[0] = FARGB_R(offset);
1.62 + out[i].offset_rgba[1] = FARGB_G(offset);
1.63 + out[i].offset_rgba[2] = FARGB_B(offset);
1.64 + out[i].offset_rgba[3] = FARGB_A(offset);
1.65 + }
1.66 + vertexes += vertex_size;
1.67 + }
1.68 +}
1.69 +
1.70 +/**
1.71 * Compute the line where k = target_k, (where k is normally one of
1.72 * r,g,b,a, or z) and determines the points at which the line intersects
1.73 * the viewport (0,0,width,height).
.