filename | src/pvr2/texcache.c |
changeset | 349:05c9b25c361d |
prev | 337:cdd757aa8e8c |
next | 352:f0df7a6d4703 |
author | nkeynes |
date | Mon Feb 05 08:52:59 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Fix compressed mipmap textures (byte count was wrong) Change internal gl format to the simple versions - let the implementation use whatever's most efficient |
file | annotate | diff | log | raw |
1.1 --- a/src/pvr2/texcache.c Sun Jan 28 11:36:00 2007 +00001.2 +++ b/src/pvr2/texcache.c Mon Feb 05 08:52:59 2007 +00001.3 @@ -1,5 +1,5 @@1.4 /**1.5 - * $Id: texcache.c,v 1.24 2007-01-28 11:36:00 nkeynes Exp $1.6 + * $Id: texcache.c,v 1.25 2007-02-05 08:52:59 nkeynes Exp $1.7 *1.8 * Texture cache. Responsible for maintaining a working set of OpenGL1.9 * textures.1.10 @@ -25,7 +25,7 @@1.11 * textures we're willing to have open at a time. If more are1.12 * needed, textures will be evicted in LRU order.1.13 */1.14 -#define MAX_TEXTURES 1281.15 +#define MAX_TEXTURES 2561.17 /**1.18 * Data structure:1.19 @@ -321,7 +321,7 @@1.20 static texcache_load_texture( uint32_t texture_addr, int width, int height,1.21 int mode ) {1.22 int bpp_shift = 1; /* bytes per (output) pixel as a power of 2 */1.23 - GLint intFormat, format, type;1.24 + GLint intFormat = GL_RGBA, format, type;1.25 int tex_format = mode & PVR2_TEX_FORMAT_MASK;1.26 struct vq_codebook codebook;1.27 GLint filter = GL_LINEAR;1.28 @@ -335,22 +335,19 @@1.29 */1.30 switch( MMIO_READ( PVR2, RENDER_PALETTE ) & 0x03 ) {1.31 case 0: /* ARGB1555 */1.32 - intFormat = GL_RGB5_A1;1.33 format = GL_BGRA;1.34 type = GL_UNSIGNED_SHORT_1_5_5_5_REV;1.35 break;1.36 case 1: /* RGB565 */1.37 - intFormat = GL_RGB5;1.38 + intFormat = GL_RGB;1.39 format = GL_RGB;1.40 type = GL_UNSIGNED_SHORT_5_6_5;1.41 break;1.42 case 2: /* ARGB4444 */1.43 - intFormat = GL_RGBA4;1.44 format = GL_BGRA;1.45 type = GL_UNSIGNED_SHORT_4_4_4_4_REV;1.46 break;1.47 case 3: /* ARGB8888 */1.48 - intFormat = GL_RGBA8;1.49 format = GL_BGRA;1.50 type = GL_UNSIGNED_INT_8_8_8_8_REV;1.51 bpp_shift = 2;1.52 @@ -359,17 +356,15 @@1.53 break;1.55 case PVR2_TEX_FORMAT_ARGB1555:1.56 - intFormat = GL_RGB5_A1;1.57 format = GL_BGRA;1.58 type = GL_UNSIGNED_SHORT_1_5_5_5_REV;1.59 break;1.60 case PVR2_TEX_FORMAT_RGB565:1.61 - intFormat = GL_RGB5;1.62 + intFormat = GL_RGB;1.63 format = GL_RGB;1.64 type = GL_UNSIGNED_SHORT_5_6_5;1.65 break;1.66 case PVR2_TEX_FORMAT_ARGB4444:1.67 - intFormat = GL_RGBA4;1.68 format = GL_BGRA;1.69 type = GL_UNSIGNED_SHORT_4_4_4_4_REV;1.70 break;1.71 @@ -378,7 +373,6 @@1.72 * it to a (reasonably) standard ARGB32.1.73 */1.74 bpp_shift = 2;1.75 - intFormat = GL_RGBA8;1.76 format = GL_BGRA;1.77 type = GL_UNSIGNED_INT_8_8_8_8_REV;1.78 break;1.79 @@ -405,7 +399,7 @@1.80 return;1.81 }1.83 - int level=0, last_level = 0, mip_width = width, mip_height = height, mip_bytes;1.84 + int level=0, last_level = 0, mip_width = width, mip_height = height, src_bytes, dest_bytes;1.85 if( PVR2_TEX_IS_MIPMAPPED(mode) ) {1.86 int i;1.87 for( i=0; 1<<i < width; i++ );1.88 @@ -414,7 +408,8 @@1.89 mip_height= 2;1.90 filter = GL_LINEAR_MIPMAP_LINEAR;1.91 }1.92 - mip_bytes = (mip_width * mip_height) << bpp_shift;1.93 + dest_bytes = (mip_width * mip_height) << bpp_shift;1.94 + src_bytes = dest_bytes; // Modes will change this (below)1.96 if( PVR2_TEX_IS_COMPRESSED(mode) ) {1.97 uint16_t tmp[VQ_CODEBOOK_SIZE];1.98 @@ -424,66 +419,67 @@1.99 }1.101 for( level=last_level; level>= 0; level-- ) {1.102 - char data[mip_bytes];1.103 + char data[dest_bytes];1.104 /* load data from image, detwiddling/uncompressing as required */1.105 if( tex_format == PVR2_TEX_FORMAT_IDX8 ) {1.106 - int inputlength = mip_bytes >> bpp_shift;1.107 + src_bytes = (mip_width * mip_height);1.108 int bank = (mode >> 25) &0x03;1.109 uint32_t *palette = ((uint32_t *)mmio_region_PVR2PAL.mem) + (bank<<8);1.110 - char tmp[inputlength];1.111 + char tmp[src_bytes];1.112 pvr2_vram64_read_twiddled_8( tmp, texture_addr, mip_width, mip_height );1.113 if( bpp_shift == 2 ) {1.114 - decode_pal8_to_32( (uint32_t *)data, tmp, inputlength, palette );1.115 + decode_pal8_to_32( (uint32_t *)data, tmp, src_bytes, palette );1.116 } else {1.117 - decode_pal8_to_16( (uint16_t *)data, tmp, inputlength, palette );1.118 + decode_pal8_to_16( (uint16_t *)data, tmp, src_bytes, palette );1.119 }1.120 } else if( tex_format == PVR2_TEX_FORMAT_IDX4 ) {1.121 - int inputlength = (mip_width * mip_height) >> 1;1.122 + src_bytes = (mip_width * mip_height) >> 1;1.123 int bank = (mode >>21 ) & 0x3F;1.124 uint32_t *palette = ((uint32_t *)mmio_region_PVR2PAL.mem) + (bank<<4);1.125 - char tmp[inputlength];1.126 + char tmp[src_bytes];1.127 pvr2_vram64_read_twiddled_4( tmp, texture_addr, mip_width, mip_height );1.128 if( bpp_shift == 2 ) {1.129 - decode_pal4_to_32( (uint32_t *)data, tmp, inputlength, palette );1.130 + decode_pal4_to_32( (uint32_t *)data, tmp, src_bytes, palette );1.131 } else {1.132 - decode_pal4_to_16( (uint16_t *)data, tmp, inputlength, palette );1.133 + decode_pal4_to_16( (uint16_t *)data, tmp, src_bytes, palette );1.134 }1.135 } else if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {1.136 - int inputlength = ((mip_width*mip_height)<<1);1.137 - char tmp[inputlength];1.138 + src_bytes = ((mip_width*mip_height)<<1);1.139 + char tmp[src_bytes];1.140 if( PVR2_TEX_IS_TWIDDLED(mode) ) {1.141 pvr2_vram64_read_twiddled_16( tmp, texture_addr, mip_width, mip_height );1.142 } else {1.143 - pvr2_vram64_read( tmp, texture_addr, inputlength );1.144 + pvr2_vram64_read( tmp, texture_addr, src_bytes );1.145 }1.146 yuv_decode( (uint32_t *)data, (uint32_t *)tmp, mip_width, mip_height );1.147 } else if( PVR2_TEX_IS_COMPRESSED(mode) ) {1.148 - int inputlength = ((mip_width*mip_height) >> 2);1.149 - char tmp[inputlength];1.150 + src_bytes = ((mip_width*mip_height) >> 2);1.151 + char tmp[src_bytes];1.152 if( PVR2_TEX_IS_TWIDDLED(mode) ) {1.153 pvr2_vram64_read_twiddled_8( tmp, texture_addr, mip_width>>1, mip_height>>1 );1.154 } else {1.155 - pvr2_vram64_read( tmp, texture_addr, inputlength );1.156 + pvr2_vram64_read( tmp, texture_addr, src_bytes );1.157 }1.158 vq_decode( (uint16_t *)data, tmp, mip_width, mip_height, &codebook );1.159 } else if( PVR2_TEX_IS_TWIDDLED(mode) ) {1.160 pvr2_vram64_read_twiddled_16( data, texture_addr, mip_width, mip_height );1.161 } else {1.162 - pvr2_vram64_read( data, texture_addr, mip_bytes );1.163 + pvr2_vram64_read( data, texture_addr, src_bytes );1.164 }1.166 /* Pass to GL */1.167 if( level == last_level && level != 0 ) { /* 1x1 stored within a 2x2 */1.168 glTexImage2D( GL_TEXTURE_2D, level, intFormat, 1, 1, 0, format, type,1.169 data + (3 << bpp_shift) );1.170 - texture_addr += mip_bytes;1.171 + texture_addr += src_bytes;1.172 } else {1.173 glTexImage2D( GL_TEXTURE_2D, level, intFormat, mip_width, mip_height, 0, format, type,1.174 data );1.175 - texture_addr += mip_bytes;1.176 + texture_addr += src_bytes;1.177 mip_width <<= 1;1.178 mip_height <<= 1;1.179 - mip_bytes <<= 2;1.180 + dest_bytes <<= 2;1.181 + src_bytes <<= 2;1.182 }1.183 }
.