Search
lxdream.org :: lxdream/src/pvr2/rendcore.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/rendcore.c
changeset 635:76c63aac3590
prev561:533f6b478071
author nkeynes
date Thu Feb 14 13:54:11 2008 +0000 (13 years ago)
branchlxdream-render
permissions -rw-r--r--
last change Commit render work in progress. Main changes:
* Preliminary OSMesa support
* Move the generic gl code out to pvr2/
* Implement scene data structure + reader
* Remove the 1/z adjustments
file annotate diff log raw
nkeynes@189
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@189
     3
 *
nkeynes@189
     4
 * PVR2 renderer core.
nkeynes@189
     5
 *
nkeynes@189
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@189
     7
 *
nkeynes@189
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@189
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@189
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@189
    11
 * (at your option) any later version.
nkeynes@189
    12
 *
nkeynes@189
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@189
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@189
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@189
    16
 * GNU General Public License for more details.
nkeynes@189
    17
 */
nkeynes@215
    18
#include <sys/time.h>
nkeynes@635
    19
#include <assert.h>
nkeynes@635
    20
#include <string.h>
nkeynes@189
    21
#include "pvr2/pvr2.h"
nkeynes@189
    22
#include "asic.h"
nkeynes@540
    23
#include "display.h"
nkeynes@429
    24
nkeynes@221
    25
int pvr2_poly_depthmode[8] = { GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL,
nkeynes@189
    26
				      GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, 
nkeynes@189
    27
				      GL_ALWAYS };
nkeynes@221
    28
int pvr2_poly_srcblend[8] = { 
nkeynes@189
    29
    GL_ZERO, GL_ONE, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
nkeynes@189
    30
    GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, 
nkeynes@189
    31
    GL_ONE_MINUS_DST_ALPHA };
nkeynes@221
    32
int pvr2_poly_dstblend[8] = {
nkeynes@189
    33
    GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
nkeynes@189
    34
    GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
nkeynes@189
    35
    GL_ONE_MINUS_DST_ALPHA };
nkeynes@221
    36
int pvr2_poly_texblend[4] = {
nkeynes@322
    37
    GL_REPLACE, 
nkeynes@322
    38
    GL_MODULATE,  
nkeynes@322
    39
    GL_DECAL, 
nkeynes@322
    40
    GL_MODULATE 
nkeynes@322
    41
};
nkeynes@221
    42
int pvr2_render_colour_format[8] = {
nkeynes@477
    43
    COLFMT_BGRA1555, COLFMT_RGB565, COLFMT_BGRA4444, COLFMT_BGRA1555,
nkeynes@477
    44
    COLFMT_BGR888, COLFMT_BGRA8888, COLFMT_BGRA8888, COLFMT_BGRA4444 };
nkeynes@189
    45
nkeynes@189
    46
extern char *video_base;
nkeynes@189
    47
nkeynes@322
    48
gboolean pvr2_force_fragment_alpha = FALSE;
nkeynes@338
    49
gboolean pvr2_debug_render = FALSE;
nkeynes@318
    50
nkeynes@189
    51
nkeynes@341
    52
void render_print_tilelist( FILE *f, uint32_t tile_entry );
nkeynes@341
    53
nkeynes@189
    54
/**
nkeynes@189
    55
 * Convert a half-float (16-bit) FP number to a regular 32-bit float.
nkeynes@189
    56
 * Source is 1-bit sign, 5-bit exponent, 10-bit mantissa.
nkeynes@189
    57
 * TODO: Check the correctness of this.
nkeynes@189
    58
 */
nkeynes@189
    59
float halftofloat( uint16_t half )
nkeynes@189
    60
{
nkeynes@189
    61
    union {
nkeynes@189
    62
        float f;
nkeynes@189
    63
        uint32_t i;
nkeynes@189
    64
    } temp;
nkeynes@308
    65
    /* int e = ((half & 0x7C00) >> 10) - 15 + 127;
nkeynes@189
    66
nkeynes@189
    67
    temp.i = ((half & 0x8000) << 16) | (e << 23) |
nkeynes@308
    68
    ((half & 0x03FF) << 13); */
nkeynes@308
    69
    temp.i = ((uint32_t)half)<<16;
nkeynes@189
    70
    return temp.f;
nkeynes@189
    71
}
nkeynes@189
    72
nkeynes@189
    73
nkeynes@189
    74
/**
nkeynes@189
    75
 * Setup the GL context for the supplied polygon context.
nkeynes@189
    76
 * @param context pointer to 3 or 5 words of polygon context
nkeynes@189
    77
 * @param modified boolean flag indicating that the modified
nkeynes@189
    78
 *  version should be used, rather than the normal version.
nkeynes@189
    79
 */
nkeynes@189
    80
void render_set_context( uint32_t *context, int render_mode )
nkeynes@189
    81
{
nkeynes@189
    82
    uint32_t poly1 = context[0], poly2, texture;
nkeynes@189
    83
    if( render_mode == RENDER_FULLMOD ) {
nkeynes@189
    84
	poly2 = context[3];
nkeynes@189
    85
	texture = context[4];
nkeynes@189
    86
    } else {
nkeynes@189
    87
	poly2 = context[1];
nkeynes@189
    88
	texture = context[2];
nkeynes@189
    89
    }
nkeynes@338
    90
    
nkeynes@189
    91
    if( POLY1_DEPTH_ENABLE(poly1) ) {
nkeynes@189
    92
	glEnable( GL_DEPTH_TEST );
nkeynes@189
    93
	glDepthFunc( POLY1_DEPTH_MODE(poly1) );
nkeynes@189
    94
    } else {
nkeynes@189
    95
	glDisable( GL_DEPTH_TEST );
nkeynes@189
    96
    }
nkeynes@189
    97
    
nkeynes@189
    98
    switch( POLY1_CULL_MODE(poly1) ) {
nkeynes@189
    99
    case CULL_NONE:
nkeynes@189
   100
    case CULL_SMALL:
nkeynes@189
   101
	glDisable( GL_CULL_FACE );
nkeynes@189
   102
	break;
nkeynes@189
   103
    case CULL_CCW:
nkeynes@189
   104
	glEnable( GL_CULL_FACE );
nkeynes@189
   105
	glFrontFace( GL_CW );
nkeynes@189
   106
	break;
nkeynes@189
   107
    case CULL_CW:
nkeynes@189
   108
	glEnable( GL_CULL_FACE );
nkeynes@189
   109
	glFrontFace( GL_CCW );
nkeynes@189
   110
	break;
nkeynes@189
   111
    }
nkeynes@189
   112
nkeynes@318
   113
    if( POLY1_SPECULAR(poly1) ) {
nkeynes@318
   114
	glEnable(GL_COLOR_SUM);
nkeynes@318
   115
    } else {
nkeynes@318
   116
	glDisable(GL_COLOR_SUM);
nkeynes@318
   117
    }
nkeynes@318
   118
nkeynes@338
   119
    pvr2_force_fragment_alpha = POLY2_ALPHA_ENABLE(poly2) ? FALSE : TRUE;
nkeynes@338
   120
nkeynes@189
   121
    if( POLY1_TEXTURED(poly1) ) {
nkeynes@189
   122
	int width = POLY2_TEX_WIDTH(poly2);
nkeynes@189
   123
	int height = POLY2_TEX_HEIGHT(poly2);
nkeynes@189
   124
	glEnable(GL_TEXTURE_2D);
nkeynes@286
   125
	texcache_get_texture( (texture&0x000FFFFF)<<3, width, height, texture );
nkeynes@338
   126
	switch( POLY2_TEX_BLEND(poly2) ) {
nkeynes@338
   127
	case 0: /* Replace */
nkeynes@338
   128
	    glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
nkeynes@338
   129
	    break;
nkeynes@338
   130
	case 2:/* Decal */
nkeynes@338
   131
	    glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
nkeynes@338
   132
	    break;
nkeynes@338
   133
	case 1: /* Modulate RGB */
nkeynes@338
   134
	    /* This is not directly supported by opengl (other than by mucking
nkeynes@338
   135
	     * with the texture format), but we get the same effect by forcing
nkeynes@338
   136
	     * the fragment alpha to 1.0 and using GL_MODULATE.
nkeynes@338
   137
	     */
nkeynes@338
   138
	    pvr2_force_fragment_alpha = TRUE;
nkeynes@338
   139
	case 3: /* Modulate RGBA */
nkeynes@338
   140
	    glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
nkeynes@338
   141
	    break;
nkeynes@338
   142
	}
nkeynes@352
   143
nkeynes@308
   144
	if( POLY2_TEX_CLAMP_U(poly2) ) {
nkeynes@308
   145
	    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
nkeynes@308
   146
	} else {
nkeynes@308
   147
	    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
nkeynes@308
   148
	}	    
nkeynes@308
   149
	if( POLY2_TEX_CLAMP_V(poly2) ) {
nkeynes@308
   150
	    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
nkeynes@308
   151
	} else {
nkeynes@350
   152
	    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
nkeynes@308
   153
	}
nkeynes@189
   154
    } else {
nkeynes@189
   155
	glDisable( GL_TEXTURE_2D );
nkeynes@189
   156
    }
nkeynes@189
   157
nkeynes@189
   158
    glShadeModel( POLY1_SHADE_MODEL(poly1) );
nkeynes@189
   159
nkeynes@221
   160
    int srcblend = POLY2_SRC_BLEND(poly2);
nkeynes@221
   161
    int destblend = POLY2_DEST_BLEND(poly2);
nkeynes@221
   162
    glBlendFunc( srcblend, destblend );
nkeynes@318
   163
nkeynes@322
   164
    if( POLY2_SRC_BLEND_TARGET(poly2) || POLY2_DEST_BLEND_TARGET(poly2) ) {
nkeynes@322
   165
	ERROR( "Accumulation buffer not supported" );
nkeynes@322
   166
    }
nkeynes@338
   167
nkeynes@318
   168
nkeynes@189
   169
}
nkeynes@189
   170
nkeynes@319
   171
#define FARGB_A(x) (((float)(((x)>>24)+1))/256.0)
nkeynes@319
   172
#define FARGB_R(x) (((float)((((x)>>16)&0xFF)+1))/256.0)
nkeynes@319
   173
#define FARGB_G(x) (((float)((((x)>>8)&0xFF)+1))/256.0)
nkeynes@319
   174
#define FARGB_B(x) (((float)(((x)&0xFF)+1))/256.0)
nkeynes@319
   175
nkeynes@319
   176
void render_unpack_vertexes( struct vertex_unpacked *out, uint32_t poly1, 
nkeynes@319
   177
			     uint32_t *vertexes, int num_vertexes,
nkeynes@319
   178
			     int vertex_size, int render_mode )
nkeynes@319
   179
{
nkeynes@319
   180
    int m = 0, i;
nkeynes@319
   181
    if( render_mode == RENDER_FULLMOD ) {
nkeynes@319
   182
	m = (vertex_size - 3)/2;
nkeynes@319
   183
    }
nkeynes@319
   184
nkeynes@319
   185
    for( i=0; i<num_vertexes; i++ ) {
nkeynes@319
   186
	float *vertexf = (float *)vertexes;
nkeynes@319
   187
	int k = m + 3;
nkeynes@319
   188
	out[i].x = vertexf[0];
nkeynes@319
   189
	out[i].y = vertexf[1];
nkeynes@319
   190
	out[i].z = vertexf[2];
nkeynes@319
   191
    	if( POLY1_TEXTURED(poly1) ) {
nkeynes@319
   192
	    if( POLY1_UV16(poly1) ) {
nkeynes@319
   193
		out[i].u = halftofloat(vertexes[k]>>16);
nkeynes@319
   194
		out[i].v = halftofloat(vertexes[k]);
nkeynes@319
   195
		k++;
nkeynes@319
   196
	    } else {
nkeynes@319
   197
		out[i].u = vertexf[k];
nkeynes@319
   198
		out[i].v = vertexf[k+1];
nkeynes@319
   199
		k+=2;
nkeynes@319
   200
	    }
nkeynes@319
   201
	} else {
nkeynes@319
   202
	    out[i].u = 0;
nkeynes@319
   203
	    out[i].v = 0;
nkeynes@319
   204
	}
nkeynes@319
   205
	uint32_t argb = vertexes[k++];
nkeynes@319
   206
	out[i].rgba[0] = FARGB_R(argb);
nkeynes@319
   207
	out[i].rgba[1] = FARGB_G(argb);
nkeynes@319
   208
        out[i].rgba[2] = FARGB_B(argb);
nkeynes@319
   209
	out[i].rgba[3] = FARGB_A(argb);
nkeynes@319
   210
	if( POLY1_SPECULAR(poly1) ) {
nkeynes@319
   211
	    uint32_t offset = vertexes[k++];
nkeynes@429
   212
	    out[i].offset_rgba[0] = FARGB_R(offset);
nkeynes@429
   213
	    out[i].offset_rgba[1] = FARGB_G(offset);
nkeynes@429
   214
	    out[i].offset_rgba[2] = FARGB_B(offset);
nkeynes@429
   215
	    out[i].offset_rgba[3] = FARGB_A(offset);
nkeynes@319
   216
	}
nkeynes@319
   217
	vertexes += vertex_size;
nkeynes@319
   218
    }
nkeynes@319
   219
}
nkeynes@319
   220
nkeynes@319
   221
/**
nkeynes@319
   222
 * Unpack the vertexes for a quad, calculating the values for the last
nkeynes@319
   223
 * vertex.
nkeynes@319
   224
 * FIXME: Integrate this with rendbkg somehow
nkeynes@319
   225
 */
nkeynes@319
   226
void render_unpack_quad( struct vertex_unpacked *unpacked, uint32_t poly1, 
nkeynes@319
   227
			 uint32_t *vertexes, int vertex_size,
nkeynes@319
   228
			 int render_mode )
nkeynes@319
   229
{
nkeynes@319
   230
    int i;
nkeynes@319
   231
    struct vertex_unpacked diff0, diff1;
nkeynes@319
   232
nkeynes@319
   233
    render_unpack_vertexes( unpacked, poly1, vertexes, 3, vertex_size, render_mode );
nkeynes@319
   234
    
nkeynes@319
   235
    diff0.x = unpacked[0].x - unpacked[1].x;
nkeynes@319
   236
    diff0.y = unpacked[0].y - unpacked[1].y;
nkeynes@319
   237
    diff1.x = unpacked[2].x - unpacked[1].x;
nkeynes@319
   238
    diff1.y = unpacked[2].y - unpacked[1].y;
nkeynes@319
   239
nkeynes@319
   240
    float detxy = ((diff1.y) * (diff0.x)) - ((diff0.y) * (diff1.x));
nkeynes@319
   241
    float *vertexf = (float *)(vertexes+(vertex_size*3));
nkeynes@319
   242
    if( detxy == 0 ) {
nkeynes@319
   243
	memcpy( &unpacked[3], &unpacked[2], sizeof(struct vertex_unpacked) );
nkeynes@319
   244
	unpacked[3].x = vertexf[0];
nkeynes@319
   245
	unpacked[3].y = vertexf[1];
nkeynes@319
   246
	return;
nkeynes@319
   247
    }	
nkeynes@319
   248
nkeynes@319
   249
    unpacked[3].x = vertexf[0];
nkeynes@319
   250
    unpacked[3].y = vertexf[1];
nkeynes@319
   251
    float t = ((unpacked[3].x - unpacked[1].x) * diff1.y -
nkeynes@319
   252
	       (unpacked[3].y - unpacked[1].y) * diff1.x) / detxy;
nkeynes@319
   253
    float s = ((unpacked[3].y - unpacked[1].y) * diff0.x -
nkeynes@319
   254
	       (unpacked[3].x - unpacked[1].x) * diff0.y) / detxy;
nkeynes@635
   255
    diff0.z = unpacked[0].z - unpacked[1].z;
nkeynes@635
   256
    diff1.z = unpacked[2].z - unpacked[1].z;
nkeynes@635
   257
    unpacked[3].z = unpacked[1].z + (t*diff0.z) + (s*diff1.z);
nkeynes@319
   258
nkeynes@319
   259
    diff0.u = unpacked[0].u - unpacked[1].u;
nkeynes@319
   260
    diff0.v = unpacked[0].v - unpacked[1].v;
nkeynes@319
   261
    diff1.u = unpacked[2].u - unpacked[1].u;
nkeynes@319
   262
    diff1.v = unpacked[2].v - unpacked[1].v;
nkeynes@319
   263
    unpacked[3].u = unpacked[1].u + (t*diff0.u) + (s*diff1.u);
nkeynes@319
   264
    unpacked[3].v = unpacked[1].v + (t*diff0.v) + (s*diff1.v);
nkeynes@319
   265
nkeynes@319
   266
    if( !POLY1_GOURAUD_SHADED(poly1) ) {
nkeynes@319
   267
	memcpy( unpacked[3].rgba, unpacked[2].rgba, sizeof(unpacked[2].rgba) );
nkeynes@319
   268
	memcpy( unpacked[3].offset_rgba, unpacked[2].offset_rgba, sizeof(unpacked[2].offset_rgba) );
nkeynes@319
   269
    } else {
nkeynes@319
   270
	for( i=0; i<4; i++ ) {
nkeynes@319
   271
	    float d0 = unpacked[0].rgba[i] - unpacked[1].rgba[i];
nkeynes@319
   272
	    float d1 = unpacked[2].rgba[i] - unpacked[1].rgba[i];
nkeynes@319
   273
	    unpacked[3].rgba[i] = unpacked[1].rgba[i] + (t*d0) + (s*d1);
nkeynes@319
   274
	    d0 = unpacked[0].offset_rgba[i] - unpacked[1].offset_rgba[i];
nkeynes@319
   275
	    d1 = unpacked[2].offset_rgba[i] - unpacked[1].offset_rgba[i];
nkeynes@319
   276
	    unpacked[3].offset_rgba[i] = unpacked[1].offset_rgba[i] + (t*d0) + (s*d1);
nkeynes@319
   277
	}
nkeynes@319
   278
    }    
nkeynes@319
   279
}
nkeynes@319
   280
nkeynes@319
   281
void render_unpacked_vertex_array( uint32_t poly1, struct vertex_unpacked *vertexes[], 
nkeynes@319
   282
				   int num_vertexes ) {
nkeynes@319
   283
    int i;
nkeynes@319
   284
nkeynes@319
   285
    glBegin( GL_TRIANGLE_STRIP );
nkeynes@319
   286
nkeynes@319
   287
    for( i=0; i<num_vertexes; i++ ) {
nkeynes@319
   288
	if( POLY1_TEXTURED(poly1) ) {
nkeynes@319
   289
	    glTexCoord2f( vertexes[i]->u, vertexes[i]->v );
nkeynes@319
   290
	}
nkeynes@319
   291
nkeynes@322
   292
	if( pvr2_force_fragment_alpha ) {
nkeynes@322
   293
	    glColor4f( vertexes[i]->rgba[0], vertexes[i]->rgba[1], vertexes[i]->rgba[2], 1.0 );
nkeynes@322
   294
	} else {
nkeynes@322
   295
	    glColor4f( vertexes[i]->rgba[0], vertexes[i]->rgba[1], vertexes[i]->rgba[2],
nkeynes@322
   296
		       vertexes[i]->rgba[3] );
nkeynes@322
   297
	}
nkeynes@319
   298
	if( POLY1_SPECULAR(poly1) ) {
nkeynes@319
   299
	    glSecondaryColor3fEXT( vertexes[i]->offset_rgba[0],
nkeynes@319
   300
				   vertexes[i]->offset_rgba[1],
nkeynes@319
   301
				   vertexes[i]->offset_rgba[2] );
nkeynes@319
   302
	}
nkeynes@635
   303
	assert( vertexes[i]->z > 0 && !isinf(vertexes[i]->z) );
nkeynes@635
   304
	glVertex3f( vertexes[i]->x, vertexes[i]->y, vertexes[i]->z );
nkeynes@319
   305
    }
nkeynes@319
   306
nkeynes@319
   307
    glEnd();
nkeynes@319
   308
}
nkeynes@319
   309
nkeynes@319
   310
void render_quad_vertexes( uint32_t poly1, uint32_t *vertexes, int vertex_size, int render_mode )
nkeynes@319
   311
{
nkeynes@319
   312
    struct vertex_unpacked unpacked[4];
nkeynes@319
   313
    struct vertex_unpacked *pt[4] = {&unpacked[0], &unpacked[1], &unpacked[3], &unpacked[2]};
nkeynes@319
   314
    render_unpack_quad( unpacked, poly1, vertexes, vertex_size, render_mode );
nkeynes@319
   315
    render_unpacked_vertex_array( poly1, pt, 4 );
nkeynes@319
   316
}
nkeynes@319
   317
nkeynes@319
   318
void render_vertex_array( uint32_t poly1, uint32_t *vert_array[], int num_vertexes, int vertex_size,
nkeynes@319
   319
			  int render_mode ) 
nkeynes@189
   320
{
nkeynes@189
   321
    int i, m=0;
nkeynes@189
   322
nkeynes@189
   323
    if( render_mode == RENDER_FULLMOD ) {
nkeynes@189
   324
	m = (vertex_size - 3)/2;
nkeynes@189
   325
    }
nkeynes@189
   326
nkeynes@189
   327
    glBegin( GL_TRIANGLE_STRIP );
nkeynes@189
   328
    
nkeynes@189
   329
    for( i=0; i<num_vertexes; i++ ) {
nkeynes@319
   330
	uint32_t *vertexes = vert_array[i];
nkeynes@319
   331
	float *vertexf = (float *)vert_array[i];
nkeynes@189
   332
	uint32_t argb;
nkeynes@318
   333
	int k = m + 3;
nkeynes@189
   334
	if( POLY1_TEXTURED(poly1) ) {
nkeynes@189
   335
	    if( POLY1_UV16(poly1) ) {
nkeynes@318
   336
		glTexCoord2f( halftofloat(vertexes[k]>>16),
nkeynes@318
   337
			      halftofloat(vertexes[k]) );
nkeynes@318
   338
		k++;
nkeynes@189
   339
	    } else {
nkeynes@318
   340
		glTexCoord2f( vertexf[k], vertexf[k+1] );
nkeynes@318
   341
		k+=2;
nkeynes@189
   342
	    }
nkeynes@189
   343
	}
nkeynes@189
   344
nkeynes@318
   345
	argb = vertexes[k++];
nkeynes@318
   346
	if( pvr2_force_fragment_alpha ) {
nkeynes@318
   347
	    glColor4ub( (GLubyte)(argb >> 16), (GLubyte)(argb >> 8), 
nkeynes@318
   348
			(GLubyte)argb, 0xFF );
nkeynes@318
   349
	} else {
nkeynes@318
   350
	    glColor4ub( (GLubyte)(argb >> 16), (GLubyte)(argb >> 8), 
nkeynes@318
   351
			(GLubyte)argb, (GLubyte)(argb >> 24) );
nkeynes@318
   352
	}
nkeynes@318
   353
nkeynes@318
   354
	if( POLY1_SPECULAR(poly1) ) {
nkeynes@318
   355
	    uint32_t spec = vertexes[k++];
nkeynes@318
   356
	    glSecondaryColor3ubEXT( (GLubyte)(spec >> 16), (GLubyte)(spec >> 8), 
nkeynes@318
   357
				 (GLubyte)spec );
nkeynes@318
   358
	}
nkeynes@635
   359
	//	assert( vertexf[2] > 0 && !isinf(vertexf[2]) );
nkeynes@635
   360
	glVertex3f( vertexf[0], vertexf[1], vertexf[2] );
nkeynes@189
   361
	vertexes += vertex_size;
nkeynes@189
   362
    }
nkeynes@189
   363
nkeynes@189
   364
    glEnd();
nkeynes@189
   365
}
nkeynes@189
   366
nkeynes@319
   367
void render_vertexes( uint32_t poly1, uint32_t *vertexes, int num_vertexes, int vertex_size,
nkeynes@319
   368
		      int render_mode )
nkeynes@319
   369
{
nkeynes@319
   370
    uint32_t *vert_array[num_vertexes];
nkeynes@319
   371
    int i;
nkeynes@319
   372
    for( i=0; i<num_vertexes; i++ ) {
nkeynes@319
   373
	vert_array[i] = vertexes;
nkeynes@319
   374
	vertexes += vertex_size;
nkeynes@319
   375
    }
nkeynes@319
   376
    render_vertex_array( poly1, vert_array, num_vertexes, vertex_size, render_mode );
nkeynes@319
   377
}
nkeynes@319
   378
nkeynes@189
   379
/**
nkeynes@189
   380
 * Render a simple (not auto-sorted) tile
nkeynes@189
   381
 */
nkeynes@189
   382
void render_tile( pvraddr_t tile_entry, int render_mode, gboolean cheap_modifier_mode ) {
nkeynes@215
   383
    uint32_t poly_bank = MMIO_READ(PVR2,RENDER_POLYBASE);
nkeynes@189
   384
    uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
nkeynes@189
   385
    do {
nkeynes@189
   386
	uint32_t entry = *tile_list++;
nkeynes@189
   387
	if( entry >> 28 == 0x0F ) {
nkeynes@189
   388
	    break;
nkeynes@189
   389
	} else if( entry >> 28 == 0x0E ) {
nkeynes@189
   390
	    tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
nkeynes@189
   391
	} else {
nkeynes@215
   392
	    uint32_t *polygon = (uint32_t *)(video_base + poly_bank + ((entry & 0x000FFFFF) << 2));
nkeynes@189
   393
	    int is_modified = entry & 0x01000000;
nkeynes@189
   394
	    int vertex_length = (entry >> 21) & 0x07;
nkeynes@189
   395
	    int context_length = 3;
nkeynes@189
   396
	    if( is_modified && !cheap_modifier_mode ) {
nkeynes@189
   397
		context_length = 5;
nkeynes@189
   398
		vertex_length *= 2 ;
nkeynes@189
   399
	    }
nkeynes@189
   400
	    vertex_length += 3;
nkeynes@308
   401
	    
nkeynes@189
   402
	    if( (entry & 0xE0000000) == 0x80000000 ) {
nkeynes@189
   403
		/* Triangle(s) */
nkeynes@189
   404
		int strip_count = ((entry >> 25) & 0x0F)+1;
nkeynes@189
   405
		int polygon_length = 3 * vertex_length + context_length;
nkeynes@189
   406
		int i;
nkeynes@189
   407
		for( i=0; i<strip_count; i++ ) {
nkeynes@189
   408
		    render_set_context( polygon, render_mode );
nkeynes@189
   409
		    render_vertexes( *polygon, polygon+context_length, 3, vertex_length,
nkeynes@477
   410
		    		     render_mode );
nkeynes@189
   411
		    polygon += polygon_length;
nkeynes@189
   412
		}
nkeynes@189
   413
	    } else if( (entry & 0xE0000000) == 0xA0000000 ) {
nkeynes@189
   414
		/* Sprite(s) */
nkeynes@319
   415
		int strip_count = ((entry >> 25) & 0x0F)+1;
nkeynes@189
   416
		int polygon_length = 4 * vertex_length + context_length;
nkeynes@189
   417
		int i;
nkeynes@189
   418
		for( i=0; i<strip_count; i++ ) {
nkeynes@189
   419
		    render_set_context( polygon, render_mode );
nkeynes@319
   420
		    render_quad_vertexes( *polygon, polygon+context_length, vertex_length,
nkeynes@477
   421
		    			  render_mode );
nkeynes@189
   422
		    polygon += polygon_length;
nkeynes@189
   423
		}
nkeynes@189
   424
	    } else {
nkeynes@189
   425
		/* Polygon */
nkeynes@189
   426
		int i, first=-1, last = -1;
nkeynes@189
   427
		for( i=0; i<6; i++ ) {
nkeynes@189
   428
		    if( entry & (0x40000000>>i) ) {
nkeynes@189
   429
			if( first == -1 ) first = i;
nkeynes@189
   430
			last = i;
nkeynes@189
   431
		    }
nkeynes@189
   432
		}
nkeynes@189
   433
		if( first != -1 ) {
nkeynes@189
   434
		    first = 0;
nkeynes@189
   435
		    render_set_context(polygon, render_mode);
nkeynes@189
   436
		    render_vertexes( *polygon, polygon+context_length + (first*vertex_length),
nkeynes@477
   437
		    		     (last-first+3), vertex_length, render_mode );
nkeynes@189
   438
		}
nkeynes@189
   439
	    }
nkeynes@189
   440
	}
nkeynes@189
   441
    } while( 1 );
nkeynes@189
   442
}
nkeynes@189
   443
nkeynes@189
   444
void pvr2_render_tilebuffer( int width, int height, int clipx1, int clipy1, 
nkeynes@189
   445
			int clipx2, int clipy2 ) {
nkeynes@189
   446
nkeynes@191
   447
    pvraddr_t segmentbase = MMIO_READ( PVR2, RENDER_TILEBASE );
nkeynes@189
   448
    int tile_sort;
nkeynes@189
   449
    gboolean cheap_shadow;
nkeynes@189
   450
nkeynes@191
   451
    int obj_config = MMIO_READ( PVR2, RENDER_OBJCFG );
nkeynes@191
   452
    int isp_config = MMIO_READ( PVR2, RENDER_ISPCFG );
nkeynes@191
   453
    int shadow_cfg = MMIO_READ( PVR2, RENDER_SHADOW );
nkeynes@189
   454
nkeynes@222
   455
    if( (obj_config & 0x00200000) == 0 ) {
nkeynes@189
   456
	if( isp_config & 1 ) {
nkeynes@189
   457
	    tile_sort = 0;
nkeynes@189
   458
	} else {
nkeynes@189
   459
	    tile_sort = 2;
nkeynes@189
   460
	}
nkeynes@189
   461
    } else {
nkeynes@189
   462
	tile_sort = 1;
nkeynes@189
   463
    }
nkeynes@189
   464
nkeynes@189
   465
    cheap_shadow = shadow_cfg & 0x100 ? TRUE : FALSE;
nkeynes@189
   466
nkeynes@189
   467
    struct tile_segment *segment = (struct tile_segment *)(video_base + segmentbase);
nkeynes@189
   468
nkeynes@189
   469
    glEnable( GL_SCISSOR_TEST );
nkeynes@268
   470
    do {
nkeynes@221
   471
	// fwrite_dump32v( (uint32_t *)segment, sizeof(struct tile_segment), 6, stderr );
nkeynes@189
   472
	int tilex = SEGMENT_X(segment->control);
nkeynes@189
   473
	int tiley = SEGMENT_Y(segment->control);
nkeynes@189
   474
	
nkeynes@189
   475
	int x1 = tilex << 5;
nkeynes@189
   476
	int y1 = tiley << 5;
nkeynes@189
   477
	if( x1 + 32 <= clipx1 ||
nkeynes@189
   478
	    y1 + 32 <= clipy1 ||
nkeynes@189
   479
	    x1 >= clipx2 ||
nkeynes@189
   480
	    y1 >= clipy2 ) {
nkeynes@189
   481
	    /* Tile completely clipped, skip */
nkeynes@189
   482
	    continue;
nkeynes@189
   483
	}
nkeynes@215
   484
nkeynes@189
   485
	/* Set a scissor on the visible part of the tile */
nkeynes@189
   486
	int w = MIN(x1+32, clipx2) - x1;
nkeynes@189
   487
	int h = MIN(y1+32, clipy2) - y1;
nkeynes@189
   488
	x1 = MAX(x1,clipx1);
nkeynes@189
   489
	y1 = MAX(y1,clipy1);
nkeynes@189
   490
	glScissor( x1, height-y1-h, w, h );
nkeynes@189
   491
nkeynes@189
   492
	if( (segment->opaque_ptr & NO_POINTER) == 0 ) {
nkeynes@338
   493
	    if( pvr2_debug_render ) {
nkeynes@338
   494
		fprintf( stderr, "Tile %d,%d Opaque\n", tilex, tiley );
nkeynes@341
   495
		render_print_tilelist( stderr, segment->opaque_ptr );
nkeynes@338
   496
	    }
nkeynes@189
   497
	    if( (segment->opaquemod_ptr & NO_POINTER) == 0 ) {
nkeynes@189
   498
		/* TODO */
nkeynes@189
   499
	    }
nkeynes@189
   500
	    render_tile( segment->opaque_ptr, RENDER_NORMAL, cheap_shadow );
nkeynes@189
   501
	}
nkeynes@189
   502
nkeynes@189
   503
	if( (segment->trans_ptr & NO_POINTER) == 0 ) {
nkeynes@338
   504
	    if( pvr2_debug_render ) {
nkeynes@338
   505
		fprintf( stderr, "Tile %d,%d Trans\n", tilex, tiley );
nkeynes@341
   506
		render_print_tilelist( stderr, segment->trans_ptr );
nkeynes@338
   507
	    }
nkeynes@189
   508
	    if( (segment->transmod_ptr & NO_POINTER) == 0 ) {
nkeynes@189
   509
		/* TODO */
nkeynes@189
   510
	    } 
nkeynes@222
   511
	    if( tile_sort == 2 || 
nkeynes@222
   512
		(tile_sort == 1 && ((segment->control & SEGMENT_SORT_TRANS)==0)) ) {
nkeynes@189
   513
		render_autosort_tile( segment->trans_ptr, RENDER_NORMAL, cheap_shadow );
nkeynes@189
   514
	    } else {
nkeynes@189
   515
		render_tile( segment->trans_ptr, RENDER_NORMAL, cheap_shadow );
nkeynes@189
   516
	    }
nkeynes@189
   517
	}
nkeynes@189
   518
nkeynes@189
   519
	if( (segment->punchout_ptr & NO_POINTER) == 0 ) {
nkeynes@338
   520
	    if( pvr2_debug_render ) {
nkeynes@338
   521
		fprintf( stderr, "Tile %d,%d Punchout\n", tilex, tiley );
nkeynes@341
   522
		render_print_tilelist( stderr, segment->punchout_ptr );
nkeynes@338
   523
	    }
nkeynes@189
   524
	    render_tile( segment->punchout_ptr, RENDER_NORMAL, cheap_shadow );
nkeynes@189
   525
	}
nkeynes@268
   526
    } while( ((segment++)->control & SEGMENT_END) == 0 );
nkeynes@189
   527
    glDisable( GL_SCISSOR_TEST );
nkeynes@189
   528
}
nkeynes@322
   529
nkeynes@635
   530
static void render_find_maximum_tile_z( pvraddr_t tile_entry, float *minimumz, float *maximumz )
nkeynes@322
   531
{
nkeynes@322
   532
    uint32_t poly_bank = MMIO_READ(PVR2,RENDER_POLYBASE);
nkeynes@322
   533
    uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
nkeynes@322
   534
    int shadow_cfg = MMIO_READ( PVR2, RENDER_SHADOW ) & 0x100;
nkeynes@322
   535
    int i, j;
nkeynes@322
   536
    do {
nkeynes@322
   537
	uint32_t entry = *tile_list++;
nkeynes@322
   538
	if( entry >> 28 == 0x0F ) {
nkeynes@322
   539
	    break;
nkeynes@322
   540
	} else if( entry >> 28 == 0x0E ) {
nkeynes@322
   541
	    tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
nkeynes@322
   542
	} else {
nkeynes@322
   543
	    uint32_t *polygon = (uint32_t *)(video_base + poly_bank + ((entry & 0x000FFFFF) << 2));
nkeynes@322
   544
	    int vertex_length = (entry >> 21) & 0x07;
nkeynes@322
   545
	    int context_length = 3;
nkeynes@351
   546
	    if( (entry & 0x01000000) && (shadow_cfg==0) ) {
nkeynes@322
   547
		context_length = 5;
nkeynes@322
   548
		vertex_length *= 2 ;
nkeynes@322
   549
	    }
nkeynes@322
   550
	    vertex_length += 3;
nkeynes@322
   551
	    if( (entry & 0xE0000000) == 0x80000000 ) {
nkeynes@322
   552
		/* Triangle(s) */
nkeynes@322
   553
		int strip_count = ((entry >> 25) & 0x0F)+1;
nkeynes@322
   554
		float *vertexz = (float *)(polygon+context_length+2);
nkeynes@322
   555
		for( i=0; i<strip_count; i++ ) {
nkeynes@322
   556
		    for( j=0; j<3; j++ ) {
nkeynes@635
   557
			if( *vertexz > *maximumz ) {
nkeynes@635
   558
			    *maximumz = *vertexz;
nkeynes@635
   559
			} else if( *vertexz < *minimumz ) {
nkeynes@635
   560
			    *minimumz = *vertexz;
nkeynes@322
   561
			}
nkeynes@322
   562
			vertexz += vertex_length;
nkeynes@322
   563
		    }
nkeynes@322
   564
		    vertexz += context_length;
nkeynes@322
   565
		}
nkeynes@322
   566
	    } else if( (entry & 0xE0000000) == 0xA0000000 ) {
nkeynes@322
   567
		/* Sprite(s) */
nkeynes@322
   568
		int strip_count = ((entry >> 25) & 0x0F)+1;
nkeynes@322
   569
		int i;
nkeynes@322
   570
		float *vertexz = (float *)(polygon+context_length+2);
nkeynes@322
   571
		for( i=0; i<strip_count; i++ ) {
nkeynes@322
   572
		    for( j=0; j<4; j++ ) {
nkeynes@635
   573
			if( *vertexz > *maximumz ) {
nkeynes@635
   574
			    *maximumz = *vertexz;
nkeynes@635
   575
			} else if( *vertexz < *minimumz ) {
nkeynes@635
   576
			    *minimumz = *vertexz;
nkeynes@322
   577
			}
nkeynes@322
   578
			vertexz += vertex_length;
nkeynes@322
   579
		    }
nkeynes@322
   580
		    vertexz+=context_length;
nkeynes@322
   581
		}
nkeynes@322
   582
	    } else {
nkeynes@322
   583
		/* Polygon */
nkeynes@429
   584
		int i;
nkeynes@322
   585
		float *vertexz = (float *)polygon+context_length+2;
nkeynes@322
   586
		for( i=0; i<6; i++ ) {
nkeynes@635
   587
		    if( (entry & (0x40000000>>i)) ) {
nkeynes@635
   588
			if( *vertexz > *maximumz ) {
nkeynes@635
   589
			    *maximumz = *vertexz;
nkeynes@635
   590
			} else if( *vertexz < *minimumz ) {
nkeynes@635
   591
			    *minimumz = *vertexz;
nkeynes@635
   592
			}
nkeynes@322
   593
		    }
nkeynes@322
   594
		    vertexz += vertex_length;
nkeynes@322
   595
		}
nkeynes@322
   596
	    }
nkeynes@322
   597
	}
nkeynes@322
   598
    } while(1);
nkeynes@322
   599
}
nkeynes@322
   600
nkeynes@322
   601
/**
nkeynes@322
   602
 * Scan through the scene to determine the largest z value (in order to set up
nkeynes@322
   603
 * an appropriate near clip plane).
nkeynes@322
   604
 */
nkeynes@635
   605
void pvr2_render_find_z_range( float *minimumz, float *maximumz )
nkeynes@322
   606
{
nkeynes@322
   607
    pvraddr_t segmentbase = MMIO_READ( PVR2, RENDER_TILEBASE );
nkeynes@635
   608
    *minimumz = MMIO_READF( PVR2, RENDER_FARCLIP ); /* Initialize to the far clip plane */
nkeynes@635
   609
    *maximumz = *minimumz;
nkeynes@322
   610
nkeynes@322
   611
    struct tile_segment *segment = (struct tile_segment *)(video_base + segmentbase);
nkeynes@322
   612
    do {
nkeynes@322
   613
	
nkeynes@322
   614
	if( (segment->opaque_ptr & NO_POINTER) == 0 ) {
nkeynes@635
   615
	    render_find_maximum_tile_z(segment->opaque_ptr, minimumz, maximumz);
nkeynes@322
   616
	}
nkeynes@322
   617
	if( (segment->opaquemod_ptr & NO_POINTER) == 0 ) {
nkeynes@635
   618
	    render_find_maximum_tile_z(segment->opaquemod_ptr, minimumz, maximumz);
nkeynes@322
   619
	}
nkeynes@322
   620
	if( (segment->trans_ptr & NO_POINTER) == 0 ) {
nkeynes@635
   621
	    render_find_maximum_tile_z(segment->trans_ptr, minimumz, maximumz);
nkeynes@322
   622
	}
nkeynes@322
   623
	if( (segment->transmod_ptr & NO_POINTER) == 0 ) {
nkeynes@635
   624
	    render_find_maximum_tile_z(segment->transmod_ptr, minimumz, maximumz);
nkeynes@322
   625
	}
nkeynes@322
   626
	if( (segment->punchout_ptr & NO_POINTER) == 0 ) {
nkeynes@635
   627
	    render_find_maximum_tile_z(segment->punchout_ptr, minimumz, maximumz);
nkeynes@322
   628
	}
nkeynes@322
   629
nkeynes@322
   630
    } while( ((segment++)->control & SEGMENT_END) == 0 );
nkeynes@322
   631
}
nkeynes@338
   632
nkeynes@338
   633
/**
nkeynes@338
   634
 * Scan the segment info to determine the width and height of the render (in 
nkeynes@338
   635
 * pixels).
nkeynes@338
   636
 * @param x,y output values to receive the width and height info.
nkeynes@338
   637
 */
nkeynes@338
   638
void pvr2_render_getsize( int *x, int *y ) 
nkeynes@338
   639
{
nkeynes@338
   640
    pvraddr_t segmentbase = MMIO_READ( PVR2, RENDER_TILEBASE );
nkeynes@338
   641
    int maxx = 0, maxy = 0;
nkeynes@338
   642
nkeynes@338
   643
    struct tile_segment *segment = (struct tile_segment *)(video_base + segmentbase);
nkeynes@338
   644
    do {
nkeynes@338
   645
	int tilex = SEGMENT_X(segment->control);
nkeynes@338
   646
	int tiley = SEGMENT_Y(segment->control);
nkeynes@338
   647
	if( tilex > maxx ) {
nkeynes@338
   648
	    maxx = tilex;
nkeynes@338
   649
	} 
nkeynes@338
   650
	if( tiley > maxy ) {
nkeynes@338
   651
	    maxy = tiley;
nkeynes@338
   652
	}
nkeynes@338
   653
    } while( ((segment++)->control & SEGMENT_END) == 0 );
nkeynes@338
   654
nkeynes@338
   655
    *x = (maxx+1)<<5;
nkeynes@338
   656
    *y = (maxy+1)<<5;
nkeynes@338
   657
}
nkeynes@341
   658
nkeynes@341
   659
void render_print_vertexes( FILE *f, uint32_t poly1, uint32_t *vert_array[], 
nkeynes@341
   660
			    int num_vertexes, int vertex_size )
nkeynes@341
   661
{
nkeynes@341
   662
    char buf[256], *p;
nkeynes@429
   663
    int i, k;
nkeynes@341
   664
    for( i=0; i<num_vertexes; i++ ) {
nkeynes@341
   665
	p = buf;
nkeynes@341
   666
	float *vertf = (float *)vert_array[i];
nkeynes@341
   667
	uint32_t *verti = (uint32_t *)vert_array[i];
nkeynes@341
   668
	p += sprintf( p, "  V %9.5f,%9.5f,%9.5f  ", vertf[0], vertf[1], vertf[2] );
nkeynes@341
   669
	k = 3;
nkeynes@341
   670
	if( POLY1_TEXTURED(poly1) ) {
nkeynes@341
   671
	    if( POLY1_UV16(poly1) ) {
nkeynes@341
   672
		p += sprintf( p, "uv=%9.5f,%9.5f  ",
nkeynes@341
   673
			       halftofloat(verti[k]>>16),
nkeynes@341
   674
			       halftofloat(verti[k]) );
nkeynes@341
   675
		k++;
nkeynes@341
   676
	    } else {
nkeynes@341
   677
		p += sprintf( p, "uv=%9.5f,%9.5f  ", vertf[k], vertf[k+1] );
nkeynes@341
   678
		k+=2;
nkeynes@341
   679
	    }
nkeynes@341
   680
	}
nkeynes@341
   681
nkeynes@341
   682
	p += sprintf( p, "%08X ", verti[k++] );
nkeynes@341
   683
	if( POLY1_SPECULAR(poly1) ) {
nkeynes@341
   684
	    p += sprintf( p, "%08X", verti[k++] );
nkeynes@341
   685
	}
nkeynes@341
   686
	p += sprintf( p, "\n" );
nkeynes@341
   687
	fprintf( f, buf );
nkeynes@341
   688
    }
nkeynes@341
   689
}
nkeynes@341
   690
nkeynes@341
   691
void render_print_polygon( FILE *f, uint32_t entry )
nkeynes@341
   692
{
nkeynes@341
   693
    uint32_t poly_bank = MMIO_READ(PVR2,RENDER_POLYBASE);
nkeynes@341
   694
    int shadow_cfg = MMIO_READ( PVR2, RENDER_SHADOW ) & 0x100;
nkeynes@429
   695
    int i;
nkeynes@341
   696
nkeynes@341
   697
    if( entry >> 28 == 0x0F ) {
nkeynes@341
   698
	fprintf( f, "EOT\n" );
nkeynes@341
   699
    } else if( entry >> 28 == 0x0E ) {
nkeynes@341
   700
	fprintf( f, "LINK %08X\n", entry &0x7FFFFF );
nkeynes@341
   701
    } else {
nkeynes@341
   702
	uint32_t *polygon = (uint32_t *)(video_base + poly_bank + ((entry & 0x000FFFFF) << 2));
nkeynes@341
   703
	int vertex_length = (entry >> 21) & 0x07;
nkeynes@341
   704
	int context_length = 3;
nkeynes@351
   705
	if( (entry & 0x01000000) && (shadow_cfg==0) ) {
nkeynes@341
   706
	    context_length = 5;
nkeynes@341
   707
	    vertex_length *= 2 ;
nkeynes@341
   708
	}
nkeynes@341
   709
	vertex_length += 3;
nkeynes@341
   710
	if( (entry & 0xE0000000) == 0x80000000 ) {
nkeynes@341
   711
	    /* Triangle(s) */
nkeynes@341
   712
	    int strip_count = ((entry >> 25) & 0x0F)+1;
nkeynes@341
   713
	    for( i=0; i<strip_count; i++ ) {
nkeynes@341
   714
		fprintf( f, "TRI  %08X %08X %08X\n", polygon[0], polygon[1], polygon[2] ); 
nkeynes@341
   715
		uint32_t *array[3];
nkeynes@341
   716
		array[0] = polygon + context_length;
nkeynes@341
   717
		array[1] = array[0] + vertex_length;
nkeynes@341
   718
		array[2] = array[1] + vertex_length;
nkeynes@341
   719
		render_print_vertexes( f, *polygon, array, 3, vertex_length );
nkeynes@341
   720
		polygon = array[2] + vertex_length;
nkeynes@341
   721
	    }
nkeynes@341
   722
	} else if( (entry & 0xE0000000) == 0xA0000000 ) {
nkeynes@341
   723
	    /* Sprite(s) */
nkeynes@341
   724
	    int strip_count = ((entry >> 25) & 0x0F)+1;
nkeynes@341
   725
	    for( i=0; i<strip_count; i++ ) {
nkeynes@341
   726
		fprintf( f, "QUAD %08X %08X %08X\n", polygon[0], polygon[1], polygon[2] ); 
nkeynes@341
   727
		uint32_t *array[4];
nkeynes@341
   728
		array[0] = polygon + context_length;
nkeynes@341
   729
		array[1] = array[0] + vertex_length;
nkeynes@341
   730
		array[2] = array[1] + vertex_length;
nkeynes@341
   731
		array[3] = array[2] + vertex_length;
nkeynes@341
   732
		render_print_vertexes( f, *polygon, array, 4, vertex_length );
nkeynes@341
   733
		polygon = array[3] + vertex_length;
nkeynes@341
   734
	    }
nkeynes@341
   735
	} else {
nkeynes@341
   736
	    /* Polygon */
nkeynes@341
   737
	    int last = -1;
nkeynes@341
   738
	    uint32_t *array[8];
nkeynes@341
   739
	    for( i=0; i<6; i++ ) {
nkeynes@341
   740
		if( entry & (0x40000000>>i) ) {
nkeynes@341
   741
		    last = i;
nkeynes@341
   742
		}
nkeynes@341
   743
	    }
nkeynes@341
   744
	    fprintf( f, "POLY %08X %08X %08X\n", polygon[0], polygon[1], polygon[2] );
nkeynes@341
   745
	    for( i=0; i<last+2; i++ ) {
nkeynes@341
   746
		array[i] = polygon + context_length + vertex_length*i;
nkeynes@341
   747
	    }
nkeynes@341
   748
	    render_print_vertexes( f, *polygon, array, last+2, vertex_length );
nkeynes@341
   749
	}
nkeynes@341
   750
    }
nkeynes@341
   751
}
nkeynes@341
   752
nkeynes@341
   753
void render_print_tilelist( FILE *f, uint32_t tile_entry )
nkeynes@341
   754
{
nkeynes@341
   755
    uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
nkeynes@341
   756
    do {
nkeynes@341
   757
	uint32_t entry = *tile_list++;
nkeynes@341
   758
	if( entry >> 28 == 0x0F ) {
nkeynes@341
   759
	    break;
nkeynes@341
   760
	} else if( entry >> 28 == 0x0E ) {
nkeynes@341
   761
	    tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
nkeynes@341
   762
	} else {
nkeynes@341
   763
	    render_print_polygon(f, entry);
nkeynes@341
   764
	}
nkeynes@341
   765
    } while( 1 );
nkeynes@341
   766
}
nkeynes@341
   767
.