X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmesa%2Fswrast%2Fs_texture.c;h=60091e3743ee7069064cbe5acf536bb5a9a7ef13;hb=1fe3b1d96459b59381be449a8dc869421071a430;hp=405eae95f04909fa2a13a1e2658e5ac3447bae2b;hpb=f1ad551604122dd2679dbd31ae6b2fa1197e9848;p=mesa.git diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c index 405eae95f04..60091e3743e 100644 --- a/src/mesa/swrast/s_texture.c +++ b/src/mesa/swrast/s_texture.c @@ -1,8 +1,8 @@ -/* $Id: s_texture.c,v 1.64 2002/06/26 14:56:20 brianp Exp $ */ +/* $Id: s_texture.c,v 1.75 2002/11/12 19:27:24 brianp Exp $ */ /* * Mesa 3-D graphics library - * Version: 4.1 + * Version: 5.0 * * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. * @@ -30,7 +30,7 @@ #include "colormac.h" #include "macros.h" #include "mmath.h" -#include "mem.h" +#include "imports.h" #include "texformat.h" #include "teximage.h" @@ -97,6 +97,31 @@ U = 1.0F - (S - (GLfloat) flr); /* flr is odd */ \ else \ U = S - (GLfloat) flr; /* flr is even */ \ + U = (U * SIZE) - 0.5F; \ + I0 = IFLOOR(U); \ + I1 = I0 + 1; \ + if (I0 < 0) \ + I0 = 0; \ + if (I1 >= (GLint) SIZE) \ + I1 = SIZE - 1; \ + } \ + else if (wrapMode == GL_MIRROR_CLAMP_ATI) { \ + U = (GLfloat) fabs(S); \ + if (U >= 1.0F) \ + U = (GLfloat) SIZE; \ + else \ + U *= SIZE; \ + U -= 0.5F; \ + I0 = IFLOOR(U); \ + I1 = I0 + 1; \ + } \ + else if (wrapMode == GL_MIRROR_CLAMP_TO_EDGE_ATI) { \ + U = (GLfloat) fabs(S); \ + if (U >= 1.0F) \ + U = (GLfloat) SIZE; \ + else \ + U *= SIZE; \ + U -= 0.5F; \ I0 = IFLOOR(U); \ I1 = I0 + 1; \ if (I0 < 0) \ @@ -170,6 +195,30 @@ else \ I = IFLOOR(u * SIZE); \ } \ + else if (wrapMode == GL_MIRROR_CLAMP_ATI) { \ + /* s limited to [0,1] */ \ + /* i limited to [0,size-1] */ \ + const GLfloat u = (GLfloat) fabs(S); \ + if (u <= 0.0F) \ + I = 0; \ + else if (u >= 1.0F) \ + I = SIZE - 1; \ + else \ + I = IFLOOR(u * SIZE); \ + } \ + else if (wrapMode == GL_MIRROR_CLAMP_TO_EDGE_ATI) { \ + /* s limited to [min,max] */ \ + /* i limited to [0, size-1] */ \ + const GLfloat min = 1.0F / (2.0F * SIZE); \ + const GLfloat max = 1.0F - min; \ + const GLfloat u = (GLfloat) fabs(S); \ + if (u < min) \ + I = 0; \ + else if (u > max) \ + I = SIZE - 1; \ + else \ + I = IFLOOR(u * SIZE); \ + } \ else { \ ASSERT(wrapMode == GL_CLAMP); \ /* s limited to [0,1] */ \ @@ -417,7 +466,7 @@ sample_1d_nearest(GLcontext *ctx, if (i < 0 || i >= (GLint) img->Width) { /* Need this test for GL_CLAMP_TO_BORDER_ARB mode */ - COPY_CHAN4(rgba, tObj->BorderColor); + COPY_CHAN4(rgba, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i, 0, 0, (GLvoid *) rgba); @@ -469,7 +518,7 @@ sample_1d_linear(GLcontext *ctx, GLchan t0[4], t1[4]; /* texels */ if (useBorderColor & I0BIT) { - COPY_CHAN4(t0, tObj->BorderColor); + COPY_CHAN4(t0, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i0, 0, 0, (GLvoid *) t0); @@ -478,7 +527,7 @@ sample_1d_linear(GLcontext *ctx, } } if (useBorderColor & I1BIT) { - COPY_CHAN4(t1, tObj->BorderColor); + COPY_CHAN4(t1, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i1, 0, 0, (GLvoid *) t1); @@ -746,7 +795,7 @@ sample_2d_nearest(GLcontext *ctx, if (i < 0 || i >= (GLint) img->Width || j < 0 || j >= (GLint) img->Height) { /* Need this test for GL_CLAMP_TO_BORDER_ARB mode */ - COPY_CHAN4(rgba, tObj->BorderColor); + COPY_CHAN4(rgba, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i, j, 0, (GLvoid *) rgba); @@ -814,7 +863,7 @@ sample_2d_linear(GLcontext *ctx, GLchan t11[4]; if (useBorderColor & (I0BIT | J0BIT)) { - COPY_CHAN4(t00, tObj->BorderColor); + COPY_CHAN4(t00, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i0, j0, 0, (GLvoid *) t00); @@ -823,7 +872,7 @@ sample_2d_linear(GLcontext *ctx, } } if (useBorderColor & (I1BIT | J0BIT)) { - COPY_CHAN4(t10, tObj->BorderColor); + COPY_CHAN4(t10, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i1, j0, 0, (GLvoid *) t10); @@ -832,7 +881,7 @@ sample_2d_linear(GLcontext *ctx, } } if (useBorderColor & (I0BIT | J1BIT)) { - COPY_CHAN4(t01, tObj->BorderColor); + COPY_CHAN4(t01, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i0, j1, 0, (GLvoid *) t01); @@ -841,7 +890,7 @@ sample_2d_linear(GLcontext *ctx, } } if (useBorderColor & (I1BIT | J1BIT)) { - COPY_CHAN4(t11, tObj->BorderColor); + COPY_CHAN4(t11, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i1, j1, 0, (GLvoid *) t11); @@ -1119,7 +1168,8 @@ sample_linear_2d( GLcontext *ctx, GLuint texUnit, * Optimized 2-D texture sampling: * S and T wrap mode == GL_REPEAT * GL_NEAREST min/mag filter - * No border + * No border, + * RowStride == Width, * Format = GL_RGB */ static void @@ -1158,6 +1208,7 @@ opt_sample_rgb_2d( GLcontext *ctx, GLuint texUnit, * S and T wrap mode == GL_REPEAT * GL_NEAREST min/mag filter * No border + * RowStride == Width, * Format = GL_RGBA */ static void @@ -1205,7 +1256,7 @@ sample_lambda_2d( GLcontext *ctx, GLuint texUnit, const GLboolean repeatNoBorder = (tObj->WrapS == GL_REPEAT) && (tObj->WrapT == GL_REPEAT) - && (tImg->Border == 0) + && (tImg->Border == 0 && (tImg->Width == tImg->RowStride)) && (tImg->Format != GL_COLOR_INDEX); ASSERT(lambda != NULL); @@ -1332,7 +1383,7 @@ sample_3d_nearest(GLcontext *ctx, j < 0 || j >= (GLint) img->Height || k < 0 || k >= (GLint) img->Depth) { /* Need this test for GL_CLAMP_TO_BORDER_ARB mode */ - COPY_CHAN4(rgba, tObj->BorderColor); + COPY_CHAN4(rgba, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i, j, k, (GLvoid *) rgba); @@ -1415,7 +1466,7 @@ sample_3d_linear(GLcontext *ctx, GLchan t100[4], t110[4], t101[4], t111[4]; if (useBorderColor & (I0BIT | J0BIT | K0BIT)) { - COPY_CHAN4(t000, tObj->BorderColor); + COPY_CHAN4(t000, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i0, j0, k0, (GLvoid *) t000); @@ -1424,7 +1475,7 @@ sample_3d_linear(GLcontext *ctx, } } if (useBorderColor & (I1BIT | J0BIT | K0BIT)) { - COPY_CHAN4(t100, tObj->BorderColor); + COPY_CHAN4(t100, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i1, j0, k0, (GLvoid *) t100); @@ -1433,7 +1484,7 @@ sample_3d_linear(GLcontext *ctx, } } if (useBorderColor & (I0BIT | J1BIT | K0BIT)) { - COPY_CHAN4(t010, tObj->BorderColor); + COPY_CHAN4(t010, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i0, j1, k0, (GLvoid *) t010); @@ -1442,7 +1493,7 @@ sample_3d_linear(GLcontext *ctx, } } if (useBorderColor & (I1BIT | J1BIT | K0BIT)) { - COPY_CHAN4(t110, tObj->BorderColor); + COPY_CHAN4(t110, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i1, j1, k0, (GLvoid *) t110); @@ -1452,7 +1503,7 @@ sample_3d_linear(GLcontext *ctx, } if (useBorderColor & (I0BIT | J0BIT | K1BIT)) { - COPY_CHAN4(t001, tObj->BorderColor); + COPY_CHAN4(t001, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i0, j0, k1, (GLvoid *) t001); @@ -1461,7 +1512,7 @@ sample_3d_linear(GLcontext *ctx, } } if (useBorderColor & (I1BIT | J0BIT | K1BIT)) { - COPY_CHAN4(t101, tObj->BorderColor); + COPY_CHAN4(t101, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i1, j0, k1, (GLvoid *) t101); @@ -1470,7 +1521,7 @@ sample_3d_linear(GLcontext *ctx, } } if (useBorderColor & (I0BIT | J1BIT | K1BIT)) { - COPY_CHAN4(t011, tObj->BorderColor); + COPY_CHAN4(t011, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i0, j1, k1, (GLvoid *) t011); @@ -1479,7 +1530,7 @@ sample_3d_linear(GLcontext *ctx, } } if (useBorderColor & (I1BIT | J1BIT | K1BIT)) { - COPY_CHAN4(t111, tObj->BorderColor); + COPY_CHAN4(t111, tObj->_BorderChan); } else { (*img->FetchTexel)(img, i1, j1, k1, (GLvoid *) t111); @@ -2151,10 +2202,14 @@ sample_linear_rect(GLcontext *ctx, GLuint texUnit, w11 = a * b ; /* compute weighted average of samples */ - rgba[i][0] = w00 * t00[0] + w10 * t10[0] + w01 * t01[0] + w11 * t11[0]; - rgba[i][1] = w00 * t00[1] + w10 * t10[1] + w01 * t01[1] + w11 * t11[1]; - rgba[i][2] = w00 * t00[2] + w10 * t10[2] + w01 * t01[2] + w11 * t11[2]; - rgba[i][3] = w00 * t00[3] + w10 * t10[3] + w01 * t01[3] + w11 * t11[3]; + rgba[i][0] = + (GLchan) (w00 * t00[0] + w10 * t10[0] + w01 * t01[0] + w11 * t11[0]); + rgba[i][1] = + (GLchan) (w00 * t00[1] + w10 * t10[1] + w01 * t01[1] + w11 * t11[1]); + rgba[i][2] = + (GLchan) (w00 * t00[2] + w10 * t10[2] + w01 * t01[2] + w11 * t11[2]); + rgba[i][3] = + (GLchan) (w00 * t00[3] + w10 * t10[3] + w01 * t01[3] + w11 * t11[3]); } } @@ -2210,7 +2265,7 @@ sample_depth_texture( GLcontext *ctx, GLuint unit, const struct gl_texture_image *texImage = tObj->Image[baseLevel]; const GLuint width = texImage->Width; const GLuint height = texImage->Height; - const GLchan ambient = tObj->ShadowAmbient; + GLchan ambient; GLenum function; GLchan result; @@ -2221,6 +2276,8 @@ sample_depth_texture( GLcontext *ctx, GLuint unit, tObj->Target == GL_TEXTURE_2D || tObj->Target == GL_TEXTURE_RECTANGLE_NV); + UNCLAMPED_FLOAT_TO_CHAN(ambient, tObj->ShadowAmbient); + /* XXXX if tObj->MinFilter != tObj->MagFilter, we're ignoring lambda */ /* XXX this could be precomputed and saved in the texture object */ @@ -2499,7 +2556,7 @@ sample_depth_texture2(const GLcontext *ctx, const struct gl_texture_image *texImage = texObj->Image[baseLevel]; const GLuint width = texImage->Width; const GLuint height = texImage->Height; - const GLchan ambient = texObj->ShadowAmbient; + GLchan ambient; GLboolean lequal, gequal; if (texObj->Target != GL_TEXTURE_2D) { @@ -2521,6 +2578,8 @@ sample_depth_texture2(const GLcontext *ctx, return; } + UNCLAMPED_FLOAT_TO_CHAN(ambient, tObj->ShadowAmbient); + if (texObj->CompareOperator == GL_TEXTURE_LEQUAL_R_SGIX) { lequal = GL_TRUE; gequal = GL_FALSE; @@ -3080,8 +3139,8 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, GLchan dot = ((arg0[i][RCOMP]-0.5F) * (arg1[i][RCOMP]-0.5F) + (arg0[i][GCOMP]-0.5F) * (arg1[i][GCOMP]-0.5F) + (arg0[i][BCOMP]-0.5F) * (arg1[i][BCOMP]-0.5F)) - * 4.0F; - dot = CLAMP(dot, 0.0, CHAN_MAXF) * RGBmult; + * 4.0F * RGBmult; + dot = CLAMP(dot, 0.0, CHAN_MAXF); #else GLint dot = (S_PROD((GLint)arg0[i][RCOMP] - half, (GLint)arg1[i][RCOMP] - half) + @@ -3089,7 +3148,8 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, (GLint)arg1[i][GCOMP] - half) + S_PROD((GLint)arg0[i][BCOMP] - half, (GLint)arg1[i][BCOMP] - half)) >> 6; - dot = CLAMP(dot, 0, CHAN_MAX) << RGBshift; + dot <<= RGBshift; + dot = CLAMP(dot, 0, CHAN_MAX); #endif rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = (GLchan) dot; } @@ -3268,7 +3328,8 @@ texture_apply( const GLcontext *ctx, format = texUnit->_Current->Image[baseLevel]->Format; - if (format == GL_COLOR_INDEX || format == GL_DEPTH_COMPONENT) { + if (format == GL_COLOR_INDEX || format == GL_DEPTH_COMPONENT + || format == GL_YCBCR_MESA) { format = GL_RGBA; /* a bit of a hack */ } @@ -3604,7 +3665,7 @@ _swrast_texture_span( GLcontext *ctx, struct sw_span *span ) * Save copy of the incoming fragment colors (the GL_PRIMARY_COLOR) */ if (swrast->_AnyTextureCombine) - MEMCPY(primary_rgba, span->color.rgba, 4 * span->end * sizeof(GLchan)); + MEMCPY(primary_rgba, span->array->rgba, 4 * span->end * sizeof(GLchan)); /* * Must do all texture sampling before combining in order to @@ -3614,7 +3675,7 @@ _swrast_texture_span( GLcontext *ctx, struct sw_span *span ) if (ctx->Texture.Unit[unit]._ReallyEnabled) { const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; const struct gl_texture_object *curObj = texUnit->_Current; - GLfloat *lambda = span->lambda[unit]; + GLfloat *lambda = span->array->lambda[unit]; GLchan (*texels)[4] = (GLchan (*)[4]) (swrast->TexelBuffer + unit * (span->end * 4 * sizeof(GLchan))); @@ -3642,7 +3703,7 @@ _swrast_texture_span( GLcontext *ctx, struct sw_span *span ) /* Sample the texture (span->end fragments) */ swrast->TextureSample[unit]( ctx, unit, texUnit->_Current, - span->end, span->texcoords[unit], + span->end, span->array->texcoords[unit], lambda, texels ); } } @@ -3659,14 +3720,14 @@ _swrast_texture_span( GLcontext *ctx, struct sw_span *span ) texture_combine( ctx, unit, span->end, (CONST GLchan (*)[4]) primary_rgba, swrast->TexelBuffer, - span->color.rgba ); + span->array->rgba ); } else if (texUnit->EnvMode == GL_COMBINE4_NV) { /* GL_NV_texture_env_combine4 */ texture_combine4( ctx, unit, span->end, (CONST GLchan (*)[4]) primary_rgba, swrast->TexelBuffer, - span->color.rgba ); + span->array->rgba ); } else { /* conventional texture blend */ @@ -3675,7 +3736,7 @@ _swrast_texture_span( GLcontext *ctx, struct sw_span *span ) (span->end * 4 * sizeof(GLchan))); texture_apply( ctx, texUnit, span->end, (CONST GLchan (*)[4]) primary_rgba, texels, - span->color.rgba ); + span->array->rgba ); } } }