From 2a9eca0ed4d07329141bf8226b60eef83101a216 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 18 Jul 2001 14:10:51 +0000 Subject: [PATCH] do some 16-bit GLchan computations in floating point (Gerk Huisma) --- src/mesa/swrast/s_texture.c | 65 ++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c index fa450db3fdb..f5c974214d1 100644 --- a/src/mesa/swrast/s_texture.c +++ b/src/mesa/swrast/s_texture.c @@ -1,4 +1,4 @@ -/* $Id: s_texture.c,v 1.34 2001/07/14 17:53:04 brianp Exp $ */ +/* $Id: s_texture.c,v 1.35 2001/07/18 14:10:51 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -324,15 +324,14 @@ sample_1d_linear(GLcontext *ctx, { const GLfloat a = FRAC(u); -#if CHAN_TYPE == GL_FLOAT +#if CHAN_TYPE == GL_FLOAT || CHAN_TYPE == GL_UNSIGNED_SHORT const GLfloat w0 = (1.0F-a); const GLfloat w1 = a ; -#else /* CHAN_BITS == 8 || CHAN_BITS == 16 */ +#else /* CHAN_BITS == 8 */ /* compute sample weights in fixed point in [0,WEIGHT_SCALE] */ const GLint w0 = IROUND_POS((1.0F - a) * WEIGHT_SCALE); const GLint w1 = IROUND_POS( a * WEIGHT_SCALE); #endif - GLchan t0[4], t1[4]; /* texels */ if (useBorderColor & I0BIT) { @@ -359,7 +358,12 @@ sample_1d_linear(GLcontext *ctx, rgba[1] = w0 * t0[1] + w1 * t1[1]; rgba[2] = w0 * t0[2] + w1 * t1[2]; rgba[3] = w0 * t0[3] + w1 * t1[3]; -#else /* CHAN_BITS == 8 || CHAN_BITS == 16 */ +#elif CHAN_TYPE == GL_UNSIGNED_SHORT + rgba[0] = (GLchan) (w0 * t0[0] + w1 * t1[0] + 0.5); + rgba[1] = (GLchan) (w0 * t0[1] + w1 * t1[1] + 0.5); + rgba[2] = (GLchan) (w0 * t0[2] + w1 * t1[2] + 0.5); + rgba[3] = (GLchan) (w0 * t0[3] + w1 * t1[3] + 0.5); +#else /* CHAN_BITS == 8 */ rgba[0] = (GLchan) ((w0 * t0[0] + w1 * t1[0]) >> WEIGHT_SHIFT); rgba[1] = (GLchan) ((w0 * t0[1] + w1 * t1[1]) >> WEIGHT_SHIFT); rgba[2] = (GLchan) ((w0 * t0[2] + w1 * t1[2]) >> WEIGHT_SHIFT); @@ -647,19 +651,18 @@ sample_2d_linear(GLcontext *ctx, const GLfloat a = FRAC(u); const GLfloat b = FRAC(v); -#if CHAN_TYPE == GL_FLOAT +#if CHAN_TYPE == GL_FLOAT || CHAN_TYPE == GL_UNSIGNED_SHORT const GLfloat w00 = (1.0F-a) * (1.0F-b); const GLfloat w10 = a * (1.0F-b); const GLfloat w01 = (1.0F-a) * b ; const GLfloat w11 = a * b ; -#else /* CHAN_BITS == 8 || CHAN_BITS == 16 */ +#else /* CHAN_BITS == 8 */ /* compute sample weights in fixed point in [0,WEIGHT_SCALE] */ const GLint w00 = IROUND_POS((1.0F-a) * (1.0F-b) * WEIGHT_SCALE); const GLint w10 = IROUND_POS( a * (1.0F-b) * WEIGHT_SCALE); const GLint w01 = IROUND_POS((1.0F-a) * b * WEIGHT_SCALE); const GLint w11 = IROUND_POS( a * b * WEIGHT_SCALE); #endif - GLchan t00[4]; GLchan t10[4]; GLchan t01[4]; @@ -706,11 +709,24 @@ sample_2d_linear(GLcontext *ctx, rgba[1] = w00 * t00[1] + w10 * t10[1] + w01 * t01[1] + w11 * t11[1]; rgba[2] = w00 * t00[2] + w10 * t10[2] + w01 * t01[2] + w11 * t11[2]; rgba[3] = w00 * t00[3] + w10 * t10[3] + w01 * t01[3] + w11 * t11[3]; -#else /* CHAN_BITS == 8 || CHAN_BITS == 16 */ - rgba[0] = (GLchan) ((w00 * t00[0] + w10 * t10[0] + w01 * t01[0] + w11 * t11[0]) >> WEIGHT_SHIFT); - rgba[1] = (GLchan) ((w00 * t00[1] + w10 * t10[1] + w01 * t01[1] + w11 * t11[1]) >> WEIGHT_SHIFT); - rgba[2] = (GLchan) ((w00 * t00[2] + w10 * t10[2] + w01 * t01[2] + w11 * t11[2]) >> WEIGHT_SHIFT); - rgba[3] = (GLchan) ((w00 * t00[3] + w10 * t10[3] + w01 * t01[3] + w11 * t11[3]) >> WEIGHT_SHIFT); +#elif CHAN_TYPE == GL_UNSIGNED_SHORT + rgba[0] = (GLchan) (w00 * t00[0] + w10 * t10[0] + + w01 * t01[0] + w11 * t11[0] + 0.5); + rgba[1] = (GLchan) (w00 * t00[1] + w10 * t10[1] + + w01 * t01[1] + w11 * t11[1] + 0.5); + rgba[2] = (GLchan) (w00 * t00[2] + w10 * t10[2] + + w01 * t01[2] + w11 * t11[2] + 0.5); + rgba[3] = (GLchan) (w00 * t00[3] + w10 * t10[3] + + w01 * t01[3] + w11 * t11[3] + 0.5); +#else /* CHAN_BITS == 8 */ + rgba[0] = (GLchan) ((w00 * t00[0] + w10 * t10[0] + + w01 * t01[0] + w11 * t11[0]) >> WEIGHT_SHIFT); + rgba[1] = (GLchan) ((w00 * t00[1] + w10 * t10[1] + + w01 * t01[1] + w11 * t11[1]) >> WEIGHT_SHIFT); + rgba[2] = (GLchan) ((w00 * t00[2] + w10 * t10[2] + + w01 * t01[2] + w11 * t11[2]) >> WEIGHT_SHIFT); + rgba[3] = (GLchan) ((w00 * t00[3] + w10 * t10[3] + + w01 * t01[3] + w11 * t11[3]) >> WEIGHT_SHIFT); #endif } @@ -1092,7 +1108,7 @@ sample_3d_linear(GLcontext *ctx, const GLfloat b = FRAC(v); const GLfloat c = FRAC(w); -#if CHAN_TYPE == GL_FLOAT +#if CHAN_TYPE == GL_FLOAT || CHAN_TYPE == GL_UNSIGNED_SHORT /* compute sample weights in fixed point in [0,WEIGHT_SCALE] */ GLfloat w000 = (1.0F-a) * (1.0F-b) * (1.0F-c); GLfloat w100 = a * (1.0F-b) * (1.0F-c); @@ -1102,7 +1118,7 @@ sample_3d_linear(GLcontext *ctx, GLfloat w101 = a * (1.0F-b) * c ; GLfloat w011 = (1.0F-a) * b * c ; GLfloat w111 = a * b * c ; -#else /* CHAN_BITS == 8 || CHAN_BITS == 16 */ +#else /* CHAN_BITS == 8 */ /* compute sample weights in fixed point in [0,WEIGHT_SCALE] */ GLint w000 = IROUND_POS((1.0F-a) * (1.0F-b) * (1.0F-c) * WEIGHT_SCALE); GLint w100 = IROUND_POS( a * (1.0F-b) * (1.0F-c) * WEIGHT_SCALE); @@ -1200,7 +1216,24 @@ sample_3d_linear(GLcontext *ctx, w100*t100[2] + w110*t110[2] + w101*t101[2] + w111*t111[2]; rgba[3] = w000*t000[3] + w010*t010[3] + w001*t001[3] + w011*t011[3] + w100*t100[3] + w110*t110[3] + w101*t101[3] + w111*t111[3]; -#else /* CHAN_BITS == 8 || CHAN_BITS == 16 */ +#elif CHAN_TYPE == GL_UNSIGNED_SHORT + rgba[0] = (GLchan) (w000*t000[0] + w010*t010[0] + + w001*t001[0] + w011*t011[0] + + w100*t100[0] + w110*t110[0] + + w101*t101[0] + w111*t111[0] + 0.5); + rgba[1] = (GLchan) (w000*t000[1] + w010*t010[1] + + w001*t001[1] + w011*t011[1] + + w100*t100[1] + w110*t110[1] + + w101*t101[1] + w111*t111[1] + 0.5); + rgba[2] = (GLchan) (w000*t000[2] + w010*t010[2] + + w001*t001[2] + w011*t011[2] + + w100*t100[2] + w110*t110[2] + + w101*t101[2] + w111*t111[2] + 0.5); + rgba[3] = (GLchan) (w000*t000[3] + w010*t010[3] + + w001*t001[3] + w011*t011[3] + + w100*t100[3] + w110*t110[3] + + w101*t101[3] + w111*t111[3] + 0.5); +#else /* CHAN_BITS == 8 */ rgba[0] = (GLchan) ( (w000*t000[0] + w010*t010[0] + w001*t001[0] + w011*t011[0] + w100*t100[0] + w110*t110[0] + w101*t101[0] + w111*t111[0] ) -- 2.30.2