Search
lxdream.org :: lxdream/src/pvr2/render.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/render.c
changeset 108:565de331ccec
prev103:9b9cfc5855e0
next113:ce4eb7959d56
author nkeynes
date Wed Mar 15 13:16:50 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change More video WIP - displays _something_ now, at least...
file annotate diff log raw
1.1 --- a/src/pvr2/render.c Mon Mar 13 12:39:07 2006 +0000
1.2 +++ b/src/pvr2/render.c Wed Mar 15 13:16:50 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: render.c,v 1.2 2006-03-13 12:39:07 nkeynes Exp $
1.6 + * $Id: render.c,v 1.3 2006-03-15 13:16:50 nkeynes Exp $
1.7 *
1.8 * PVR2 Renderer support. This is where the real work happens.
1.9 *
1.10 @@ -36,6 +36,8 @@
1.11 GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
1.12 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
1.13 GL_ONE_MINUS_DST_ALPHA };
1.14 +static int pvr2_poly_texblend[4] = {
1.15 + GL_REPLACE, GL_BLEND, GL_DECAL, GL_MODULATE };
1.16 static int pvr2_render_colour_format[8] = {
1.17 COLFMT_ARGB1555, COLFMT_RGB565, COLFMT_ARGB4444, COLFMT_ARGB1555,
1.18 COLFMT_RGB888, COLFMT_ARGB8888, COLFMT_ARGB8888, COLFMT_ARGB4444 };
1.19 @@ -48,6 +50,7 @@
1.20 #define POLY_TEX_HEIGHT(poly) ( 1<< (((poly->poly_mode) & 0x07 ) + 3) )
1.21 #define POLY_BLEND_SRC(poly) ( pvr2_poly_srcblend[(poly->poly_mode) >> 29] )
1.22 #define POLY_BLEND_DEST(poly) ( pvr2_poly_dstblend[((poly->poly_mode)>>26)&0x07] )
1.23 +#define POLY_TEX_BLEND(poly) ( pvr2_poly_texblend[((poly->poly_mode) >> 6)&0x03] )
1.24
1.25 extern uint32_t pvr2_frame_counter;
1.26
1.27 @@ -112,6 +115,31 @@
1.28 void pvr2_render_copy_to_sh4( pvr2_render_buffer_t buffer,
1.29 gboolean backBuffer );
1.30
1.31 +int pvr2_render_font_list = -1;
1.32 +
1.33 +int glPrintf( const char *fmt, ... )
1.34 +{
1.35 + va_list ap; /* our argument pointer */
1.36 + char buf[256];
1.37 + int len;
1.38 + if (fmt == NULL) /* if there is no string to draw do nothing */
1.39 + return;
1.40 + va_start(ap, fmt);
1.41 + len = vsnprintf(buf, sizeof(buf), fmt, ap);
1.42 + va_end(ap);
1.43 +
1.44 + if( pvr2_render_font_list == -1 ) {
1.45 + pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
1.46 + }
1.47 +
1.48 + glPushAttrib(GL_LIST_BIT);
1.49 + glListBase(pvr2_render_font_list - 32);
1.50 + glCallLists(len, GL_UNSIGNED_BYTE, buf);
1.51 + glPopAttrib();
1.52 +
1.53 + return len;
1.54 +}
1.55 +
1.56
1.57 gboolean pvr2_render_init( void )
1.58 {
1.59 @@ -142,7 +170,7 @@
1.60 return TRUE;
1.61 }
1.62 return FALSE;
1.63 -}
1.64 +}
1.65
1.66 /**
1.67 * Prepare the OpenGL context to receive instructions for a new frame.
1.68 @@ -182,9 +210,10 @@
1.69 glViewport( 0, 0, width, height );
1.70 glMatrixMode(GL_PROJECTION);
1.71 glLoadIdentity();
1.72 - glOrtho( 0, width, height, 0, 0, 65535 );
1.73 + glOrtho( 0, width, height, 0, 0, -65535 );
1.74 glMatrixMode(GL_MODELVIEW);
1.75 glLoadIdentity();
1.76 + glCullFace( GL_BACK );
1.77
1.78 /* Clear out the buffers */
1.79 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1.80 @@ -202,14 +231,14 @@
1.81 switch( *cmd_ptr >> 24 ) {
1.82 case PVR2_CMD_POLY_OPAQUE:
1.83 poly = (struct pvr2_poly *)cmd_ptr;
1.84 -
1.85 if( poly->command & PVR2_POLY_TEXTURED ) {
1.86 uint32_t addr = PVR2_TEX_ADDR(poly->texture);
1.87 int width = POLY_TEX_WIDTH(poly);
1.88 int height = POLY_TEX_HEIGHT(poly);
1.89 + glEnable( GL_TEXTURE_2D );
1.90 texcache_get_texture( addr, width, height, poly->texture );
1.91 textured = TRUE;
1.92 - glEnable( GL_TEXTURE_2D );
1.93 + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, POLY_TEX_BLEND(poly) );
1.94 } else {
1.95 textured = FALSE;
1.96 glDisable( GL_TEXTURE_2D );
1.97 @@ -225,13 +254,25 @@
1.98 glDisable( GL_DEPTH_TEST );
1.99 }
1.100
1.101 + switch( (poly->poly_cfg >> 27) & 0x03 ) {
1.102 + case 0:
1.103 + case 1:
1.104 + glDisable( GL_CULL_FACE );
1.105 + break;
1.106 + case 2:
1.107 + glEnable( GL_CULL_FACE );
1.108 + glFrontFace( GL_CW );
1.109 + break;
1.110 + case 3:
1.111 + glEnable( GL_CULL_FACE );
1.112 + glFrontFace( GL_CCW );
1.113 + }
1.114 expect_vertexes = POLY_STRIP_VERTEXES( poly );
1.115 if( expect_vertexes == 3 )
1.116 glBegin( GL_TRIANGLES );
1.117 - else if( expect_vertexes == 4 )
1.118 - glBegin( GL_QUADS );
1.119 else
1.120 glBegin( GL_TRIANGLE_STRIP );
1.121 + fprintf( stderr, "Begin %d\n", expect_vertexes );
1.122 break;
1.123 case PVR2_CMD_VERTEX_LAST:
1.124 case PVR2_CMD_VERTEX:
1.125 @@ -241,13 +282,18 @@
1.126 }
1.127 expect_vertexes--;
1.128 struct pvr2_vertex_basic *vertex = (struct pvr2_vertex_basic *)cmd_ptr;
1.129 + fprintf( stderr, "(%f,%f,%f)", vertex->x, vertex->y, vertex->z );
1.130 if( textured ) {
1.131 + fprintf( stderr, "{%f,%f}", vertex->s, vertex->t );
1.132 glTexCoord2f( vertex->s, vertex->t );
1.133 }
1.134 + fprintf( stderr, "\n" );
1.135 glVertex3f( vertex->x, vertex->y, vertex->z );
1.136
1.137 - if( expect_vertexes == 0 )
1.138 + if( expect_vertexes == 0 ) {
1.139 glEnd();
1.140 + fprintf( stderr, "End" );
1.141 + }
1.142 break;
1.143 }
1.144 cmd_ptr += 8; /* Next record */
1.145 @@ -307,6 +353,10 @@
1.146
1.147 /* Post-render cleanup and update */
1.148
1.149 + /* Add frame, fps, etc data */
1.150 + glRasterPos2i( 4, 16 );
1.151 + // glColor3f( 0.0f, 0.0f, 1.0f );
1.152 + glPrintf( "Frame %d", pvr2_frame_counter );
1.153
1.154 /* Generate end of render event */
1.155 asic_event( EVENT_PVR_RENDER_DONE );
.