filename | src/pvr2/texcache.c |
changeset | 654:d40b3b68fbdf |
prev | 653:3202ff01d48e |
next | 677:3ee62740ff8f |
author | nkeynes |
date | Tue Apr 01 01:04:13 2008 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Load mipmap textures from largest-to-smallest (instead of the other way around) - works around bug in the ATI drivers |
file | annotate | diff | log | raw |
1.1 --- a/src/pvr2/texcache.c Fri Mar 28 12:32:25 2008 +00001.2 +++ b/src/pvr2/texcache.c Tue Apr 01 01:04:13 2008 +00001.3 @@ -334,6 +334,7 @@1.4 GLint filter = GL_LINEAR;1.6 glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );1.7 +1.8 /* Decode the format parameters */1.9 switch( tex_format ) {1.10 case PVR2_TEX_FORMAT_IDX4:1.11 @@ -412,18 +413,6 @@1.12 return;1.13 }1.15 - int level=0, last_level = 0, mip_width = width, mip_height = height, src_bytes, dest_bytes;1.16 - if( PVR2_TEX_IS_MIPMAPPED(mode) ) {1.17 - int i;1.18 - for( i=0; 1<<i < width; i++ );1.19 - last_level = i;1.20 - mip_width = 2;1.21 - mip_height= 2;1.22 - filter = GL_LINEAR_MIPMAP_LINEAR;1.23 - }1.24 - dest_bytes = (mip_width * mip_height) << bpp_shift;1.25 - src_bytes = dest_bytes; // Modes will change this (below)1.26 -1.27 if( PVR2_TEX_IS_COMPRESSED(mode) ) {1.28 uint16_t tmp[VQ_CODEBOOK_SIZE];1.29 pvr2_vram64_read( (unsigned char *)tmp, texture_addr, VQ_CODEBOOK_SIZE );1.30 @@ -431,7 +420,35 @@1.31 vq_get_codebook( &codebook, tmp );1.32 }1.34 - for( level=last_level; level>= 0; level-- ) {1.35 + int level=0, last_level = 0, mip_width = width, mip_height = height, src_bytes, dest_bytes;1.36 + if( PVR2_TEX_IS_MIPMAPPED(mode) ) {1.37 + uint32_t src_offset = 0;1.38 + filter = GL_LINEAR_MIPMAP_LINEAR;1.39 + mip_height = height = width;1.40 + while( (1<<last_level) < width ) {1.41 + last_level++;1.42 + src_offset += ((width>>last_level)*(width>>last_level));1.43 + }1.44 + if( width != 1 ) {1.45 + src_offset += 3;1.46 + }1.47 + if( PVR2_TEX_IS_COMPRESSED(mode) ) {1.48 + src_offset >>= 2;1.49 + } else if( tex_format == PVR2_TEX_FORMAT_IDX4 ) {1.50 + src_offset >>= 1;1.51 + } else if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {1.52 + src_offset <<= 1;1.53 + } else if( tex_format != PVR2_TEX_FORMAT_IDX8 ) {1.54 + src_offset <<= bpp_shift;1.55 + }1.56 + texture_addr += src_offset;1.57 + }1.58 +1.59 +1.60 + dest_bytes = (mip_width * mip_height) << bpp_shift;1.61 + src_bytes = dest_bytes; // Modes will change this (below)1.62 +1.63 + for( level=0; level<= last_level; level++ ) {1.64 unsigned char data[dest_bytes];1.65 /* load data from image, detwiddling/uncompressing as required */1.66 if( tex_format == PVR2_TEX_FORMAT_IDX8 ) {1.67 @@ -484,15 +501,16 @@1.68 if( level == last_level && level != 0 ) { /* 1x1 stored within a 2x2 */1.69 glTexImage2D( GL_TEXTURE_2D, level, intFormat, 1, 1, 0, format, type,1.70 data + (3 << bpp_shift) );1.71 - texture_addr += src_bytes;1.72 } else {1.73 glTexImage2D( GL_TEXTURE_2D, level, intFormat, mip_width, mip_height, 0, format, type,1.74 data );1.75 - texture_addr += src_bytes;1.76 - mip_width <<= 1;1.77 - mip_height <<= 1;1.78 - dest_bytes <<= 2;1.79 - src_bytes <<= 2;1.80 + if( mip_width > 2 ) {1.81 + mip_width >>= 1;1.82 + mip_height >>= 1;1.83 + dest_bytes >>= 2;1.84 + src_bytes >>= 2;1.85 + }1.86 + texture_addr -= src_bytes;1.87 }1.88 }
.