Search
lxdream.org :: lxdream/src/pvr2/render.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/render.c
changeset 189:615b70cfd729
prev169:abbdc6943587
next191:df4441cf3128
author nkeynes
date Wed Aug 02 04:06:45 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Issue 0003: TA Vertex compiler
Initial implementation of the TA.
Renderer hooked up to the TA "properly" now as well
file annotate diff log raw
1.1 --- a/src/pvr2/render.c Tue Jun 27 09:32:09 2006 +0000
1.2 +++ b/src/pvr2/render.c Wed Aug 02 04:06:45 2006 +0000
1.3 @@ -1,7 +1,7 @@
1.4 /**
1.5 - * $Id: render.c,v 1.10 2006-06-27 09:32:09 nkeynes Exp $
1.6 + * $Id: render.c,v 1.11 2006-08-02 04:06:45 nkeynes Exp $
1.7 *
1.8 - * PVR2 Renderer support. This is where the real work happens.
1.9 + * PVR2 Renderer support. This part is primarily
1.10 *
1.11 * Copyright (c) 2005 Nathan Keynes.
1.12 *
1.13 @@ -19,41 +19,10 @@
1.14 #include "pvr2/pvr2.h"
1.15 #include "asic.h"
1.16
1.17 -
1.18 -#define POLY_COLOUR_PACKED 0x00000000
1.19 -#define POLY_COLOUR_FLOAT 0x00000010
1.20 -#define POLY_COLOUR_INTENSITY 0x00000020
1.21 -#define POLY_COLOUR_INTENSITY_PREV 0x00000030
1.22 -
1.23 -static int pvr2_poly_vertexes[4] = { 3, 4, 6, 8 };
1.24 -static int pvr2_poly_type[4] = { GL_TRIANGLES, GL_QUADS, GL_TRIANGLE_STRIP, GL_TRIANGLE_STRIP };
1.25 -static int pvr2_poly_depthmode[8] = { GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL,
1.26 - GL_GREATER, GL_NOTEQUAL, GL_GEQUAL,
1.27 - GL_ALWAYS };
1.28 -static int pvr2_poly_srcblend[8] = {
1.29 - GL_ZERO, GL_ONE, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
1.30 - GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
1.31 - GL_ONE_MINUS_DST_ALPHA };
1.32 -static int pvr2_poly_dstblend[8] = {
1.33 - GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
1.34 - GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
1.35 - GL_ONE_MINUS_DST_ALPHA };
1.36 -static int pvr2_poly_texblend[4] = {
1.37 - GL_REPLACE, GL_BLEND, GL_DECAL, GL_MODULATE };
1.38 static int pvr2_render_colour_format[8] = {
1.39 COLFMT_ARGB1555, COLFMT_RGB565, COLFMT_ARGB4444, COLFMT_ARGB1555,
1.40 COLFMT_RGB888, COLFMT_ARGB8888, COLFMT_ARGB8888, COLFMT_ARGB4444 };
1.41
1.42 -#define POLY_STRIP_TYPE(poly) ( pvr2_poly_type[((poly->command)>>18)&0x03] )
1.43 -#define POLY_STRIP_VERTEXES(poly) ( pvr2_poly_vertexes[((poly->command)>>18)&0x03] )
1.44 -#define POLY_DEPTH_MODE(poly) ( pvr2_poly_depthmode[poly->poly_cfg>>29] )
1.45 -#define POLY_DEPTH_WRITE(poly) ((poly->poly_cfg&0x04000000) == 0 )
1.46 -#define POLY_TEX_WIDTH(poly) ( 1<< (((poly->poly_mode >> 3) & 0x07 ) + 3) )
1.47 -#define POLY_TEX_HEIGHT(poly) ( 1<< (((poly->poly_mode) & 0x07 ) + 3) )
1.48 -#define POLY_BLEND_SRC(poly) ( pvr2_poly_srcblend[(poly->poly_mode) >> 29] )
1.49 -#define POLY_BLEND_DEST(poly) ( pvr2_poly_dstblend[((poly->poly_mode)>>26)&0x07] )
1.50 -#define POLY_TEX_BLEND(poly) ( pvr2_poly_texblend[((poly->poly_mode) >> 6)&0x03] )
1.51 -#define POLY_COLOUR_TYPE(poly) ( poly->command & 0x00000030 )
1.52
1.53 /**
1.54 * Describes a rendering buffer that's actually held in GL, for when we need
1.55 @@ -69,61 +38,6 @@
1.56 struct pvr2_render_buffer front_buffer;
1.57 struct pvr2_render_buffer back_buffer;
1.58
1.59 -struct tile_descriptor {
1.60 - uint32_t header[6];
1.61 - struct tile_pointers {
1.62 - uint32_t tile_id;
1.63 - uint32_t opaque_ptr;
1.64 - uint32_t opaque_mod_ptr;
1.65 - uint32_t trans_ptr;
1.66 - uint32_t trans_mod_ptr;
1.67 - uint32_t punchout_ptr;
1.68 - } tile[0];
1.69 -};
1.70 -
1.71 -/* Textured polygon */
1.72 -struct pvr2_poly {
1.73 - uint32_t command;
1.74 - uint32_t poly_cfg; /* Bitmask */
1.75 - uint32_t poly_mode; /* texture/blending mask */
1.76 - uint32_t texture; /* texture data */
1.77 - float alpha;
1.78 - float red;
1.79 - float green;
1.80 - float blue;
1.81 -};
1.82 -
1.83 -struct pvr2_specular_highlight {
1.84 - float base_alpha;
1.85 - float base_red;
1.86 - float base_green;
1.87 - float base_blue;
1.88 - float offset_alpha;
1.89 - float offset_red;
1.90 - float offset_green;
1.91 - float offset_blue;
1.92 -};
1.93 -
1.94 -
1.95 -struct pvr2_vertex_packed {
1.96 - uint32_t command;
1.97 - float x, y, z;
1.98 - float s,t;
1.99 - uint32_t colour;
1.100 - float f;
1.101 -};
1.102 -
1.103 -struct pvr2_vertex_float {
1.104 - uint32_t command;
1.105 - float x,y,z;
1.106 - float a, r, g, b;
1.107 -};
1.108 -
1.109 -union pvr2_vertex {
1.110 - struct pvr2_vertex_packed pack;
1.111 - struct pvr2_vertex_float flt;
1.112 -};
1.113 -
1.114 typedef struct pvr2_bgplane_packed {
1.115 uint32_t poly_cfg, poly_mode;
1.116 uint32_t texture_mode;
1.117 @@ -160,6 +74,7 @@
1.118 glDisable( GL_BLEND );
1.119 glDisable( GL_TEXTURE_2D );
1.120 glDisable( GL_ALPHA_TEST );
1.121 + glDisable( GL_CULL_FACE );
1.122 glListBase(pvr2_render_font_list - 32);
1.123 glColor3f( 1.0, 1.0, 1.0 );
1.124 glRasterPos2i( x, y );
1.125 @@ -169,6 +84,27 @@
1.126 return len;
1.127 }
1.128
1.129 +void glDrawGrid( int width, int height )
1.130 +{
1.131 + int i;
1.132 + glDisable( GL_DEPTH_TEST );
1.133 + glLineWidth(1);
1.134 +
1.135 + glBegin( GL_LINES );
1.136 + glColor4f( 1.0, 1.0, 1.0, 1.0 );
1.137 + for( i=32; i<width; i+=32 ) {
1.138 + glVertex3f( i, 0.0, 3.0 );
1.139 + glVertex3f( i,height-1, 3.0 );
1.140 + }
1.141 +
1.142 + for( i=32; i<height; i+=32 ) {
1.143 + glVertex3f( 0.0, i, 3.0 );
1.144 + glVertex3f( width, i, 3.0 );
1.145 + }
1.146 + glEnd();
1.147 +
1.148 +}
1.149 +
1.150
1.151 gboolean pvr2_render_init( void )
1.152 {
1.153 @@ -276,160 +212,12 @@
1.154 glCullFace( GL_BACK );
1.155
1.156 /* Clear out the buffers */
1.157 + glDisable( GL_SCISSOR_TEST );
1.158 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1.159 glClearDepth(bgplanez);
1.160 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1.161 }
1.162
1.163 -static void pvr2_dump_display_list( uint32_t * display_list, uint32_t length )
1.164 -{
1.165 - uint32_t i;
1.166 - gboolean vertex = FALSE;
1.167 - for( i =0; i<length>>2; i++ ) {
1.168 - if( (i % 8) == 0 ) {
1.169 - if( i != 0 )
1.170 - fprintf( stderr, "\n" );
1.171 - fprintf( stderr, "%08X:", i*4 );
1.172 - if( display_list[i] == 0xE0000000 ||
1.173 - display_list[i] == 0xF0000000 )
1.174 - vertex = TRUE;
1.175 - else vertex = FALSE;
1.176 - }
1.177 - if( vertex && (i%8) > 0 && (i%8) < 4 )
1.178 - fprintf( stderr, " %f", ((float *)display_list)[i] );
1.179 - else
1.180 - fprintf( stderr, " %08X", display_list[i] );
1.181 - }
1.182 - fprintf( stderr, "\n" );
1.183 -}
1.184 -
1.185 -static void pvr2_render_display_list( uint32_t *display_list, uint32_t length )
1.186 -{
1.187 - uint32_t *cmd_ptr = display_list;
1.188 - int strip_length = 0, vertex_count = 0;
1.189 - int colour_type;
1.190 - gboolean textured = FALSE;
1.191 - gboolean shaded = FALSE;
1.192 - struct pvr2_poly *poly;
1.193 - if( pvr2_render_trace ) {
1.194 - fprintf( stderr, "-------- %d\n", pvr2_get_frame_count() );
1.195 - pvr2_dump_display_list( display_list, length );
1.196 - }
1.197 - while( cmd_ptr < display_list+(length>>2) ) {
1.198 - unsigned int cmd = *cmd_ptr >> 24;
1.199 - switch( cmd ) {
1.200 - case PVR2_CMD_POLY_OPAQUE:
1.201 - case PVR2_CMD_POLY_TRANS:
1.202 - case PVR2_CMD_POLY_PUNCHOUT:
1.203 - poly = (struct pvr2_poly *)cmd_ptr;
1.204 - if( poly->command & PVR2_POLY_TEXTURED ) {
1.205 - uint32_t addr = PVR2_TEX_ADDR(poly->texture);
1.206 - int width = POLY_TEX_WIDTH(poly);
1.207 - int height = POLY_TEX_HEIGHT(poly);
1.208 - glEnable( GL_TEXTURE_2D );
1.209 - texcache_get_texture( addr, width, height, poly->texture );
1.210 - textured = TRUE;
1.211 - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, POLY_TEX_BLEND(poly) );
1.212 - } else {
1.213 - textured = FALSE;
1.214 - glDisable( GL_TEXTURE_2D );
1.215 - }
1.216 - glBlendFunc( POLY_BLEND_SRC(poly), POLY_BLEND_DEST(poly) );
1.217 - if( poly->command & PVR2_POLY_SPECULAR ) {
1.218 - /* Second block expected */
1.219 - }
1.220 - if( POLY_DEPTH_WRITE(poly) ) {
1.221 - glEnable( GL_DEPTH_TEST );
1.222 - glDepthFunc( POLY_DEPTH_MODE(poly) );
1.223 - } else {
1.224 - glDisable( GL_DEPTH_TEST );
1.225 - }
1.226 -
1.227 - switch( (poly->poly_cfg >> 27) & 0x03 ) {
1.228 - case 0:
1.229 - case 1:
1.230 - glDisable( GL_CULL_FACE );
1.231 - break;
1.232 - case 2:
1.233 - glEnable( GL_CULL_FACE );
1.234 - glFrontFace( GL_CW );
1.235 - break;
1.236 - case 3:
1.237 - glEnable( GL_CULL_FACE );
1.238 - glFrontFace( GL_CCW );
1.239 - }
1.240 - strip_length = POLY_STRIP_VERTEXES( poly );
1.241 - colour_type = POLY_COLOUR_TYPE( poly );
1.242 - vertex_count = 0;
1.243 - if( poly->command & PVR2_POLY_SHADED ) {
1.244 - shaded = TRUE;
1.245 - } else {
1.246 - shaded = FALSE;
1.247 - }
1.248 - if( poly->poly_mode & PVR2_POLY_MODE_TEXALPHA ) {
1.249 - glDisable( GL_BLEND );
1.250 - } else {
1.251 - glEnable( GL_BLEND );
1.252 - }
1.253 -
1.254 - break;
1.255 - case PVR2_CMD_MOD_OPAQUE:
1.256 - case PVR2_CMD_MOD_TRANS:
1.257 - /* TODO */
1.258 - break;
1.259 - case PVR2_CMD_END_OF_LIST:
1.260 - break;
1.261 - case PVR2_CMD_VERTEX_LAST:
1.262 - case PVR2_CMD_VERTEX:
1.263 - if( vertex_count == 0 ) {
1.264 - glBegin( GL_TRIANGLE_STRIP );
1.265 - }
1.266 - vertex_count++;
1.267 -
1.268 - struct pvr2_vertex_packed *vertex = (struct pvr2_vertex_packed *)cmd_ptr;
1.269 - if( textured ) {
1.270 - glTexCoord2f( vertex->s, vertex->t );
1.271 -
1.272 - if( shaded || vertex_count == 1) {
1.273 - switch( colour_type ) {
1.274 - case POLY_COLOUR_PACKED:
1.275 - glColor4ub( vertex->colour >> 16, vertex->colour >> 8,
1.276 - vertex->colour, vertex->colour >> 24 );
1.277 - break;
1.278 - }
1.279 - }
1.280 - } else {
1.281 - if( shaded || vertex_count == 1 ) {
1.282 - switch( colour_type ) {
1.283 - case POLY_COLOUR_PACKED:
1.284 - glColor4ub( vertex->colour >> 16, vertex->colour >> 8,
1.285 - vertex->colour, vertex->colour >> 24 );
1.286 - break;
1.287 - case POLY_COLOUR_FLOAT:
1.288 - {
1.289 - struct pvr2_vertex_float *v = (struct pvr2_vertex_float *)cmd_ptr;
1.290 - glColor4f( v->r, v->g, v->b, v->a );
1.291 - }
1.292 - break;
1.293 - }
1.294 - }
1.295 - }
1.296 -
1.297 - glVertex3f( vertex->x, vertex->y, vertex->z );
1.298 -
1.299 - if( cmd == PVR2_CMD_VERTEX_LAST ) {
1.300 - glEnd();
1.301 - vertex_count = 0;
1.302 - }
1.303 - break;
1.304 - default:
1.305 - ERROR( "Unhandled command %08X in display list", *cmd_ptr );
1.306 - pvr2_dump_display_list( display_list, length );
1.307 - return;
1.308 - }
1.309 - cmd_ptr += 8; /* Next record */
1.310 - }
1.311 -}
1.312
1.313 #define MIN3( a,b,c ) ((a) < (b) ? ( (a) < (c) ? (a) : (c) ) : ((b) < (c) ? (b) : (c)) )
1.314 #define MAX3( a,b,c ) ((a) > (b) ? ( (a) > (c) ? (a) : (c) ) : ((b) > (c) ? (b) : (c)) )
1.315 @@ -440,11 +228,15 @@
1.316 */
1.317 void pvr2_render_draw_backplane( uint32_t mode, uint32_t *poly )
1.318 {
1.319 +
1.320 if( (mode >> 24) == 0x01 ) {
1.321 /* Packed colour. I think */
1.322 pvr2_bgplane_packed_t bg = (pvr2_bgplane_packed_t)poly;
1.323 if( bg->colour1 != bg->colour2 || bg->colour2 != bg->colour3 ) {
1.324 WARN( "Multiple background colours specified. Confused" );
1.325 + fprintf( stderr, "bgplane mode: %08X PBUF: %08X\n", mode,
1.326 + MMIO_READ( PVR2, OBJBASE ) );
1.327 + fwrite_dump( poly, 80, stderr );
1.328 }
1.329 float x1 = MIN3( bg->x1, bg->x2, bg->x3 );
1.330 float y1 = MIN3( bg->y1, bg->y2, bg->y3 );
1.331 @@ -500,38 +292,29 @@
1.332 pvr2_render_prepare_context( render_addr, width, height, colour_format,
1.333 bgplanez, render_to_tex );
1.334
1.335 - uint32_t *display_list =
1.336 - (uint32_t *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, OBJBASE ));
1.337 -
1.338 - uint32_t display_length = *display_list++;
1.339 -
1.340 int clip_x = MMIO_READ( PVR2, HCLIP ) & 0x03FF;
1.341 int clip_y = MMIO_READ( PVR2, VCLIP ) & 0x03FF;
1.342 int clip_width = ((MMIO_READ( PVR2, HCLIP ) >> 16) & 0x03FF) - clip_x + 1;
1.343 int clip_height= ((MMIO_READ( PVR2, VCLIP ) >> 16) & 0x03FF) - clip_y + 1;
1.344
1.345 - if( clip_x == 0 && clip_y == 0 && clip_width == width && clip_height == height ) {
1.346 - glDisable( GL_SCISSOR_TEST );
1.347 - } else {
1.348 - glEnable( GL_SCISSOR_TEST );
1.349 - glScissor( clip_x, clip_y, clip_width, clip_height );
1.350 - }
1.351 -
1.352 /* Fog setup goes here */
1.353
1.354 /* Render the background plane */
1.355 uint32_t bgplane_mode = MMIO_READ(PVR2, BGPLANE);
1.356 - uint32_t *bgplane = display_list + (((bgplane_mode & 0x00FFFFFF)) >> 3) - 1;
1.357 + uint32_t *display_list =
1.358 + (uint32_t *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, OBJBASE ));
1.359 +
1.360 + uint32_t *bgplane = display_list + (((bgplane_mode & 0x00FFFFFF)) >> 3) ;
1.361 pvr2_render_draw_backplane( bgplane_mode, bgplane );
1.362
1.363 - /* Render the display list */
1.364 - pvr2_render_display_list( display_list, display_length );
1.365 + pvr2_render_tilebuffer( width, height, clip_x, clip_y,
1.366 + clip_x + clip_width, clip_y + clip_height );
1.367
1.368 /* Post-render cleanup and update */
1.369
1.370 /* Add frame, fps, etc data */
1.371 + //glDrawGrid( width, height );
1.372 glPrintf( 4, 16, "Frame %d", pvr2_get_frame_count() );
1.373 -
1.374 /* Generate end of render event */
1.375 asic_event( EVENT_PVR_RENDER_DONE );
1.376 DEBUG( "Rendered frame %d", pvr2_get_frame_count() );
.