Search
lxdream.org :: lxdream/src/pvr2/rendbkg.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/rendbkg.c
changeset 219:dfd3292143f2
next221:cf5c6d326162
author nkeynes
date Tue Aug 29 08:12:13 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Initial implementation of new background support
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/pvr2/rendbkg.c Tue Aug 29 08:12:13 2006 +0000
1.3 @@ -0,0 +1,117 @@
1.4 +/**
1.5 + * $Id: rendbkg.c,v 1.1 2006-08-29 08:12:13 nkeynes Exp $
1.6 + *
1.7 + * PVR2 background renderer.
1.8 + *
1.9 + * Yes, it uses the same basic data structure. Yes, it needs to be handled
1.10 + * completely differently.
1.11 + *
1.12 + * Copyright (c) 2005 Nathan Keynes.
1.13 + *
1.14 + * This program is free software; you can redistribute it and/or modify
1.15 + * it under the terms of the GNU General Public License as published by
1.16 + * the Free Software Foundation; either version 2 of the License, or
1.17 + * (at your option) any later version.
1.18 + *
1.19 + * This program is distributed in the hope that it will be useful,
1.20 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.21 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.22 + * GNU General Public License for more details.
1.23 + */
1.24 +
1.25 +#include <sys/time.h>
1.26 +#include "pvr2/pvr2.h"
1.27 +
1.28 +struct vertex_rgba {
1.29 + float x,y,z;
1.30 + uint32_t argb;
1.31 +};
1.32 +
1.33 +struct vertex_all {
1.34 + float x,y,z;
1.35 + float u,v;
1.36 + float rgba[4]; /* Note - RGBA order, as preferred by GL */
1.37 + float spec_rgba[4];
1.38 +};
1.39 +
1.40 +#define FARGB_A(x) (((float)(((x)>>24)+1))/256.0)
1.41 +#define FARGB_R(x) (((float)((((x)>>16)&0xFF)+1))/256.0)
1.42 +#define FARGB_G(x) (((float)((((x)>>8)&0xFF)+1))/256.0)
1.43 +#define FARGB_B(x) (((float)(((x)&0xFF)+1))/256.0)
1.44 +
1.45 +/**
1.46 + * Compute the values for an array of vertexes, given x,y for each
1.47 + * vertex and the base 3-vertex triple used to define the background
1.48 + * plane. Essentially the base vertexes are used to find the
1.49 + * plane equation for each of z,a,r,g,b,etc, which is then solved for
1.50 + * each of the required compute vertexes (normally the corner points).
1.51 + *
1.52 + * @param base The 3 vertexes supplied as the background definition
1.53 + * @param compute An array of vertexes to compute. x and y must be
1.54 + * preset, other values are computed.
1.55 + * @param num_compute number of vertexes in the compute array.
1.56 + */
1.57 +void compute_vertexes( struct vertex_rgba *base,
1.58 + struct vertex_all *compute,
1.59 + int num_compute )
1.60 +{
1.61 + struct vertex_all center;
1.62 + struct vertex_all diff0, diff1;
1.63 + int i;
1.64 +
1.65 + center.x = base[1].x;
1.66 + center.y = base[1].y;
1.67 + center.z = base[1].z;
1.68 + center.rgba[0] = FARGB_R(base[1].argb);
1.69 + center.rgba[1] = FARGB_G(base[1].argb);
1.70 + center.rgba[2] = FARGB_B(base[1].argb);
1.71 + center.rgba[3] = FARGB_A(base[1].argb);
1.72 + diff0.x = base[0].x - base[1].x;
1.73 + diff0.y = base[0].y - base[1].y;
1.74 + diff0.z = base[0].z - base[1].z;
1.75 + diff1.x = base[2].x - base[1].x;
1.76 + diff1.y = base[2].y - base[1].y;
1.77 + diff1.z = base[2].z - base[1].z;
1.78 + diff0.rgba[0] = FARGB_R(base[0].argb) - center.rgba[0];
1.79 + diff0.rgba[1] = FARGB_G(base[0].argb) - center.rgba[1];
1.80 + diff0.rgba[2] = FARGB_B(base[0].argb) - center.rgba[2];
1.81 + diff0.rgba[3] = FARGB_A(base[0].argb) - center.rgba[3];
1.82 + diff1.rgba[0] = FARGB_R(base[2].argb) - center.rgba[0];
1.83 + diff1.rgba[1] = FARGB_G(base[2].argb) - center.rgba[1];
1.84 + diff1.rgba[2] = FARGB_B(base[2].argb) - center.rgba[2];
1.85 + diff1.rgba[3] = FARGB_A(base[2].argb) - center.rgba[3];
1.86 +
1.87 + float divisor = ((diff1.y) * (diff0.x)) - ((diff0.y) * (diff1.x));
1.88 + if( divisor == 0 ) {
1.89 + /* The points lie on a single line - no plane for you. *shrugs* */
1.90 + } else {
1.91 + for( i=0; i<num_compute; i++ ) {
1.92 + float t = ((compute[i].x - center.x) * diff1.y -
1.93 + (compute[i].y - center.y) * diff1.x) / divisor;
1.94 + float s = ((compute[i].y - center.y) * diff0.x -
1.95 + (compute[i].x - center.x) * diff0.y) / divisor;
1.96 + compute[i].z = center.z + (t*diff0.z) + (s*diff1.z);
1.97 + compute[i].rgba[0] = center.rgba[0] + (t*diff0.rgba[0]) + (s*diff1.rgba[0]);
1.98 + compute[i].rgba[1] = center.rgba[1] + (t*diff0.rgba[1]) + (s*diff1.rgba[1]);
1.99 + compute[i].rgba[2] = center.rgba[2] + (t*diff0.rgba[2]) + (s*diff1.rgba[2]);
1.100 + compute[i].rgba[3] = center.rgba[3] + (t*diff0.rgba[3]) + (s*diff1.rgba[3]);
1.101 + }
1.102 + }
1.103 +}
1.104 +
1.105 +void render_backplane( uint32_t *polygon, uint32_t width, uint32_t height, uint32_t mode ) {
1.106 + struct vertex_rgba *vertex = (struct vertex_rgba *)(polygon + 3);
1.107 + struct vertex_all compute[4] = { {0.0,0.0}, {width,0.0}, {width, height}, {0.0,height} };
1.108 + int i;
1.109 +
1.110 + render_set_context(polygon, 0);
1.111 + compute_vertexes( vertex, compute, 4 );
1.112 + glBegin(GL_QUADS);
1.113 + for( i=0; i<4; i++ ) {
1.114 + glColor4fv(compute[i].rgba);
1.115 + glVertex3f(compute[i].x, compute[i].y, compute[i].z);
1.116 + fprintf( stderr, "BG %d,%d: %f %f %f\n", (int)compute[i].x, (int)compute[i].y,
1.117 + compute[i].rgba[0], compute[i].rgba[1], compute[i].rgba[2] );
1.118 + }
1.119 + glEnd();
1.120 +}
.