2 * $Id: rendbkg.c,v 1.1 2006-08-29 08:12:13 nkeynes Exp $
4 * PVR2 background renderer.
6 * Yes, it uses the same basic data structure. Yes, it needs to be handled
7 * completely differently.
9 * Copyright (c) 2005 Nathan Keynes.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
23 #include "pvr2/pvr2.h"
33 float rgba[4]; /* Note - RGBA order, as preferred by GL */
37 #define FARGB_A(x) (((float)(((x)>>24)+1))/256.0)
38 #define FARGB_R(x) (((float)((((x)>>16)&0xFF)+1))/256.0)
39 #define FARGB_G(x) (((float)((((x)>>8)&0xFF)+1))/256.0)
40 #define FARGB_B(x) (((float)(((x)&0xFF)+1))/256.0)
43 * Compute the values for an array of vertexes, given x,y for each
44 * vertex and the base 3-vertex triple used to define the background
45 * plane. Essentially the base vertexes are used to find the
46 * plane equation for each of z,a,r,g,b,etc, which is then solved for
47 * each of the required compute vertexes (normally the corner points).
49 * @param base The 3 vertexes supplied as the background definition
50 * @param compute An array of vertexes to compute. x and y must be
51 * preset, other values are computed.
52 * @param num_compute number of vertexes in the compute array.
54 void compute_vertexes( struct vertex_rgba *base,
55 struct vertex_all *compute,
58 struct vertex_all center;
59 struct vertex_all diff0, diff1;
65 center.rgba[0] = FARGB_R(base[1].argb);
66 center.rgba[1] = FARGB_G(base[1].argb);
67 center.rgba[2] = FARGB_B(base[1].argb);
68 center.rgba[3] = FARGB_A(base[1].argb);
69 diff0.x = base[0].x - base[1].x;
70 diff0.y = base[0].y - base[1].y;
71 diff0.z = base[0].z - base[1].z;
72 diff1.x = base[2].x - base[1].x;
73 diff1.y = base[2].y - base[1].y;
74 diff1.z = base[2].z - base[1].z;
75 diff0.rgba[0] = FARGB_R(base[0].argb) - center.rgba[0];
76 diff0.rgba[1] = FARGB_G(base[0].argb) - center.rgba[1];
77 diff0.rgba[2] = FARGB_B(base[0].argb) - center.rgba[2];
78 diff0.rgba[3] = FARGB_A(base[0].argb) - center.rgba[3];
79 diff1.rgba[0] = FARGB_R(base[2].argb) - center.rgba[0];
80 diff1.rgba[1] = FARGB_G(base[2].argb) - center.rgba[1];
81 diff1.rgba[2] = FARGB_B(base[2].argb) - center.rgba[2];
82 diff1.rgba[3] = FARGB_A(base[2].argb) - center.rgba[3];
84 float divisor = ((diff1.y) * (diff0.x)) - ((diff0.y) * (diff1.x));
86 /* The points lie on a single line - no plane for you. *shrugs* */
88 for( i=0; i<num_compute; i++ ) {
89 float t = ((compute[i].x - center.x) * diff1.y -
90 (compute[i].y - center.y) * diff1.x) / divisor;
91 float s = ((compute[i].y - center.y) * diff0.x -
92 (compute[i].x - center.x) * diff0.y) / divisor;
93 compute[i].z = center.z + (t*diff0.z) + (s*diff1.z);
94 compute[i].rgba[0] = center.rgba[0] + (t*diff0.rgba[0]) + (s*diff1.rgba[0]);
95 compute[i].rgba[1] = center.rgba[1] + (t*diff0.rgba[1]) + (s*diff1.rgba[1]);
96 compute[i].rgba[2] = center.rgba[2] + (t*diff0.rgba[2]) + (s*diff1.rgba[2]);
97 compute[i].rgba[3] = center.rgba[3] + (t*diff0.rgba[3]) + (s*diff1.rgba[3]);
102 void render_backplane( uint32_t *polygon, uint32_t width, uint32_t height, uint32_t mode ) {
103 struct vertex_rgba *vertex = (struct vertex_rgba *)(polygon + 3);
104 struct vertex_all compute[4] = { {0.0,0.0}, {width,0.0}, {width, height}, {0.0,height} };
107 render_set_context(polygon, 0);
108 compute_vertexes( vertex, compute, 4 );
110 for( i=0; i<4; i++ ) {
111 glColor4fv(compute[i].rgba);
112 glVertex3f(compute[i].x, compute[i].y, compute[i].z);
113 fprintf( stderr, "BG %d,%d: %f %f %f\n", (int)compute[i].x, (int)compute[i].y,
114 compute[i].rgba[0], compute[i].rgba[1], compute[i].rgba[2] );
.