--- a/src/pvr2/texcache.c Tue Mar 20 08:29:38 2012 +1000 +++ b/src/pvr2/texcache.c Tue Mar 27 08:23:52 2012 +1000 @@ -61,7 +61,6 @@ static uint32_t texcache_palette_mode; static uint32_t texcache_stride_width; static gboolean texcache_have_palette_shader; -static gboolean texcache_have_bgra; static gboolean texcache_palette_valid; static GLuint texcache_palette_texid; @@ -142,14 +141,13 @@ } else { texcache_have_palette_shader = FALSE; } - texcache_have_bgra = isGLBGRATextureSupported(); glGenTextures( MAX_TEXTURES, texids ); for( i=0; icapabilities.has_bgra ? "BGRA" : "RGBA") ); } /** @@ -252,73 +250,6 @@ } /** - * Convert BGRA data in buffer to RGBA format (for systems that don't natively - * support BGRA). - * @return converted format type - * @param data BGRA pixel data - * @param nPixels total number of pixels (width*height) - * @param glFormatType GL format of source data. One of - * GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_SHORT_4_4_4_4_REV, or GL_UNSIGNED_BYTE - */ -static int bgra_to_rgba( unsigned char *data, unsigned nPixels, int glFormatType ) -{ - unsigned i; - switch( glFormatType ) { - case GL_UNSIGNED_SHORT_1_5_5_5_REV: { - uint16_t *p = (uint16_t *)data; - uint16_t *end = p + nPixels; - while( p != end ) { - uint16_t v = *p; - *p = (v >> 15) | (v<<1); - p++; - } - return GL_UNSIGNED_SHORT_5_5_5_1; - } - case GL_UNSIGNED_SHORT_4_4_4_4_REV: { /* ARGB => RGBA */ - uint16_t *p = (uint16_t *)data; - uint16_t *end = p + nPixels; - while( p != end ) { - uint16_t v = *p; - *p = (v >> 12) | (v<<4); - p++; - } - return GL_UNSIGNED_SHORT_4_4_4_4; - } - case GL_UNSIGNED_BYTE: { /* ARGB => ABGR */ - uint32_t *p = (uint32_t *)data; - uint32_t *end = p + nPixels; - while( p != end ) { - uint32_t v = *p; - *p = (v&0xFF000000) | ((v<<16) & 0x00FF0000) | (v & 0x0000FF00) | ((v>>16) & 0x000000FF); - p++; - } - return GL_UNSIGNED_BYTE; - } - default: - assert( 0 && "Unsupported BGRA format" ); - return glFormatType; - } -} - -/** - * Install the image data in the currently bound 2D texture. - * May modify the buffered data if needed to make the texture compatible with - * the GL. - */ -static void texcache_load_image_2D( int level, GLint intFormat, int width, int height, GLint format, GLint type, unsigned char *data ) -{ - if( format == GL_BGRA && !texcache_have_bgra ) { - GLint rgbaType = bgra_to_rgba( data, width*height, type ); - glTexImage2D( GL_TEXTURE_2D, level, intFormat, width, height, 0, GL_RGBA, rgbaType, - data ); - } else { - glTexImage2D( GL_TEXTURE_2D, level, intFormat, width, height, 0, format, type, - data ); - } - -} - -/** * Load the palette into 4 textures of 256 entries each. This mirrors the * banking done by the PVR2 for 8-bit textures, and also ensures that we * can use 8-bit paletted textures ourselves. @@ -329,7 +260,7 @@ unsigned i; int bpp = 2; uint32_t *palette = (uint32_t *)mmio_region_PVR2PAL.mem; - char buf[4096]; + uint16_t packed_palette[1024]; char *data = (char *)palette; switch( texcache_palette_mode ) { @@ -356,27 +287,17 @@ } if( bpp == 2 ) { - data = buf; - uint16_t *packed_palette = (uint16_t *)buf; for( i=0; i<1024; i++ ) { packed_palette[i] = (uint16_t)palette[i]; } - if( !texcache_have_bgra && format == GL_BGRA ) { - type = bgra_to_rgba(data, 1024, type); - format = GL_RGBA; - } - } else if( !texcache_have_bgra && format == GL_BGRA ) { /* bpp == 4 */ - data = buf; - memcpy( buf, palette, 4096 ); - type = bgra_to_rgba(buf, 1024, type); - format = GL_RGBA; + data = (char *)packed_palette; } glActiveTexture(GL_TEXTURE1); if( format_changed ) - glTexImage2D(GL_TEXTURE_2D, 0, intFormat, 1024, 1, 0, format, type, data ); + glTexImage2DBGRA(0, intFormat, 1024, 1, format, type, data, data == (char *)palette ); else - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1024, 1, format, type, data); + glTexSubImage2DBGRA(0, 0, 0, 1024, 1, format, type, data, data == (char *)palette); glActiveTexture(GL_TEXTURE0); texcache_palette_valid = TRUE; } @@ -660,7 +581,7 @@ } else { pvr2_vram64_read_stride( data, width< 2 ) { mip_width >>= 1; mip_height >>= 1;