1.1 --- a/src/pvr2/texcache.c Sun Jan 14 11:43:00 2007 +0000
1.2 +++ b/src/pvr2/texcache.c Mon Jan 15 10:11:13 2007 +0000
1.5 - * $Id: texcache.c,v 1.10 2007-01-14 11:43:00 nkeynes Exp $
1.6 + * $Id: texcache.c,v 1.11 2007-01-15 08:32:09 nkeynes Exp $
1.8 * Texture cache. Responsible for maintaining a working set of OpenGL
1.12 static texcache_load_texture( uint32_t texture_addr, int width, int height,
1.14 - uint32_t bytes = width * height;
1.16 + int bpp_shift = 1; /* bytes per (output) pixel as a power of 2 */
1.17 GLint intFormat, format, type;
1.18 int tex_format = mode & PVR2_TEX_FORMAT_MASK;
1.19 struct vq_codebook codebook;
1.20 @@ -334,52 +333,54 @@
1.21 case PVR2_TEX_FORMAT_IDX4:
1.22 ERROR( "4-bit indexed textures not supported" );
1.23 case PVR2_TEX_FORMAT_IDX8:
1.24 + /* For indexed-colour modes, we need to lookup the palette control
1.25 + * word to determine the de-indexed texture format.
1.27 switch( MMIO_READ( PVR2, RENDER_PALETTE ) & 0x03 ) {
1.28 case 0: /* ARGB1555 */
1.29 intFormat = GL_RGB5_A1;
1.31 type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
1.34 + case 1: /* RGB565 */
1.37 type = GL_UNSIGNED_SHORT_5_6_5_REV;
1.40 + case 2: /* ARGB4444 */
1.41 intFormat = GL_RGBA4;
1.43 type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
1.46 + case 3: /* ARGB8888 */
1.47 intFormat = GL_RGBA8;
1.49 type = GL_UNSIGNED_INT_8_8_8_8_REV;
1.57 case PVR2_TEX_FORMAT_ARGB1555:
1.59 intFormat = GL_RGB5_A1;
1.61 type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
1.63 case PVR2_TEX_FORMAT_RGB565:
1.67 type = GL_UNSIGNED_SHORT_5_6_5_REV;
1.69 case PVR2_TEX_FORMAT_ARGB4444:
1.71 intFormat = GL_RGBA4;
1.73 type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
1.75 case PVR2_TEX_FORMAT_YUV422:
1.77 + /* YUV422 isn't directly supported by most implementations, so decode
1.78 + * it to a (reasonably) standard ARGB32.
1.81 intFormat = GL_RGBA8;
1.83 type = GL_UNSIGNED_INT_8_8_8_8_REV;
1.84 @@ -389,16 +390,33 @@
1.88 - int level=0, last_level = 0, mip_width = width, mip_height = height, mip_bytes = bytes;
1.89 + if( PVR2_TEX_IS_STRIDE(mode) ) {
1.90 + /* Stride textures cannot be mip-mapped, compressed, indexed or twiddled */
1.91 + uint32_t stride = (MMIO_READ( PVR2, RENDER_TEXSIZE ) & 0x003F) << 5;
1.92 + char data[(width*height) << bpp_shift];
1.93 + if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {
1.94 + char tmp[(width*height)<<1];
1.95 + pvr2_vram64_read_stride( &tmp, width<<1, texture_addr, stride<<1, height );
1.96 + yuv_decode(width, height, &tmp, &data );
1.98 + pvr2_vram64_read_stride( &data, width<<bpp_shift, texture_addr, stride<<bpp_shift, height );
1.100 + glTexImage2D( GL_TEXTURE_2D, 0, intFormat, width, height, 0, format, type, data );
1.101 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
1.102 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1.106 + int level=0, last_level = 0, mip_width = width, mip_height = height, mip_bytes;
1.107 if( PVR2_TEX_IS_MIPMAPPED(mode) ) {
1.109 for( i=0; 1<<(i+1) < width; i++ );
1.111 mip_width = width >> i;
1.112 mip_height= height >> i;
1.113 - mip_bytes = bytes >> (i*2);
1.114 filter = GL_LINEAR_MIPMAP_LINEAR;
1.116 + mip_bytes = (mip_width * mip_width) << bpp_shift;
1.118 if( PVR2_TEX_IS_COMPRESSED(mode) ) {
1.119 uint16_t tmp[VQ_CODEBOOK_SIZE];
1.120 @@ -411,13 +429,13 @@
1.121 char data[mip_bytes];
1.122 /* load data from image, detwiddling/uncompressing as required */
1.123 if( tex_format == PVR2_TEX_FORMAT_IDX8 ) {
1.124 - int inputlength = mip_bytes >> shift;
1.125 + int inputlength = mip_bytes >> bpp_shift;
1.126 int bank = (mode >> 25) &0x03;
1.127 - char *palette = mmio_region_PVR2PAL.mem + (bank * (256 << shift));
1.128 + char *palette = mmio_region_PVR2PAL.mem + (bank * (256 << bpp_shift));
1.129 char tmp[inputlength];
1.131 pvr2_vram64_read( tmp, texture_addr, inputlength );
1.132 - if( shift == 2 ) {
1.133 + if( bpp_shift == 2 ) {
1.134 detwiddle_pal8_to_32( 0, 0, mip_width, mip_width, &p,
1.135 (uint32_t *)data, (uint32_t *)palette );