Search
lxdream.org :: lxdream/src/pvr2/texcache.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/texcache.c
changeset 1282:9f445c5e252b
prev1275:83b15705cdde
next1298:d0eb2307b847
author nkeynes
date Tue Mar 27 08:23:52 2012 +1000 (10 years ago)
permissions -rw-r--r--
last change Android: Preserve render buffers when switching away from app.
- fix gl_read_render_buffer + gl_load_frame_buffer to work in GLES
a) glReadPixels only (guaranteed to) work for GL_RGBA,GL_UNSIGNED_BYTE
b) glTexSubImage2D can only load GL_RGBA into a GL_RGBA render buffer.
file annotate diff log raw
1.1 --- a/src/pvr2/texcache.c Tue Mar 20 08:29:38 2012 +1000
1.2 +++ b/src/pvr2/texcache.c Tue Mar 27 08:23:52 2012 +1000
1.3 @@ -61,7 +61,6 @@
1.4 static uint32_t texcache_palette_mode;
1.5 static uint32_t texcache_stride_width;
1.6 static gboolean texcache_have_palette_shader;
1.7 -static gboolean texcache_have_bgra;
1.8 static gboolean texcache_palette_valid;
1.9 static GLuint texcache_palette_texid;
1.10
1.11 @@ -142,14 +141,13 @@
1.12 } else {
1.13 texcache_have_palette_shader = FALSE;
1.14 }
1.15 - texcache_have_bgra = isGLBGRATextureSupported();
1.16
1.17 glGenTextures( MAX_TEXTURES, texids );
1.18 for( i=0; i<MAX_TEXTURES; i++ ) {
1.19 texcache_active_list[i].texture_id = texids[i];
1.20 }
1.21 INFO( "Texcache initialized (%s, %s)", (texcache_have_palette_shader ? "Palette shader" : "No palette support"),
1.22 - (texcache_have_bgra ? "BGRA" : "RGBA") );
1.23 + (display_driver->capabilities.has_bgra ? "BGRA" : "RGBA") );
1.24 }
1.25
1.26 /**
1.27 @@ -252,73 +250,6 @@
1.28 }
1.29
1.30 /**
1.31 - * Convert BGRA data in buffer to RGBA format (for systems that don't natively
1.32 - * support BGRA).
1.33 - * @return converted format type
1.34 - * @param data BGRA pixel data
1.35 - * @param nPixels total number of pixels (width*height)
1.36 - * @param glFormatType GL format of source data. One of
1.37 - * GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_SHORT_4_4_4_4_REV, or GL_UNSIGNED_BYTE
1.38 - */
1.39 -static int bgra_to_rgba( unsigned char *data, unsigned nPixels, int glFormatType )
1.40 -{
1.41 - unsigned i;
1.42 - switch( glFormatType ) {
1.43 - case GL_UNSIGNED_SHORT_1_5_5_5_REV: {
1.44 - uint16_t *p = (uint16_t *)data;
1.45 - uint16_t *end = p + nPixels;
1.46 - while( p != end ) {
1.47 - uint16_t v = *p;
1.48 - *p = (v >> 15) | (v<<1);
1.49 - p++;
1.50 - }
1.51 - return GL_UNSIGNED_SHORT_5_5_5_1;
1.52 - }
1.53 - case GL_UNSIGNED_SHORT_4_4_4_4_REV: { /* ARGB => RGBA */
1.54 - uint16_t *p = (uint16_t *)data;
1.55 - uint16_t *end = p + nPixels;
1.56 - while( p != end ) {
1.57 - uint16_t v = *p;
1.58 - *p = (v >> 12) | (v<<4);
1.59 - p++;
1.60 - }
1.61 - return GL_UNSIGNED_SHORT_4_4_4_4;
1.62 - }
1.63 - case GL_UNSIGNED_BYTE: { /* ARGB => ABGR */
1.64 - uint32_t *p = (uint32_t *)data;
1.65 - uint32_t *end = p + nPixels;
1.66 - while( p != end ) {
1.67 - uint32_t v = *p;
1.68 - *p = (v&0xFF000000) | ((v<<16) & 0x00FF0000) | (v & 0x0000FF00) | ((v>>16) & 0x000000FF);
1.69 - p++;
1.70 - }
1.71 - return GL_UNSIGNED_BYTE;
1.72 - }
1.73 - default:
1.74 - assert( 0 && "Unsupported BGRA format" );
1.75 - return glFormatType;
1.76 - }
1.77 -}
1.78 -
1.79 -/**
1.80 - * Install the image data in the currently bound 2D texture.
1.81 - * May modify the buffered data if needed to make the texture compatible with
1.82 - * the GL.
1.83 - */
1.84 -static void texcache_load_image_2D( int level, GLint intFormat, int width, int height, GLint format, GLint type, unsigned char *data )
1.85 -{
1.86 - if( format == GL_BGRA && !texcache_have_bgra ) {
1.87 - GLint rgbaType = bgra_to_rgba( data, width*height, type );
1.88 - glTexImage2D( GL_TEXTURE_2D, level, intFormat, width, height, 0, GL_RGBA, rgbaType,
1.89 - data );
1.90 - } else {
1.91 - glTexImage2D( GL_TEXTURE_2D, level, intFormat, width, height, 0, format, type,
1.92 - data );
1.93 - }
1.94 -
1.95 -}
1.96 -
1.97 -/**
1.98 * Load the palette into 4 textures of 256 entries each. This mirrors the
1.99 * banking done by the PVR2 for 8-bit textures, and also ensures that we
1.100 * can use 8-bit paletted textures ourselves.
1.101 @@ -329,7 +260,7 @@
1.102 unsigned i;
1.103 int bpp = 2;
1.104 uint32_t *palette = (uint32_t *)mmio_region_PVR2PAL.mem;
1.105 - char buf[4096];
1.106 + uint16_t packed_palette[1024];
1.107 char *data = (char *)palette;
1.108
1.109 switch( texcache_palette_mode ) {
1.110 @@ -356,27 +287,17 @@
1.111 }
1.112
1.113 if( bpp == 2 ) {
1.114 - data = buf;
1.115 - uint16_t *packed_palette = (uint16_t *)buf;
1.116 for( i=0; i<1024; i++ ) {
1.117 packed_palette[i] = (uint16_t)palette[i];
1.118 }
1.119 - if( !texcache_have_bgra && format == GL_BGRA ) {
1.120 - type = bgra_to_rgba(data, 1024, type);
1.121 - format = GL_RGBA;
1.122 - }
1.123 - } else if( !texcache_have_bgra && format == GL_BGRA ) { /* bpp == 4 */
1.124 - data = buf;
1.125 - memcpy( buf, palette, 4096 );
1.126 - type = bgra_to_rgba(buf, 1024, type);
1.127 - format = GL_RGBA;
1.128 + data = (char *)packed_palette;
1.129 }
1.130
1.131 glActiveTexture(GL_TEXTURE1);
1.132 if( format_changed )
1.133 - glTexImage2D(GL_TEXTURE_2D, 0, intFormat, 1024, 1, 0, format, type, data );
1.134 + glTexImage2DBGRA(0, intFormat, 1024, 1, format, type, data, data == (char *)palette );
1.135 else
1.136 - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1024, 1, format, type, data);
1.137 + glTexSubImage2DBGRA(0, 0, 0, 1024, 1, format, type, data, data == (char *)palette);
1.138 glActiveTexture(GL_TEXTURE0);
1.139 texcache_palette_valid = TRUE;
1.140 }
1.141 @@ -660,7 +581,7 @@
1.142 } else {
1.143 pvr2_vram64_read_stride( data, width<<bpp_shift, texture_addr, texcache_stride_width<<bpp_shift, height );
1.144 }
1.145 - texcache_load_image_2D( 0, intFormat, width, height, format, type, data );
1.146 + glTexImage2DBGRA( 0, intFormat, width, height, format, type, data, FALSE );
1.147 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
1.148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, max_filter);
1.149 return;
1.150 @@ -761,10 +682,10 @@
1.151
1.152 /* Pass to GL */
1.153 if( level == last_level && level != 0 ) { /* 1x1 stored within a 2x2 */
1.154 - texcache_load_image_2D( level, intFormat, 1, 1, format, type,
1.155 - data + (3 << bpp_shift) );
1.156 + glTexImage2DBGRA( level, intFormat, 1, 1, format, type,
1.157 + data + (3 << bpp_shift), FALSE );
1.158 } else {
1.159 - texcache_load_image_2D( level, intFormat, mip_width, mip_height, format, type, data );
1.160 + glTexImage2DBGRA( level, intFormat, mip_width, mip_height, format, type, data, FALSE );
1.161 if( mip_width > 2 ) {
1.162 mip_width >>= 1;
1.163 mip_height >>= 1;
.