-/* $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
#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 \
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; \
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; \
#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; \
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; \
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; \
&& 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) {
}
else {
if (needLambda) {
- swrast->Triangle = lambda_textured_triangle;
+ swrast->Triangle = lambda_textured_triangle;
dputs("lambda_textured_triangle");
}
else {
-/* $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"),
* 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
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
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 );
/*
#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