From 4b90e68ac6d0fe4ffca5e2cd51794bb4350cac28 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 29 Jan 2001 18:51:25 +0000 Subject: [PATCH] optimized lambda computation (Klaus Niederkrueger) --- src/mesa/swrast/s_triangle.c | 19 +++++++-------- src/mesa/swrast/s_tritemp.h | 46 ++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c index aac7c6030ec..1819e4430fc 100644 --- a/src/mesa/swrast/s_triangle.c +++ b/src/mesa/swrast/s_triangle.c @@ -1,4 +1,4 @@ -/* $Id: s_triangle.c,v 1.9 2001/01/23 23:39:37 brianp Exp $ */ +/* $Id: s_triangle.c,v 1.10 2001/01/29 18:51:25 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -1826,6 +1826,7 @@ static void lambda_textured_triangle1( GLcontext *ctx, #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define INTERP_RGB 1 #define INTERP_ALPHA 1 +#define INTERP_LAMBDA 1 #define INTERP_TEX 1 #define SETUP_CODE \ @@ -1864,8 +1865,7 @@ static void lambda_textured_triangle1( GLcontext *ctx, s[i] = ss*invQ; \ t[i] = tt*invQ; \ u[i] = uu*invQ; \ - lambda[i] = compute_lambda( dsdx, dsdy, dtdx, dtdy, \ - invQ, twidth, theight );\ + lambda[i] = COMPUTE_LAMBDA(invQ); \ ffz += fdzdx; \ fffog += fdfogdx; \ ss += dsdx; \ @@ -1886,8 +1886,7 @@ static void lambda_textured_triangle1( GLcontext *ctx, s[i] = ss*invQ; \ t[i] = tt*invQ; \ u[i] = uu*invQ; \ - lambda[i] = compute_lambda( dsdx, dsdy, dtdx, dtdy, \ - invQ, twidth, theight );\ + lambda[i] = COMPUTE_LAMBDA(invQ); \ ffz += fdzdx; \ fffog += fdfogdx; \ ffr += fdrdx; \ @@ -1932,6 +1931,7 @@ static void lambda_textured_spec_triangle1( GLcontext *ctx, #define INTERP_SPEC 1 #define INTERP_ALPHA 1 #define INTERP_TEX 1 +#define INTERP_LAMBDA 1 #define SETUP_CODE \ const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; \ @@ -1976,8 +1976,7 @@ static void lambda_textured_spec_triangle1( GLcontext *ctx, s[i] = ss*invQ; \ t[i] = tt*invQ; \ u[i] = uu*invQ; \ - lambda[i] = compute_lambda( dsdx, dsdy, dtdx, dtdy, \ - invQ, twidth, theight );\ + lambda[i] = COMPUTE_LAMBDA(invQ); \ fffog += fdfogdx; \ ffz += fdzdx; \ ss += dsdx; \ @@ -2001,8 +2000,7 @@ static void lambda_textured_spec_triangle1( GLcontext *ctx, s[i] = ss*invQ; \ t[i] = tt*invQ; \ u[i] = uu*invQ; \ - lambda[i] = compute_lambda( dsdx, dsdy, dtdx, dtdy, \ - invQ, twidth, theight );\ + lambda[i] = COMPUTE_LAMBDA(invQ); \ fffog += fdfogdx; \ ffz += fdzdx; \ ffr += fdrdx; \ @@ -2307,6 +2305,7 @@ _swrast_choose_triangle( GLcontext *ctx ) && image->Border==0 && ((format = image->Format)==GL_RGB || format==GL_RGBA) && (filter = current2Dtex->MinFilter)==current2Dtex->MagFilter + /* ==> current2Dtex->MinFilter != GL_XXX_MIPMAP_XXX */ && ctx->Light.Model.ColorControl==GL_SINGLE_COLOR && ctx->Texture.Unit[0].EnvMode!=GL_COMBINE_EXT) { @@ -2384,7 +2383,7 @@ _swrast_choose_triangle( GLcontext *ctx ) } else { if (needLambda) { - swrast->Triangle = lambda_textured_triangle; + swrast->Triangle = lambda_textured_triangle; dputs("lambda_textured_triangle"); } else { diff --git a/src/mesa/swrast/s_tritemp.h b/src/mesa/swrast/s_tritemp.h index e139f3fc9f9..c0ab9f9d2c0 100644 --- a/src/mesa/swrast/s_tritemp.h +++ b/src/mesa/swrast/s_tritemp.h @@ -1,10 +1,10 @@ -/* $Id: s_tritemp.h,v 1.7 2001/01/23 23:39:37 brianp Exp $ */ +/* $Id: s_tritemp.h,v 1.8 2001/01/29 18:51:25 brianp Exp $ */ /* * Mesa 3-D graphics library * Version: 3.5 * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -39,6 +39,8 @@ * INTERP_INDEX - if defined, interpolate color index values * INTERP_INT_TEX - if defined, interpolate integer ST texcoords * (fast, simple 2-D texture mapping) + * INTERP_LAMBDA - if defined, the lambda value is computed at every + * pixel, to apply MIPMAPPING, and min/maxification * INTERP_TEX - if defined, interpolate set 0 float STRQ texcoords * NOTE: OpenGL STRQ = Mesa STUV (R was taken for red) * INTERP_MULTITEX - if defined, interpolate N units of STRQ texcoords @@ -278,6 +280,14 @@ GLfloat dudx[MAX_TEXTURE_UNITS], dudy[MAX_TEXTURE_UNITS]; GLfloat dvdx[MAX_TEXTURE_UNITS], dvdy[MAX_TEXTURE_UNITS]; #endif +#ifdef INTERP_LAMBDA + +#ifndef INTERP_TEX +#error "Mipmapping without texturing doesn't make sense." +#endif + GLfloat lambda_nominator; +#endif + /* * Execute user-supplied setup code @@ -955,6 +965,36 @@ if (ffi<0) ffi = 0; #endif +#ifdef INTERP_LAMBDA +/* + * The lambda value is: + * log_2(sqrt(f(n))) = 1/2*log_2(f(n)), where f(n) is a function + * defined by + * f(n):= dudx * dudx + dudy * dudy + dvdx * dvdx + dvdy * dvdy; + * and each of this terms is resp. + * dudx = dsdx * invQ(n) * tex_width; + * dudy = dsdy * invQ(n) * tex_width; + * dvdx = dtdx * invQ(n) * tex_height; + * dvdy = dtdy * invQ(n) * tex_height; + * Therefore the function lambda can be represented (by factoring out) as: + * f(n) = lambda_nominator * invQ(n) * invQ(n), + * which saves some computation time. + */ + { + GLfloat dudx = dsdx /* * invQ*/ * twidth; + GLfloat dudy = dsdy /* * invQ*/ * twidth; + GLfloat dvdx = dtdx /* * invQ*/ * theight; + GLfloat dvdy = dtdy /* * invQ*/ * theight; + GLfloat r1 = dudx * dudx + dudy * dudy; + GLfloat r2 = dvdx * dvdx + dvdy * dvdy; + GLfloat rho2 = r1 + r2; /* used to be: rho2 = MAX2(r1,r2); */ + lambda_nominator = rho2; + } + + /* return log base 2 of sqrt(rho) */ +#define COMPUTE_LAMBDA(X) log( lambda_nominator * (X)*(X) ) * 1.442695F * 0.5F /* 1.442695 = 1/log(2) */ +#endif + INNER_LOOP( left, right, iy ); /* @@ -1084,6 +1124,8 @@ #undef INTERP_SPEC #undef INTERP_ALPHA #undef INTERP_INDEX +#undef INTERP_LAMBDA +#undef COMPUTE_LAMBDA #undef INTERP_INT_TEX #undef INTERP_TEX #undef INTERP_MULTITEX -- 2.30.2