Search
lxdream.org :: lxdream/src/pvr2/rendbkg.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/rendbkg.c
changeset 653:3202ff01d48e
prev561:533f6b478071
next677:3ee62740ff8f
author nkeynes
date Fri Mar 28 12:32:25 2008 +0000 (16 years ago)
permissions -rw-r--r--
last change Merge lxdream-render branch (643:670) to trunk
file annotate diff log raw
1.1 --- a/src/pvr2/rendbkg.c Tue Jan 01 05:08:38 2008 +0000
1.2 +++ b/src/pvr2/rendbkg.c Fri Mar 28 12:32:25 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).
1.74 @@ -426,15 +490,15 @@
1.75
1.76 center.x = base[1].x;
1.77 center.y = base[1].y;
1.78 - center.z = (1/base[1].z);
1.79 + center.z = base[1].z;
1.80 center.u = base[1].u;
1.81 center.v = base[1].v;
1.82 diff0.x = base[0].x - center.x;
1.83 diff0.y = base[0].y - center.y;
1.84 - diff0.z = (1/base[0].z) - center.z;
1.85 + diff0.z = base[0].z - center.z;
1.86 diff1.x = base[2].x - center.x;
1.87 diff1.y = base[2].y - center.y;
1.88 - diff1.z = (1/base[2].z) - center.z;
1.89 + diff1.z = base[2].z - center.z;
1.90
1.91 float detxy = ((diff1.y) * (diff0.x)) - ((diff0.y) * (diff1.x));
1.92
1.93 @@ -461,7 +525,7 @@
1.94 scene->vertexes[i].rgba[1] = base[2].rgba[1];
1.95 scene->vertexes[i].rgba[2] = base[2].rgba[2];
1.96 scene->vertexes[i].rgba[3] = base[2].rgba[3];
1.97 - scene->vertexes[i].z = 1/base[2].z;
1.98 + scene->vertexes[i].z = base[2].z;
1.99 scene->vertexes[i].u = base[2].u;
1.100 scene->vertexes[i].v = base[2].v;
1.101 }
1.102 @@ -608,4 +672,6 @@
1.103 glDisable(GL_DEPTH_TEST);
1.104 glBlendFunc(GL_ONE, GL_ZERO); /* For now, just disable alpha blending on the bkg */
1.105 bkg_render_region(&scene, 0, screen_vertexes, 4, *polygon);
1.106 + glEnable(GL_CULL_FACE);
1.107 + glEnable(GL_DEPTH_TEST);
1.108 }
.