Search
lxdream.org :: lxdream :: r132:48a8cc541742
lxdream 0.9.1
released Jun 29
Download Now
changeset132:48a8cc541742
parent131:4c25f1b20664
child133:249aeda31f02
authornkeynes
dateThu Mar 30 11:29:54 2006 +0000 (14 years ago)
Differentiate between flat + gouraud shaded polys - use colour of first vertex only
Remove vertex count checks - doesn't seem to be correct anyway.
Add check for unrecognized command codes
other minor tweaks
src/pvr2/render.c
1.1 --- a/src/pvr2/render.c Thu Mar 30 11:27:11 2006 +0000
1.2 +++ b/src/pvr2/render.c Thu Mar 30 11:29:54 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: render.c,v 1.6 2006-03-23 13:19:55 nkeynes Exp $
1.6 + * $Id: render.c,v 1.7 2006-03-30 11:29:54 nkeynes Exp $
1.7 *
1.8 * PVR2 Renderer support. This is where the real work happens.
1.9 *
1.10 @@ -55,8 +55,6 @@
1.11 #define POLY_TEX_BLEND(poly) ( pvr2_poly_texblend[((poly->poly_mode) >> 6)&0x03] )
1.12 #define POLY_COLOUR_TYPE(poly) ( poly->command & 0x00000030 )
1.13
1.14 -extern uint32_t pvr2_frame_counter;
1.15 -
1.16 /**
1.17 * Describes a rendering buffer that's actually held in GL, for when we need
1.18 * to fetch the bits back to vram.
1.19 @@ -142,8 +140,9 @@
1.20 gboolean backBuffer );
1.21
1.22 int pvr2_render_font_list = -1;
1.23 +int pvr2_render_trace = 0;
1.24
1.25 -int glPrintf( const char *fmt, ... )
1.26 +int glPrintf( int x, int y, const char *fmt, ... )
1.27 {
1.28 va_list ap; /* our argument pointer */
1.29 char buf[256];
1.30 @@ -154,13 +153,15 @@
1.31 len = vsnprintf(buf, sizeof(buf), fmt, ap);
1.32 va_end(ap);
1.33
1.34 - if( pvr2_render_font_list == -1 ) {
1.35 - glColor3f( 1.0, 1.0, 1.0 );
1.36 - pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
1.37 - }
1.38
1.39 glPushAttrib(GL_LIST_BIT);
1.40 + glDisable( GL_DEPTH_TEST );
1.41 + glDisable( GL_BLEND );
1.42 + glDisable( GL_TEXTURE_2D );
1.43 + glDisable( GL_ALPHA_TEST );
1.44 glListBase(pvr2_render_font_list - 32);
1.45 + glColor3f( 1.0, 1.0, 1.0 );
1.46 + glRasterPos2i( x, y );
1.47 glCallLists(len, GL_UNSIGNED_BYTE, buf);
1.48 glPopAttrib();
1.49
1.50 @@ -211,6 +212,10 @@
1.51 /* Select and initialize the render context */
1.52 video_driver->set_render_format( width, height, colour_format, texture_target );
1.53
1.54 + if( pvr2_render_font_list == -1 ) {
1.55 + pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
1.56 + }
1.57 +
1.58 if( back_buffer.render_addr != -1 &&
1.59 back_buffer.render_addr != render_addr ) {
1.60 /* There's a current back buffer, and we're rendering somewhere else -
1.61 @@ -257,7 +262,7 @@
1.62 if( (i % 8) == 0 ) {
1.63 if( i != 0 )
1.64 fprintf( stderr, "\n" );
1.65 - fprintf( stderr, "%08X:", i*32 );
1.66 + fprintf( stderr, "%08X:", i*4 );
1.67 if( display_list[i] == 0xE0000000 ||
1.68 display_list[i] == 0xF0000000 )
1.69 vertex = TRUE;
1.70 @@ -277,20 +282,18 @@
1.71 int strip_length = 0, vertex_count = 0;
1.72 int colour_type;
1.73 gboolean textured = FALSE;
1.74 + gboolean shaded = FALSE;
1.75 struct pvr2_poly *poly;
1.76 - fprintf( stderr, "-------- %d\n", pvr2_frame_counter );
1.77 - pvr2_dump_display_list( display_list, length );
1.78 - while( cmd_ptr < display_list+length ) {
1.79 + if( pvr2_render_trace ) {
1.80 + fprintf( stderr, "-------- %d\n", pvr2_get_frame_count() );
1.81 + pvr2_dump_display_list( display_list, length );
1.82 + }
1.83 + while( cmd_ptr < display_list+(length>>2) ) {
1.84 unsigned int cmd = *cmd_ptr >> 24;
1.85 switch( cmd ) {
1.86 case PVR2_CMD_POLY_OPAQUE:
1.87 case PVR2_CMD_POLY_TRANS:
1.88 - if( cmd == PVR2_CMD_POLY_TRANS ) {
1.89 - glEnable( GL_BLEND );
1.90 - } else {
1.91 - glDisable( GL_BLEND );
1.92 - }
1.93 -
1.94 + case PVR2_CMD_POLY_PUNCHOUT:
1.95 poly = (struct pvr2_poly *)cmd_ptr;
1.96 if( poly->command & PVR2_POLY_TEXTURED ) {
1.97 uint32_t addr = PVR2_TEX_ADDR(poly->texture);
1.98 @@ -331,14 +334,28 @@
1.99 strip_length = POLY_STRIP_VERTEXES( poly );
1.100 colour_type = POLY_COLOUR_TYPE( poly );
1.101 vertex_count = 0;
1.102 + if( poly->command & PVR2_POLY_SHADED ) {
1.103 + shaded = TRUE;
1.104 + } else {
1.105 + shaded = FALSE;
1.106 + }
1.107 + if( poly->poly_mode & PVR2_POLY_MODE_TEXALPHA ) {
1.108 + glDisable( GL_BLEND );
1.109 + } else {
1.110 + glEnable( GL_BLEND );
1.111 + }
1.112 +
1.113 + break;
1.114 + case PVR2_CMD_MOD_OPAQUE:
1.115 + case PVR2_CMD_MOD_TRANS:
1.116 + /* TODO */
1.117 + break;
1.118 + case PVR2_CMD_END_OF_LIST:
1.119 break;
1.120 case PVR2_CMD_VERTEX_LAST:
1.121 case PVR2_CMD_VERTEX:
1.122 if( vertex_count == 0 ) {
1.123 - if( strip_length == 3 )
1.124 - glBegin( GL_TRIANGLES );
1.125 - else
1.126 - glBegin( GL_TRIANGLE_STRIP );
1.127 + glBegin( GL_TRIANGLE_STRIP );
1.128 }
1.129 vertex_count++;
1.130
1.131 @@ -346,24 +363,28 @@
1.132 if( textured ) {
1.133 glTexCoord2f( vertex->s, vertex->t );
1.134
1.135 - switch( colour_type ) {
1.136 - case POLY_COLOUR_PACKED:
1.137 - glColor4ub( vertex->colour >> 16, vertex->colour >> 8,
1.138 - vertex->colour, vertex->colour >> 24 );
1.139 - break;
1.140 + if( shaded || vertex_count == 1) {
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 + }
1.147 }
1.148 } else {
1.149 - switch( colour_type ) {
1.150 - case POLY_COLOUR_PACKED:
1.151 - glColor4ub( vertex->colour >> 16, vertex->colour >> 8,
1.152 - vertex->colour, vertex->colour >> 24 );
1.153 - break;
1.154 - case POLY_COLOUR_FLOAT:
1.155 - {
1.156 - struct pvr2_vertex_float *v = (struct pvr2_vertex_float *)cmd_ptr;
1.157 - glColor4f( v->r, v->g, v->b, v->a );
1.158 + if( shaded || vertex_count == 1 ) {
1.159 + switch( colour_type ) {
1.160 + case POLY_COLOUR_PACKED:
1.161 + glColor4ub( vertex->colour >> 16, vertex->colour >> 8,
1.162 + vertex->colour, vertex->colour >> 24 );
1.163 + break;
1.164 + case POLY_COLOUR_FLOAT:
1.165 + {
1.166 + struct pvr2_vertex_float *v = (struct pvr2_vertex_float *)cmd_ptr;
1.167 + glColor4f( v->r, v->g, v->b, v->a );
1.168 + }
1.169 + break;
1.170 }
1.171 - break;
1.172 }
1.173 }
1.174
1.175 @@ -373,13 +394,11 @@
1.176 glEnd();
1.177 vertex_count = 0;
1.178 }
1.179 -
1.180 - if( vertex_count >= strip_length ) {
1.181 - ERROR( "Rendering long strip (expected end after %d)", strip_length );
1.182 - pvr2_dump_display_list( display_list, length );
1.183 - return;
1.184 - }
1.185 break;
1.186 + default:
1.187 + ERROR( "Unhandled command %08X in display list", *cmd_ptr );
1.188 + pvr2_dump_display_list( display_list, length );
1.189 + return;
1.190 }
1.191 cmd_ptr += 8; /* Next record */
1.192 }
1.193 @@ -484,12 +503,11 @@
1.194 /* Post-render cleanup and update */
1.195
1.196 /* Add frame, fps, etc data */
1.197 - glRasterPos2i( 4, 16 );
1.198 - glPrintf( "Frame %d", pvr2_frame_counter );
1.199 + glPrintf( 4, 16, "Frame %d", pvr2_get_frame_count() );
1.200
1.201 /* Generate end of render event */
1.202 asic_event( EVENT_PVR_RENDER_DONE );
1.203 - DEBUG( "Rendered frame %d", pvr2_frame_counter );
1.204 + DEBUG( "Rendered frame %d", pvr2_get_frame_count() );
1.205 }
1.206
1.207
.