Search
lxdream.org :: lxdream :: r735:c3aac20f118e
lxdream 0.9.1
released Jun 29
Download Now
changeset735:c3aac20f118e
parent734:f8fcc8322b45
child736:a02d1475ccfd
authornkeynes
dateMon Jul 14 07:42:45 2008 +0000 (15 years ago)
Remove obsolete files
src/gdrom/cdi.h
src/pvr2/rendbkg.c
1.1 --- a/src/gdrom/cdi.h Mon Jul 14 00:09:51 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,39 +0,0 @@
1.4 -/**
1.5 - * $Id$
1.6 - *
1.7 - * CDI CD-image file support
1.8 - *
1.9 - * Copyright (c) 2005 Nathan Keynes.
1.10 - *
1.11 - * This program is free software; you can redistribute it and/or modify
1.12 - * it under the terms of the GNU General Public License as published by
1.13 - * the Free Software Foundation; either version 2 of the License, or
1.14 - * (at your option) any later version.
1.15 - *
1.16 - * This program is distributed in the hope that it will be useful,
1.17 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 - * GNU General Public License for more details.
1.20 - */
1.21 -
1.22 -#ifndef cdi_H
1.23 -#define cdi_H 1
1.24 -
1.25 -#ifdef __cplusplus
1.26 -extern "C" {
1.27 -#if 0
1.28 -}
1.29 -#endif
1.30 -#endif
1.31 -
1.32 -#include <stdio.h>
1.33 -
1.34 -typedef struct cdi_handle *cdi_t;
1.35 -
1.36 -cdi_t cdi_open( char *filename );
1.37 -
1.38 -#ifdef __cplusplus
1.39 -}
1.40 -#endif
1.41 -
1.42 -#endif
2.1 --- a/src/pvr2/rendbkg.c Mon Jul 14 00:09:51 2008 +0000
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,678 +0,0 @@
2.4 -/**
2.5 - * $Id$
2.6 - *
2.7 - * PVR2 background renderer.
2.8 - *
2.9 - * Yes, it uses the same basic data structure. Yes, it needs to be handled
2.10 - * completely differently.
2.11 - *
2.12 - * PVR2 backgrounds are defined as a set of three fully specified vertexes,
2.13 - * stored in compiled-vertex format. The vertexes form a triangle which is
2.14 - * rendered in the normal fashion. Points outside the triangle are rendered
2.15 - * by extrapolating from the gradients established by the triangle, giving
2.16 - * an overall smooth gradient across the background. Points are colour-clamped
2.17 - * prior to output to the buffer.
2.18 - *
2.19 - * As a special case, if all three points lie on the same line (or are the same
2.20 - * point, the third point is used by itself to define the entire buffer (ie
2.21 - * effectively a solid colour).
2.22 - *
2.23 - * Note: this would be really simple if GL did unclamped colour interpolation
2.24 - * but it doesn't (portably), which makes this roughly 2 orders of magnitude
2.25 - * more complicated than it otherwise would be.
2.26 - *
2.27 - * Copyright (c) 2005 Nathan Keynes.
2.28 - *
2.29 - * This program is free software; you can redistribute it and/or modify
2.30 - * it under the terms of the GNU General Public License as published by
2.31 - * the Free Software Foundation; either version 2 of the License, or
2.32 - * (at your option) any later version.
2.33 - *
2.34 - * This program is distributed in the hope that it will be useful,
2.35 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.36 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.37 - * GNU General Public License for more details.
2.38 - */
2.39 -
2.40 -#include <sys/time.h>
2.41 -#include "display.h"
2.42 -#include "pvr2/pvr2.h"
2.43 -#include "pvr2/pvr2mmio.h"
2.44 -#include <math.h>
2.45 -
2.46 -#define MAX_CLAMP_LINES 8
2.47 -#define MAX_VERTEXES 256
2.48 -#define MAX_REGIONS 256
2.49 -
2.50 -#define FARGB_A(x) (((float)(((x)>>24)+1))/256.0)
2.51 -#define FARGB_R(x) (((float)((((x)>>16)&0xFF)+1))/256.0)
2.52 -#define FARGB_G(x) (((float)((((x)>>8)&0xFF)+1))/256.0)
2.53 -#define FARGB_B(x) (((float)(((x)&0xFF)+1))/256.0)
2.54 -
2.55 -/**
2.56 - * Convert a half-float (16-bit) FP number to a regular 32-bit float.
2.57 - * Source is 1-bit sign, 5-bit exponent, 10-bit mantissa.
2.58 - * TODO: Check the correctness of this.
2.59 - */
2.60 -static float halftofloat( uint16_t half )
2.61 -{
2.62 - union {
2.63 - float f;
2.64 - uint32_t i;
2.65 - } temp;
2.66 - /* int e = ((half & 0x7C00) >> 10) - 15 + 127;
2.67 -
2.68 - temp.i = ((half & 0x8000) << 16) | (e << 23) |
2.69 - ((half & 0x03FF) << 13); */
2.70 - temp.i = ((uint32_t)half)<<16;
2.71 - return temp.f;
2.72 -}
2.73 -
2.74 -void render_unpack_vertexes( struct vertex_unpacked *out, uint32_t poly1,
2.75 - uint32_t *vertexes, int num_vertexes,
2.76 - int vertex_size, int render_mode )
2.77 -{
2.78 - int m = 0, i;
2.79 - if( render_mode == RENDER_FULLMOD ) {
2.80 - m = (vertex_size - 3)/2;
2.81 - }
2.82 -
2.83 - for( i=0; i<num_vertexes; i++ ) {
2.84 - float *vertexf = (float *)vertexes;
2.85 - int k = m + 3;
2.86 - out[i].x = vertexf[0];
2.87 - out[i].y = vertexf[1];
2.88 - out[i].z = vertexf[2];
2.89 - if( POLY1_TEXTURED(poly1) ) {
2.90 - if( POLY1_UV16(poly1) ) {
2.91 - out[i].u = halftofloat(vertexes[k]>>16);
2.92 - out[i].v = halftofloat(vertexes[k]);
2.93 - k++;
2.94 - } else {
2.95 - out[i].u = vertexf[k];
2.96 - out[i].v = vertexf[k+1];
2.97 - k+=2;
2.98 - }
2.99 - } else {
2.100 - out[i].u = 0;
2.101 - out[i].v = 0;
2.102 - }
2.103 - uint32_t argb = vertexes[k++];
2.104 - out[i].rgba[0] = FARGB_R(argb);
2.105 - out[i].rgba[1] = FARGB_G(argb);
2.106 - out[i].rgba[2] = FARGB_B(argb);
2.107 - out[i].rgba[3] = FARGB_A(argb);
2.108 - if( POLY1_SPECULAR(poly1) ) {
2.109 - uint32_t offset = vertexes[k++];
2.110 - out[i].offset_rgba[0] = FARGB_R(offset);
2.111 - out[i].offset_rgba[1] = FARGB_G(offset);
2.112 - out[i].offset_rgba[2] = FARGB_B(offset);
2.113 - out[i].offset_rgba[3] = FARGB_A(offset);
2.114 - }
2.115 - vertexes += vertex_size;
2.116 - }
2.117 -}
2.118 -
2.119 -/**
2.120 - * Compute the line where k = target_k, (where k is normally one of
2.121 - * r,g,b,a, or z) and determines the points at which the line intersects
2.122 - * the viewport (0,0,width,height).
2.123 - *
2.124 - * @param center_x the x value for the center position
2.125 - * @param center_y the y value for the center position
2.126 - * @param center_k the k value for the center position
2.127 - * @param width Width of the viewport (ie 640)
2.128 - * @param height Height of the viewport (ie 480)
2.129 - * @param target_k determine the line where k = this value, ie 1.0
2.130 - * @param detxy
2.131 - * @param target Array to write the resultant x,y pairs to (note this
2.132 - * function only sets x and y values).
2.133 - * @return number of vertexes written to the target.
2.134 - */
2.135 -static int compute_colour_line( float center_x, float center_y, float center_k,
2.136 - int width, int height, float target_k,
2.137 - float detxy, float detxk, float detyk,
2.138 - struct vertex_unpacked *target ) {
2.139 - int num_points = 0;
2.140 - float tmpk = (target_k - center_k) * detxy;
2.141 - float x0 = -1;
2.142 - float x1 = -1;
2.143 -
2.144 - if( detyk != 0 ) {
2.145 - x0 = (tmpk - ((0-center_y)*detxk))/detyk + center_x; /* x where y=0 */
2.146 - if( x0 >= 0.0 && x0 <= width ) {
2.147 - target[num_points].x = x0;
2.148 - target[num_points].y = 0.0;
2.149 - num_points++;
2.150 - }
2.151 -
2.152 - x1 = (tmpk - ((height-center_y)*detxk))/detyk + center_x; /* x where y=height */
2.153 - if( x1 >= 0.0 && x1 <= width ) {
2.154 - target[num_points].x = x1;
2.155 - target[num_points].y = height;
2.156 - num_points++;
2.157 - }
2.158 - }
2.159 -
2.160 - if( detxk != 0 ) {
2.161 - if( x0 != 0.0 && x1 != 0.0 ) { /* If x0 == 0 or x1 == 0, then we already have this one */
2.162 - float y0 = (tmpk - ((0-center_x)*detyk))/detxk + center_y; /* y where x=0 */
2.163 - if( y0 >= 0.0 && y0 <= height ) {
2.164 - target[num_points].x = 0.0;
2.165 - target[num_points].y = y0;
2.166 - num_points++;
2.167 - }
2.168 - }
2.169 -
2.170 - if( x0 != width && x1 != width ) {
2.171 - float y1 = (tmpk - ((width-center_x)*detyk))/detxk + center_y; /* y where x=width */
2.172 - if( y1 >= 0.0 && y1 <= height ) {
2.173 - target[num_points].x = width;
2.174 - target[num_points].y = y1;
2.175 - num_points++;
2.176 - }
2.177 - }
2.178 - }
2.179 -
2.180 - if( num_points == 0 || num_points == 2 ) {
2.181 - /* 0 = no points - line doesn't pass through the viewport */
2.182 - /* 2 = normal case - got 2 endpoints */
2.183 - return num_points;
2.184 - } else {
2.185 - ERROR( "compute_colour_line got bad number of points: %d", num_points );
2.186 - return 0;
2.187 - }
2.188 -}
2.189 -
2.190 -/**
2.191 - * A region describes a portion of the screen, possibly subdivided by a line.
2.192 - * if region_left and region_right are -1, this is a terminal region that can
2.193 - * be rendered directly. Otherwise region_left and region_right refer two
2.194 - * sub-regions that are separated by the line segment vertex1-vertex2.
2.195 - */
2.196 -struct bkg_region {
2.197 - /* Vertexes marking the line segment that splits this region */
2.198 - int vertex1;
2.199 - int vertex2;
2.200 - /* Index of the left sub-region */
2.201 - int region_left;
2.202 - /* Index of the right sub-region */
2.203 - int region_right;
2.204 -};
2.205 -
2.206 -/**
2.207 - * Convenience structure to bundle together the vertex and region data.
2.208 - */
2.209 -struct bkg_scene {
2.210 - int num_vertexes;
2.211 - int num_regions;
2.212 - struct vertex_unpacked vertexes[MAX_VERTEXES];
2.213 - struct bkg_region regions[MAX_REGIONS];
2.214 -};
2.215 -
2.216 -/**
2.217 - * Constants returned by compute_line_intersection. Note that for these purposes,
2.218 - * "Left" means the point(s) result in a negative value in the line equation, while
2.219 - * "Right" means the points(s) result in a positive value in the line equation. The
2.220 - * exact meaning isn't particularly important though, as long as we're consistent
2.221 - * throughout this process
2.222 - */
2.223 -#define LINE_COLLINEAR 0 /* The line segments are part of the same line */
2.224 -#define LINE_SIDE_LEFT 1 /* The second line is entirely to the "left" of the first line */
2.225 -#define LINE_SIDE_RIGHT 2 /* The second line is entirely to the "right" of the first line */
2.226 -#define LINE_INTERSECT_FROM_LEFT 3 /* The lines intersect, and (x3,y3) is to the "left" of the first line */
2.227 -#define LINE_INTERSECT_FROM_RIGHT 4 /* The lines intersect, and (x3,y3) is to the "right" of the first line */
2.228 -#define LINE_SKEW 5 /* The line segments neither intersect nor do any of the above apply (should never happen here) */
2.229 -
2.230 -/**
2.231 - * Compute the intersection of two line segments, where
2.232 - * (x1,y1)-(x2,y2) defines the target segment, and
2.233 - * (x3,y3)-(x4,y4) defines the line intersecting it.
2.234 - *
2.235 - * Based off work by Mukesh Prasad (http://www.acm.org/pubs/tog/GraphicsGems/index.html)
2.236 - *
2.237 - * @return one of the above LINE_* constants
2.238 - */
2.239 -static int compute_line_intersection( float x1, float y1, /* First line segment */
2.240 - float x2, float y2,
2.241 - float x3, float y3, /* Second line segment */
2.242 - float x4, float y4,
2.243 - float *x, float *y ) /* Output value: */
2.244 -{
2.245 - float a1, a2, b1, b2, c1, c2; /* Coefficients of line eqns. */
2.246 - float r1, r2, r3, r4; /* test values */
2.247 - float denom; /* Intermediate values */
2.248 -
2.249 - /* Compute a1, b1, c1, where line joining points 1 and 2
2.250 - * is "a1 x + b1 y + c1 = 0".
2.251 - */
2.252 -
2.253 - a1 = y2 - y1;
2.254 - b1 = x1 - x2;
2.255 - c1 = x2 * y1 - x1 * y2;
2.256 -
2.257 - /* Compute r3 and r4. */
2.258 -
2.259 - r3 = a1 * x3 + b1 * y3 + c1;
2.260 - r4 = a1 * x4 + b1 * y4 + c1;
2.261 -
2.262 - /* Check signs of r3 and r4. If both point 3 and point 4 lie on
2.263 - * same side of line 1, the line segments do not intersect.
2.264 - */
2.265 -
2.266 - if( r3 == 0 && r4 == 0 ) {
2.267 - return LINE_COLLINEAR;
2.268 - } else if( r3 <= 0 && r4 <= 0 ) {
2.269 - return LINE_SIDE_LEFT;
2.270 - } else if( r3 >= 0 && r4 >= 0 ) {
2.271 - return LINE_SIDE_RIGHT;
2.272 - }
2.273 -
2.274 - /* Compute a2, b2, c2 */
2.275 -
2.276 - a2 = y4 - y3;
2.277 - b2 = x3 - x4;
2.278 - c2 = x4 * y3 - x3 * y4;
2.279 -
2.280 - /* Compute r1 and r2 */
2.281 -
2.282 - r1 = a2 * x1 + b2 * y1 + c2;
2.283 - r2 = a2 * x2 + b2 * y2 + c2;
2.284 -
2.285 - /* Check signs of r1 and r2. If both point 1 and point 2 lie
2.286 - * on same side of second line segment, the line segments do
2.287 - * not intersect.
2.288 - */
2.289 -
2.290 - if ( r1 != 0 && r2 != 0 &&
2.291 - signbit(r1) == signbit(r2) ) {
2.292 - return LINE_SKEW; /* Should never happen */
2.293 - }
2.294 -
2.295 - /* Cmpute intersection point.
2.296 - */
2.297 - denom = a1 * b2 - a2 * b1;
2.298 - if ( denom == 0 )
2.299 - return LINE_COLLINEAR; /* Should never get to this point either */
2.300 -
2.301 - *x = (b1 * c2 - b2 * c1) / denom;
2.302 - *y = (a2 * c1 - a1 * c2) / denom;
2.303 -
2.304 - if( r3 <= 0 && r4 >= 0 ) {
2.305 - return LINE_INTERSECT_FROM_LEFT;
2.306 - } else {
2.307 - return LINE_INTERSECT_FROM_RIGHT;
2.308 - }
2.309 -}
2.310 -
2.311 -/**
2.312 - * Given a set of vertexes and a line segment to use to split them, generates
2.313 - * two sets of vertexes representing the polygon on either side of the line
2.314 - * segment. This method preserves the winding direction of the input vertexes.
2.315 - */
2.316 -static void compute_subregions( struct bkg_scene *scene,
2.317 - int splitv1, int splitv2,
2.318 - int *vertex_in, int num_vertex_in,
2.319 - int *left_vertex_out, int *num_left_vertex_out,
2.320 - int *right_vertex_out, int *num_right_vertex_out )
2.321 -{
2.322 - float x1 = scene->vertexes[splitv1].x;
2.323 - float y1 = scene->vertexes[splitv1].y;
2.324 - float x2 = scene->vertexes[splitv2].x;
2.325 - float y2 = scene->vertexes[splitv2].y;
2.326 -
2.327 - float a1 = y2 - y1;
2.328 - float b1 = x1 - x2;
2.329 - float c1 = x2 * y1 - x1 * y2;
2.330 - int i;
2.331 -
2.332 - *num_left_vertex_out = 0;
2.333 - *num_right_vertex_out = 0;
2.334 - int last = 0;
2.335 - for( i=0; i<num_vertex_in; i++ ) {
2.336 - struct vertex_unpacked *vertex = &scene->vertexes[vertex_in[i]];
2.337 - float r = a1 * vertex->x + b1 * vertex->y + c1;
2.338 - if( r <= 0 ) {
2.339 - if( last == 1 ) {
2.340 - /* cross-point. add the split vertexes */
2.341 - int v1 = vertex_in[i-1];
2.342 - int v2 = vertex_in[i];
2.343 - /* Determine which point is closer to the line. Strictly speaking
2.344 - * one of them must be ON the line, but this way allows for floating
2.345 - * point inaccuracies.
2.346 - */
2.347 - float a2 = scene->vertexes[v2].y - scene->vertexes[v1].y;
2.348 - float b2 = scene->vertexes[v1].x - scene->vertexes[v2].x;
2.349 - float c2 = scene->vertexes[v2].x * scene->vertexes[v1].y -
2.350 - scene->vertexes[v1].x * scene->vertexes[v2].y;
2.351 - float r1 = a2 * x1 + b2 * y1 + c2;
2.352 - float r2 = a2 * x2 + b2 * y2 + c2;
2.353 - if( fabsf(r1) > fabs(r2) ) {
2.354 - int tmp = splitv1;
2.355 - splitv1 = splitv2;
2.356 - splitv2 = tmp;
2.357 - }
2.358 - right_vertex_out[(*num_right_vertex_out)++] = splitv1;
2.359 - right_vertex_out[(*num_right_vertex_out)++] = splitv2;
2.360 - left_vertex_out[(*num_left_vertex_out)++] = splitv2;
2.361 - left_vertex_out[(*num_left_vertex_out)++] = splitv1;
2.362 - last = 2;
2.363 - } else if( last != 2 ) {
2.364 - last = -1;
2.365 - }
2.366 - left_vertex_out[(*num_left_vertex_out)++] = vertex_in[i];
2.367 - } else {
2.368 - if( last == -1 ) {
2.369 - /* cross-point. add the split vertexes */
2.370 - int v1 = vertex_in[i-1];
2.371 - int v2 = vertex_in[i];
2.372 - /* Determine which point is closer to the line. Strictly speaking
2.373 - * one of them must be ON the line, but this way allows for floating
2.374 - * point inaccuracies.
2.375 - */
2.376 - float a2 = scene->vertexes[v2].y - scene->vertexes[v1].y;
2.377 - float b2 = scene->vertexes[v1].x - scene->vertexes[v2].x;
2.378 - float c2 = scene->vertexes[v2].x * scene->vertexes[v1].y -
2.379 - scene->vertexes[v1].x * scene->vertexes[v2].y;
2.380 - float r1 = a2 * x1 + b2 * y1 + c2;
2.381 - float r2 = a2 * x2 + b2 * y2 + c2;
2.382 - if( fabsf(r1) > fabs(r2) ) {
2.383 - int tmp = splitv1;
2.384 - splitv1 = splitv2;
2.385 - splitv2 = tmp;
2.386 - }
2.387 - left_vertex_out[(*num_left_vertex_out)++] = splitv1;
2.388 - left_vertex_out[(*num_left_vertex_out)++] = splitv2;
2.389 - right_vertex_out[(*num_right_vertex_out)++] = splitv2;
2.390 - right_vertex_out[(*num_right_vertex_out)++] = splitv1;
2.391 - last = 2;
2.392 - } else if( last != 2 ) {
2.393 - last = 1;
2.394 - }
2.395 - right_vertex_out[(*num_right_vertex_out)++] = vertex_in[i];
2.396 - }
2.397 - }
2.398 -}
2.399 -
2.400 -/**
2.401 - * Subdivide the region tree by splitting it along a given line.
2.402 - *
2.403 - * @param scene current bkg scene data
2.404 - * @param region current region under examination
2.405 - * @param vertex1 first vertex of the new line segment
2.406 - * @param vertex2 second vertex of the new line segment
2.407 - */
2.408 -static void bkg_region_subdivide( struct bkg_scene *scene, int region, int vertex1, int vertex2 ) {
2.409 - struct bkg_region *this_region = &scene->regions[region];
2.410 -
2.411 - if( scene->regions[region].region_left == -1 || scene->regions[region].region_right == -1 ) {
2.412 - /* Reached the end of the tree. Setup new left+right regions */
2.413 - int i = scene->num_regions;
2.414 - scene->regions[i].region_left = scene->regions[i].region_right = -1;
2.415 - scene->regions[i+1].region_left = scene->regions[i+1].region_right = -1;
2.416 - this_region->region_left = i;
2.417 - this_region->region_right = i+1;
2.418 - this_region->vertex1 = vertex1;
2.419 - this_region->vertex2 = vertex2;
2.420 - scene->num_regions += 2;
2.421 - } else {
2.422 - float x,y;
2.423 - int thisv1 = this_region->vertex1;
2.424 - int thisv2 = this_region->vertex2;
2.425 - int vertex3;
2.426 - int status =
2.427 - compute_line_intersection( scene->vertexes[thisv1].x, scene->vertexes[thisv1].y,
2.428 - scene->vertexes[thisv2].x, scene->vertexes[thisv2].y,
2.429 - scene->vertexes[vertex1].x, scene->vertexes[vertex1].y,
2.430 - scene->vertexes[vertex2].x, scene->vertexes[vertex2].y,
2.431 - &x, &y );
2.432 - switch( status ) {
2.433 - case LINE_INTERSECT_FROM_LEFT:
2.434 - /* if new line segment intersects our current line segment,
2.435 - * subdivide the segment (add a new vertex) and recurse on both
2.436 - * sub trees
2.437 - */
2.438 - /* Compute split-point vertex */
2.439 - vertex3 = scene->num_vertexes++;
2.440 - scene->vertexes[vertex3].x = x;
2.441 - scene->vertexes[vertex3].y = y;
2.442 - /* Recurse */
2.443 - bkg_region_subdivide( scene, scene->regions[region].region_left, vertex1,vertex3 );
2.444 - bkg_region_subdivide( scene, scene->regions[region].region_right, vertex3, vertex2 );
2.445 - break;
2.446 - case LINE_INTERSECT_FROM_RIGHT:
2.447 - /* Same except line runs in the opposite direction */
2.448 - vertex3 = scene->num_vertexes++;
2.449 - scene->vertexes[vertex3].x = x;
2.450 - scene->vertexes[vertex3].y = y;
2.451 - /* Recurse */
2.452 - bkg_region_subdivide( scene, scene->regions[region].region_left, vertex2,vertex3 );
2.453 - bkg_region_subdivide( scene, scene->regions[region].region_right, vertex3, vertex1 );
2.454 - break;
2.455 - case LINE_COLLINEAR:
2.456 - case LINE_SKEW:
2.457 - /* Collinear - ignore */
2.458 - break;
2.459 - case LINE_SIDE_LEFT:
2.460 - /* else if line segment passes through the left sub-region alone,
2.461 - * left-recurse only.
2.462 - */
2.463 - bkg_region_subdivide( scene, scene->regions[region].region_left, vertex1, vertex2 );
2.464 - break;
2.465 - case LINE_SIDE_RIGHT:
2.466 - /* Otherwise line segment passes through the right sub-region alone,
2.467 - * so right-recurse.
2.468 - */
2.469 - bkg_region_subdivide( scene, scene->regions[region].region_right, vertex1, vertex2 );
2.470 - break;
2.471 - }
2.472 - }
2.473 -}
2.474 -
2.475 -
2.476 -
2.477 -/**
2.478 - * Compute the values for an array of vertexes, given x,y for each
2.479 - * vertex and the base 3-vertex triple used to define the background
2.480 - * plane. Essentially the base vertexes are used to find the
2.481 - * plane equation for each of z,a,r,g,b,etc, which is then solved for
2.482 - * each of the required compute vertexes (normally the corner points).
2.483 - *
2.484 - * @param base The 3 vertexes supplied as the background definition
2.485 - * @param compute An array of vertexes to compute. x and y must be
2.486 - * preset, other values are computed.
2.487 - */
2.488 -static void bkg_compute_scene( struct vertex_unpacked *base, int width, int height,
2.489 - struct bkg_scene *scene )
2.490 -{
2.491 - struct vertex_unpacked center;
2.492 - struct vertex_unpacked diff0, diff1;
2.493 - int i,k;
2.494 -
2.495 - center.x = base[1].x;
2.496 - center.y = base[1].y;
2.497 - center.z = base[1].z;
2.498 - center.u = base[1].u;
2.499 - center.v = base[1].v;
2.500 - diff0.x = base[0].x - center.x;
2.501 - diff0.y = base[0].y - center.y;
2.502 - diff0.z = base[0].z - center.z;
2.503 - diff1.x = base[2].x - center.x;
2.504 - diff1.y = base[2].y - center.y;
2.505 - diff1.z = base[2].z - center.z;
2.506 -
2.507 - float detxy = ((diff1.y) * (diff0.x)) - ((diff0.y) * (diff1.x));
2.508 -
2.509 - /* Corner points first */
2.510 - scene->vertexes[0].x = 0.0;
2.511 - scene->vertexes[0].y = 0.0;
2.512 - scene->vertexes[1].x = width;
2.513 - scene->vertexes[1].y = 0.0;
2.514 - scene->vertexes[2].x = width;
2.515 - scene->vertexes[2].y = height;
2.516 - scene->vertexes[3].x = 0.0;
2.517 - scene->vertexes[3].y = height;
2.518 - scene->regions[0].region_left = -1;
2.519 - scene->regions[0].region_right = -1;
2.520 - scene->num_vertexes = 4;
2.521 - scene->num_regions = 1;
2.522 -
2.523 - if( detxy == 0 ) {
2.524 - /* The points lie on a single line - no plane for you. Use the values
2.525 - * from the 3rd point for the whole screen.
2.526 - */
2.527 - for( i=0; i<4; i++ ) {
2.528 - scene->vertexes[i].rgba[0] = base[2].rgba[0];
2.529 - scene->vertexes[i].rgba[1] = base[2].rgba[1];
2.530 - scene->vertexes[i].rgba[2] = base[2].rgba[2];
2.531 - scene->vertexes[i].rgba[3] = base[2].rgba[3];
2.532 - scene->vertexes[i].z = base[2].z;
2.533 - scene->vertexes[i].u = base[2].u;
2.534 - scene->vertexes[i].v = base[2].v;
2.535 - }
2.536 - } else {
2.537 - /* Compute the colour values at each corner */
2.538 - center.rgba[0] = base[1].rgba[0];
2.539 - center.rgba[1] = base[1].rgba[1];
2.540 - center.rgba[2] = base[1].rgba[2];
2.541 - center.rgba[3] = base[1].rgba[3];
2.542 - diff0.rgba[0] = base[0].rgba[0] - center.rgba[0];
2.543 - diff0.rgba[1] = base[0].rgba[1] - center.rgba[1];
2.544 - diff0.rgba[2] = base[0].rgba[2] - center.rgba[2];
2.545 - diff0.rgba[3] = base[0].rgba[3] - center.rgba[3];
2.546 - diff0.u = base[0].u - center.u;
2.547 - diff0.v = base[0].v - center.v;
2.548 - diff1.rgba[0] = base[2].rgba[0] - center.rgba[0];
2.549 - diff1.rgba[1] = base[2].rgba[1] - center.rgba[1];
2.550 - diff1.rgba[2] = base[2].rgba[2] - center.rgba[2];
2.551 - diff1.rgba[3] = base[2].rgba[3] - center.rgba[3];
2.552 - diff1.u = base[2].u - center.u;
2.553 - diff1.v = base[2].v - center.v;
2.554 - for( i=0; i<4; i++ ) {
2.555 - float t = ((scene->vertexes[i].x - center.x) * diff1.y -
2.556 - (scene->vertexes[i].y - center.y) * diff1.x) / detxy;
2.557 - float s = ((scene->vertexes[i].y - center.y) * diff0.x -
2.558 - (scene->vertexes[i].x - center.x) * diff0.y) / detxy;
2.559 - scene->vertexes[i].z = center.z + (t*diff0.z) + (s*diff1.z);
2.560 - scene->vertexes[i].rgba[0] = center.rgba[0] + (t*diff0.rgba[0]) + (s*diff1.rgba[0]);
2.561 - scene->vertexes[i].rgba[1] = center.rgba[1] + (t*diff0.rgba[1]) + (s*diff1.rgba[1]);
2.562 - scene->vertexes[i].rgba[2] = center.rgba[2] + (t*diff0.rgba[2]) + (s*diff1.rgba[2]);
2.563 - scene->vertexes[i].rgba[3] = center.rgba[3] + (t*diff0.rgba[3]) + (s*diff1.rgba[3]);
2.564 - scene->vertexes[i].u = center.u + (t*diff0.u) + (s*diff1.u);
2.565 - scene->vertexes[i].v = center.v + (t*diff0.v) + (s*diff1.v);
2.566 - }
2.567 -
2.568 - /* Check for values > 1.0 | < 0.0 */
2.569 - for( k=0; k<4; k++ ) {
2.570 - float detyk = ((diff1.y) * (diff0.rgba[k])) - ((diff0.y)*(diff1.rgba[k]));
2.571 - float detxk = ((diff0.x) * (diff1.rgba[k])) - ((diff1.x)*(diff0.rgba[k]));
2.572 - if( scene->vertexes[0].rgba[k] > 1.0 || scene->vertexes[1].rgba[k] > 1.0 ||
2.573 - scene->vertexes[2].rgba[k] > 1.0 || scene->vertexes[3].rgba[k] > 1.0 ) {
2.574 - int v1 = scene->num_vertexes;
2.575 - scene->num_vertexes += compute_colour_line(center.x, center.y, center.rgba[k],
2.576 - width, height, 1.0,
2.577 - detxy, detxk, detyk,
2.578 - scene->vertexes+scene->num_vertexes );
2.579 - if( scene->num_vertexes != v1 ) {
2.580 - bkg_region_subdivide( scene, 0, v1, v1+1 );
2.581 - }
2.582 - }
2.583 -
2.584 - if( scene->vertexes[0].rgba[k] < 0.0 || scene->vertexes[1].rgba[k] < 0.0 ||
2.585 - scene->vertexes[2].rgba[k] < 0.0 || scene->vertexes[3].rgba[k] < 0.0 ) {
2.586 - int v1 = scene->num_vertexes;
2.587 - scene->num_vertexes += compute_colour_line(center.x, center.y, center.rgba[k],
2.588 - width, height, 0.0,
2.589 - detxy, detxk, detyk,
2.590 - scene->vertexes+scene->num_vertexes );
2.591 - if( scene->num_vertexes != v1 ) {
2.592 - bkg_region_subdivide( scene, 0, v1, v1+1 );
2.593 - }
2.594 -
2.595 - }
2.596 - }
2.597 -
2.598 - /* Finally compute the colour values for all vertexes
2.599 - * (excluding the 4 we did upfront) */
2.600 - for( i=4; i<scene->num_vertexes; i++ ) {
2.601 - float t = ((scene->vertexes[i].x - center.x) * diff1.y -
2.602 - (scene->vertexes[i].y - center.y) * diff1.x) / detxy;
2.603 - float s = ((scene->vertexes[i].y - center.y) * diff0.x -
2.604 - (scene->vertexes[i].x - center.x) * diff0.y) / detxy;
2.605 - scene->vertexes[i].z = center.z + (t*diff0.z) + (s*diff1.z);
2.606 - scene->vertexes[i].rgba[0] = center.rgba[0] + (t*diff0.rgba[0]) + (s*diff1.rgba[0]);
2.607 - scene->vertexes[i].rgba[1] = center.rgba[1] + (t*diff0.rgba[1]) + (s*diff1.rgba[1]);
2.608 - scene->vertexes[i].rgba[2] = center.rgba[2] + (t*diff0.rgba[2]) + (s*diff1.rgba[2]);
2.609 - scene->vertexes[i].rgba[3] = center.rgba[3] + (t*diff0.rgba[3]) + (s*diff1.rgba[3]);
2.610 - scene->vertexes[i].u = center.u + (t*diff0.u) + (s*diff1.u);
2.611 - scene->vertexes[i].v = center.v + (t*diff0.v) + (s*diff1.v);
2.612 - }
2.613 - }
2.614 -}
2.615 -
2.616 -/**
2.617 - * Render a bkg_region.
2.618 - * @param scene the background scene data
2.619 - * @param region the region to render
2.620 - * @param vertexes the vertexes surrounding the region
2.621 - * @param num_vertexes the number of vertexes in the vertex array
2.622 - */
2.623 -void bkg_render_region( struct bkg_scene *scene, int region, int *vertexes, int num_vertexes,
2.624 - uint32_t poly1 )
2.625 -{
2.626 - if( scene->regions[region].region_left == -1 && scene->regions[region].region_right == -1 ) {
2.627 - /* Leaf node - render the points as given */
2.628 - int i,k;
2.629 - glBegin(GL_POLYGON);
2.630 - for( i=0; i<num_vertexes; i++ ) {
2.631 - k = vertexes[i];
2.632 - glColor4fv(scene->vertexes[k].rgba);
2.633 - if( POLY1_TEXTURED(poly1) ) {
2.634 - glTexCoord2f(scene->vertexes[k].u, scene->vertexes[k].v);
2.635 - }
2.636 - glVertex3f(scene->vertexes[k].x, scene->vertexes[k].y, scene->vertexes[k].z);
2.637 - }
2.638 - glEnd();
2.639 - } else {
2.640 - /* split the region into left and right regions */
2.641 - int left_vertexes[num_vertexes+1];
2.642 - int right_vertexes[num_vertexes+1];
2.643 - int num_left = 0;
2.644 - int num_right = 0;
2.645 - struct bkg_region *reg = &scene->regions[region];
2.646 - compute_subregions( scene, reg->vertex1, reg->vertex2, vertexes, num_vertexes,
2.647 - left_vertexes, &num_left, right_vertexes, &num_right );
2.648 - bkg_render_region( scene, reg->region_left, left_vertexes, num_left, poly1 );
2.649 - bkg_render_region( scene, reg->region_right, right_vertexes, num_right, poly1 );
2.650 - }
2.651 -
2.652 -}
2.653 -
2.654 -
2.655 -void render_backplane( uint32_t *polygon, uint32_t width, uint32_t height, uint32_t mode ) {
2.656 - struct vertex_unpacked vertex[3];
2.657 - int screen_vertexes[4] = {0,1,2,3};
2.658 - struct bkg_scene scene;
2.659 - int vertex_length = (mode >> 24) & 0x07;
2.660 - int cheap_shadow = MMIO_READ( PVR2, RENDER_SHADOW ) & 0x100;
2.661 - int is_modified = mode & 0x08000000;
2.662 - int context_length = 3;
2.663 - if( is_modified && !cheap_shadow ) {
2.664 - context_length = 5;
2.665 - vertex_length *= 2;
2.666 - }
2.667 - vertex_length += 3;
2.668 - context_length += (mode & 0x07) * vertex_length;
2.669 -
2.670 -
2.671 - render_unpack_vertexes( vertex, *polygon, polygon+context_length, 3, vertex_length,
2.672 - RENDER_NORMAL );
2.673 - bkg_compute_scene(vertex, width, height, &scene);
2.674 - render_set_context(polygon, RENDER_NORMAL);
2.675 - glDisable(GL_CULL_FACE);
2.676 - glDisable(GL_DEPTH_TEST);
2.677 - glBlendFunc(GL_ONE, GL_ZERO); /* For now, just disable alpha blending on the bkg */
2.678 - bkg_render_region(&scene, 0, screen_vertexes, 4, *polygon);
2.679 - glEnable(GL_CULL_FACE);
2.680 - glEnable(GL_DEPTH_TEST);
2.681 -}
.