From ff1f093a0bab87bc08f4bc2a8fef6a5a8878f861 Mon Sep 17 00:00:00 2001 From: SmileTheory Date: Fri, 1 Aug 2014 23:57:26 -0700 Subject: [PATCH] OpenGL2: Remove R_MipMap() and R_MipMap2(), and fix gamma conversion in R_MipMapsRGB() --- code/renderergl2/tr_image.c | 102 ++---------------------------------- 1 file changed, 3 insertions(+), 99 deletions(-) diff --git a/code/renderergl2/tr_image.c b/code/renderergl2/tr_image.c index eff21988..6c8dc456 100644 --- a/code/renderergl2/tr_image.c +++ b/code/renderergl2/tr_image.c @@ -1275,61 +1275,12 @@ void R_LightScaleTexture (byte *in, int inwidth, int inheight, qboolean only_gam /* ================ -R_MipMap2 +R_MipMapsRGB Operates in place, quartering the size of the texture -Proper linear filter +Colors are gamma correct ================ */ -static void R_MipMap2( byte *in, int inWidth, int inHeight ) { - int i, j, k; - byte *outpix; - int inWidthMask, inHeightMask; - int total; - int outWidth, outHeight; - unsigned *temp; - - outWidth = inWidth >> 1; - outHeight = inHeight >> 1; - temp = ri.Hunk_AllocateTempMemory( outWidth * outHeight * 4 ); - - inWidthMask = inWidth - 1; - inHeightMask = inHeight - 1; - - for ( i = 0 ; i < outHeight ; i++ ) { - for ( j = 0 ; j < outWidth ; j++ ) { - outpix = (byte *) ( temp + i * outWidth + j ); - for ( k = 0 ; k < 4 ; k++ ) { - total = - 1 * (&in[ 4*(((i*2-1)&inHeightMask)*inWidth + ((j*2-1)&inWidthMask)) ])[k] + - 2 * (&in[ 4*(((i*2-1)&inHeightMask)*inWidth + ((j*2 )&inWidthMask)) ])[k] + - 2 * (&in[ 4*(((i*2-1)&inHeightMask)*inWidth + ((j*2+1)&inWidthMask)) ])[k] + - 1 * (&in[ 4*(((i*2-1)&inHeightMask)*inWidth + ((j*2+2)&inWidthMask)) ])[k] + - - 2 * (&in[ 4*(((i*2 )&inHeightMask)*inWidth + ((j*2-1)&inWidthMask)) ])[k] + - 4 * (&in[ 4*(((i*2 )&inHeightMask)*inWidth + ((j*2 )&inWidthMask)) ])[k] + - 4 * (&in[ 4*(((i*2 )&inHeightMask)*inWidth + ((j*2+1)&inWidthMask)) ])[k] + - 2 * (&in[ 4*(((i*2 )&inHeightMask)*inWidth + ((j*2+2)&inWidthMask)) ])[k] + - - 2 * (&in[ 4*(((i*2+1)&inHeightMask)*inWidth + ((j*2-1)&inWidthMask)) ])[k] + - 4 * (&in[ 4*(((i*2+1)&inHeightMask)*inWidth + ((j*2 )&inWidthMask)) ])[k] + - 4 * (&in[ 4*(((i*2+1)&inHeightMask)*inWidth + ((j*2+1)&inWidthMask)) ])[k] + - 2 * (&in[ 4*(((i*2+1)&inHeightMask)*inWidth + ((j*2+2)&inWidthMask)) ])[k] + - - 1 * (&in[ 4*(((i*2+2)&inHeightMask)*inWidth + ((j*2-1)&inWidthMask)) ])[k] + - 2 * (&in[ 4*(((i*2+2)&inHeightMask)*inWidth + ((j*2 )&inWidthMask)) ])[k] + - 2 * (&in[ 4*(((i*2+2)&inHeightMask)*inWidth + ((j*2+1)&inWidthMask)) ])[k] + - 1 * (&in[ 4*(((i*2+2)&inHeightMask)*inWidth + ((j*2+2)&inWidthMask)) ])[k]; - outpix[k] = total / 36; - } - } - } - - Com_Memcpy( in, temp, outWidth * outHeight * 4 ); - ri.Hunk_FreeTempMemory( temp ); -} - - static void R_MipMapsRGB( byte *in, int inWidth, int inHeight) { int x, y, c, stride; @@ -1341,7 +1292,7 @@ static void R_MipMapsRGB( byte *in, int inWidth, int inHeight) if (!downmipSrgbLookupSet) { for (x = 0; x < 256; x++) - downmipSrgbLookup[x] = ((x < 10) ? x / 3294.6f : powf((x / 255.0f + 0.055f) / 1.055f, 2.4f)) * 0.25f; + downmipSrgbLookup[x] = powf(x / 255.0f, 2.2f) * 0.25f; downmipSrgbLookupSet = 1; } @@ -1379,53 +1330,6 @@ static void R_MipMapsRGB( byte *in, int inWidth, int inHeight) } } -/* -================ -R_MipMap - -Operates in place, quartering the size of the texture -================ -*/ -static void R_MipMap (byte *in, int width, int height) { - int i, j; - byte *out; - int row; - - if ( !r_simpleMipMaps->integer ) { - R_MipMap2( in, width, height ); - return; - } - - if ( width == 1 && height == 1 ) { - return; - } - - row = width * 4; - out = in; - width >>= 1; - height >>= 1; - - if ( width == 0 || height == 0 ) { - width += height; // get largest - for (i=0 ; i>1; - out[1] = ( in[1] + in[5] )>>1; - out[2] = ( in[2] + in[6] )>>1; - out[3] = ( in[3] + in[7] )>>1; - } - return; - } - - for (i=0 ; i>2; - out[1] = (in[1] + in[5] + in[row+1] + in[row+5])>>2; - out[2] = (in[2] + in[6] + in[row+2] + in[row+6])>>2; - out[3] = (in[3] + in[7] + in[row+3] + in[row+7])>>2; - } - } -} - static void R_MipMapLuminanceAlpha (const byte *in, byte *out, int width, int height) {