filename | src/pvr2/texcache.c |
changeset | 284:808617ee7135 |
prev | 282:01e53698ff38 |
next | 287:fead4f5f3e2c |
author | nkeynes |
date | Mon Jan 15 08:32:09 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Break vram routines out into pvr2mem.c Initial (untested) implementation of stride textures Hookup YUV converter code in pvr2.c |
file | annotate | diff | log | raw |
1.1 --- a/src/pvr2/texcache.c Sun Jan 14 11:43:00 2007 +00001.2 +++ b/src/pvr2/texcache.c Mon Jan 15 08:32:09 2007 +00001.3 @@ -1,5 +1,5 @@1.4 /**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.7 *1.8 * Texture cache. Responsible for maintaining a working set of OpenGL1.9 * textures.1.10 @@ -322,8 +322,7 @@1.11 */1.12 static texcache_load_texture( uint32_t texture_addr, int width, int height,1.13 int mode ) {1.14 - uint32_t bytes = width * height;1.15 - int shift = 1;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 control1.25 + * word to determine the de-indexed texture format.1.26 + */1.27 switch( MMIO_READ( PVR2, RENDER_PALETTE ) & 0x03 ) {1.28 case 0: /* ARGB1555 */1.29 intFormat = GL_RGB5_A1;1.30 format = GL_RGBA;1.31 type = GL_UNSIGNED_SHORT_1_5_5_5_REV;1.32 break;1.33 - case 1:1.34 + case 1: /* RGB565 */1.35 intFormat = GL_RGB;1.36 format = GL_RGB;1.37 type = GL_UNSIGNED_SHORT_5_6_5_REV;1.38 break;1.39 - case 2:1.40 + case 2: /* ARGB4444 */1.41 intFormat = GL_RGBA4;1.42 format = GL_BGRA;1.43 type = GL_UNSIGNED_SHORT_4_4_4_4_REV;1.44 break;1.45 - case 3:1.46 + case 3: /* ARGB8888 */1.47 intFormat = GL_RGBA8;1.48 format = GL_BGRA;1.49 type = GL_UNSIGNED_INT_8_8_8_8_REV;1.50 - shift = 2;1.51 + bpp_shift = 2;1.52 break;1.53 }1.54 - bytes <<= shift;1.55 break;1.57 case PVR2_TEX_FORMAT_ARGB1555:1.58 - bytes <<= 1;1.59 intFormat = GL_RGB5_A1;1.60 format = GL_RGBA;1.61 type = GL_UNSIGNED_SHORT_1_5_5_5_REV;1.62 break;1.63 case PVR2_TEX_FORMAT_RGB565:1.64 - bytes <<= 1;1.65 intFormat = GL_RGB;1.66 format = GL_RGB;1.67 type = GL_UNSIGNED_SHORT_5_6_5_REV;1.68 break;1.69 case PVR2_TEX_FORMAT_ARGB4444:1.70 - bytes <<= 1;1.71 intFormat = GL_RGBA4;1.72 format = GL_BGRA;1.73 type = GL_UNSIGNED_SHORT_4_4_4_4_REV;1.74 break;1.75 case PVR2_TEX_FORMAT_YUV422:1.76 - bytes <<= 2;1.77 + /* YUV422 isn't directly supported by most implementations, so decode1.78 + * it to a (reasonably) standard ARGB32.1.79 + */1.80 + bpp_shift = 2;1.81 intFormat = GL_RGBA8;1.82 format = GL_BGRA;1.83 type = GL_UNSIGNED_INT_8_8_8_8_REV;1.84 @@ -389,16 +390,33 @@1.85 break;1.86 }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.97 + } else {1.98 + pvr2_vram64_read_stride( &data, width<<bpp_shift, texture_addr, stride<<bpp_shift, height );1.99 + }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.103 + return;1.104 + }1.105 +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.108 int i;1.109 for( i=0; 1<<(i+1) < width; i++ );1.110 last_level = 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.115 }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.130 char *p = tmp;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 );1.136 } else {
.