6 * Copyright (c) 2005 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include "pvr2/pvr2.h"
23 int pvr2_poly_depthmode[8] = { GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL,
24 GL_GREATER, GL_NOTEQUAL, GL_GEQUAL,
26 int pvr2_poly_srcblend[8] = {
27 GL_ZERO, GL_ONE, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
28 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
29 GL_ONE_MINUS_DST_ALPHA };
30 int pvr2_poly_dstblend[8] = {
31 GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
32 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
33 GL_ONE_MINUS_DST_ALPHA };
34 int pvr2_poly_texblend[4] = {
40 int pvr2_render_colour_format[8] = {
41 COLFMT_BGRA1555, COLFMT_RGB565, COLFMT_BGRA4444, COLFMT_BGRA1555,
42 COLFMT_BGR888, COLFMT_BGRA8888, COLFMT_BGRA8888, COLFMT_BGRA4444 };
50 #define SEGMENT_END 0x80000000
51 #define SEGMENT_ZCLEAR 0x40000000
52 #define SEGMENT_SORT_TRANS 0x20000000
53 #define SEGMENT_START 0x10000000
54 #define SEGMENT_X(c) (((c) >> 2) & 0x3F)
55 #define SEGMENT_Y(c) (((c) >> 8) & 0x3F)
56 #define NO_POINTER 0x80000000
58 extern char *video_base;
60 gboolean pvr2_force_fragment_alpha = FALSE;
61 gboolean pvr2_debug_render = FALSE;
66 pvraddr_t opaquemod_ptr;
68 pvraddr_t transmod_ptr;
69 pvraddr_t punchout_ptr;
72 void render_print_tilelist( FILE *f, uint32_t tile_entry );
75 * Convert a half-float (16-bit) FP number to a regular 32-bit float.
76 * Source is 1-bit sign, 5-bit exponent, 10-bit mantissa.
77 * TODO: Check the correctness of this.
79 float halftofloat( uint16_t half )
85 /* int e = ((half & 0x7C00) >> 10) - 15 + 127;
87 temp.i = ((half & 0x8000) << 16) | (e << 23) |
88 ((half & 0x03FF) << 13); */
89 temp.i = ((uint32_t)half)<<16;
95 * Setup the GL context for the supplied polygon context.
96 * @param context pointer to 3 or 5 words of polygon context
97 * @param modified boolean flag indicating that the modified
98 * version should be used, rather than the normal version.
100 void render_set_context( uint32_t *context, int render_mode )
102 uint32_t poly1 = context[0], poly2, texture;
103 if( render_mode == RENDER_FULLMOD ) {
105 texture = context[4];
108 texture = context[2];
111 if( POLY1_DEPTH_ENABLE(poly1) ) {
112 glEnable( GL_DEPTH_TEST );
113 glDepthFunc( POLY1_DEPTH_MODE(poly1) );
115 glDisable( GL_DEPTH_TEST );
118 switch( POLY1_CULL_MODE(poly1) ) {
121 glDisable( GL_CULL_FACE );
124 glEnable( GL_CULL_FACE );
125 glFrontFace( GL_CW );
128 glEnable( GL_CULL_FACE );
129 glFrontFace( GL_CCW );
133 if( POLY1_SPECULAR(poly1) ) {
134 glEnable(GL_COLOR_SUM);
136 glDisable(GL_COLOR_SUM);
139 pvr2_force_fragment_alpha = POLY2_ALPHA_ENABLE(poly2) ? FALSE : TRUE;
141 if( POLY1_TEXTURED(poly1) ) {
142 int width = POLY2_TEX_WIDTH(poly2);
143 int height = POLY2_TEX_HEIGHT(poly2);
144 glEnable(GL_TEXTURE_2D);
145 texcache_get_texture( (texture&0x000FFFFF)<<3, width, height, texture );
146 switch( POLY2_TEX_BLEND(poly2) ) {
147 case 0: /* Replace */
148 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
151 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
153 case 1: /* Modulate RGB */
154 /* This is not directly supported by opengl (other than by mucking
155 * with the texture format), but we get the same effect by forcing
156 * the fragment alpha to 1.0 and using GL_MODULATE.
158 pvr2_force_fragment_alpha = TRUE;
159 case 3: /* Modulate RGBA */
160 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
164 if( POLY2_TEX_CLAMP_U(poly2) ) {
165 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
167 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
169 if( POLY2_TEX_CLAMP_V(poly2) ) {
170 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
172 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
175 glDisable( GL_TEXTURE_2D );
178 glShadeModel( POLY1_SHADE_MODEL(poly1) );
180 int srcblend = POLY2_SRC_BLEND(poly2);
181 int destblend = POLY2_DEST_BLEND(poly2);
182 glBlendFunc( srcblend, destblend );
184 if( POLY2_SRC_BLEND_TARGET(poly2) || POLY2_DEST_BLEND_TARGET(poly2) ) {
185 ERROR( "Accumulation buffer not supported" );
191 #define FARGB_A(x) (((float)(((x)>>24)+1))/256.0)
192 #define FARGB_R(x) (((float)((((x)>>16)&0xFF)+1))/256.0)
193 #define FARGB_G(x) (((float)((((x)>>8)&0xFF)+1))/256.0)
194 #define FARGB_B(x) (((float)(((x)&0xFF)+1))/256.0)
196 void render_unpack_vertexes( struct vertex_unpacked *out, uint32_t poly1,
197 uint32_t *vertexes, int num_vertexes,
198 int vertex_size, int render_mode )
201 if( render_mode == RENDER_FULLMOD ) {
202 m = (vertex_size - 3)/2;
205 for( i=0; i<num_vertexes; i++ ) {
206 float *vertexf = (float *)vertexes;
208 out[i].x = vertexf[0];
209 out[i].y = vertexf[1];
210 out[i].z = vertexf[2];
211 if( POLY1_TEXTURED(poly1) ) {
212 if( POLY1_UV16(poly1) ) {
213 out[i].u = halftofloat(vertexes[k]>>16);
214 out[i].v = halftofloat(vertexes[k]);
217 out[i].u = vertexf[k];
218 out[i].v = vertexf[k+1];
225 uint32_t argb = vertexes[k++];
226 out[i].rgba[0] = FARGB_R(argb);
227 out[i].rgba[1] = FARGB_G(argb);
228 out[i].rgba[2] = FARGB_B(argb);
229 out[i].rgba[3] = FARGB_A(argb);
230 if( POLY1_SPECULAR(poly1) ) {
231 uint32_t offset = vertexes[k++];
232 out[i].offset_rgba[0] = FARGB_R(offset);
233 out[i].offset_rgba[1] = FARGB_G(offset);
234 out[i].offset_rgba[2] = FARGB_B(offset);
235 out[i].offset_rgba[3] = FARGB_A(offset);
237 vertexes += vertex_size;
242 * Unpack the vertexes for a quad, calculating the values for the last
244 * FIXME: Integrate this with rendbkg somehow
246 void render_unpack_quad( struct vertex_unpacked *unpacked, uint32_t poly1,
247 uint32_t *vertexes, int vertex_size,
251 struct vertex_unpacked diff0, diff1;
253 render_unpack_vertexes( unpacked, poly1, vertexes, 3, vertex_size, render_mode );
255 diff0.x = unpacked[0].x - unpacked[1].x;
256 diff0.y = unpacked[0].y - unpacked[1].y;
257 diff1.x = unpacked[2].x - unpacked[1].x;
258 diff1.y = unpacked[2].y - unpacked[1].y;
260 float detxy = ((diff1.y) * (diff0.x)) - ((diff0.y) * (diff1.x));
261 float *vertexf = (float *)(vertexes+(vertex_size*3));
263 memcpy( &unpacked[3], &unpacked[2], sizeof(struct vertex_unpacked) );
264 unpacked[3].x = vertexf[0];
265 unpacked[3].y = vertexf[1];
269 unpacked[3].x = vertexf[0];
270 unpacked[3].y = vertexf[1];
271 float t = ((unpacked[3].x - unpacked[1].x) * diff1.y -
272 (unpacked[3].y - unpacked[1].y) * diff1.x) / detxy;
273 float s = ((unpacked[3].y - unpacked[1].y) * diff0.x -
274 (unpacked[3].x - unpacked[1].x) * diff0.y) / detxy;
275 diff0.z = (1/unpacked[0].z) - (1/unpacked[1].z);
276 diff1.z = (1/unpacked[2].z) - (1/unpacked[1].z);
277 unpacked[3].z = 1/((1/unpacked[1].z) + (t*diff0.z) + (s*diff1.z));
279 diff0.u = unpacked[0].u - unpacked[1].u;
280 diff0.v = unpacked[0].v - unpacked[1].v;
281 diff1.u = unpacked[2].u - unpacked[1].u;
282 diff1.v = unpacked[2].v - unpacked[1].v;
283 unpacked[3].u = unpacked[1].u + (t*diff0.u) + (s*diff1.u);
284 unpacked[3].v = unpacked[1].v + (t*diff0.v) + (s*diff1.v);
286 if( !POLY1_GOURAUD_SHADED(poly1) ) {
287 memcpy( unpacked[3].rgba, unpacked[2].rgba, sizeof(unpacked[2].rgba) );
288 memcpy( unpacked[3].offset_rgba, unpacked[2].offset_rgba, sizeof(unpacked[2].offset_rgba) );
290 for( i=0; i<4; i++ ) {
291 float d0 = unpacked[0].rgba[i] - unpacked[1].rgba[i];
292 float d1 = unpacked[2].rgba[i] - unpacked[1].rgba[i];
293 unpacked[3].rgba[i] = unpacked[1].rgba[i] + (t*d0) + (s*d1);
294 d0 = unpacked[0].offset_rgba[i] - unpacked[1].offset_rgba[i];
295 d1 = unpacked[2].offset_rgba[i] - unpacked[1].offset_rgba[i];
296 unpacked[3].offset_rgba[i] = unpacked[1].offset_rgba[i] + (t*d0) + (s*d1);
301 void render_unpacked_vertex_array( uint32_t poly1, struct vertex_unpacked *vertexes[],
305 glBegin( GL_TRIANGLE_STRIP );
307 for( i=0; i<num_vertexes; i++ ) {
308 if( POLY1_TEXTURED(poly1) ) {
309 glTexCoord2f( vertexes[i]->u, vertexes[i]->v );
312 if( pvr2_force_fragment_alpha ) {
313 glColor4f( vertexes[i]->rgba[0], vertexes[i]->rgba[1], vertexes[i]->rgba[2], 1.0 );
315 glColor4f( vertexes[i]->rgba[0], vertexes[i]->rgba[1], vertexes[i]->rgba[2],
316 vertexes[i]->rgba[3] );
318 if( POLY1_SPECULAR(poly1) ) {
319 glSecondaryColor3fEXT( vertexes[i]->offset_rgba[0],
320 vertexes[i]->offset_rgba[1],
321 vertexes[i]->offset_rgba[2] );
323 glVertex3f( vertexes[i]->x, vertexes[i]->y, 1/vertexes[i]->z );
329 void render_quad_vertexes( uint32_t poly1, uint32_t *vertexes, int vertex_size, int render_mode )
331 struct vertex_unpacked unpacked[4];
332 struct vertex_unpacked *pt[4] = {&unpacked[0], &unpacked[1], &unpacked[3], &unpacked[2]};
333 render_unpack_quad( unpacked, poly1, vertexes, vertex_size, render_mode );
334 render_unpacked_vertex_array( poly1, pt, 4 );
337 void render_vertex_array( uint32_t poly1, uint32_t *vert_array[], int num_vertexes, int vertex_size,
342 if( render_mode == RENDER_FULLMOD ) {
343 m = (vertex_size - 3)/2;
346 glBegin( GL_TRIANGLE_STRIP );
348 for( i=0; i<num_vertexes; i++ ) {
349 uint32_t *vertexes = vert_array[i];
350 float *vertexf = (float *)vert_array[i];
353 if( POLY1_TEXTURED(poly1) ) {
354 if( POLY1_UV16(poly1) ) {
355 glTexCoord2f( halftofloat(vertexes[k]>>16),
356 halftofloat(vertexes[k]) );
359 glTexCoord2f( vertexf[k], vertexf[k+1] );
364 argb = vertexes[k++];
365 if( pvr2_force_fragment_alpha ) {
366 glColor4ub( (GLubyte)(argb >> 16), (GLubyte)(argb >> 8),
367 (GLubyte)argb, 0xFF );
369 glColor4ub( (GLubyte)(argb >> 16), (GLubyte)(argb >> 8),
370 (GLubyte)argb, (GLubyte)(argb >> 24) );
373 if( POLY1_SPECULAR(poly1) ) {
374 uint32_t spec = vertexes[k++];
375 glSecondaryColor3ubEXT( (GLubyte)(spec >> 16), (GLubyte)(spec >> 8),
378 glVertex3f( vertexf[0], vertexf[1], 1/vertexf[2] );
379 vertexes += vertex_size;
385 void render_vertexes( uint32_t poly1, uint32_t *vertexes, int num_vertexes, int vertex_size,
388 uint32_t *vert_array[num_vertexes];
390 for( i=0; i<num_vertexes; i++ ) {
391 vert_array[i] = vertexes;
392 vertexes += vertex_size;
394 render_vertex_array( poly1, vert_array, num_vertexes, vertex_size, render_mode );
398 * Render a simple (not auto-sorted) tile
400 void render_tile( pvraddr_t tile_entry, int render_mode, gboolean cheap_modifier_mode ) {
401 uint32_t poly_bank = MMIO_READ(PVR2,RENDER_POLYBASE);
402 uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
404 uint32_t entry = *tile_list++;
405 if( entry >> 28 == 0x0F ) {
407 } else if( entry >> 28 == 0x0E ) {
408 tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
410 uint32_t *polygon = (uint32_t *)(video_base + poly_bank + ((entry & 0x000FFFFF) << 2));
411 int is_modified = entry & 0x01000000;
412 int vertex_length = (entry >> 21) & 0x07;
413 int context_length = 3;
414 if( is_modified && !cheap_modifier_mode ) {
420 if( (entry & 0xE0000000) == 0x80000000 ) {
422 int strip_count = ((entry >> 25) & 0x0F)+1;
423 int polygon_length = 3 * vertex_length + context_length;
425 for( i=0; i<strip_count; i++ ) {
426 render_set_context( polygon, render_mode );
427 render_vertexes( *polygon, polygon+context_length, 3, vertex_length,
429 polygon += polygon_length;
431 } else if( (entry & 0xE0000000) == 0xA0000000 ) {
433 int strip_count = ((entry >> 25) & 0x0F)+1;
434 int polygon_length = 4 * vertex_length + context_length;
436 for( i=0; i<strip_count; i++ ) {
437 render_set_context( polygon, render_mode );
438 render_quad_vertexes( *polygon, polygon+context_length, vertex_length,
440 polygon += polygon_length;
444 int i, first=-1, last = -1;
445 for( i=0; i<6; i++ ) {
446 if( entry & (0x40000000>>i) ) {
447 if( first == -1 ) first = i;
453 render_set_context(polygon, render_mode);
454 render_vertexes( *polygon, polygon+context_length + (first*vertex_length),
455 (last-first+3), vertex_length, render_mode );
462 void pvr2_render_tilebuffer( int width, int height, int clipx1, int clipy1,
463 int clipx2, int clipy2 ) {
465 pvraddr_t segmentbase = MMIO_READ( PVR2, RENDER_TILEBASE );
467 gboolean cheap_shadow;
469 int obj_config = MMIO_READ( PVR2, RENDER_OBJCFG );
470 int isp_config = MMIO_READ( PVR2, RENDER_ISPCFG );
471 int shadow_cfg = MMIO_READ( PVR2, RENDER_SHADOW );
473 if( (obj_config & 0x00200000) == 0 ) {
474 if( isp_config & 1 ) {
483 cheap_shadow = shadow_cfg & 0x100 ? TRUE : FALSE;
485 struct tile_segment *segment = (struct tile_segment *)(video_base + segmentbase);
487 glEnable( GL_SCISSOR_TEST );
489 // fwrite_dump32v( (uint32_t *)segment, sizeof(struct tile_segment), 6, stderr );
490 int tilex = SEGMENT_X(segment->control);
491 int tiley = SEGMENT_Y(segment->control);
495 if( x1 + 32 <= clipx1 ||
499 /* Tile completely clipped, skip */
503 /* Set a scissor on the visible part of the tile */
504 int w = MIN(x1+32, clipx2) - x1;
505 int h = MIN(y1+32, clipy2) - y1;
508 glScissor( x1, height-y1-h, w, h );
510 if( (segment->opaque_ptr & NO_POINTER) == 0 ) {
511 if( pvr2_debug_render ) {
512 fprintf( stderr, "Tile %d,%d Opaque\n", tilex, tiley );
513 render_print_tilelist( stderr, segment->opaque_ptr );
515 if( (segment->opaquemod_ptr & NO_POINTER) == 0 ) {
518 render_tile( segment->opaque_ptr, RENDER_NORMAL, cheap_shadow );
521 if( (segment->trans_ptr & NO_POINTER) == 0 ) {
522 if( pvr2_debug_render ) {
523 fprintf( stderr, "Tile %d,%d Trans\n", tilex, tiley );
524 render_print_tilelist( stderr, segment->trans_ptr );
526 if( (segment->transmod_ptr & NO_POINTER) == 0 ) {
529 if( tile_sort == 2 ||
530 (tile_sort == 1 && ((segment->control & SEGMENT_SORT_TRANS)==0)) ) {
531 render_autosort_tile( segment->trans_ptr, RENDER_NORMAL, cheap_shadow );
533 render_tile( segment->trans_ptr, RENDER_NORMAL, cheap_shadow );
537 if( (segment->punchout_ptr & NO_POINTER) == 0 ) {
538 if( pvr2_debug_render ) {
539 fprintf( stderr, "Tile %d,%d Punchout\n", tilex, tiley );
540 render_print_tilelist( stderr, segment->punchout_ptr );
542 render_tile( segment->punchout_ptr, RENDER_NORMAL, cheap_shadow );
544 } while( ((segment++)->control & SEGMENT_END) == 0 );
545 glDisable( GL_SCISSOR_TEST );
548 static float render_find_maximum_tile_z( pvraddr_t tile_entry, float inputz )
550 uint32_t poly_bank = MMIO_READ(PVR2,RENDER_POLYBASE);
551 uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
552 int shadow_cfg = MMIO_READ( PVR2, RENDER_SHADOW ) & 0x100;
556 uint32_t entry = *tile_list++;
557 if( entry >> 28 == 0x0F ) {
559 } else if( entry >> 28 == 0x0E ) {
560 tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
562 uint32_t *polygon = (uint32_t *)(video_base + poly_bank + ((entry & 0x000FFFFF) << 2));
563 int vertex_length = (entry >> 21) & 0x07;
564 int context_length = 3;
565 if( (entry & 0x01000000) && (shadow_cfg==0) ) {
570 if( (entry & 0xE0000000) == 0x80000000 ) {
572 int strip_count = ((entry >> 25) & 0x0F)+1;
573 float *vertexz = (float *)(polygon+context_length+2);
574 for( i=0; i<strip_count; i++ ) {
575 for( j=0; j<3; j++ ) {
579 vertexz += vertex_length;
581 vertexz += context_length;
583 } else if( (entry & 0xE0000000) == 0xA0000000 ) {
585 int strip_count = ((entry >> 25) & 0x0F)+1;
587 float *vertexz = (float *)(polygon+context_length+2);
588 for( i=0; i<strip_count; i++ ) {
589 for( j=0; j<4; j++ ) {
593 vertexz += vertex_length;
595 vertexz+=context_length;
600 float *vertexz = (float *)polygon+context_length+2;
601 for( i=0; i<6; i++ ) {
602 if( (entry & (0x40000000>>i)) && *vertexz > z ) {
605 vertexz += vertex_length;
614 * Scan through the scene to determine the largest z value (in order to set up
615 * an appropriate near clip plane).
617 float pvr2_render_find_maximum_z( )
619 pvraddr_t segmentbase = MMIO_READ( PVR2, RENDER_TILEBASE );
620 float maximumz = MMIO_READF( PVR2, RENDER_FARCLIP ); /* Initialize to the far clip plane */
622 struct tile_segment *segment = (struct tile_segment *)(video_base + segmentbase);
625 if( (segment->opaque_ptr & NO_POINTER) == 0 ) {
626 maximumz = render_find_maximum_tile_z(segment->opaque_ptr, maximumz);
628 if( (segment->opaquemod_ptr & NO_POINTER) == 0 ) {
629 maximumz = render_find_maximum_tile_z(segment->opaquemod_ptr, maximumz);
631 if( (segment->trans_ptr & NO_POINTER) == 0 ) {
632 maximumz = render_find_maximum_tile_z(segment->trans_ptr, maximumz);
634 if( (segment->transmod_ptr & NO_POINTER) == 0 ) {
635 maximumz = render_find_maximum_tile_z(segment->transmod_ptr, maximumz);
637 if( (segment->punchout_ptr & NO_POINTER) == 0 ) {
638 maximumz = render_find_maximum_tile_z(segment->punchout_ptr, maximumz);
641 } while( ((segment++)->control & SEGMENT_END) == 0 );
647 * Scan the segment info to determine the width and height of the render (in
649 * @param x,y output values to receive the width and height info.
651 void pvr2_render_getsize( int *x, int *y )
653 pvraddr_t segmentbase = MMIO_READ( PVR2, RENDER_TILEBASE );
654 int maxx = 0, maxy = 0;
656 struct tile_segment *segment = (struct tile_segment *)(video_base + segmentbase);
658 int tilex = SEGMENT_X(segment->control);
659 int tiley = SEGMENT_Y(segment->control);
666 } while( ((segment++)->control & SEGMENT_END) == 0 );
672 void render_print_vertexes( FILE *f, uint32_t poly1, uint32_t *vert_array[],
673 int num_vertexes, int vertex_size )
677 for( i=0; i<num_vertexes; i++ ) {
679 float *vertf = (float *)vert_array[i];
680 uint32_t *verti = (uint32_t *)vert_array[i];
681 p += sprintf( p, " V %9.5f,%9.5f,%9.5f ", vertf[0], vertf[1], vertf[2] );
683 if( POLY1_TEXTURED(poly1) ) {
684 if( POLY1_UV16(poly1) ) {
685 p += sprintf( p, "uv=%9.5f,%9.5f ",
686 halftofloat(verti[k]>>16),
687 halftofloat(verti[k]) );
690 p += sprintf( p, "uv=%9.5f,%9.5f ", vertf[k], vertf[k+1] );
695 p += sprintf( p, "%08X ", verti[k++] );
696 if( POLY1_SPECULAR(poly1) ) {
697 p += sprintf( p, "%08X", verti[k++] );
699 p += sprintf( p, "\n" );
704 void render_print_polygon( FILE *f, uint32_t entry )
706 uint32_t poly_bank = MMIO_READ(PVR2,RENDER_POLYBASE);
707 int shadow_cfg = MMIO_READ( PVR2, RENDER_SHADOW ) & 0x100;
710 if( entry >> 28 == 0x0F ) {
711 fprintf( f, "EOT\n" );
712 } else if( entry >> 28 == 0x0E ) {
713 fprintf( f, "LINK %08X\n", entry &0x7FFFFF );
715 uint32_t *polygon = (uint32_t *)(video_base + poly_bank + ((entry & 0x000FFFFF) << 2));
716 int vertex_length = (entry >> 21) & 0x07;
717 int context_length = 3;
718 if( (entry & 0x01000000) && (shadow_cfg==0) ) {
723 if( (entry & 0xE0000000) == 0x80000000 ) {
725 int strip_count = ((entry >> 25) & 0x0F)+1;
726 for( i=0; i<strip_count; i++ ) {
727 fprintf( f, "TRI %08X %08X %08X\n", polygon[0], polygon[1], polygon[2] );
729 array[0] = polygon + context_length;
730 array[1] = array[0] + vertex_length;
731 array[2] = array[1] + vertex_length;
732 render_print_vertexes( f, *polygon, array, 3, vertex_length );
733 polygon = array[2] + vertex_length;
735 } else if( (entry & 0xE0000000) == 0xA0000000 ) {
737 int strip_count = ((entry >> 25) & 0x0F)+1;
738 for( i=0; i<strip_count; i++ ) {
739 fprintf( f, "QUAD %08X %08X %08X\n", polygon[0], polygon[1], polygon[2] );
741 array[0] = polygon + context_length;
742 array[1] = array[0] + vertex_length;
743 array[2] = array[1] + vertex_length;
744 array[3] = array[2] + vertex_length;
745 render_print_vertexes( f, *polygon, array, 4, vertex_length );
746 polygon = array[3] + vertex_length;
752 for( i=0; i<6; i++ ) {
753 if( entry & (0x40000000>>i) ) {
757 fprintf( f, "POLY %08X %08X %08X\n", polygon[0], polygon[1], polygon[2] );
758 for( i=0; i<last+2; i++ ) {
759 array[i] = polygon + context_length + vertex_length*i;
761 render_print_vertexes( f, *polygon, array, last+2, vertex_length );
766 void render_print_tilelist( FILE *f, uint32_t tile_entry )
768 uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
770 uint32_t entry = *tile_list++;
771 if( entry >> 28 == 0x0F ) {
773 } else if( entry >> 28 == 0x0E ) {
774 tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
776 render_print_polygon(f, entry);
.