revision 108:565de331ccec
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 108:565de331ccec |
parent | 107:e576dd36073a |
child | 109:cc84a653c781 |
author | nkeynes |
date | Wed Mar 15 13:16:50 2006 +0000 (16 years ago) |
More video WIP - displays _something_ now, at least...
1.1 --- a/src/drivers/video_gtk.c Tue Mar 14 13:02:06 2006 +00001.2 +++ b/src/drivers/video_gtk.c Wed Mar 15 13:16:50 2006 +00001.3 @@ -1,5 +1,5 @@1.4 /**1.5 - * $Id: video_gtk.c,v 1.3 2006-03-14 12:45:53 nkeynes Exp $1.6 + * $Id: video_gtk.c,v 1.4 2006-03-15 13:16:46 nkeynes Exp $1.7 *1.8 * The PC side of the video support (responsible for actually displaying /1.9 * rendering frames)1.10 @@ -32,6 +32,8 @@1.12 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,1.13 int colour_format );1.14 +gboolean video_gtk_set_render_format( uint32_t width, uint32_t height,1.15 + int colour_format );1.16 gboolean video_gtk_display_frame( video_buffer_t frame );1.17 gboolean video_gtk_blank( uint32_t rgb );1.19 @@ -39,10 +41,10 @@1.20 NULL,1.21 NULL,1.22 video_gtk_set_output_format,1.23 - NULL,1.24 + video_gtk_set_render_format,1.25 video_gtk_display_frame,1.26 video_gtk_blank,1.27 - NULL };1.28 + video_glx_swap_buffers };1.30 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,1.31 int colour_format )1.32 @@ -151,3 +153,8 @@1.33 return TRUE;1.34 }1.36 +gboolean video_gtk_set_render_format( uint32_t width, uint32_t height,1.37 + int colour_format )1.38 +{1.39 + return video_glx_set_render_format( 0, 0, width, height );1.40 +}
2.1 --- a/src/drivers/video_x11.c Tue Mar 14 13:02:06 2006 +00002.2 +++ b/src/drivers/video_x11.c Wed Mar 15 13:16:50 2006 +00002.3 @@ -1,5 +1,5 @@2.4 /**2.5 - * $Id: video_x11.c,v 1.2 2006-03-13 12:39:07 nkeynes Exp $2.6 + * $Id: video_x11.c,v 1.3 2006-03-15 13:16:46 nkeynes Exp $2.7 *2.8 * Shared functions for all X11-based display drivers.2.9 *2.10 @@ -129,6 +129,27 @@2.11 return TRUE;2.12 }2.14 +int video_glx_load_font( const gchar *font_name )2.15 +{2.16 + int lists;2.17 + XFontStruct *font = XLoadQueryFont(video_x11_display, font_name );2.18 + if (font == NULL)2.19 + return -1;2.20 +2.21 + lists = glGenLists(96);2.22 + glXUseXFont(font->fid, 32, 96, lists);2.23 + XFreeFont(video_x11_display, font);2.24 +}2.25 +2.26 +2.27 +2.28 +gboolean video_glx_set_render_format( int x, int y, int width, int height )2.29 +{2.30 + if( glx_open )2.31 + return TRUE;2.32 + return video_glx_create_window( x, y, width, height );2.33 +}2.34 +2.35 void video_glx_swap_buffers( void )2.36 {2.37 glXSwapBuffers( video_x11_display, glx_window );
3.1 --- a/src/drivers/video_x11.h Tue Mar 14 13:02:06 2006 +00003.2 +++ b/src/drivers/video_x11.h Wed Mar 15 13:16:50 2006 +00003.3 @@ -1,5 +1,5 @@3.4 /**3.5 - * $Id: video_x11.h,v 1.1 2006-02-05 04:05:27 nkeynes Exp $3.6 + * $Id: video_x11.h,v 1.2 2006-03-15 13:16:46 nkeynes Exp $3.7 *3.8 * Parent for all X11 display drivers.3.9 *3.10 @@ -28,4 +28,8 @@3.11 extern Screen *video_x11_screen;3.12 extern Window video_x11_window;3.14 +3.15 +gboolean video_glx_set_render_format( int x, int y, int width, int height );3.16 +void video_glx_swap_buffers();3.17 +3.18 #endif
4.1 --- a/src/pvr2/pvr2.c Tue Mar 14 13:02:06 2006 +00004.2 +++ b/src/pvr2/pvr2.c Wed Mar 15 13:16:50 2006 +00004.3 @@ -1,5 +1,5 @@4.4 /**4.5 - * $Id: pvr2.c,v 1.19 2006-03-14 13:02:06 nkeynes Exp $4.6 + * $Id: pvr2.c,v 1.20 2006-03-15 13:16:50 nkeynes Exp $4.7 *4.8 * PVR2 (Video) Core MMIO registers.4.9 *4.10 @@ -44,12 +44,12 @@4.11 struct video_timing {4.12 int fields_per_second;4.13 int total_lines;4.14 - int display_lines;4.15 + int retrace_lines;4.16 int line_time_ns;4.17 };4.19 -struct video_timing pal_timing = { 50, 625, 575, 32000 };4.20 -struct video_timing ntsc_timing= { 60, 525, 480, 31746 };4.21 +struct video_timing pal_timing = { 50, 625, 50, 32000 };4.22 +struct video_timing ntsc_timing= { 60, 525, 65, 31746 };4.24 struct dreamcast_module pvr2_module = { "PVR2", pvr2_init, NULL, NULL,4.25 pvr2_run_slice, NULL,4.26 @@ -74,12 +74,15 @@4.27 if( driver->init_driver != NULL )4.28 driver->init_driver();4.29 driver->set_display_format( 640, 480, COLFMT_RGB32 );4.30 + driver->set_render_format( 640, 480, COLFMT_RGB32, FALSE );4.31 + texcache_gl_init();4.32 }4.34 uint32_t pvr2_line_count = 0;4.35 uint32_t pvr2_line_remainder = 0;4.36 uint32_t pvr2_irq_vpos1 = 0;4.37 uint32_t pvr2_irq_vpos2 = 0;4.38 +gboolean pvr2_retrace = FALSE;4.39 struct video_timing *pvr2_timing = &ntsc_timing;4.40 uint32_t pvr2_time_counter = 0;4.41 uint32_t pvr2_frame_counter = 0;4.42 @@ -97,11 +100,15 @@4.43 if( pvr2_line_count == pvr2_irq_vpos2 ) {4.44 asic_event( EVENT_SCANLINE2 );4.45 }4.46 - if( pvr2_line_count == pvr2_timing->display_lines ) {4.47 + if( pvr2_line_count == pvr2_timing->total_lines ) {4.48 asic_event( EVENT_RETRACE );4.49 - } else if( pvr2_line_count == pvr2_timing->total_lines ) {4.50 - pvr2_display_frame();4.51 pvr2_line_count = 0;4.52 + pvr2_retrace = TRUE;4.53 + } else if( pvr2_line_count == pvr2_timing->retrace_lines ) {4.54 + if( pvr2_retrace ) {4.55 + pvr2_display_frame();4.56 + pvr2_retrace = FALSE;4.57 + }4.58 }4.59 }4.60 return nanosecs;4.61 @@ -189,8 +196,16 @@4.63 INFO( "PVR2 write to %08X <= %08X [%s: %s]", reg, val,4.64 MMIO_REGID(PVR2,reg), MMIO_REGDESC(PVR2,reg) );4.65 +4.66 + MMIO_WRITE( PVR2, reg, val );4.68 switch(reg) {4.69 + case DISPADDR1:4.70 + if( pvr2_retrace ) {4.71 + pvr2_display_frame();4.72 + pvr2_retrace = FALSE;4.73 + }4.74 + break;4.75 case VPOS_IRQ:4.76 pvr2_irq_vpos1 = (val >> 16) & 0x03FF;4.77 pvr2_irq_vpos2 = val & 0x03FF;4.78 @@ -204,7 +219,6 @@4.79 pvr2_render_scene();4.80 break;4.81 }4.82 - MMIO_WRITE( PVR2, reg, val );4.83 }4.85 MMIO_REGION_READ_FN( PVR2, reg )4.86 @@ -254,8 +268,10 @@4.87 texcache_invalidate_page( i );4.88 }4.90 - banks[0] = ((uint32_t *)(video_base + (destaddr>>3)));4.91 + banks[0] = ((uint32_t *)(video_base + ((destaddr & 0x007FFFF8) >>1)));4.92 banks[1] = banks[0] + 0x100000;4.93 + if( bank_flag )4.94 + banks[0]++;4.96 /* Handle non-aligned start of source */4.97 if( destaddr & 0x03 ) {4.98 @@ -295,8 +311,10 @@4.99 if( srcaddr + length > 0x800000 )4.100 length = 0x800000 - srcaddr;4.102 - banks[0] = ((uint32_t *)(video_base + (srcaddr>>3)));4.103 + banks[0] = ((uint32_t *)(video_base + ((srcaddr&0x007FFFF8)>>1)));4.104 banks[1] = banks[0] + 0x100000;4.105 + if( bank_flag )4.106 + banks[0]++;4.108 /* Handle non-aligned start of source */4.109 if( srcaddr & 0x03 ) {
5.1 --- a/src/pvr2/pvr2.h Tue Mar 14 13:02:06 2006 +00005.2 +++ b/src/pvr2/pvr2.h Wed Mar 15 13:16:50 2006 +00005.3 @@ -1,5 +1,5 @@5.4 /**5.5 - * $Id: pvr2.h,v 1.9 2006-03-13 12:39:07 nkeynes Exp $5.6 + * $Id: pvr2.h,v 1.10 2006-03-15 13:16:50 nkeynes Exp $5.7 *5.8 * PVR2 (video chip) functions and macros.5.9 *5.10 @@ -84,7 +84,7 @@5.11 #define PVR2_TEX_FORMAT_MASK 0x380000005.12 #define PVR2_TEX_UNTWIDDLED 0x040000005.14 -#define PVR2_TEX_ADDR(x) ( ((x)&0x1FFFFF)<<3 );5.15 +#define PVR2_TEX_ADDR(x) ( ((x)&0x01FFFFF)<<3 );5.16 #define PVR2_TEX_IS_MIPMAPPED(x) ( (x) & PVR2_TEX_MIPMAP )5.17 #define PVR2_TEX_IS_COMPRESSED(x) ( (x) & PVR2_TEX_COMPRESSED )5.18 #define PVR2_TEX_IS_TWIDDLED(x) (((x) & PVR2_TEX_UNTWIDDLED) == 0)5.19 @@ -140,11 +140,14 @@5.20 /****************************** Texture Cache ****************************/5.22 /**5.23 - * Initialize the texture cache. Note that the GL context must have been5.24 - * initialized before calling this function.5.25 + * Initialize the texture cache.5.26 */5.27 void texcache_init( void );5.29 +/**5.30 + * Initialize the GL side of the texture cache (texture ids and such).5.31 + */5.32 +void texcache_gl_init( void );5.34 /**5.35 * Flush all textures and delete. The cache will be non-functional until
6.1 --- a/src/pvr2/pvr2mmio.h Tue Mar 14 13:02:06 2006 +00006.2 +++ b/src/pvr2/pvr2mmio.h Wed Mar 15 13:16:50 2006 +00006.3 @@ -1,5 +1,5 @@6.4 /**6.5 - * $Id: pvr2mmio.h,v 1.1 2006-03-13 12:39:07 nkeynes Exp $6.6 + * $Id: pvr2mmio.h,v 1.2 2006-03-15 13:16:50 nkeynes Exp $6.7 *6.8 * PVR2 (video chip) MMIO register definitions.6.9 *6.10 @@ -58,6 +58,7 @@6.11 LONG_PORT( 0x0E8, DISPCFG2, PORT_MRW, 0, "Video configuration 2" )6.12 LONG_PORT( 0x0F0, VPOS, PORT_MRW, 0, "Vertical display position" )6.13 LONG_PORT( 0x0F4, SCALERCFG, PORT_MRW, 0, "Scaler configuration (?)" )6.14 + LONG_PORT( 0x108, PALETTECFG, PORT_MRW, 0, "Palette configuration" )6.15 LONG_PORT( 0x10C, BEAMPOS, PORT_R, 0, "Raster beam position" )6.16 LONG_PORT( 0x124, TAOBJPBASE, PORT_MRW, 0, "TA Object Pointer Buffer start" )6.17 LONG_PORT( 0x128, TAOBJBASE, PORT_MRW, 0, "TA Object Buffer start" )
7.1 --- a/src/pvr2/render.c Tue Mar 14 13:02:06 2006 +00007.2 +++ b/src/pvr2/render.c Wed Mar 15 13:16:50 2006 +00007.3 @@ -1,5 +1,5 @@7.4 /**7.5 - * $Id: render.c,v 1.2 2006-03-13 12:39:07 nkeynes Exp $7.6 + * $Id: render.c,v 1.3 2006-03-15 13:16:50 nkeynes Exp $7.7 *7.8 * PVR2 Renderer support. This is where the real work happens.7.9 *7.10 @@ -36,6 +36,8 @@7.11 GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,7.12 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,7.13 GL_ONE_MINUS_DST_ALPHA };7.14 +static int pvr2_poly_texblend[4] = {7.15 + GL_REPLACE, GL_BLEND, GL_DECAL, GL_MODULATE };7.16 static int pvr2_render_colour_format[8] = {7.17 COLFMT_ARGB1555, COLFMT_RGB565, COLFMT_ARGB4444, COLFMT_ARGB1555,7.18 COLFMT_RGB888, COLFMT_ARGB8888, COLFMT_ARGB8888, COLFMT_ARGB4444 };7.19 @@ -48,6 +50,7 @@7.20 #define POLY_TEX_HEIGHT(poly) ( 1<< (((poly->poly_mode) & 0x07 ) + 3) )7.21 #define POLY_BLEND_SRC(poly) ( pvr2_poly_srcblend[(poly->poly_mode) >> 29] )7.22 #define POLY_BLEND_DEST(poly) ( pvr2_poly_dstblend[((poly->poly_mode)>>26)&0x07] )7.23 +#define POLY_TEX_BLEND(poly) ( pvr2_poly_texblend[((poly->poly_mode) >> 6)&0x03] )7.25 extern uint32_t pvr2_frame_counter;7.27 @@ -112,6 +115,31 @@7.28 void pvr2_render_copy_to_sh4( pvr2_render_buffer_t buffer,7.29 gboolean backBuffer );7.31 +int pvr2_render_font_list = -1;7.32 +7.33 +int glPrintf( const char *fmt, ... )7.34 +{7.35 + va_list ap; /* our argument pointer */7.36 + char buf[256];7.37 + int len;7.38 + if (fmt == NULL) /* if there is no string to draw do nothing */7.39 + return;7.40 + va_start(ap, fmt);7.41 + len = vsnprintf(buf, sizeof(buf), fmt, ap);7.42 + va_end(ap);7.43 +7.44 + if( pvr2_render_font_list == -1 ) {7.45 + pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");7.46 + }7.47 +7.48 + glPushAttrib(GL_LIST_BIT);7.49 + glListBase(pvr2_render_font_list - 32);7.50 + glCallLists(len, GL_UNSIGNED_BYTE, buf);7.51 + glPopAttrib();7.52 +7.53 + return len;7.54 +}7.55 +7.57 gboolean pvr2_render_init( void )7.58 {7.59 @@ -142,7 +170,7 @@7.60 return TRUE;7.61 }7.62 return FALSE;7.63 -}7.64 +}7.66 /**7.67 * Prepare the OpenGL context to receive instructions for a new frame.7.68 @@ -182,9 +210,10 @@7.69 glViewport( 0, 0, width, height );7.70 glMatrixMode(GL_PROJECTION);7.71 glLoadIdentity();7.72 - glOrtho( 0, width, height, 0, 0, 65535 );7.73 + glOrtho( 0, width, height, 0, 0, -65535 );7.74 glMatrixMode(GL_MODELVIEW);7.75 glLoadIdentity();7.76 + glCullFace( GL_BACK );7.78 /* Clear out the buffers */7.79 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);7.80 @@ -202,14 +231,14 @@7.81 switch( *cmd_ptr >> 24 ) {7.82 case PVR2_CMD_POLY_OPAQUE:7.83 poly = (struct pvr2_poly *)cmd_ptr;7.84 -7.85 if( poly->command & PVR2_POLY_TEXTURED ) {7.86 uint32_t addr = PVR2_TEX_ADDR(poly->texture);7.87 int width = POLY_TEX_WIDTH(poly);7.88 int height = POLY_TEX_HEIGHT(poly);7.89 + glEnable( GL_TEXTURE_2D );7.90 texcache_get_texture( addr, width, height, poly->texture );7.91 textured = TRUE;7.92 - glEnable( GL_TEXTURE_2D );7.93 + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, POLY_TEX_BLEND(poly) );7.94 } else {7.95 textured = FALSE;7.96 glDisable( GL_TEXTURE_2D );7.97 @@ -225,13 +254,25 @@7.98 glDisable( GL_DEPTH_TEST );7.99 }7.101 + switch( (poly->poly_cfg >> 27) & 0x03 ) {7.102 + case 0:7.103 + case 1:7.104 + glDisable( GL_CULL_FACE );7.105 + break;7.106 + case 2:7.107 + glEnable( GL_CULL_FACE );7.108 + glFrontFace( GL_CW );7.109 + break;7.110 + case 3:7.111 + glEnable( GL_CULL_FACE );7.112 + glFrontFace( GL_CCW );7.113 + }7.114 expect_vertexes = POLY_STRIP_VERTEXES( poly );7.115 if( expect_vertexes == 3 )7.116 glBegin( GL_TRIANGLES );7.117 - else if( expect_vertexes == 4 )7.118 - glBegin( GL_QUADS );7.119 else7.120 glBegin( GL_TRIANGLE_STRIP );7.121 + fprintf( stderr, "Begin %d\n", expect_vertexes );7.122 break;7.123 case PVR2_CMD_VERTEX_LAST:7.124 case PVR2_CMD_VERTEX:7.125 @@ -241,13 +282,18 @@7.126 }7.127 expect_vertexes--;7.128 struct pvr2_vertex_basic *vertex = (struct pvr2_vertex_basic *)cmd_ptr;7.129 + fprintf( stderr, "(%f,%f,%f)", vertex->x, vertex->y, vertex->z );7.130 if( textured ) {7.131 + fprintf( stderr, "{%f,%f}", vertex->s, vertex->t );7.132 glTexCoord2f( vertex->s, vertex->t );7.133 }7.134 + fprintf( stderr, "\n" );7.135 glVertex3f( vertex->x, vertex->y, vertex->z );7.137 - if( expect_vertexes == 0 )7.138 + if( expect_vertexes == 0 ) {7.139 glEnd();7.140 + fprintf( stderr, "End" );7.141 + }7.142 break;7.143 }7.144 cmd_ptr += 8; /* Next record */7.145 @@ -307,6 +353,10 @@7.147 /* Post-render cleanup and update */7.149 + /* Add frame, fps, etc data */7.150 + glRasterPos2i( 4, 16 );7.151 + // glColor3f( 0.0f, 0.0f, 1.0f );7.152 + glPrintf( "Frame %d", pvr2_frame_counter );7.154 /* Generate end of render event */7.155 asic_event( EVENT_PVR_RENDER_DONE );
8.1 --- a/src/pvr2/ta.c Tue Mar 14 13:02:06 2006 +00008.2 +++ b/src/pvr2/ta.c Wed Mar 15 13:16:50 2006 +00008.3 @@ -1,5 +1,5 @@8.4 /**8.5 - * $Id: ta.c,v 1.2 2006-03-13 12:39:07 nkeynes Exp $8.6 + * $Id: ta.c,v 1.3 2006-03-15 13:16:50 nkeynes Exp $8.7 *8.8 * PVR2 Tile Accelerator support. In principle this does a lot more work8.9 * than is currently implemented - we cheat. A lot.8.10 @@ -89,9 +89,9 @@8.11 unsigned int type = (cmd_list[i].command >> 24) & 0xFF;8.12 if( type == 0xE0 || type == 0xF0 ) {8.13 struct vertex_type1 *vert = (struct vertex_type1 *)&cmd_list[i];8.14 - DEBUG( "PVR2 vrt: %f %f %f %08X %08X %08X %f", vert->x, vert->y, vert->z, vert->blank, vert->blank2, vert->col, vert->f );8.15 + // DEBUG( "PVR2 vrt: %f %f %f %08X %08X %08X %f", vert->x, vert->y, vert->z, vert->blank, vert->blank2, vert->col, vert->f );8.16 } else {8.17 - DEBUG( "PVR2 cmd: %08X %08X %08X %08X %08X %08X %08X %08X", cmd_list[i].command, cmd_list[i].param1, cmd_list[i].param2, cmd_list[i].texture, cmd_list[i].alpha, cmd_list[i].red, cmd_list[i].green, cmd_list[i].blue );8.18 + // DEBUG( "PVR2 cmd: %08X %08X %08X %08X %08X %08X %08X %08X", cmd_list[i].command, cmd_list[i].param1, cmd_list[i].param2, cmd_list[i].texture, cmd_list[i].alpha, cmd_list[i].red, cmd_list[i].green, cmd_list[i].blue );8.19 }8.20 if( type == 0 ) {8.21 /* End of list */
9.1 --- a/src/pvr2/texcache.c Tue Mar 14 13:02:06 2006 +00009.2 +++ b/src/pvr2/texcache.c Wed Mar 15 13:16:50 2006 +00009.3 @@ -1,5 +1,5 @@9.4 /**9.5 - * $Id: texcache.c,v 1.2 2006-03-14 13:02:06 nkeynes Exp $9.6 + * $Id: texcache.c,v 1.3 2006-03-15 13:16:50 nkeynes Exp $9.7 *9.8 * Texture cache. Responsible for maintaining a working set of OpenGL9.9 * textures.9.10 @@ -52,24 +52,19 @@9.11 } *texcache_entry_t;9.13 static uint8_t texcache_page_lookup[PVR2_RAM_PAGES];9.14 -static uint32_t texcache_active_ptr;9.15 static uint32_t texcache_ref_counter;9.16 static struct texcache_entry texcache_active_list[MAX_TEXTURES];9.18 /**9.19 - * Initialize the texture cache. Note that the GL context must have been9.20 - * initialized before calling this function.9.21 + * Initialize the texture cache.9.22 */9.23 void texcache_init( )9.24 {9.25 int i;9.26 - GLuint texids[MAX_TEXTURES];9.27 - glGenTextures( MAX_TEXTURES, texids );9.28 for( i=0; i<PVR2_RAM_PAGES; i++ ) {9.29 texcache_page_lookup[i] = EMPTY_ENTRY;9.30 }9.31 for( i=0; i<MAX_TEXTURES; i++ ) {9.32 - texcache_active_list[i].texture_id = texids[i];9.33 texcache_free_list[i] = i;9.34 }9.35 texcache_free_ptr = 0;9.36 @@ -77,6 +72,21 @@9.37 }9.39 /**9.40 + * Setup the initial texture ids (must be called after the GL context is9.41 + * prepared)9.42 + */9.43 +void texcache_gl_init( )9.44 +{9.45 + int i;9.46 + GLuint texids[MAX_TEXTURES];9.47 +9.48 + glGenTextures( MAX_TEXTURES, texids );9.49 + for( i=0; i<MAX_TEXTURES; i++ ) {9.50 + texcache_active_list[i].texture_id = texids[i];9.51 + }9.52 +}9.53 +9.54 +/**9.55 * Flush all textures from the cache, returning them to the free list.9.56 */9.57 void texcache_flush( )9.58 @@ -176,62 +186,113 @@9.59 static texcache_load_texture( uint32_t texture_addr, int width, int height,9.60 int mode ) {9.61 uint32_t bytes = width * height;9.62 - int bpp = 2;9.63 + int shift = 1;9.64 GLint intFormat, format, type;9.65 - switch( mode & PVR2_TEX_FORMAT_MASK ) {9.66 - case PVR2_TEX_FORMAT_ARGB1555:9.67 - bytes <<= 1;9.68 - intFormat = GL_RGB5_A1;9.69 - format = GL_RGBA;9.70 - type = GL_UNSIGNED_SHORT_5_5_5_1;9.71 - break;9.72 - case PVR2_TEX_FORMAT_RGB565:9.73 - bytes <<= 1;9.74 - intFormat = GL_RGBA;9.75 - format = GL_RGBA;9.76 - type = GL_UNSIGNED_SHORT_5_6_5;9.77 - break;9.78 - case PVR2_TEX_FORMAT_ARGB4444:9.79 - bytes <<= 1;9.80 - intFormat = GL_RGBA4;9.81 - format = GL_RGBA;9.82 - type = GL_UNSIGNED_SHORT_4_4_4_4;9.83 - break;9.84 - case PVR2_TEX_FORMAT_YUV422:9.85 - ERROR( "YUV textures not supported" );9.86 - break;9.87 - case PVR2_TEX_FORMAT_BUMPMAP:9.88 - ERROR( "Bumpmap not supported" );9.89 - break;9.90 - case PVR2_TEX_FORMAT_IDX4:9.91 - /* Supported? */9.92 - bytes >>= 1;9.93 - intFormat = GL_INTENSITY4;9.94 - format = GL_COLOR_INDEX;9.95 - type = GL_UNSIGNED_BYTE;9.96 - bpp = 0;9.97 - break;9.98 - case PVR2_TEX_FORMAT_IDX8:9.99 - intFormat = GL_INTENSITY8;9.100 - format = GL_COLOR_INDEX;9.101 - type = GL_UNSIGNED_BYTE;9.102 - bpp = 1;9.103 - break;9.104 + int tex_format = mode & PVR2_TEX_FORMAT_MASK;9.105 +9.106 + if( tex_format == PVR2_TEX_FORMAT_IDX8 ||9.107 + tex_format == PVR2_TEX_FORMAT_IDX4 ) {9.108 + switch( MMIO_READ( PVR2, PALETTECFG ) & 0x03 ) {9.109 + case 0: /* ARGB1555 */9.110 + intFormat = GL_RGB5_A1;9.111 + format = GL_RGBA;9.112 + type = GL_UNSIGNED_SHORT_5_5_5_1;9.113 + break;9.114 + case 1:9.115 + intFormat = GL_RGB;9.116 + format = GL_RGB;9.117 + type = GL_UNSIGNED_SHORT_5_6_5;9.118 + break;9.119 + case 2:9.120 + intFormat = GL_RGBA4;9.121 + format = GL_RGBA;9.122 + type = GL_UNSIGNED_SHORT_4_4_4_4;9.123 + break;9.124 + case 3:9.125 + intFormat = GL_RGBA8;9.126 + format = GL_RGBA;9.127 + type = GL_UNSIGNED_INT_8_8_8_8;9.128 + shift = 2;9.129 + break;9.130 + }9.131 +9.132 + if( tex_format == PVR2_TEX_FORMAT_IDX8 ) {9.133 + int bank = (mode >> 25) &0x03;9.134 + unsigned char data[bytes<<shift];9.135 + char *palette = mmio_region_PVR2PAL.mem + (bank * (256 << shift));9.136 + int i;9.137 + pvr2_vram64_read( &data, texture_addr, bytes );9.138 + for( i=bytes-1; i>=0; i-- ) {9.139 + char ch = data[i];9.140 + if( shift == 2 )9.141 + ((uint32_t *)data)[i] = ((uint32_t *)palette)[ch];9.142 + else9.143 + ((uint16_t *)data)[i] = ((uint16_t *)palette)[ch];9.144 + }9.145 + /* TODO: Detwiddle */9.146 + glTexImage2D( GL_TEXTURE_2D, 0, intFormat, width, height, 0, format, type,9.147 + data );9.148 +9.149 + }9.150 + } else {9.151 + switch( tex_format ) {9.152 + case PVR2_TEX_FORMAT_ARGB1555:9.153 + bytes <<= 1;9.154 + intFormat = GL_RGB5_A1;9.155 + format = GL_RGBA;9.156 + type = GL_UNSIGNED_SHORT_5_5_5_1;9.157 + break;9.158 + case PVR2_TEX_FORMAT_RGB565:9.159 + bytes <<= 1;9.160 + intFormat = GL_RGBA;9.161 + format = GL_RGBA;9.162 + type = GL_UNSIGNED_SHORT_5_6_5;9.163 + break;9.164 + case PVR2_TEX_FORMAT_ARGB4444:9.165 + bytes <<= 1;9.166 + intFormat = GL_RGBA4;9.167 + format = GL_RGBA;9.168 + type = GL_UNSIGNED_SHORT_4_4_4_4;9.169 + break;9.170 + case PVR2_TEX_FORMAT_YUV422:9.171 + ERROR( "YUV textures not supported" );9.172 + break;9.173 + case PVR2_TEX_FORMAT_BUMPMAP:9.174 + ERROR( "Bumpmap not supported" );9.175 + break;9.176 + case PVR2_TEX_FORMAT_IDX4:9.177 + /* Supported? */9.178 + bytes >>= 1;9.179 + intFormat = GL_INTENSITY4;9.180 + format = GL_COLOR_INDEX;9.181 + type = GL_UNSIGNED_BYTE;9.182 + shift = 0;9.183 + break;9.184 + case PVR2_TEX_FORMAT_IDX8:9.185 + intFormat = GL_INTENSITY8;9.186 + format = GL_COLOR_INDEX;9.187 + type = GL_UNSIGNED_BYTE;9.188 + shift = 0;9.189 + break;9.190 + }9.191 +9.192 + unsigned char data[bytes];9.193 + /* load data from image, detwiddling/uncompressing as required */9.194 + if( PVR2_TEX_IS_COMPRESSED(mode) ) {9.195 + ERROR( "VQ Compression not supported" );9.196 + } else {9.197 + pvr2_vram64_read( &data, texture_addr, bytes );9.198 + if( PVR2_TEX_IS_TWIDDLED(mode) ) {9.199 + /* Untwiddle */9.200 + }9.201 + }9.202 +9.203 + /* Pass to GL */9.204 + glTexImage2D( GL_TEXTURE_2D, 0, intFormat, width, height, 0, format, type,9.205 + data );9.206 }9.207 -9.208 - unsigned char data[bytes];9.209 - /* load data from image, detwiddling/uncompressing as required */9.210 - if( PVR2_TEX_IS_COMPRESSED(mode) ) {9.211 - ERROR( "VQ Compression not supported" );9.212 - } else {9.213 - pvr2_vram64_read( &data, texture_addr, bytes );9.214 - if( PVR2_TEX_IS_TWIDDLED(mode) ) {9.215 - /* Untwiddle */9.216 - }9.217 - }9.218 - /* Pass to GL */9.219 - glTexImage2D( GL_TEXTURE_2D, 0, intFormat, width, height, 0, format, type,9.220 - data );9.221 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);9.222 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);9.223 }9.225 /**9.226 @@ -283,8 +344,7 @@9.227 texcache_page_lookup[texture_page] = slot;9.229 /* Construct the GL texture */9.230 - GLuint texid = texcache_free_list[texcache_free_ptr++];9.231 - glBindTexture( GL_TEXTURE_2D, texid );9.232 + glBindTexture( GL_TEXTURE_2D, texcache_active_list[slot].texture_id );9.233 texcache_load_texture( texture_addr, width, height, mode );9.235 return texcache_active_list[slot].texture_id;
.