filename | src/pvr2/render.c |
changeset | 128:f98ce97cacdd |
prev | 118:fcec54454d10 |
next | 132:48a8cc541742 |
author | nkeynes |
date | Thu Mar 23 13:19:55 2006 +0000 (14 years ago) |
permissions | -rw-r--r-- |
last change | Add initial backplane support Turn GL_BLEND on for translucent polys |
file | annotate | diff | log | raw |
1.1 --- a/src/pvr2/render.c Mon Mar 20 11:59:15 2006 +00001.2 +++ b/src/pvr2/render.c Thu Mar 23 13:19:55 2006 +00001.3 @@ -1,5 +1,5 @@1.4 /**1.5 - * $Id: render.c,v 1.5 2006-03-20 11:59:15 nkeynes Exp $1.6 + * $Id: render.c,v 1.6 2006-03-23 13:19:55 nkeynes Exp $1.7 *1.8 * PVR2 Renderer support. This is where the real work happens.1.9 *1.10 @@ -47,7 +47,7 @@1.11 #define POLY_STRIP_TYPE(poly) ( pvr2_poly_type[((poly->command)>>18)&0x03] )1.12 #define POLY_STRIP_VERTEXES(poly) ( pvr2_poly_vertexes[((poly->command)>>18)&0x03] )1.13 #define POLY_DEPTH_MODE(poly) ( pvr2_poly_depthmode[poly->poly_cfg>>29] )1.14 -#define POLY_DEPTH_WRITE(poly) (poly->poly_cfg&0x04000000)1.15 +#define POLY_DEPTH_WRITE(poly) ((poly->poly_cfg&0x04000000) == 0 )1.16 #define POLY_TEX_WIDTH(poly) ( 1<< (((poly->poly_mode >> 3) & 0x07 ) + 3) )1.17 #define POLY_TEX_HEIGHT(poly) ( 1<< (((poly->poly_mode) & 0x07 ) + 3) )1.18 #define POLY_BLEND_SRC(poly) ( pvr2_poly_srcblend[(poly->poly_mode) >> 29] )1.19 @@ -114,6 +114,29 @@1.20 float f;1.21 };1.23 +struct pvr2_vertex_float {1.24 + uint32_t command;1.25 + float x,y,z;1.26 + float a, r, g, b;1.27 +};1.28 +1.29 +union pvr2_vertex {1.30 + struct pvr2_vertex_packed pack;1.31 + struct pvr2_vertex_float flt;1.32 +};1.33 +1.34 +typedef struct pvr2_bgplane_packed {1.35 + uint32_t poly_cfg, poly_mode;1.36 + uint32_t texture_mode;1.37 + float x1, y1, z1;1.38 + uint32_t colour1;1.39 + float x2, y2, z2;1.40 + uint32_t colour2;1.41 + float x3, y3, z3;1.42 + uint32_t colour3;1.43 +} *pvr2_bgplane_packed_t;1.44 +1.45 +1.47 void pvr2_render_copy_to_sh4( pvr2_render_buffer_t buffer,1.48 gboolean backBuffer );1.49 @@ -132,6 +155,7 @@1.50 va_end(ap);1.52 if( pvr2_render_font_list == -1 ) {1.53 + glColor3f( 1.0, 1.0, 1.0 );1.54 pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");1.55 }1.57 @@ -181,6 +205,7 @@1.58 static void pvr2_render_prepare_context( sh4addr_t render_addr,1.59 uint32_t width, uint32_t height,1.60 uint32_t colour_format,1.61 + float bgplanez,1.62 gboolean texture_target )1.63 {1.64 /* Select and initialize the render context */1.65 @@ -213,28 +238,37 @@1.66 glViewport( 0, 0, width, height );1.67 glMatrixMode(GL_PROJECTION);1.68 glLoadIdentity();1.69 - glOrtho( 0, width, height, 0, 0, -65535 );1.70 + glOrtho( 0, width, height, 0, bgplanez, -1 );1.71 glMatrixMode(GL_MODELVIEW);1.72 glLoadIdentity();1.73 glCullFace( GL_BACK );1.75 /* Clear out the buffers */1.76 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);1.77 - glClearDepth(1.0f);1.78 + glClearDepth(bgplanez);1.79 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );1.80 }1.82 static void pvr2_dump_display_list( uint32_t * display_list, uint32_t length )1.83 {1.84 uint32_t i;1.85 - for( i =0; i<length; i+=4 ) {1.86 - if( (i % 32) == 0 ) {1.87 + gboolean vertex = FALSE;1.88 + for( i =0; i<length>>2; i++ ) {1.89 + if( (i % 8) == 0 ) {1.90 if( i != 0 )1.91 fprintf( stderr, "\n" );1.92 - fprintf( stderr, "%08X:", i );1.93 + fprintf( stderr, "%08X:", i*32 );1.94 + if( display_list[i] == 0xE0000000 ||1.95 + display_list[i] == 0xF0000000 )1.96 + vertex = TRUE;1.97 + else vertex = FALSE;1.98 }1.99 - fprintf( stderr, " %08X", display_list[i] );1.100 + if( vertex && (i%8) > 0 && (i%8) < 4 )1.101 + fprintf( stderr, " %f", ((float *)display_list)[i] );1.102 + else1.103 + fprintf( stderr, " %08X", display_list[i] );1.104 }1.105 + fprintf( stderr, "\n" );1.106 }1.108 static void pvr2_render_display_list( uint32_t *display_list, uint32_t length )1.109 @@ -244,10 +278,19 @@1.110 int colour_type;1.111 gboolean textured = FALSE;1.112 struct pvr2_poly *poly;1.113 + fprintf( stderr, "-------- %d\n", pvr2_frame_counter );1.114 + pvr2_dump_display_list( display_list, length );1.115 while( cmd_ptr < display_list+length ) {1.116 unsigned int cmd = *cmd_ptr >> 24;1.117 switch( cmd ) {1.118 case PVR2_CMD_POLY_OPAQUE:1.119 + case PVR2_CMD_POLY_TRANS:1.120 + if( cmd == PVR2_CMD_POLY_TRANS ) {1.121 + glEnable( GL_BLEND );1.122 + } else {1.123 + glDisable( GL_BLEND );1.124 + }1.125 +1.126 poly = (struct pvr2_poly *)cmd_ptr;1.127 if( poly->command & PVR2_POLY_TEXTURED ) {1.128 uint32_t addr = PVR2_TEX_ADDR(poly->texture);1.129 @@ -302,14 +345,28 @@1.130 struct pvr2_vertex_packed *vertex = (struct pvr2_vertex_packed *)cmd_ptr;1.131 if( textured ) {1.132 glTexCoord2f( vertex->s, vertex->t );1.133 +1.134 + switch( colour_type ) {1.135 + case POLY_COLOUR_PACKED:1.136 + glColor4ub( vertex->colour >> 16, vertex->colour >> 8,1.137 + vertex->colour, vertex->colour >> 24 );1.138 + break;1.139 + }1.140 + } else {1.141 + switch( colour_type ) {1.142 + case POLY_COLOUR_PACKED:1.143 + glColor4ub( vertex->colour >> 16, vertex->colour >> 8,1.144 + vertex->colour, vertex->colour >> 24 );1.145 + break;1.146 + case POLY_COLOUR_FLOAT:1.147 + {1.148 + struct pvr2_vertex_float *v = (struct pvr2_vertex_float *)cmd_ptr;1.149 + glColor4f( v->r, v->g, v->b, v->a );1.150 + }1.151 + break;1.152 + }1.153 }1.155 - switch( colour_type ) {1.156 - case POLY_COLOUR_PACKED:1.157 - glColor4ub( vertex->colour >> 16, vertex->colour >> 8,1.158 - vertex->colour, vertex->colour >> 24 );1.159 - break;1.160 - }1.161 glVertex3f( vertex->x, vertex->y, vertex->z );1.163 if( cmd == PVR2_CMD_VERTEX_LAST ) {1.164 @@ -328,6 +385,42 @@1.165 }1.166 }1.168 +#define MIN3( a,b,c ) ((a) < (b) ? ( (a) < (c) ? (a) : (c) ) : ((b) < (c) ? (b) : (c)) )1.169 +#define MAX3( a,b,c ) ((a) > (b) ? ( (a) > (c) ? (a) : (c) ) : ((b) > (c) ? (b) : (c)) )1.170 +1.171 +/**1.172 + * Render the background plane as best we can. Unfortunately information1.173 + * is a little scant, to say the least.1.174 + */1.175 +void pvr2_render_draw_backplane( uint32_t mode, uint32_t *poly )1.176 +{1.177 + if( (mode >> 24) == 0x01 ) {1.178 + /* Packed colour. I think */1.179 + pvr2_bgplane_packed_t bg = (pvr2_bgplane_packed_t)poly;1.180 + if( bg->colour1 != bg->colour2 || bg->colour2 != bg->colour3 ) {1.181 + WARN( "Multiple background colours specified. Confused" );1.182 + }1.183 + float x1 = MIN3( bg->x1, bg->x2, bg->x3 );1.184 + float y1 = MIN3( bg->y1, bg->y2, bg->y3 );1.185 + float x2 = MAX3( bg->x1, bg->x2, bg->x3 );1.186 + float y2 = MAX3( bg->y1, bg->y2, bg->y3 );1.187 + float z = MIN3( bg->z1, bg->z2, bg->z3 );1.188 + glDisable( GL_TEXTURE_2D );1.189 + glDisable( GL_DEPTH_TEST );1.190 + glColor3ub( (uint8_t)(bg->colour1 >> 16), (uint8_t)(bg->colour1 >> 8),1.191 + (uint8_t)bg->colour1 );1.192 + glBegin( GL_QUADS );1.193 + glVertex3f( x1, y1, z );1.194 + glVertex3f( x2, y1, z );1.195 + glVertex3f( x2, y2, z );1.196 + glVertex3f( x1, y2, z );1.197 + glEnd();1.198 + } else {1.199 + WARN( "Unknown bgplane mode: %08X", mode );1.200 + fwrite_dump( poly, 48, stderr );1.201 + }1.202 +}1.203 +1.204 /**1.205 * Render a complete scene into the OpenGL back buffer.1.206 * Note: this will probably need to be broken up eventually once timings are1.207 @@ -352,15 +445,18 @@1.208 render_addr = (render_addr & 0x00FFFFFF) + PVR2_RAM_BASE;1.209 render_to_tex = FALSE;1.210 }1.211 +1.212 + float bgplanez = MMIO_READF( PVR2, BGPLANEZ );1.213 uint32_t render_mode = MMIO_READ( PVR2, RENDMODE );1.214 int width = 640; /* FIXME - get this from the tile buffer */1.215 int height = 480;1.216 int colour_format = pvr2_render_colour_format[render_mode&0x07];1.217 pvr2_render_prepare_context( render_addr, width, height, colour_format,1.218 - render_to_tex );1.219 + bgplanez, render_to_tex );1.221 uint32_t *display_list =1.222 (uint32_t *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, OBJBASE ));1.223 +1.224 uint32_t display_length = *display_list++;1.226 int clip_x = MMIO_READ( PVR2, HCLIP ) & 0x03FF;1.227 @@ -377,6 +473,11 @@1.229 /* Fog setup goes here */1.231 + /* Render the background plane */1.232 + uint32_t bgplane_mode = MMIO_READ(PVR2, BGPLANE);1.233 + uint32_t *bgplane = display_list + (((bgplane_mode & 0x00FFFFFF)) >> 3) - 1;1.234 + pvr2_render_draw_backplane( bgplane_mode, bgplane );1.235 +1.236 /* Render the display list */1.237 pvr2_render_display_list( display_list, display_length );1.239 @@ -384,7 +485,6 @@1.241 /* Add frame, fps, etc data */1.242 glRasterPos2i( 4, 16 );1.243 - // glColor3f( 0.0f, 0.0f, 1.0f );1.244 glPrintf( "Frame %d", pvr2_frame_counter );1.246 /* Generate end of render event */
.