Search
lxdream.org :: lxdream :: r128:f98ce97cacdd
lxdream 0.9.1
released Jun 29
Download Now
changeset128:f98ce97cacdd
parent127:4ba79389bb6d
child129:88e5ebc991e3
authornkeynes
dateThu Mar 23 13:19:55 2006 +0000 (18 years ago)
Add initial backplane support
Turn GL_BLEND on for translucent polys
src/pvr2/pvr2mmio.h
src/pvr2/render.c
1.1 --- a/src/pvr2/pvr2mmio.h Thu Mar 23 13:19:15 2006 +0000
1.2 +++ b/src/pvr2/pvr2mmio.h Thu Mar 23 13:19:55 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: pvr2mmio.h,v 1.2 2006-03-15 13:16:50 nkeynes Exp $
1.6 + * $Id: pvr2mmio.h,v 1.3 2006-03-23 13:19:55 nkeynes Exp $
1.7 *
1.8 * PVR2 (video chip) MMIO register definitions.
1.9 *
1.10 @@ -41,7 +41,7 @@
1.11 LONG_PORT( 0x07C, OBJCFG, PORT_MRW, 0, "Object config" )
1.12 LONG_PORT( 0x084, TSPCLIP, PORT_MRW, 0, "Texture clip distance (float32)" )
1.13 LONG_PORT( 0x088, BGPLANEZ, PORT_MRW, 0, "Background plane depth (float32)" )
1.14 - LONG_PORT( 0x08C, BGPLANECFG, PORT_MRW, 0, "Background plane config" )
1.15 + LONG_PORT( 0x08C, BGPLANE, PORT_MRW, 0, "Background plane config" )
1.16 LONG_PORT( 0x0B0, FOGTBLCOL, PORT_MRW, 0, "Fog table colour" )
1.17 LONG_PORT( 0x0B4, FOGVRTCOL, PORT_MRW, 0, "Fog vertex colour" )
1.18 LONG_PORT( 0x0B8, FOGCOEFF, PORT_MRW, 0, "Fog density coefficient (float16)" )
2.1 --- a/src/pvr2/render.c Thu Mar 23 13:19:15 2006 +0000
2.2 +++ b/src/pvr2/render.c Thu Mar 23 13:19:55 2006 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: render.c,v 1.5 2006-03-20 11:59:15 nkeynes Exp $
2.6 + * $Id: render.c,v 1.6 2006-03-23 13:19:55 nkeynes Exp $
2.7 *
2.8 * PVR2 Renderer support. This is where the real work happens.
2.9 *
2.10 @@ -47,7 +47,7 @@
2.11 #define POLY_STRIP_TYPE(poly) ( pvr2_poly_type[((poly->command)>>18)&0x03] )
2.12 #define POLY_STRIP_VERTEXES(poly) ( pvr2_poly_vertexes[((poly->command)>>18)&0x03] )
2.13 #define POLY_DEPTH_MODE(poly) ( pvr2_poly_depthmode[poly->poly_cfg>>29] )
2.14 -#define POLY_DEPTH_WRITE(poly) (poly->poly_cfg&0x04000000)
2.15 +#define POLY_DEPTH_WRITE(poly) ((poly->poly_cfg&0x04000000) == 0 )
2.16 #define POLY_TEX_WIDTH(poly) ( 1<< (((poly->poly_mode >> 3) & 0x07 ) + 3) )
2.17 #define POLY_TEX_HEIGHT(poly) ( 1<< (((poly->poly_mode) & 0x07 ) + 3) )
2.18 #define POLY_BLEND_SRC(poly) ( pvr2_poly_srcblend[(poly->poly_mode) >> 29] )
2.19 @@ -114,6 +114,29 @@
2.20 float f;
2.21 };
2.22
2.23 +struct pvr2_vertex_float {
2.24 + uint32_t command;
2.25 + float x,y,z;
2.26 + float a, r, g, b;
2.27 +};
2.28 +
2.29 +union pvr2_vertex {
2.30 + struct pvr2_vertex_packed pack;
2.31 + struct pvr2_vertex_float flt;
2.32 +};
2.33 +
2.34 +typedef struct pvr2_bgplane_packed {
2.35 + uint32_t poly_cfg, poly_mode;
2.36 + uint32_t texture_mode;
2.37 + float x1, y1, z1;
2.38 + uint32_t colour1;
2.39 + float x2, y2, z2;
2.40 + uint32_t colour2;
2.41 + float x3, y3, z3;
2.42 + uint32_t colour3;
2.43 +} *pvr2_bgplane_packed_t;
2.44 +
2.45 +
2.46
2.47 void pvr2_render_copy_to_sh4( pvr2_render_buffer_t buffer,
2.48 gboolean backBuffer );
2.49 @@ -132,6 +155,7 @@
2.50 va_end(ap);
2.51
2.52 if( pvr2_render_font_list == -1 ) {
2.53 + glColor3f( 1.0, 1.0, 1.0 );
2.54 pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
2.55 }
2.56
2.57 @@ -181,6 +205,7 @@
2.58 static void pvr2_render_prepare_context( sh4addr_t render_addr,
2.59 uint32_t width, uint32_t height,
2.60 uint32_t colour_format,
2.61 + float bgplanez,
2.62 gboolean texture_target )
2.63 {
2.64 /* Select and initialize the render context */
2.65 @@ -213,28 +238,37 @@
2.66 glViewport( 0, 0, width, height );
2.67 glMatrixMode(GL_PROJECTION);
2.68 glLoadIdentity();
2.69 - glOrtho( 0, width, height, 0, 0, -65535 );
2.70 + glOrtho( 0, width, height, 0, bgplanez, -1 );
2.71 glMatrixMode(GL_MODELVIEW);
2.72 glLoadIdentity();
2.73 glCullFace( GL_BACK );
2.74
2.75 /* Clear out the buffers */
2.76 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
2.77 - glClearDepth(1.0f);
2.78 + glClearDepth(bgplanez);
2.79 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
2.80 }
2.81
2.82 static void pvr2_dump_display_list( uint32_t * display_list, uint32_t length )
2.83 {
2.84 uint32_t i;
2.85 - for( i =0; i<length; i+=4 ) {
2.86 - if( (i % 32) == 0 ) {
2.87 + gboolean vertex = FALSE;
2.88 + for( i =0; i<length>>2; i++ ) {
2.89 + if( (i % 8) == 0 ) {
2.90 if( i != 0 )
2.91 fprintf( stderr, "\n" );
2.92 - fprintf( stderr, "%08X:", i );
2.93 + fprintf( stderr, "%08X:", i*32 );
2.94 + if( display_list[i] == 0xE0000000 ||
2.95 + display_list[i] == 0xF0000000 )
2.96 + vertex = TRUE;
2.97 + else vertex = FALSE;
2.98 }
2.99 - fprintf( stderr, " %08X", display_list[i] );
2.100 + if( vertex && (i%8) > 0 && (i%8) < 4 )
2.101 + fprintf( stderr, " %f", ((float *)display_list)[i] );
2.102 + else
2.103 + fprintf( stderr, " %08X", display_list[i] );
2.104 }
2.105 + fprintf( stderr, "\n" );
2.106 }
2.107
2.108 static void pvr2_render_display_list( uint32_t *display_list, uint32_t length )
2.109 @@ -244,10 +278,19 @@
2.110 int colour_type;
2.111 gboolean textured = FALSE;
2.112 struct pvr2_poly *poly;
2.113 + fprintf( stderr, "-------- %d\n", pvr2_frame_counter );
2.114 + pvr2_dump_display_list( display_list, length );
2.115 while( cmd_ptr < display_list+length ) {
2.116 unsigned int cmd = *cmd_ptr >> 24;
2.117 switch( cmd ) {
2.118 case PVR2_CMD_POLY_OPAQUE:
2.119 + case PVR2_CMD_POLY_TRANS:
2.120 + if( cmd == PVR2_CMD_POLY_TRANS ) {
2.121 + glEnable( GL_BLEND );
2.122 + } else {
2.123 + glDisable( GL_BLEND );
2.124 + }
2.125 +
2.126 poly = (struct pvr2_poly *)cmd_ptr;
2.127 if( poly->command & PVR2_POLY_TEXTURED ) {
2.128 uint32_t addr = PVR2_TEX_ADDR(poly->texture);
2.129 @@ -302,14 +345,28 @@
2.130 struct pvr2_vertex_packed *vertex = (struct pvr2_vertex_packed *)cmd_ptr;
2.131 if( textured ) {
2.132 glTexCoord2f( vertex->s, vertex->t );
2.133 +
2.134 + switch( colour_type ) {
2.135 + case POLY_COLOUR_PACKED:
2.136 + glColor4ub( vertex->colour >> 16, vertex->colour >> 8,
2.137 + vertex->colour, vertex->colour >> 24 );
2.138 + break;
2.139 + }
2.140 + } else {
2.141 + switch( colour_type ) {
2.142 + case POLY_COLOUR_PACKED:
2.143 + glColor4ub( vertex->colour >> 16, vertex->colour >> 8,
2.144 + vertex->colour, vertex->colour >> 24 );
2.145 + break;
2.146 + case POLY_COLOUR_FLOAT:
2.147 + {
2.148 + struct pvr2_vertex_float *v = (struct pvr2_vertex_float *)cmd_ptr;
2.149 + glColor4f( v->r, v->g, v->b, v->a );
2.150 + }
2.151 + break;
2.152 + }
2.153 }
2.154
2.155 - switch( colour_type ) {
2.156 - case POLY_COLOUR_PACKED:
2.157 - glColor4ub( vertex->colour >> 16, vertex->colour >> 8,
2.158 - vertex->colour, vertex->colour >> 24 );
2.159 - break;
2.160 - }
2.161 glVertex3f( vertex->x, vertex->y, vertex->z );
2.162
2.163 if( cmd == PVR2_CMD_VERTEX_LAST ) {
2.164 @@ -328,6 +385,42 @@
2.165 }
2.166 }
2.167
2.168 +#define MIN3( a,b,c ) ((a) < (b) ? ( (a) < (c) ? (a) : (c) ) : ((b) < (c) ? (b) : (c)) )
2.169 +#define MAX3( a,b,c ) ((a) > (b) ? ( (a) > (c) ? (a) : (c) ) : ((b) > (c) ? (b) : (c)) )
2.170 +
2.171 +/**
2.172 + * Render the background plane as best we can. Unfortunately information
2.173 + * is a little scant, to say the least.
2.174 + */
2.175 +void pvr2_render_draw_backplane( uint32_t mode, uint32_t *poly )
2.176 +{
2.177 + if( (mode >> 24) == 0x01 ) {
2.178 + /* Packed colour. I think */
2.179 + pvr2_bgplane_packed_t bg = (pvr2_bgplane_packed_t)poly;
2.180 + if( bg->colour1 != bg->colour2 || bg->colour2 != bg->colour3 ) {
2.181 + WARN( "Multiple background colours specified. Confused" );
2.182 + }
2.183 + float x1 = MIN3( bg->x1, bg->x2, bg->x3 );
2.184 + float y1 = MIN3( bg->y1, bg->y2, bg->y3 );
2.185 + float x2 = MAX3( bg->x1, bg->x2, bg->x3 );
2.186 + float y2 = MAX3( bg->y1, bg->y2, bg->y3 );
2.187 + float z = MIN3( bg->z1, bg->z2, bg->z3 );
2.188 + glDisable( GL_TEXTURE_2D );
2.189 + glDisable( GL_DEPTH_TEST );
2.190 + glColor3ub( (uint8_t)(bg->colour1 >> 16), (uint8_t)(bg->colour1 >> 8),
2.191 + (uint8_t)bg->colour1 );
2.192 + glBegin( GL_QUADS );
2.193 + glVertex3f( x1, y1, z );
2.194 + glVertex3f( x2, y1, z );
2.195 + glVertex3f( x2, y2, z );
2.196 + glVertex3f( x1, y2, z );
2.197 + glEnd();
2.198 + } else {
2.199 + WARN( "Unknown bgplane mode: %08X", mode );
2.200 + fwrite_dump( poly, 48, stderr );
2.201 + }
2.202 +}
2.203 +
2.204 /**
2.205 * Render a complete scene into the OpenGL back buffer.
2.206 * Note: this will probably need to be broken up eventually once timings are
2.207 @@ -352,15 +445,18 @@
2.208 render_addr = (render_addr & 0x00FFFFFF) + PVR2_RAM_BASE;
2.209 render_to_tex = FALSE;
2.210 }
2.211 +
2.212 + float bgplanez = MMIO_READF( PVR2, BGPLANEZ );
2.213 uint32_t render_mode = MMIO_READ( PVR2, RENDMODE );
2.214 int width = 640; /* FIXME - get this from the tile buffer */
2.215 int height = 480;
2.216 int colour_format = pvr2_render_colour_format[render_mode&0x07];
2.217 pvr2_render_prepare_context( render_addr, width, height, colour_format,
2.218 - render_to_tex );
2.219 + bgplanez, render_to_tex );
2.220
2.221 uint32_t *display_list =
2.222 (uint32_t *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, OBJBASE ));
2.223 +
2.224 uint32_t display_length = *display_list++;
2.225
2.226 int clip_x = MMIO_READ( PVR2, HCLIP ) & 0x03FF;
2.227 @@ -377,6 +473,11 @@
2.228
2.229 /* Fog setup goes here */
2.230
2.231 + /* Render the background plane */
2.232 + uint32_t bgplane_mode = MMIO_READ(PVR2, BGPLANE);
2.233 + uint32_t *bgplane = display_list + (((bgplane_mode & 0x00FFFFFF)) >> 3) - 1;
2.234 + pvr2_render_draw_backplane( bgplane_mode, bgplane );
2.235 +
2.236 /* Render the display list */
2.237 pvr2_render_display_list( display_list, display_length );
2.238
2.239 @@ -384,7 +485,6 @@
2.240
2.241 /* Add frame, fps, etc data */
2.242 glRasterPos2i( 4, 16 );
2.243 - // glColor3f( 0.0f, 0.0f, 1.0f );
2.244 glPrintf( "Frame %d", pvr2_frame_counter );
2.245
2.246 /* Generate end of render event */
.