diff options
Diffstat (limited to 'src/mesa/swrast')
-rw-r--r-- | src/mesa/swrast/s_atifragshader.c | 7 | ||||
-rw-r--r-- | src/mesa/swrast/s_context.c | 62 | ||||
-rw-r--r-- | src/mesa/swrast/s_context.h | 7 | ||||
-rw-r--r-- | src/mesa/swrast/s_fragprog.c | 21 | ||||
-rw-r--r-- | src/mesa/swrast/s_points.c | 5 | ||||
-rw-r--r-- | src/mesa/swrast/s_span.c | 24 | ||||
-rw-r--r-- | src/mesa/swrast/s_texcombine.c | 1273 | ||||
-rw-r--r-- | src/mesa/swrast/s_texfilter.c | 1001 |
8 files changed, 852 insertions, 1548 deletions
diff --git a/src/mesa/swrast/s_atifragshader.c b/src/mesa/swrast/s_atifragshader.c index 458fe18163..5fefae6c42 100644 --- a/src/mesa/swrast/s_atifragshader.c +++ b/src/mesa/swrast/s_atifragshader.c @@ -47,17 +47,12 @@ static void fetch_texel(GLcontext * ctx, const GLfloat texcoord[4], GLfloat lambda, GLuint unit, GLfloat color[4]) { - GLchan rgba[4]; SWcontext *swrast = SWRAST_CONTEXT(ctx); /* XXX use a float-valued TextureSample routine here!!! */ swrast->TextureSample[unit](ctx, ctx->Texture.Unit[unit]._Current, 1, (const GLfloat(*)[4]) texcoord, - &lambda, &rgba); - color[0] = CHAN_TO_FLOAT(rgba[0]); - color[1] = CHAN_TO_FLOAT(rgba[1]); - color[2] = CHAN_TO_FLOAT(rgba[2]); - color[3] = CHAN_TO_FLOAT(rgba[3]); + &lambda, (GLfloat (*)[4]) color); } static void diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c index 4dbccbb2d5..a7eaf76a0a 100644 --- a/src/mesa/swrast/s_context.c +++ b/src/mesa/swrast/s_context.c @@ -172,19 +172,29 @@ _swrast_update_fog_hint( GLcontext *ctx ) /** - * Update the swrast->_AnyTextureCombine flag. + * Update the swrast->_TextureCombinePrimary flag. */ static void _swrast_update_texture_env( GLcontext *ctx ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); GLuint i; - swrast->_AnyTextureCombine = GL_FALSE; + + swrast->_TextureCombinePrimary = GL_FALSE; + for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { - if (ctx->Texture.Unit[i].EnvMode == GL_COMBINE_EXT || - ctx->Texture.Unit[i].EnvMode == GL_COMBINE4_NV) { - swrast->_AnyTextureCombine = GL_TRUE; - return; + const struct gl_tex_env_combine_state *combine = + ctx->Texture.Unit[i]._CurrentCombine; + GLuint term; + for (term = 0; term < combine->_NumArgsRGB; term++) { + if (combine->SourceRGB[term] == GL_PRIMARY_COLOR) { + swrast->_TextureCombinePrimary = GL_TRUE; + return; + } + if (combine->SourceA[term] == GL_PRIMARY_COLOR) { + swrast->_TextureCombinePrimary = GL_TRUE; + return; + } } } } @@ -265,6 +275,24 @@ _swrast_update_fragment_program(GLcontext *ctx, GLbitfield newState) } +/** + * See if we can do early diffuse+specular (primary+secondary) color + * add per vertex instead of per-fragment. + */ +static void +_swrast_update_specular_vertex_add(GLcontext *ctx) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + GLboolean separateSpecular = ctx->Fog.ColorSumEnabled || + (ctx->Light.Enabled && + ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR); + + swrast->SpecularVertexAdd = (separateSpecular + && ctx->Texture._EnabledUnits == 0x0 + && !ctx->FragmentProgram._Current + && !ctx->ATIFragmentShader._Enabled); +} + #define _SWRAST_NEW_DERIVED (_SWRAST_NEW_RASTERMASK | \ _NEW_TEXTURE | \ @@ -326,9 +354,7 @@ _swrast_validate_triangle( GLcontext *ctx, swrast->choose_triangle( ctx ); ASSERT(swrast->Triangle); - if (ctx->Texture._EnabledUnits == 0 - && NEED_SECONDARY_COLOR(ctx) - && !ctx->FragmentProgram._Current) { + if (swrast->SpecularVertexAdd) { /* separate specular color, but no texture */ swrast->SpecTriangle = swrast->Triangle; swrast->Triangle = _swrast_add_spec_terms_triangle; @@ -350,9 +376,7 @@ _swrast_validate_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 ) swrast->choose_line( ctx ); ASSERT(swrast->Line); - if (ctx->Texture._EnabledUnits == 0 - && NEED_SECONDARY_COLOR(ctx) - && !ctx->FragmentProgram._Current) { + if (swrast->SpecularVertexAdd) { swrast->SpecLine = swrast->Line; swrast->Line = _swrast_add_spec_terms_line; } @@ -372,9 +396,7 @@ _swrast_validate_point( GLcontext *ctx, const SWvertex *v0 ) _swrast_validate_derived( ctx ); swrast->choose_point( ctx ); - if (ctx->Texture._EnabledUnits == 0 - && NEED_SECONDARY_COLOR(ctx) - && !ctx->FragmentProgram._Current) { + if (swrast->SpecularVertexAdd) { swrast->SpecPoint = swrast->Point; swrast->Point = _swrast_add_spec_terms_point; } @@ -656,6 +678,12 @@ _swrast_validate_derived( GLcontext *ctx ) _NEW_TEXTURE)) _swrast_update_active_attribs(ctx); + if (swrast->NewState & (_NEW_FOG | + _NEW_PROGRAM | + _NEW_LIGHT | + _NEW_TEXTURE)) + _swrast_update_specular_vertex_add(ctx); + swrast->NewState = 0; swrast->StateChanges = 0; swrast->InvalidateState = _swrast_invalidate_state; @@ -820,8 +848,8 @@ _swrast_CreateContext( GLcontext *ctx ) swrast->PointSpan.facing = 0; swrast->PointSpan.array = swrast->SpanArrays; - swrast->TexelBuffer = (GLchan *) MALLOC(ctx->Const.MaxTextureImageUnits * - MAX_WIDTH * 4 * sizeof(GLchan)); + swrast->TexelBuffer = (GLfloat *) MALLOC(ctx->Const.MaxTextureImageUnits * + MAX_WIDTH * 4 * sizeof(GLfloat)); if (!swrast->TexelBuffer) { FREE(swrast->SpanArrays); FREE(swrast); diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h index 6e8d080704..9059f9b5ec 100644 --- a/src/mesa/swrast/s_context.h +++ b/src/mesa/swrast/s_context.h @@ -52,7 +52,7 @@ typedef void (*texture_sample_func)(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], - const GLfloat lambda[], GLchan rgba[][4]); + const GLfloat lambda[], GLfloat rgba[][4]); typedef void (_ASMAPIP blend_func)( GLcontext *ctx, GLuint n, const GLubyte mask[], @@ -131,7 +131,7 @@ typedef struct GLfloat _BackfaceSign; /** +1 or -1 */ GLfloat _BackfaceCullSign; /** +1, 0, or -1 */ GLboolean _PreferPixelFog; /* Compute fog blend factor per fragment? */ - GLboolean _AnyTextureCombine; + GLboolean _TextureCombinePrimary; GLboolean _FogEnabled; GLboolean _DeferredTexture; GLenum _FogMode; /* either GL_FOG_MODE or fragment program's fog mode */ @@ -157,6 +157,7 @@ typedef struct GLbitfield NewState; GLuint StateChanges; GLenum Primitive; /* current primitive being drawn (ala glBegin) */ + GLboolean SpecularVertexAdd; /**< Add specular/secondary color per vertex */ void (*InvalidateState)( GLcontext *ctx, GLbitfield new_state ); @@ -221,7 +222,7 @@ typedef struct /** Buffer for saving the sampled texture colors. * Needed for GL_ARB_texture_env_crossbar implementation. */ - GLchan *TexelBuffer; + GLfloat *TexelBuffer; validate_texture_image_func ValidateTextureImage; diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index ae1dea16a0..b71fb9eae9 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -37,20 +37,17 @@ * and return results in 'colorOut'. */ static INLINE void -swizzle_texel(const GLchan texel[4], GLfloat colorOut[4], GLuint swizzle) +swizzle_texel(const GLfloat texel[4], GLfloat colorOut[4], GLuint swizzle) { if (swizzle == SWIZZLE_NOOP) { - colorOut[0] = CHAN_TO_FLOAT(texel[0]); - colorOut[1] = CHAN_TO_FLOAT(texel[1]); - colorOut[2] = CHAN_TO_FLOAT(texel[2]); - colorOut[3] = CHAN_TO_FLOAT(texel[3]); + COPY_4V(colorOut, texel); } else { GLfloat vector[6]; - vector[SWIZZLE_X] = CHAN_TO_FLOAT(texel[0]); - vector[SWIZZLE_Y] = CHAN_TO_FLOAT(texel[1]); - vector[SWIZZLE_Z] = CHAN_TO_FLOAT(texel[2]); - vector[SWIZZLE_W] = CHAN_TO_FLOAT(texel[3]); + vector[SWIZZLE_X] = texel[0]; + vector[SWIZZLE_Y] = texel[1]; + vector[SWIZZLE_Z] = texel[2]; + vector[SWIZZLE_W] = texel[3]; vector[SWIZZLE_ZERO] = 0.0F; vector[SWIZZLE_ONE] = 1.0F; colorOut[0] = vector[GET_SWZ(swizzle, 0)]; @@ -73,11 +70,10 @@ fetch_texel_lod( GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda, if (texObj) { SWcontext *swrast = SWRAST_CONTEXT(ctx); - GLchan rgba[4]; + GLfloat rgba[4]; lambda = CLAMP(lambda, texObj->MinLod, texObj->MaxLod); - /* XXX use a float-valued TextureSample routine here!!! */ swrast->TextureSample[unit](ctx, texObj, 1, (const GLfloat (*)[4]) texcoord, &lambda, &rgba); @@ -108,7 +104,7 @@ fetch_texel_deriv( GLcontext *ctx, const GLfloat texcoord[4], const GLfloat texW = (GLfloat) texImg->WidthScale; const GLfloat texH = (GLfloat) texImg->HeightScale; GLfloat lambda; - GLchan rgba[4]; + GLfloat rgba[4]; lambda = _swrast_compute_lambda(texdx[0], texdy[0], /* ds/dx, ds/dy */ texdx[1], texdy[1], /* dt/dx, dt/dy */ @@ -119,7 +115,6 @@ fetch_texel_deriv( GLcontext *ctx, const GLfloat texcoord[4], lambda = CLAMP(lambda, texObj->MinLod, texObj->MaxLod); - /* XXX use a float-valued TextureSample routine here!!! */ swrast->TextureSample[unit](ctx, texObj, 1, (const GLfloat (*)[4]) texcoord, &lambda, &rgba); diff --git a/src/mesa/swrast/s_points.c b/src/mesa/swrast/s_points.c index 61ff4d0b84..0a3ad97a71 100644 --- a/src/mesa/swrast/s_points.c +++ b/src/mesa/swrast/s_points.c @@ -570,6 +570,9 @@ void _swrast_choose_point(GLcontext *ctx) { SWcontext *swrast = SWRAST_CONTEXT(ctx); + const GLfloat size = CLAMP(ctx->Point.Size, + ctx->Point.MinSize, + ctx->Point.MaxSize); if (ctx->RenderMode == GL_RENDER) { if (ctx->Point.PointSprite) { @@ -578,7 +581,7 @@ _swrast_choose_point(GLcontext *ctx) else if (ctx->Point.SmoothFlag) { swrast->Point = smooth_point; } - else if (ctx->Point.Size > 1.0 || + else if (size > 1.0 || ctx->Point._Attenuated || ctx->VertexProgram.PointSizeEnabled) { swrast->Point = large_point; diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index 15a783b236..cfff82b051 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -1377,12 +1377,14 @@ _swrast_write_rgba_span( GLcontext *ctx, SWspan *span) ASSERT(span->arrayMask & SPAN_RGBA); - if (!shader) { - /* Add base and specular colors */ - if (ctx->Fog.ColorSumEnabled || - (ctx->Light.Enabled && - ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)) { - add_specular(ctx, span); + if (span->primitive == GL_BITMAP || !swrast->SpecularVertexAdd) { + /* Add primary and specular (diffuse + specular) colors */ + if (!shader) { + if (ctx->Fog.ColorSumEnabled || + (ctx->Light.Enabled && + ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)) { + add_specular(ctx, span); + } } } @@ -1403,11 +1405,17 @@ _swrast_write_rgba_span( GLcontext *ctx, SWspan *span) } /* - * Write to renderbuffers + * Write to renderbuffers. + * Depending on glDrawBuffer() state and the which color outputs are + * written by the fragment shader, we may either replicate one color to + * all renderbuffers or write a different color to each renderbuffer. + * multiFragOutputs=TRUE for the later case. */ { const GLuint numBuffers = fb->_NumColorDrawBuffers; - const GLboolean multiFragOutputs = numBuffers > 1; + const struct gl_fragment_program *fp = ctx->FragmentProgram._Current; + const GLboolean multiFragOutputs = + (fp && fp->Base.OutputsWritten >= (1 << FRAG_RESULT_DATA0)); GLuint buf; for (buf = 0; buf < numBuffers; buf++) { diff --git a/src/mesa/swrast/s_texcombine.c b/src/mesa/swrast/s_texcombine.c index aa28311672..fae7280efb 100644 --- a/src/mesa/swrast/s_texcombine.c +++ b/src/mesa/swrast/s_texcombine.c @@ -29,7 +29,6 @@ #include "main/colormac.h" #include "main/image.h" #include "main/imports.h" -#include "main/macros.h" #include "main/pixel.h" #include "shader/prog_instruction.h" @@ -37,109 +36,128 @@ #include "s_texcombine.h" -#define PROD(A,B) ( (GLuint)(A) * ((GLuint)(B)+1) ) -#define S_PROD(A,B) ( (GLint)(A) * ((GLint)(B)+1) ) -#if CHAN_BITS == 32 -typedef GLfloat ChanTemp; -#else -typedef GLuint ChanTemp; -#endif +/** + * Pointer to array of float[4] + * This type makes the code below more concise and avoids a lot of casting. + */ +typedef float (*float4_array)[4]; + + +/** + * Return array of texels for given unit. + */ +static INLINE float4_array +get_texel_array(SWcontext *swrast, GLuint unit) +{ + return (float4_array) + (swrast->TexelBuffer + unit * MAX_WIDTH * 4 * sizeof(GLfloat)); +} + /** - * Do texture application for GL_ARB/EXT_texture_env_combine. - * This function also supports GL_{EXT,ARB}_texture_env_dot3 and - * GL_ATI_texture_env_combine3. Since "classic" texture environments are - * implemented using GL_ARB_texture_env_combine-like state, this same function - * is used for classic texture environment application as well. + * Do texture application for: + * GL_EXT_texture_env_combine + * GL_ARB_texture_env_combine + * GL_EXT_texture_env_dot3 + * GL_ARB_texture_env_dot3 + * GL_ATI_texture_env_combine3 + * GL_NV_texture_env_combine4 + * conventional GL texture env modes * * \param ctx rendering context - * \param textureUnit the texture unit to apply + * \param unit the texture combiner unit * \param n number of fragments to process (span width) * \param primary_rgba incoming fragment color array * \param texelBuffer pointer to texel colors for all texture units * - * \param rgba incoming colors, which get modified here + * \param rgba incoming/result fragment colors */ static void -texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, - CONST GLchan (*primary_rgba)[4], - CONST GLchan *texelBuffer, - GLchan (*rgba)[4] ) +texture_combine( GLcontext *ctx, GLuint unit, GLuint n, + const float4_array primary_rgba, + const GLfloat *texelBuffer, + GLchan (*rgbaChan)[4] ) { + SWcontext *swrast = SWRAST_CONTEXT(ctx); const struct gl_texture_unit *textureUnit = &(ctx->Texture.Unit[unit]); - const GLchan (*argRGB [4])[4]; - const GLchan (*argA [4])[4]; - const GLint RGBshift = textureUnit->_CurrentCombine->ScaleShiftRGB; - const GLuint Ashift = textureUnit->_CurrentCombine->ScaleShiftA; -#if CHAN_TYPE == GL_FLOAT - const GLchan RGBmult = (GLfloat) (1 << RGBshift); - const GLchan Amult = (GLfloat) (1 << Ashift); -#else - const GLint half = (CHAN_MAX + 1) / 2; -#endif - static const GLchan one[4] = { CHAN_MAX, CHAN_MAX, CHAN_MAX, CHAN_MAX }; - static const GLchan zero[4] = { 0, 0, 0, 0 }; - const GLuint numColorArgs = textureUnit->_CurrentCombine->_NumArgsRGB; - const GLuint numAlphaArgs = textureUnit->_CurrentCombine->_NumArgsA; - GLchan ccolor[4][MAX_WIDTH][4]; - GLuint i, j; - - ASSERT(ctx->Extensions.EXT_texture_env_combine || - ctx->Extensions.ARB_texture_env_combine); - ASSERT(CONST_SWRAST_CONTEXT(ctx)->_AnyTextureCombine); + const struct gl_tex_env_combine_state *combine = textureUnit->_CurrentCombine; + float4_array argRGB[MAX_COMBINER_TERMS]; + float4_array argA[MAX_COMBINER_TERMS]; + const GLfloat scaleRGB = (GLfloat) (1 << combine->ScaleShiftRGB); + const GLfloat scaleA = (GLfloat) (1 << combine->ScaleShiftA); + const GLuint numArgsRGB = combine->_NumArgsRGB; + const GLuint numArgsA = combine->_NumArgsA; + GLfloat ccolor[MAX_COMBINER_TERMS][MAX_WIDTH][4]; /* temp color buffers */ + GLfloat rgba[MAX_WIDTH][4]; + GLuint i, term; + + for (i = 0; i < n; i++) { + rgba[i][RCOMP] = CHAN_TO_FLOAT(rgbaChan[i][RCOMP]); + rgba[i][GCOMP] = CHAN_TO_FLOAT(rgbaChan[i][GCOMP]); + rgba[i][BCOMP] = CHAN_TO_FLOAT(rgbaChan[i][BCOMP]); + rgba[i][ACOMP] = CHAN_TO_FLOAT(rgbaChan[i][ACOMP]); + } /* printf("modeRGB 0x%x modeA 0x%x srcRGB1 0x%x srcA1 0x%x srcRGB2 0x%x srcA2 0x%x\n", - textureUnit->_CurrentCombine->ModeRGB, - textureUnit->_CurrentCombine->ModeA, - textureUnit->_CurrentCombine->SourceRGB[0], - textureUnit->_CurrentCombine->SourceA[0], - textureUnit->_CurrentCombine->SourceRGB[1], - textureUnit->_CurrentCombine->SourceA[1]); + combine->ModeRGB, + combine->ModeA, + combine->SourceRGB[0], + combine->SourceA[0], + combine->SourceRGB[1], + combine->SourceA[1]); */ /* * Do operand setup for up to 4 operands. Loop over the terms. */ - for (j = 0; j < numColorArgs; j++) { - const GLenum srcRGB = textureUnit->_CurrentCombine->SourceRGB[j]; + for (term = 0; term < numArgsRGB; term++) { + const GLenum srcRGB = combine->SourceRGB[term]; + const GLenum operandRGB = combine->OperandRGB[term]; switch (srcRGB) { case GL_TEXTURE: - argRGB[j] = (const GLchan (*)[4]) - (texelBuffer + unit * (n * 4 * sizeof(GLchan))); + argRGB[term] = get_texel_array(swrast, unit); break; case GL_PRIMARY_COLOR: - argRGB[j] = primary_rgba; + argRGB[term] = primary_rgba; break; case GL_PREVIOUS: - argRGB[j] = (const GLchan (*)[4]) rgba; + argRGB[term] = rgba; break; case GL_CONSTANT: { - GLchan (*c)[4] = ccolor[j]; - GLchan red, green, blue, alpha; - UNCLAMPED_FLOAT_TO_CHAN(red, textureUnit->EnvColor[0]); - UNCLAMPED_FLOAT_TO_CHAN(green, textureUnit->EnvColor[1]); - UNCLAMPED_FLOAT_TO_CHAN(blue, textureUnit->EnvColor[2]); - UNCLAMPED_FLOAT_TO_CHAN(alpha, textureUnit->EnvColor[3]); + float4_array c = ccolor[term]; + GLfloat red = textureUnit->EnvColor[0]; + GLfloat green = textureUnit->EnvColor[1]; + GLfloat blue = textureUnit->EnvColor[2]; + GLfloat alpha = textureUnit->EnvColor[3]; for (i = 0; i < n; i++) { - c[i][RCOMP] = red; - c[i][GCOMP] = green; - c[i][BCOMP] = blue; - c[i][ACOMP] = alpha; + ASSIGN_4V(c[i], red, green, blue, alpha); } - argRGB[j] = (const GLchan (*)[4]) ccolor[j]; + argRGB[term] = ccolor[term]; } break; /* GL_ATI_texture_env_combine3 allows GL_ZERO & GL_ONE as sources. */ case GL_ZERO: - argRGB[j] = & zero; + { + float4_array c = ccolor[term]; + for (i = 0; i < n; i++) { + ASSIGN_4V(c[i], 0.0F, 0.0F, 0.0F, 0.0F); + } + argRGB[term] = ccolor[term]; + } break; case GL_ONE: - argRGB[j] = & one; + { + float4_array c = ccolor[term]; + for (i = 0; i < n; i++) { + ASSIGN_4V(c[i], 1.0F, 1.0F, 1.0F, 1.0F); + } + argRGB[term] = ccolor[term]; + } break; default: /* ARB_texture_env_crossbar source */ @@ -148,76 +166,88 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, ASSERT(srcUnit < ctx->Const.MaxTextureUnits); if (!ctx->Texture.Unit[srcUnit]._ReallyEnabled) return; - argRGB[j] = (const GLchan (*)[4]) - (texelBuffer + srcUnit * (n * 4 * sizeof(GLchan))); + argRGB[term] = get_texel_array(swrast, srcUnit); } } - if (textureUnit->_CurrentCombine->OperandRGB[j] != GL_SRC_COLOR) { - const GLchan (*src)[4] = argRGB[j]; - GLchan (*dst)[4] = ccolor[j]; + if (operandRGB != GL_SRC_COLOR) { + float4_array src = argRGB[term]; + float4_array dst = ccolor[term]; - /* point to new arg[j] storage */ - argRGB[j] = (const GLchan (*)[4]) ccolor[j]; + /* point to new arg[term] storage */ + argRGB[term] = ccolor[term]; - if (textureUnit->_CurrentCombine->OperandRGB[j] == GL_ONE_MINUS_SRC_COLOR) { + switch (operandRGB) { + case GL_ONE_MINUS_SRC_COLOR: for (i = 0; i < n; i++) { - dst[i][RCOMP] = CHAN_MAX - src[i][RCOMP]; - dst[i][GCOMP] = CHAN_MAX - src[i][GCOMP]; - dst[i][BCOMP] = CHAN_MAX - src[i][BCOMP]; + dst[i][RCOMP] = 1.0F - src[i][RCOMP]; + dst[i][GCOMP] = 1.0F - src[i][GCOMP]; + dst[i][BCOMP] = 1.0F - src[i][BCOMP]; } - } - else if (textureUnit->_CurrentCombine->OperandRGB[j] == GL_SRC_ALPHA) { + break; + case GL_SRC_ALPHA: for (i = 0; i < n; i++) { - dst[i][RCOMP] = src[i][ACOMP]; - dst[i][GCOMP] = src[i][ACOMP]; + dst[i][RCOMP] = + dst[i][GCOMP] = dst[i][BCOMP] = src[i][ACOMP]; } - } - else { - ASSERT(textureUnit->_CurrentCombine->OperandRGB[j] ==GL_ONE_MINUS_SRC_ALPHA); + break; + case GL_ONE_MINUS_SRC_ALPHA: for (i = 0; i < n; i++) { - dst[i][RCOMP] = CHAN_MAX - src[i][ACOMP]; - dst[i][GCOMP] = CHAN_MAX - src[i][ACOMP]; - dst[i][BCOMP] = CHAN_MAX - src[i][ACOMP]; + dst[i][RCOMP] = + dst[i][GCOMP] = + dst[i][BCOMP] = 1.0F - src[i][ACOMP]; } + break; + default: + _mesa_problem(ctx, "Bad operandRGB"); } } } /* - * Set up the argA[i] pointers + * Set up the argA[term] pointers */ - for (j = 0; j < numAlphaArgs; j++) { - const GLenum srcA = textureUnit->_CurrentCombine->SourceA[j]; + for (term = 0; term < numArgsA; term++) { + const GLenum srcA = combine->SourceA[term]; + const GLenum operandA = combine->OperandA[term]; switch (srcA) { case GL_TEXTURE: - argA[j] = (const GLchan (*)[4]) - (texelBuffer + unit * (n * 4 * sizeof(GLchan))); + argA[term] = get_texel_array(swrast, unit); break; case GL_PRIMARY_COLOR: - argA[j] = primary_rgba; + argA[term] = primary_rgba; break; case GL_PREVIOUS: - argA[j] = (const GLchan (*)[4]) rgba; + argA[term] = rgba; break; case GL_CONSTANT: { - GLchan alpha, (*c)[4] = ccolor[j]; - UNCLAMPED_FLOAT_TO_CHAN(alpha, textureUnit->EnvColor[3]); + float4_array c = ccolor[term]; + GLfloat alpha = textureUnit->EnvColor[3]; for (i = 0; i < n; i++) c[i][ACOMP] = alpha; - argA[j] = (const GLchan (*)[4]) ccolor[j]; + argA[term] = ccolor[term]; } break; /* GL_ATI_texture_env_combine3 allows GL_ZERO & GL_ONE as sources. */ case GL_ZERO: - argA[j] = & zero; + { + float4_array c = ccolor[term]; + for (i = 0; i < n; i++) + c[i][ACOMP] = 0.0F; + argA[term] = ccolor[term]; + } break; case GL_ONE: - argA[j] = & one; + { + float4_array c = ccolor[term]; + for (i = 0; i < n; i++) + c[i][ACOMP] = 1.0F; + argA[term] = ccolor[term]; + } break; default: /* ARB_texture_env_crossbar source */ @@ -226,598 +256,258 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, ASSERT(srcUnit < ctx->Const.MaxTextureUnits); if (!ctx->Texture.Unit[srcUnit]._ReallyEnabled) return; - argA[j] = (const GLchan (*)[4]) - (texelBuffer + srcUnit * (n * 4 * sizeof(GLchan))); + argA[term] = get_texel_array(swrast, srcUnit); } } - if (textureUnit->_CurrentCombine->OperandA[j] == GL_ONE_MINUS_SRC_ALPHA) { - const GLchan (*src)[4] = argA[j]; - GLchan (*dst)[4] = ccolor[j]; - argA[j] = (const GLchan (*)[4]) ccolor[j]; + if (operandA == GL_ONE_MINUS_SRC_ALPHA) { + float4_array src = argA[term]; + float4_array dst = ccolor[term]; + argA[term] = ccolor[term]; for (i = 0; i < n; i++) { - dst[i][ACOMP] = CHAN_MAX - src[i][ACOMP]; + dst[i][ACOMP] = 1.0F - src[i][ACOMP]; } } } - /* - * Do the texture combine. - */ - switch (textureUnit->_CurrentCombine->ModeRGB) { + /* RGB channel combine */ + { + float4_array arg0 = argRGB[0]; + float4_array arg1 = argRGB[1]; + float4_array arg2 = argRGB[2]; + float4_array arg3 = argRGB[3]; + + switch (combine->ModeRGB) { case GL_REPLACE: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - if (RGBshift) { - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][RCOMP] = arg0[i][RCOMP] * RGBmult; - rgba[i][GCOMP] = arg0[i][GCOMP] * RGBmult; - rgba[i][BCOMP] = arg0[i][BCOMP] * RGBmult; -#else - GLuint r = (GLuint) arg0[i][RCOMP] << RGBshift; - GLuint g = (GLuint) arg0[i][GCOMP] << RGBshift; - GLuint b = (GLuint) arg0[i][BCOMP] << RGBshift; - rgba[i][RCOMP] = MIN2(r, CHAN_MAX); - rgba[i][GCOMP] = MIN2(g, CHAN_MAX); - rgba[i][BCOMP] = MIN2(b, CHAN_MAX); -#endif - } - } - else { - for (i = 0; i < n; i++) { - rgba[i][RCOMP] = arg0[i][RCOMP]; - rgba[i][GCOMP] = arg0[i][GCOMP]; - rgba[i][BCOMP] = arg0[i][BCOMP]; - } - } + for (i = 0; i < n; i++) { + rgba[i][RCOMP] = arg0[i][RCOMP] * scaleRGB; + rgba[i][GCOMP] = arg0[i][GCOMP] * scaleRGB; + rgba[i][BCOMP] = arg0[i][BCOMP] * scaleRGB; } break; case GL_MODULATE: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; -#if CHAN_TYPE != GL_FLOAT - const GLint shift = CHAN_BITS - RGBshift; -#endif - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][RCOMP] = arg0[i][RCOMP] * arg1[i][RCOMP] * RGBmult; - rgba[i][GCOMP] = arg0[i][GCOMP] * arg1[i][GCOMP] * RGBmult; - rgba[i][BCOMP] = arg0[i][BCOMP] * arg1[i][BCOMP] * RGBmult; -#else - GLuint r = PROD(arg0[i][RCOMP], arg1[i][RCOMP]) >> shift; - GLuint g = PROD(arg0[i][GCOMP], arg1[i][GCOMP]) >> shift; - GLuint b = PROD(arg0[i][BCOMP], arg1[i][BCOMP]) >> shift; - rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX); - rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX); - rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX); -#endif - } + for (i = 0; i < n; i++) { + rgba[i][RCOMP] = arg0[i][RCOMP] * arg1[i][RCOMP] * scaleRGB; + rgba[i][GCOMP] = arg0[i][GCOMP] * arg1[i][GCOMP] * scaleRGB; + rgba[i][BCOMP] = arg0[i][BCOMP] * arg1[i][BCOMP] * scaleRGB; } break; case GL_ADD: if (textureUnit->EnvMode == GL_COMBINE4_NV) { /* (a * b) + (c * d) */ - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; - const GLchan (*arg2)[4] = (const GLchan (*)[4]) argRGB[2]; - const GLchan (*arg3)[4] = (const GLchan (*)[4]) argRGB[3]; for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT rgba[i][RCOMP] = (arg0[i][RCOMP] * arg1[i][RCOMP] + - arg2[i][RCOMP] * arg3[i][RCOMP]) * RGBmult; + arg2[i][RCOMP] * arg3[i][RCOMP]) * scaleRGB; rgba[i][GCOMP] = (arg0[i][GCOMP] * arg1[i][GCOMP] + - arg2[i][GCOMP] * arg3[i][GCOMP]) * RGBmult; + arg2[i][GCOMP] * arg3[i][GCOMP]) * scaleRGB; rgba[i][BCOMP] = (arg0[i][BCOMP] * arg1[i][BCOMP] + - arg2[i][BCOMP] * arg3[i][BCOMP]) * RGBmult; -#else - const GLint shift = CHAN_BITS - RGBshift; - GLint r = (PROD(arg0[i][RCOMP], arg1[i][RCOMP]) >> shift) + - (PROD(arg2[i][RCOMP], arg3[i][RCOMP]) >> shift); - GLint g = (PROD(arg0[i][GCOMP], arg1[i][GCOMP]) >> shift) + - (PROD(arg2[i][GCOMP], arg3[i][GCOMP]) >> shift); - GLint b = (PROD(arg0[i][BCOMP], arg1[i][BCOMP]) >> shift) + - (PROD(arg2[i][BCOMP], arg3[i][BCOMP]) >> shift); - rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX); - rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX); - rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX); -#endif + arg2[i][BCOMP] * arg3[i][BCOMP]) * scaleRGB; } } else { /* 2-term addition */ - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][RCOMP] = (arg0[i][RCOMP] + arg1[i][RCOMP]) * RGBmult; - rgba[i][GCOMP] = (arg0[i][GCOMP] + arg1[i][GCOMP]) * RGBmult; - rgba[i][BCOMP] = (arg0[i][BCOMP] + arg1[i][BCOMP]) * RGBmult; -#else - GLint r = ((GLint) arg0[i][RCOMP] + (GLint) arg1[i][RCOMP]) << RGBshift; - GLint g = ((GLint) arg0[i][GCOMP] + (GLint) arg1[i][GCOMP]) << RGBshift; - GLint b = ((GLint) arg0[i][BCOMP] + (GLint) arg1[i][BCOMP]) << RGBshift; - rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX); - rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX); - rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX); -#endif + rgba[i][RCOMP] = (arg0[i][RCOMP] + arg1[i][RCOMP]) * scaleRGB; + rgba[i][GCOMP] = (arg0[i][GCOMP] + arg1[i][GCOMP]) * scaleRGB; + rgba[i][BCOMP] = (arg0[i][BCOMP] + arg1[i][BCOMP]) * scaleRGB; } } break; case GL_ADD_SIGNED: if (textureUnit->EnvMode == GL_COMBINE4_NV) { /* (a * b) + (c * d) - 0.5 */ - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; - const GLchan (*arg2)[4] = (const GLchan (*)[4]) argRGB[2]; - const GLchan (*arg3)[4] = (const GLchan (*)[4]) argRGB[3]; for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][RCOMP] = (arg0[i][RCOMP] + arg1[i][RCOMP] * - arg2[i][RCOMP] + arg3[i][RCOMP] - 0.5) * RGBmult; - rgba[i][GCOMP] = (arg0[i][GCOMP] + arg1[i][GCOMP] * - arg2[i][GCOMP] + arg3[i][GCOMP] - 0.5) * RGBmult; - rgba[i][BCOMP] = (arg0[i][BCOMP] + arg1[i][BCOMP] * - arg2[i][BCOMP] + arg3[i][BCOMP] - 0.5) * RGBmult; -#else - GLint r = (((PROD(arg0[i][RCOMP], arg1[i][RCOMP]) + - PROD(arg2[i][RCOMP], arg3[i][RCOMP])) >> CHAN_BITS) - half) - << RGBshift; - GLint g = (((PROD(arg0[i][GCOMP], arg1[i][GCOMP]) + - PROD(arg2[i][GCOMP], arg3[i][GCOMP])) >> CHAN_BITS) - half) - << RGBshift; - GLint b = (((PROD(arg0[i][BCOMP], arg1[i][BCOMP]) + - PROD(arg2[i][BCOMP], arg3[i][BCOMP])) >> CHAN_BITS) - half) - << RGBshift; - rgba[i][RCOMP] = (GLchan) CLAMP(r, 0, CHAN_MAX); - rgba[i][GCOMP] = (GLchan) CLAMP(g, 0, CHAN_MAX); - rgba[i][BCOMP] = (GLchan) CLAMP(b, 0, CHAN_MAX); -#endif + rgba[i][RCOMP] = (arg0[i][RCOMP] * arg1[i][RCOMP] + + arg2[i][RCOMP] * arg3[i][RCOMP] - 0.5) * scaleRGB; + rgba[i][GCOMP] = (arg0[i][GCOMP] * arg1[i][GCOMP] + + arg2[i][GCOMP] * arg3[i][GCOMP] - 0.5) * scaleRGB; + rgba[i][BCOMP] = (arg0[i][BCOMP] * arg1[i][BCOMP] + + arg2[i][BCOMP] * arg3[i][BCOMP] - 0.5) * scaleRGB; } } else { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][RCOMP] = (arg0[i][RCOMP] + arg1[i][RCOMP] - 0.5) * RGBmult; - rgba[i][GCOMP] = (arg0[i][GCOMP] + arg1[i][GCOMP] - 0.5) * RGBmult; - rgba[i][BCOMP] = (arg0[i][BCOMP] + arg1[i][BCOMP] - 0.5) * RGBmult; -#else - GLint r = (GLint) arg0[i][RCOMP] + (GLint) arg1[i][RCOMP] - half; - GLint g = (GLint) arg0[i][GCOMP] + (GLint) arg1[i][GCOMP] - half; - GLint b = (GLint) arg0[i][BCOMP] + (GLint) arg1[i][BCOMP] - half; - r = (r < 0) ? 0 : r << RGBshift; - g = (g < 0) ? 0 : g << RGBshift; - b = (b < 0) ? 0 : b << RGBshift; - rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX); - rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX); - rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX); -#endif + rgba[i][RCOMP] = (arg0[i][RCOMP] + arg1[i][RCOMP] - 0.5) * scaleRGB; + rgba[i][GCOMP] = (arg0[i][GCOMP] + arg1[i][GCOMP] - 0.5) * scaleRGB; + rgba[i][BCOMP] = (arg0[i][BCOMP] + arg1[i][BCOMP] - 0.5) * scaleRGB; } } break; case GL_INTERPOLATE: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; - const GLchan (*arg2)[4] = (const GLchan (*)[4]) argRGB[2]; -#if CHAN_TYPE != GL_FLOAT - const GLint shift = CHAN_BITS - RGBshift; -#endif - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][RCOMP] = (arg0[i][RCOMP] * arg2[i][RCOMP] + - arg1[i][RCOMP] * (CHAN_MAXF - arg2[i][RCOMP])) * RGBmult; - rgba[i][GCOMP] = (arg0[i][GCOMP] * arg2[i][GCOMP] + - arg1[i][GCOMP] * (CHAN_MAXF - arg2[i][GCOMP])) * RGBmult; - rgba[i][BCOMP] = (arg0[i][BCOMP] * arg2[i][BCOMP] + - arg1[i][BCOMP] * (CHAN_MAXF - arg2[i][BCOMP])) * RGBmult; -#else - GLuint r = (PROD(arg0[i][RCOMP], arg2[i][RCOMP]) - + PROD(arg1[i][RCOMP], CHAN_MAX - arg2[i][RCOMP])) - >> shift; - GLuint g = (PROD(arg0[i][GCOMP], arg2[i][GCOMP]) - + PROD(arg1[i][GCOMP], CHAN_MAX - arg2[i][GCOMP])) - >> shift; - GLuint b = (PROD(arg0[i][BCOMP], arg2[i][BCOMP]) - + PROD(arg1[i][BCOMP], CHAN_MAX - arg2[i][BCOMP])) - >> shift; - rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX); - rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX); - rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX); -#endif - } + for (i = 0; i < n; i++) { + rgba[i][RCOMP] = (arg0[i][RCOMP] * arg2[i][RCOMP] + + arg1[i][RCOMP] * (1.0F - arg2[i][RCOMP])) * scaleRGB; + rgba[i][GCOMP] = (arg0[i][GCOMP] * arg2[i][GCOMP] + + arg1[i][GCOMP] * (1.0F - arg2[i][GCOMP])) * scaleRGB; + rgba[i][BCOMP] = (arg0[i][BCOMP] * arg2[i][BCOMP] + + arg1[i][BCOMP] * (1.0F - arg2[i][BCOMP])) * scaleRGB; } break; case GL_SUBTRACT: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][RCOMP] = (arg0[i][RCOMP] - arg1[i][RCOMP]) * RGBmult; - rgba[i][GCOMP] = (arg0[i][GCOMP] - arg1[i][GCOMP]) * RGBmult; - rgba[i][BCOMP] = (arg0[i][BCOMP] - arg1[i][BCOMP]) * RGBmult; -#else - GLint r = ((GLint) arg0[i][RCOMP] - (GLint) arg1[i][RCOMP]) << RGBshift; - GLint g = ((GLint) arg0[i][GCOMP] - (GLint) arg1[i][GCOMP]) << RGBshift; - GLint b = ((GLint) arg0[i][BCOMP] - (GLint) arg1[i][BCOMP]) << RGBshift; - rgba[i][RCOMP] = (GLchan) CLAMP(r, 0, CHAN_MAX); - rgba[i][GCOMP] = (GLchan) CLAMP(g, 0, CHAN_MAX); - rgba[i][BCOMP] = (GLchan) CLAMP(b, 0, CHAN_MAX); -#endif - } + for (i = 0; i < n; i++) { + rgba[i][RCOMP] = (arg0[i][RCOMP] - arg1[i][RCOMP]) * scaleRGB; + rgba[i][GCOMP] = (arg0[i][GCOMP] - arg1[i][GCOMP]) * scaleRGB; + rgba[i][BCOMP] = (arg0[i][BCOMP] - arg1[i][BCOMP]) * scaleRGB; } break; case GL_DOT3_RGB_EXT: case GL_DOT3_RGBA_EXT: - { - /* Do not scale the result by 1 2 or 4 */ - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - 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.0F, CHAN_MAXF); -#else - GLint dot = (S_PROD((GLint)arg0[i][RCOMP] - half, - (GLint)arg1[i][RCOMP] - half) + - S_PROD((GLint)arg0[i][GCOMP] - half, - (GLint)arg1[i][GCOMP] - half) + - S_PROD((GLint)arg0[i][BCOMP] - half, - (GLint)arg1[i][BCOMP] - half)) >> 6; - dot = CLAMP(dot, 0, CHAN_MAX); -#endif - rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = (GLchan) dot; - } + /* Do not scale the result by 1 2 or 4 */ + for (i = 0; i < n; i++) { + GLfloat 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.0F, 1.0F); + rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = dot; } break; case GL_DOT3_RGB: case GL_DOT3_RGBA: - { - /* DO scale the result by 1 2 or 4 */ - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - 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 * RGBmult; - dot = CLAMP(dot, 0.0, CHAN_MAXF); -#else - GLint dot = (S_PROD((GLint)arg0[i][RCOMP] - half, - (GLint)arg1[i][RCOMP] - half) + - S_PROD((GLint)arg0[i][GCOMP] - half, - (GLint)arg1[i][GCOMP] - half) + - S_PROD((GLint)arg0[i][BCOMP] - half, - (GLint)arg1[i][BCOMP] - half)) >> 6; - dot <<= RGBshift; - dot = CLAMP(dot, 0, CHAN_MAX); -#endif - rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = (GLchan) dot; - } + /* DO scale the result by 1 2 or 4 */ + for (i = 0; i < n; i++) { + GLfloat 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 * scaleRGB; + dot = CLAMP(dot, 0.0, 1.0F); + rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = dot; } break; case GL_MODULATE_ADD_ATI: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; - const GLchan (*arg2)[4] = (const GLchan (*)[4]) argRGB[2]; -#if CHAN_TYPE != GL_FLOAT - const GLint shift = CHAN_BITS - RGBshift; -#endif - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) + arg1[i][RCOMP]) * RGBmult; - rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) + arg1[i][GCOMP]) * RGBmult; - rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) + arg1[i][BCOMP]) * RGBmult; -#else - GLuint r = (PROD(arg0[i][RCOMP], arg2[i][RCOMP]) - + ((GLuint) arg1[i][RCOMP] << CHAN_BITS)) >> shift; - GLuint g = (PROD(arg0[i][GCOMP], arg2[i][GCOMP]) - + ((GLuint) arg1[i][GCOMP] << CHAN_BITS)) >> shift; - GLuint b = (PROD(arg0[i][BCOMP], arg2[i][BCOMP]) - + ((GLuint) arg1[i][BCOMP] << CHAN_BITS)) >> shift; - rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX); - rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX); - rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX); -#endif - } + for (i = 0; i < n; i++) { + rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) + + arg1[i][RCOMP]) * scaleRGB; + rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) + + arg1[i][GCOMP]) * scaleRGB; + rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) + + arg1[i][BCOMP]) * scaleRGB; } break; case GL_MODULATE_SIGNED_ADD_ATI: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; - const GLchan (*arg2)[4] = (const GLchan (*)[4]) argRGB[2]; -#if CHAN_TYPE != GL_FLOAT - const GLint shift = CHAN_BITS - RGBshift; -#endif - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) + arg1[i][RCOMP] - 0.5) * RGBmult; - rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) + arg1[i][GCOMP] - 0.5) * RGBmult; - rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) + arg1[i][BCOMP] - 0.5) * RGBmult; -#else - GLint r = (S_PROD(arg0[i][RCOMP], arg2[i][RCOMP]) - + (((GLint) arg1[i][RCOMP] - half) << CHAN_BITS)) - >> shift; - GLint g = (S_PROD(arg0[i][GCOMP], arg2[i][GCOMP]) - + (((GLint) arg1[i][GCOMP] - half) << CHAN_BITS)) - >> shift; - GLint b = (S_PROD(arg0[i][BCOMP], arg2[i][BCOMP]) - + (((GLint) arg1[i][BCOMP] - half) << CHAN_BITS)) - >> shift; - rgba[i][RCOMP] = (GLchan) CLAMP(r, 0, CHAN_MAX); - rgba[i][GCOMP] = (GLchan) CLAMP(g, 0, CHAN_MAX); - rgba[i][BCOMP] = (GLchan) CLAMP(b, 0, CHAN_MAX); -#endif - } + for (i = 0; i < n; i++) { + rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) + + arg1[i][RCOMP] - 0.5) * scaleRGB; + rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) + + arg1[i][GCOMP] - 0.5) * scaleRGB; + rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) + + arg1[i][BCOMP] - 0.5) * scaleRGB; } break; case GL_MODULATE_SUBTRACT_ATI: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; - const GLchan (*arg2)[4] = (const GLchan (*)[4]) argRGB[2]; -#if CHAN_TYPE != GL_FLOAT - const GLint shift = CHAN_BITS - RGBshift; -#endif - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) - arg1[i][RCOMP]) * RGBmult; - rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) - arg1[i][GCOMP]) * RGBmult; - rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) - arg1[i][BCOMP]) * RGBmult; -#else - GLint r = (S_PROD(arg0[i][RCOMP], arg2[i][RCOMP]) - - ((GLint) arg1[i][RCOMP] << CHAN_BITS)) - >> shift; - GLint g = (S_PROD(arg0[i][GCOMP], arg2[i][GCOMP]) - - ((GLint) arg1[i][GCOMP] << CHAN_BITS)) - >> shift; - GLint b = (S_PROD(arg0[i][BCOMP], arg2[i][BCOMP]) - - ((GLint) arg1[i][BCOMP] << CHAN_BITS)) - >> shift; - rgba[i][RCOMP] = (GLchan) CLAMP(r, 0, CHAN_MAX); - rgba[i][GCOMP] = (GLchan) CLAMP(g, 0, CHAN_MAX); - rgba[i][BCOMP] = (GLchan) CLAMP(b, 0, CHAN_MAX); -#endif - } + for (i = 0; i < n; i++) { + rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) - + arg1[i][RCOMP]) * scaleRGB; + rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) - + arg1[i][GCOMP]) * scaleRGB; + rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) - + arg1[i][BCOMP]) * scaleRGB; } break; case GL_BUMP_ENVMAP_ATI: - { - /* this produces a fixed rgba color, and the coord calc is done elsewhere */ - for (i = 0; i < n; i++) { + /* this produces a fixed rgba color, and the coord calc is done elsewhere */ + for (i = 0; i < n; i++) { /* rgba result is 0,0,0,1 */ #if CHAN_TYPE == GL_FLOAT - rgba[i][RCOMP] = 0.0; - rgba[i][GCOMP] = 0.0; - rgba[i][BCOMP] = 0.0; - rgba[i][ACOMP] = 1.0; + rgba[i][RCOMP] = 0.0; + rgba[i][GCOMP] = 0.0; + rgba[i][BCOMP] = 0.0; + rgba[i][ACOMP] = 1.0; #else - rgba[i][RCOMP] = 0; - rgba[i][GCOMP] = 0; - rgba[i][BCOMP] = 0; - rgba[i][ACOMP] = CHAN_MAX; + rgba[i][RCOMP] = 0; + rgba[i][GCOMP] = 0; + rgba[i][BCOMP] = 0; + rgba[i][ACOMP] = CHAN_MAX; #endif - } } return; /* no alpha processing */ default: _mesa_problem(ctx, "invalid combine mode"); + } } - switch (textureUnit->_CurrentCombine->ModeA) { + /* Alpha channel combine */ + { + float4_array arg0 = argA[0]; + float4_array arg1 = argA[1]; + float4_array arg2 = argA[2]; + float4_array arg3 = argA[3]; + + switch (combine->ModeA) { case GL_REPLACE: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; - if (Ashift) { - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - GLchan a = arg0[i][ACOMP] * Amult; -#else - GLuint a = (GLuint) arg0[i][ACOMP] << Ashift; -#endif - rgba[i][ACOMP] = (GLchan) MIN2(a, CHAN_MAX); - } - } - else { - for (i = 0; i < n; i++) { - rgba[i][ACOMP] = arg0[i][ACOMP]; - } - } + for (i = 0; i < n; i++) { + rgba[i][ACOMP] = arg0[i][ACOMP] * scaleA; } break; case GL_MODULATE: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; -#if CHAN_TYPE != GL_FLOAT - const GLint shift = CHAN_BITS - Ashift; -#endif - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][ACOMP] = arg0[i][ACOMP] * arg1[i][ACOMP] * Amult; -#else - GLuint a = (PROD(arg0[i][ACOMP], arg1[i][ACOMP]) >> shift); - rgba[i][ACOMP] = (GLchan) MIN2(a, CHAN_MAX); -#endif - } + for (i = 0; i < n; i++) { + rgba[i][ACOMP] = arg0[i][ACOMP] * arg1[i][ACOMP] * scaleA; } break; case GL_ADD: if (textureUnit->EnvMode == GL_COMBINE4_NV) { /* (a * b) + (c * d) */ - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; - const GLchan (*arg2)[4] = (const GLchan (*)[4]) argA[2]; - const GLchan (*arg3)[4] = (const GLchan (*)[4]) argA[3]; for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT rgba[i][ACOMP] = (arg0[i][ACOMP] * arg1[i][ACOMP] + - arg2[i][ACOMP] * arg3[i][ACOMP]) * Amult; -#else - const GLint shift = CHAN_BITS - Ashift; - GLint a = (PROD(arg0[i][ACOMP], arg1[i][ACOMP]) >> shift) + - (PROD(arg2[i][ACOMP], arg3[i][ACOMP]) >> shift); - rgba[i][ACOMP] = (GLchan) MIN2(a, CHAN_MAX); -#endif + arg2[i][ACOMP] * arg3[i][ACOMP]) * scaleA; } } else { /* two-term add */ - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][ACOMP] = (arg0[i][ACOMP] + arg1[i][ACOMP]) * Amult; -#else - GLint a = ((GLint) arg0[i][ACOMP] + arg1[i][ACOMP]) << Ashift; - rgba[i][ACOMP] = (GLchan) MIN2(a, CHAN_MAX); -#endif + rgba[i][ACOMP] = (arg0[i][ACOMP] + arg1[i][ACOMP]) * scaleA; } } break; case GL_ADD_SIGNED: if (textureUnit->EnvMode == GL_COMBINE4_NV) { /* (a * b) + (c * d) - 0.5 */ - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; - const GLchan (*arg2)[4] = (const GLchan (*)[4]) argA[2]; - const GLchan (*arg3)[4] = (const GLchan (*)[4]) argA[3]; for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT rgba[i][ACOMP] = (arg0[i][ACOMP] * arg1[i][ACOMP] + arg2[i][ACOMP] * arg3[i][ACOMP] - - 0.5) * Amult; -#else - GLint a = (((PROD(arg0[i][ACOMP], arg1[i][ACOMP]) + - PROD(arg2[i][ACOMP], arg3[i][ACOMP])) >> CHAN_BITS) - half) - << Ashift; - rgba[i][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX); -#endif + 0.5) * scaleA; } } else { /* a + b - 0.5 */ - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][ACOMP] = (arg0[i][ACOMP] + arg1[i][ACOMP] - 0.5F) * Amult; -#else - GLint a = (GLint) arg0[i][ACOMP] + (GLint) arg1[i][ACOMP] -half; - a = (a < 0) ? 0 : a << Ashift; - rgba[i][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX); -#endif + rgba[i][ACOMP] = (arg0[i][ACOMP] + arg1[i][ACOMP] - 0.5F) * scaleA; } } break; case GL_INTERPOLATE: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; - const GLchan (*arg2)[4] = (const GLchan (*)[4]) argA[2]; -#if CHAN_TYPE != GL_FLOAT - const GLint shift = CHAN_BITS - Ashift; -#endif - for (i=0; i<n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][ACOMP] = (arg0[i][ACOMP] * arg2[i][ACOMP] + - arg1[i][ACOMP] * (CHAN_MAXF - arg2[i][ACOMP])) - * Amult; -#else - GLuint a = (PROD(arg0[i][ACOMP], arg2[i][ACOMP]) - + PROD(arg1[i][ACOMP], CHAN_MAX - arg2[i][ACOMP])) - >> shift; - rgba[i][ACOMP] = (GLchan) MIN2(a, CHAN_MAX); -#endif - } + for (i = 0; i < n; i++) { + rgba[i][ACOMP] = (arg0[i][ACOMP] * arg2[i][ACOMP] + + arg1[i][ACOMP] * (1.0F - arg2[i][ACOMP])) + * scaleA; } break; case GL_SUBTRACT: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][ACOMP] = (arg0[i][ACOMP] - arg1[i][ACOMP]) * Amult; -#else - GLint a = ((GLint) arg0[i][ACOMP] - (GLint) arg1[i][ACOMP]) << Ashift; - rgba[i][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX); -#endif - } + for (i = 0; i < n; i++) { + rgba[i][ACOMP] = (arg0[i][ACOMP] - arg1[i][ACOMP]) * scaleA; } break; case GL_MODULATE_ADD_ATI: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; - const GLchan (*arg2)[4] = (const GLchan (*)[4]) argA[2]; -#if CHAN_TYPE != GL_FLOAT - const GLint shift = CHAN_BITS - Ashift; -#endif - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP]) + arg1[i][ACOMP]) * Amult; -#else - GLint a = (PROD(arg0[i][ACOMP], arg2[i][ACOMP]) - + ((GLuint) arg1[i][ACOMP] << CHAN_BITS)) - >> shift; - rgba[i][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX); -#endif - } + for (i = 0; i < n; i++) { + rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP]) + + arg1[i][ACOMP]) * scaleA; } break; case GL_MODULATE_SIGNED_ADD_ATI: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; - const GLchan (*arg2)[4] = (const GLchan (*)[4]) argA[2]; -#if CHAN_TYPE != GL_FLOAT - const GLint shift = CHAN_BITS - Ashift; -#endif - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP]) + arg1[i][ACOMP] - 0.5F) * Amult; -#else - GLint a = (S_PROD(arg0[i][ACOMP], arg2[i][ACOMP]) - + (((GLint) arg1[i][ACOMP] - half) << CHAN_BITS)) - >> shift; - rgba[i][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX); -#endif - } + for (i = 0; i < n; i++) { + rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP]) + + arg1[i][ACOMP] - 0.5F) * scaleA; } break; case GL_MODULATE_SUBTRACT_ATI: - { - const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; - const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; - const GLchan (*arg2)[4] = (const GLchan (*)[4]) argA[2]; -#if CHAN_TYPE != GL_FLOAT - const GLint shift = CHAN_BITS - Ashift; -#endif - for (i = 0; i < n; i++) { -#if CHAN_TYPE == GL_FLOAT - rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP]) - arg1[i][ACOMP]) * Amult; -#else - GLint a = (S_PROD(arg0[i][ACOMP], arg2[i][ACOMP]) - - ((GLint) arg1[i][ACOMP] << CHAN_BITS)) - >> shift; - rgba[i][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX); -#endif - } + for (i = 0; i < n; i++) { + rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP]) + - arg1[i][ACOMP]) * scaleA; } break; default: _mesa_problem(ctx, "invalid combine mode"); + } } /* Fix the alpha component for GL_DOT3_RGBA_EXT/ARB combining. @@ -825,14 +515,20 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, * were written such that the GL_COMBINE_ALPHA value could be set to * GL_DOT3. */ - if (textureUnit->_CurrentCombine->ModeRGB == GL_DOT3_RGBA_EXT || - textureUnit->_CurrentCombine->ModeRGB == GL_DOT3_RGBA) { + if (combine->ModeRGB == GL_DOT3_RGBA_EXT || + combine->ModeRGB == GL_DOT3_RGBA) { for (i = 0; i < n; i++) { rgba[i][ACOMP] = rgba[i][RCOMP]; } } + + for (i = 0; i < n; i++) { + UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][RCOMP], rgba[i][RCOMP]); + UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][GCOMP], rgba[i][GCOMP]); + UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][BCOMP], rgba[i][BCOMP]); + UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][ACOMP], rgba[i][ACOMP]); + } } -#undef PROD /** @@ -840,17 +536,17 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, * See GL_EXT_texture_swizzle. */ static void -swizzle_texels(GLuint swizzle, GLuint count, GLchan (*texels)[4]) +swizzle_texels(GLuint swizzle, GLuint count, float4_array texels) { const GLuint swzR = GET_SWZ(swizzle, 0); const GLuint swzG = GET_SWZ(swizzle, 1); const GLuint swzB = GET_SWZ(swizzle, 2); const GLuint swzA = GET_SWZ(swizzle, 3); - GLchan vector[6]; + GLfloat vector[6]; GLuint i; vector[SWIZZLE_ZERO] = 0; - vector[SWIZZLE_ONE] = CHAN_MAX; + vector[SWIZZLE_ONE] = 1.0F; for (i = 0; i < count; i++) { vector[SWIZZLE_X] = texels[i][0]; @@ -866,394 +562,45 @@ swizzle_texels(GLuint swizzle, GLuint count, GLchan (*texels)[4]) /** - * Apply a conventional OpenGL texture env mode (REPLACE, ADD, BLEND, - * MODULATE, or DECAL) to an array of fragments. - * Input: textureUnit - pointer to texture unit to apply - * format - base internal texture format - * n - number of fragments - * primary_rgba - primary colors (may alias rgba for single texture) - * texels - array of texel colors - * InOut: rgba - incoming fragment colors modified by texel colors - * according to the texture environment mode. - */ -static void -texture_apply( const GLcontext *ctx, - const struct gl_texture_unit *texUnit, - GLuint n, - CONST GLchan primary_rgba[][4], CONST GLchan texel[][4], - GLchan rgba[][4] ) -{ - GLint baseLevel; - GLuint i; - GLchan Rc, Gc, Bc, Ac; - GLenum format; - (void) primary_rgba; - - ASSERT(texUnit); - ASSERT(texUnit->_Current); - - baseLevel = texUnit->_Current->BaseLevel; - ASSERT(texUnit->_Current->Image[0][baseLevel]); - - format = texUnit->_Current->Image[0][baseLevel]->_BaseFormat; - - if (format == GL_COLOR_INDEX || format == GL_YCBCR_MESA) { - format = GL_RGBA; /* a bit of a hack */ - } - else if (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL_EXT) { - format = texUnit->_Current->DepthMode; - } - - switch (texUnit->EnvMode) { - case GL_REPLACE: - switch (format) { - case GL_ALPHA: - for (i=0;i<n;i++) { - /* Cv = Cf */ - /* Av = At */ - rgba[i][ACOMP] = texel[i][ACOMP]; - } - break; - case GL_LUMINANCE: - for (i=0;i<n;i++) { - /* Cv = Lt */ - GLchan Lt = texel[i][RCOMP]; - rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = Lt; - /* Av = Af */ - } - break; - case GL_LUMINANCE_ALPHA: - for (i=0;i<n;i++) { - GLchan Lt = texel[i][RCOMP]; - /* Cv = Lt */ - rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = Lt; - /* Av = At */ - rgba[i][ACOMP] = texel[i][ACOMP]; - } - break; - case GL_INTENSITY: - for (i=0;i<n;i++) { - /* Cv = It */ - GLchan It = texel[i][RCOMP]; - rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = It; - /* Av = It */ - rgba[i][ACOMP] = It; - } - break; - case GL_RGB: - for (i=0;i<n;i++) { - /* Cv = Ct */ - rgba[i][RCOMP] = texel[i][RCOMP]; - rgba[i][GCOMP] = texel[i][GCOMP]; - rgba[i][BCOMP] = texel[i][BCOMP]; - /* Av = Af */ - } - break; - case GL_RGBA: - for (i=0;i<n;i++) { - /* Cv = Ct */ - rgba[i][RCOMP] = texel[i][RCOMP]; - rgba[i][GCOMP] = texel[i][GCOMP]; - rgba[i][BCOMP] = texel[i][BCOMP]; - /* Av = At */ - rgba[i][ACOMP] = texel[i][ACOMP]; - } - break; - default: - _mesa_problem(ctx, "Bad format (GL_REPLACE) in texture_apply"); - return; - } - break; - - case GL_MODULATE: - switch (format) { - case GL_ALPHA: - for (i=0;i<n;i++) { - /* Cv = Cf */ - /* Av = AfAt */ - rgba[i][ACOMP] = CHAN_PRODUCT( rgba[i][ACOMP], texel[i][ACOMP] ); - } - break; - case GL_LUMINANCE: - for (i=0;i<n;i++) { - /* Cv = LtCf */ - GLchan Lt = texel[i][RCOMP]; - rgba[i][RCOMP] = CHAN_PRODUCT( rgba[i][RCOMP], Lt ); - rgba[i][GCOMP] = CHAN_PRODUCT( rgba[i][GCOMP], Lt ); - rgba[i][BCOMP] = CHAN_PRODUCT( rgba[i][BCOMP], Lt ); - /* Av = Af */ - } - break; - case GL_LUMINANCE_ALPHA: - for (i=0;i<n;i++) { - /* Cv = CfLt */ - GLchan Lt = texel[i][RCOMP]; - rgba[i][RCOMP] = CHAN_PRODUCT( rgba[i][RCOMP], Lt ); - rgba[i][GCOMP] = CHAN_PRODUCT( rgba[i][GCOMP], Lt ); - rgba[i][BCOMP] = CHAN_PRODUCT( rgba[i][BCOMP], Lt ); - /* Av = AfAt */ - rgba[i][ACOMP] = CHAN_PRODUCT( rgba[i][ACOMP], texel[i][ACOMP] ); - } - break; - case GL_INTENSITY: - for (i=0;i<n;i++) { - /* Cv = CfIt */ - GLchan It = texel[i][RCOMP]; - rgba[i][RCOMP] = CHAN_PRODUCT( rgba[i][RCOMP], It ); - rgba[i][GCOMP] = CHAN_PRODUCT( rgba[i][GCOMP], It ); - rgba[i][BCOMP] = CHAN_PRODUCT( rgba[i][BCOMP], It ); - /* Av = AfIt */ - rgba[i][ACOMP] = CHAN_PRODUCT( rgba[i][ACOMP], It ); - } - break; - case GL_RGB: - for (i=0;i<n;i++) { - /* Cv = CfCt */ - rgba[i][RCOMP] = CHAN_PRODUCT( rgba[i][RCOMP], texel[i][RCOMP] ); - rgba[i][GCOMP] = CHAN_PRODUCT( rgba[i][GCOMP], texel[i][GCOMP] ); - rgba[i][BCOMP] = CHAN_PRODUCT( rgba[i][BCOMP], texel[i][BCOMP] ); - /* Av = Af */ - } - break; - case GL_RGBA: - for (i=0;i<n;i++) { - /* Cv = CfCt */ - rgba[i][RCOMP] = CHAN_PRODUCT( rgba[i][RCOMP], texel[i][RCOMP] ); - rgba[i][GCOMP] = CHAN_PRODUCT( rgba[i][GCOMP], texel[i][GCOMP] ); - rgba[i][BCOMP] = CHAN_PRODUCT( rgba[i][BCOMP], texel[i][BCOMP] ); - /* Av = AfAt */ - rgba[i][ACOMP] = CHAN_PRODUCT( rgba[i][ACOMP], texel[i][ACOMP] ); - } - break; - default: - _mesa_problem(ctx, "Bad format (GL_MODULATE) in texture_apply"); - return; - } - break; - - case GL_DECAL: - switch (format) { - case GL_ALPHA: - case GL_LUMINANCE: - case GL_LUMINANCE_ALPHA: - case GL_INTENSITY: - /* undefined */ - break; - case GL_RGB: - for (i=0;i<n;i++) { - /* Cv = Ct */ - rgba[i][RCOMP] = texel[i][RCOMP]; - rgba[i][GCOMP] = texel[i][GCOMP]; - rgba[i][BCOMP] = texel[i][BCOMP]; - /* Av = Af */ - } - break; - case GL_RGBA: - for (i=0;i<n;i++) { - /* Cv = Cf(1-At) + CtAt */ - GLchan t = texel[i][ACOMP], s = CHAN_MAX - t; - rgba[i][RCOMP] = CHAN_PRODUCT(rgba[i][RCOMP], s) + CHAN_PRODUCT(texel[i][RCOMP],t); - rgba[i][GCOMP] = CHAN_PRODUCT(rgba[i][GCOMP], s) + CHAN_PRODUCT(texel[i][GCOMP],t); - rgba[i][BCOMP] = CHAN_PRODUCT(rgba[i][BCOMP], s) + CHAN_PRODUCT(texel[i][BCOMP],t); - /* Av = Af */ - } - break; - default: - _mesa_problem(ctx, "Bad format (GL_DECAL) in texture_apply"); - return; - } - break; - - case GL_BLEND: - UNCLAMPED_FLOAT_TO_CHAN(Rc, texUnit->EnvColor[0]); - UNCLAMPED_FLOAT_TO_CHAN(Gc, texUnit->EnvColor[1]); - UNCLAMPED_FLOAT_TO_CHAN(Bc, texUnit->EnvColor[2]); - UNCLAMPED_FLOAT_TO_CHAN(Ac, texUnit->EnvColor[3]); - switch (format) { - case GL_ALPHA: - for (i=0;i<n;i++) { - /* Cv = Cf */ - /* Av = AfAt */ - rgba[i][ACOMP] = CHAN_PRODUCT(rgba[i][ACOMP], texel[i][ACOMP]); - } - break; - case GL_LUMINANCE: - for (i=0;i<n;i++) { - /* Cv = Cf(1-Lt) + CcLt */ - GLchan Lt = texel[i][RCOMP], s = CHAN_MAX - Lt; - rgba[i][RCOMP] = CHAN_PRODUCT(rgba[i][RCOMP], s) + CHAN_PRODUCT(Rc, Lt); - rgba[i][GCOMP] = CHAN_PRODUCT(rgba[i][GCOMP], s) + CHAN_PRODUCT(Gc, Lt); - rgba[i][BCOMP] = CHAN_PRODUCT(rgba[i][BCOMP], s) + CHAN_PRODUCT(Bc, Lt); - /* Av = Af */ - } - break; - case GL_LUMINANCE_ALPHA: - for (i=0;i<n;i++) { - /* Cv = Cf(1-Lt) + CcLt */ - GLchan Lt = texel[i][RCOMP], s = CHAN_MAX - Lt; - rgba[i][RCOMP] = CHAN_PRODUCT(rgba[i][RCOMP], s) + CHAN_PRODUCT(Rc, Lt); - rgba[i][GCOMP] = CHAN_PRODUCT(rgba[i][GCOMP], s) + CHAN_PRODUCT(Gc, Lt); - rgba[i][BCOMP] = CHAN_PRODUCT(rgba[i][BCOMP], s) + CHAN_PRODUCT(Bc, Lt); - /* Av = AfAt */ - rgba[i][ACOMP] = CHAN_PRODUCT(rgba[i][ACOMP],texel[i][ACOMP]); - } - break; - case GL_INTENSITY: - for (i=0;i<n;i++) { - /* Cv = Cf(1-It) + CcIt */ - GLchan It = texel[i][RCOMP], s = CHAN_MAX - It; - rgba[i][RCOMP] = CHAN_PRODUCT(rgba[i][RCOMP], s) + CHAN_PRODUCT(Rc, It); - rgba[i][GCOMP] = CHAN_PRODUCT(rgba[i][GCOMP], s) + CHAN_PRODUCT(Gc, It); - rgba[i][BCOMP] = CHAN_PRODUCT(rgba[i][BCOMP], s) + CHAN_PRODUCT(Bc, It); - /* Av = Af(1-It) + Ac*It */ - rgba[i][ACOMP] = CHAN_PRODUCT(rgba[i][ACOMP], s) + CHAN_PRODUCT(Ac, It); - } - break; - case GL_RGB: - for (i=0;i<n;i++) { - /* Cv = Cf(1-Ct) + CcCt */ - rgba[i][RCOMP] = CHAN_PRODUCT(rgba[i][RCOMP], (CHAN_MAX-texel[i][RCOMP])) + CHAN_PRODUCT(Rc,texel[i][RCOMP]); - rgba[i][GCOMP] = CHAN_PRODUCT(rgba[i][GCOMP], (CHAN_MAX-texel[i][GCOMP])) + CHAN_PRODUCT(Gc,texel[i][GCOMP]); - rgba[i][BCOMP] = CHAN_PRODUCT(rgba[i][BCOMP], (CHAN_MAX-texel[i][BCOMP])) + CHAN_PRODUCT(Bc,texel[i][BCOMP]); - /* Av = Af */ - } - break; - case GL_RGBA: - for (i=0;i<n;i++) { - /* Cv = Cf(1-Ct) + CcCt */ - rgba[i][RCOMP] = CHAN_PRODUCT(rgba[i][RCOMP], (CHAN_MAX-texel[i][RCOMP])) + CHAN_PRODUCT(Rc,texel[i][RCOMP]); - rgba[i][GCOMP] = CHAN_PRODUCT(rgba[i][GCOMP], (CHAN_MAX-texel[i][GCOMP])) + CHAN_PRODUCT(Gc,texel[i][GCOMP]); - rgba[i][BCOMP] = CHAN_PRODUCT(rgba[i][BCOMP], (CHAN_MAX-texel[i][BCOMP])) + CHAN_PRODUCT(Bc,texel[i][BCOMP]); - /* Av = AfAt */ - rgba[i][ACOMP] = CHAN_PRODUCT(rgba[i][ACOMP],texel[i][ACOMP]); - } - break; - default: - _mesa_problem(ctx, "Bad format (GL_BLEND) in texture_apply"); - return; - } - break; - - /* XXX don't clamp results if GLchan is float??? */ - - case GL_ADD: /* GL_EXT_texture_add_env */ - switch (format) { - case GL_ALPHA: - for (i=0;i<n;i++) { - /* Rv = Rf */ - /* Gv = Gf */ - /* Bv = Bf */ - rgba[i][ACOMP] = CHAN_PRODUCT(rgba[i][ACOMP], texel[i][ACOMP]); - } - break; - case GL_LUMINANCE: - for (i=0;i<n;i++) { - ChanTemp Lt = texel[i][RCOMP]; - ChanTemp r = rgba[i][RCOMP] + Lt; - ChanTemp g = rgba[i][GCOMP] + Lt; - ChanTemp b = rgba[i][BCOMP] + Lt; - rgba[i][RCOMP] = MIN2(r, CHAN_MAX); - rgba[i][GCOMP] = MIN2(g, CHAN_MAX); - rgba[i][BCOMP] = MIN2(b, CHAN_MAX); - /* Av = Af */ - } - break; - case GL_LUMINANCE_ALPHA: - for (i=0;i<n;i++) { - ChanTemp Lt = texel[i][RCOMP]; - ChanTemp r = rgba[i][RCOMP] + Lt; - ChanTemp g = rgba[i][GCOMP] + Lt; - ChanTemp b = rgba[i][BCOMP] + Lt; - rgba[i][RCOMP] = MIN2(r, CHAN_MAX); - rgba[i][GCOMP] = MIN2(g, CHAN_MAX); - rgba[i][BCOMP] = MIN2(b, CHAN_MAX); - rgba[i][ACOMP] = CHAN_PRODUCT(rgba[i][ACOMP], texel[i][ACOMP]); - } - break; - case GL_INTENSITY: - for (i=0;i<n;i++) { - GLchan It = texel[i][RCOMP]; - ChanTemp r = rgba[i][RCOMP] + It; - ChanTemp g = rgba[i][GCOMP] + It; - ChanTemp b = rgba[i][BCOMP] + It; - ChanTemp a = rgba[i][ACOMP] + It; - rgba[i][RCOMP] = MIN2(r, CHAN_MAX); - rgba[i][GCOMP] = MIN2(g, CHAN_MAX); - rgba[i][BCOMP] = MIN2(b, CHAN_MAX); - rgba[i][ACOMP] = MIN2(a, CHAN_MAX); - } - break; - case GL_RGB: - for (i=0;i<n;i++) { - ChanTemp r = rgba[i][RCOMP] + texel[i][RCOMP]; - ChanTemp g = rgba[i][GCOMP] + texel[i][GCOMP]; - ChanTemp b = rgba[i][BCOMP] + texel[i][BCOMP]; - rgba[i][RCOMP] = MIN2(r, CHAN_MAX); - rgba[i][GCOMP] = MIN2(g, CHAN_MAX); - rgba[i][BCOMP] = MIN2(b, CHAN_MAX); - /* Av = Af */ - } - break; - case GL_RGBA: - for (i=0;i<n;i++) { - ChanTemp r = rgba[i][RCOMP] + texel[i][RCOMP]; - ChanTemp g = rgba[i][GCOMP] + texel[i][GCOMP]; - ChanTemp b = rgba[i][BCOMP] + texel[i][BCOMP]; - rgba[i][RCOMP] = MIN2(r, CHAN_MAX); - rgba[i][GCOMP] = MIN2(g, CHAN_MAX); - rgba[i][BCOMP] = MIN2(b, CHAN_MAX); - rgba[i][ACOMP] = CHAN_PRODUCT(rgba[i][ACOMP], texel[i][ACOMP]); - } - break; - default: - _mesa_problem(ctx, "Bad format (GL_ADD) in texture_apply"); - return; - } - break; - - default: - _mesa_problem(ctx, "Bad env mode in texture_apply"); - return; - } -} - - - -/** * Apply texture mapping to a span of fragments. */ void _swrast_texture_span( GLcontext *ctx, SWspan *span ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); - GLchan primary_rgba[MAX_WIDTH][4]; + GLfloat primary_rgba[MAX_WIDTH][4]; GLuint unit; - ASSERT(span->end < MAX_WIDTH); + ASSERT(span->end <= MAX_WIDTH); /* * Save copy of the incoming fragment colors (the GL_PRIMARY_COLOR) */ - if (swrast->_AnyTextureCombine) - MEMCPY(primary_rgba, span->array->rgba, 4 * span->end * sizeof(GLchan)); + if (swrast->_TextureCombinePrimary) { + GLuint i; + for (i = 0; i < span->end; i++) { + primary_rgba[i][RCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][RCOMP]); + primary_rgba[i][GCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][GCOMP]); + primary_rgba[i][BCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][BCOMP]); + primary_rgba[i][ACOMP] = CHAN_TO_FLOAT(span->array->rgba[i][ACOMP]); + } + } /* First must sample all bump maps */ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { - if (ctx->Texture.Unit[unit]._ReallyEnabled && - ctx->Texture.Unit[unit]._CurrentCombine->ModeRGB == GL_BUMP_ENVMAP_ATI) { - const GLfloat (*texcoords)[4] - = (const GLfloat (*)[4]) + const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; + + if (texUnit->_ReallyEnabled && + texUnit->_CurrentCombine->ModeRGB == GL_BUMP_ENVMAP_ATI) { + const GLfloat (*texcoords)[4] = (const GLfloat (*)[4]) span->array->attribs[FRAG_ATTRIB_TEX0 + unit]; - GLfloat (*targetcoords)[4] - = (GLfloat (*)[4]) + float4_array targetcoords = span->array->attribs[FRAG_ATTRIB_TEX0 + ctx->Texture.Unit[unit].BumpTarget - GL_TEXTURE0]; - const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; const struct gl_texture_object *curObj = texUnit->_Current; GLfloat *lambda = span->array->lambda[unit]; - GLchan (*texels)[4] = (GLchan (*)[4]) - (swrast->TexelBuffer + unit * (span->end * 4 * sizeof(GLchan))); + float4_array texels = get_texel_array(swrast, unit); GLuint i; GLfloat rotMatrix00 = ctx->Texture.Unit[unit].RotMatrix[0]; GLfloat rotMatrix01 = ctx->Texture.Unit[unit].RotMatrix[1]; @@ -1293,19 +640,10 @@ _swrast_texture_span( GLcontext *ctx, SWspan *span ) not sure this can work correctly even ignoring the problem that channel is unsigned */ for (i = 0; i < span->end; i++) { -#if CHAN_TYPE == GL_FLOAT targetcoords[i][0] += (texels[i][0] * rotMatrix00 + texels[i][1] * rotMatrix01) / targetcoords[i][3]; targetcoords[i][1] += (texels[i][0] * rotMatrix10 + texels[i][1] * rotMatrix11) / targetcoords[i][3]; -#else - targetcoords[i][0] += (CHAN_TO_FLOAT(texels[i][1]) * rotMatrix00 + - CHAN_TO_FLOAT(texels[i][1]) * rotMatrix01) / - targetcoords[i][3]; - targetcoords[i][1] += (CHAN_TO_FLOAT(texels[i][0]) * rotMatrix10 + - CHAN_TO_FLOAT(texels[i][1]) * rotMatrix11) / - targetcoords[i][3]; -#endif } } } @@ -1315,16 +653,14 @@ _swrast_texture_span( GLcontext *ctx, SWspan *span ) * accomodate GL_ARB_texture_env_crossbar. */ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { - if (ctx->Texture.Unit[unit]._ReallyEnabled && - ctx->Texture.Unit[unit]._CurrentCombine->ModeRGB != GL_BUMP_ENVMAP_ATI) { - const GLfloat (*texcoords)[4] - = (const GLfloat (*)[4]) + const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; + if (texUnit->_ReallyEnabled && + texUnit->_CurrentCombine->ModeRGB != GL_BUMP_ENVMAP_ATI) { + const GLfloat (*texcoords)[4] = (const GLfloat (*)[4]) span->array->attribs[FRAG_ATTRIB_TEX0 + unit]; - const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; const struct gl_texture_object *curObj = texUnit->_Current; GLfloat *lambda = span->array->lambda[unit]; - GLchan (*texels)[4] = (GLchan (*)[4]) - (swrast->TexelBuffer + unit * (span->end * 4 * sizeof(GLchan))); + float4_array texels = get_texel_array(swrast, unit); /* adjust texture lod (lambda) */ if (span->arrayMask & SPAN_LAMBDA) { @@ -1357,13 +693,7 @@ _swrast_texture_span( GLcontext *ctx, SWspan *span ) /* GL_SGI_texture_color_table */ if (texUnit->ColorTableEnabled) { -#if CHAN_TYPE == GL_UNSIGNED_BYTE - _mesa_lookup_rgba_ubyte(&texUnit->ColorTable, span->end, texels); -#elif CHAN_TYPE == GL_UNSIGNED_SHORT - _mesa_lookup_rgba_ubyte(&texUnit->ColorTable, span->end, texels); -#else _mesa_lookup_rgba_float(&texUnit->ColorTable, span->end, texels); -#endif } /* GL_EXT_texture_swizzle */ @@ -1373,31 +703,16 @@ _swrast_texture_span( GLcontext *ctx, SWspan *span ) } } - /* * OK, now apply the texture (aka texture combine/blend). * We modify the span->color.rgba values. */ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { if (ctx->Texture.Unit[unit]._ReallyEnabled) { - const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; - if (texUnit->_CurrentCombine != &texUnit->_EnvMode ) { - texture_combine( ctx, unit, span->end, - (CONST GLchan (*)[4]) primary_rgba, - swrast->TexelBuffer, - span->array->rgba ); - } - else { - /* conventional texture blend */ - const GLchan (*texels)[4] = (const GLchan (*)[4]) - (swrast->TexelBuffer + unit * - (span->end * 4 * sizeof(GLchan))); - - - texture_apply( ctx, texUnit, span->end, - (CONST GLchan (*)[4]) primary_rgba, texels, - span->array->rgba ); - } + texture_combine( ctx, unit, span->end, + primary_rgba, + swrast->TexelBuffer, + span->array->rgba ); } } } diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c index 19317c393a..a483023a50 100644 --- a/src/mesa/swrast/s_texfilter.c +++ b/src/mesa/swrast/s_texfilter.c @@ -43,18 +43,11 @@ #define FRAC(f) ((f) - IFLOOR(f)) -/** - * Constants for integer linear interpolation. - */ -#define ILERP_SCALE 65536.0F -#define ILERP_SHIFT 16 - /** - * Linear interpolation macros + * Linear interpolation macro */ #define LERP(T, A, B) ( (A) + (T) * ((B) - (A)) ) -#define ILERP(IT, A, B) ( (A) + (((IT) * ((B) - (A))) >> ILERP_SHIFT) ) /** @@ -76,21 +69,6 @@ lerp_2d(GLfloat a, GLfloat b, /** - * Do 2D/biliner interpolation of integer values. - * \sa lerp_2d - */ -static INLINE GLint -ilerp_2d(GLint ia, GLint ib, - GLint v00, GLint v10, GLint v01, GLint v11) -{ - /* fixed point interpolants in [0, ILERP_SCALE] */ - const GLint temp0 = ILERP(ia, v00, v10); - const GLint temp1 = ILERP(ia, v01, v11); - return ILERP(ib, temp0, temp1); -} - - -/** * Do 3D/trilinear interpolation of float values. * \sa lerp_2d */ @@ -110,50 +88,15 @@ lerp_3d(GLfloat a, GLfloat b, GLfloat c, /** - * Do 3D/trilinear interpolation of integer values. - * \sa lerp_2d - */ -static INLINE GLint -ilerp_3d(GLint ia, GLint ib, GLint ic, - GLint v000, GLint v100, GLint v010, GLint v110, - GLint v001, GLint v101, GLint v011, GLint v111) -{ - /* fixed point interpolants in [0, ILERP_SCALE] */ - const GLint temp00 = ILERP(ia, v000, v100); - const GLint temp10 = ILERP(ia, v010, v110); - const GLint temp01 = ILERP(ia, v001, v101); - const GLint temp11 = ILERP(ia, v011, v111); - const GLint temp0 = ILERP(ib, temp00, temp10); - const GLint temp1 = ILERP(ib, temp01, temp11); - return ILERP(ic, temp0, temp1); -} - - -/** * Do linear interpolation of colors. */ static INLINE void -lerp_rgba(GLchan result[4], GLfloat t, const GLchan a[4], const GLchan b[4]) +lerp_rgba(GLfloat result[4], GLfloat t, const GLfloat a[4], const GLfloat b[4]) { -#if CHAN_TYPE == GL_FLOAT result[0] = LERP(t, a[0], b[0]); result[1] = LERP(t, a[1], b[1]); result[2] = LERP(t, a[2], b[2]); result[3] = LERP(t, a[3], b[3]); -#elif CHAN_TYPE == GL_UNSIGNED_SHORT - result[0] = (GLchan) (LERP(t, a[0], b[0]) + 0.5); - result[1] = (GLchan) (LERP(t, a[1], b[1]) + 0.5); - result[2] = (GLchan) (LERP(t, a[2], b[2]) + 0.5); - result[3] = (GLchan) (LERP(t, a[3], b[3]) + 0.5); -#else - /* fixed point interpolants in [0, ILERP_SCALE] */ - const GLint it = IROUND_POS(t * ILERP_SCALE); - ASSERT(CHAN_TYPE == GL_UNSIGNED_BYTE); - result[0] = ILERP(it, a[0], b[0]); - result[1] = ILERP(it, a[1], b[1]); - result[2] = ILERP(it, a[2], b[2]); - result[3] = ILERP(it, a[3], b[3]); -#endif } @@ -161,29 +104,14 @@ lerp_rgba(GLchan result[4], GLfloat t, const GLchan a[4], const GLchan b[4]) * Do bilinear interpolation of colors. */ static INLINE void -lerp_rgba_2d(GLchan result[4], GLfloat a, GLfloat b, - const GLchan t00[4], const GLchan t10[4], - const GLchan t01[4], const GLchan t11[4]) +lerp_rgba_2d(GLfloat result[4], GLfloat a, GLfloat b, + const GLfloat t00[4], const GLfloat t10[4], + const GLfloat t01[4], const GLfloat t11[4]) { -#if CHAN_TYPE == GL_FLOAT result[0] = lerp_2d(a, b, t00[0], t10[0], t01[0], t11[0]); result[1] = lerp_2d(a, b, t00[1], t10[1], t01[1], t11[1]); result[2] = lerp_2d(a, b, t00[2], t10[2], t01[2], t11[2]); result[3] = lerp_2d(a, b, t00[3], t10[3], t01[3], t11[3]); -#elif CHAN_TYPE == GL_UNSIGNED_SHORT - result[0] = (GLchan) (lerp_2d(a, b, t00[0], t10[0], t01[0], t11[0]) + 0.5); - result[1] = (GLchan) (lerp_2d(a, b, t00[1], t10[1], t01[1], t11[1]) + 0.5); - result[2] = (GLchan) (lerp_2d(a, b, t00[2], t10[2], t01[2], t11[2]) + 0.5); - result[3] = (GLchan) (lerp_2d(a, b, t00[3], t10[3], t01[3], t11[3]) + 0.5); -#else - const GLint ia = IROUND_POS(a * ILERP_SCALE); - const GLint ib = IROUND_POS(b * ILERP_SCALE); - ASSERT(CHAN_TYPE == GL_UNSIGNED_BYTE); - result[0] = ilerp_2d(ia, ib, t00[0], t10[0], t01[0], t11[0]); - result[1] = ilerp_2d(ia, ib, t00[1], t10[1], t01[1], t11[1]); - result[2] = ilerp_2d(ia, ib, t00[2], t10[2], t01[2], t11[2]); - result[3] = ilerp_2d(ia, ib, t00[3], t10[3], t01[3], t11[3]); -#endif } @@ -191,34 +119,18 @@ lerp_rgba_2d(GLchan result[4], GLfloat a, GLfloat b, * Do trilinear interpolation of colors. */ static INLINE void -lerp_rgba_3d(GLchan result[4], GLfloat a, GLfloat b, GLfloat c, - const GLchan t000[4], const GLchan t100[4], - const GLchan t010[4], const GLchan t110[4], - const GLchan t001[4], const GLchan t101[4], - const GLchan t011[4], const GLchan t111[4]) +lerp_rgba_3d(GLfloat result[4], GLfloat a, GLfloat b, GLfloat c, + const GLfloat t000[4], const GLfloat t100[4], + const GLfloat t010[4], const GLfloat t110[4], + const GLfloat t001[4], const GLfloat t101[4], + const GLfloat t011[4], const GLfloat t111[4]) { GLuint k; /* compiler should unroll these short loops */ -#if CHAN_TYPE == GL_FLOAT for (k = 0; k < 4; k++) { result[k] = lerp_3d(a, b, c, t000[k], t100[k], t010[k], t110[k], t001[k], t101[k], t011[k], t111[k]); } -#elif CHAN_TYPE == GL_UNSIGNED_SHORT - for (k = 0; k < 4; k++) { - result[k] = (GLchan)(lerp_3d(a, b, c, - t000[k], t100[k], t010[k], t110[k], - t001[k], t101[k], t011[k], t111[k]) + 0.5F); - } -#else - GLint ia = IROUND_POS(a * ILERP_SCALE); - GLint ib = IROUND_POS(b * ILERP_SCALE); - GLint ic = IROUND_POS(c * ILERP_SCALE); - for (k = 0; k < 4; k++) { - result[k] = ilerp_3d(ia, ib, ic, t000[k], t100[k], t010[k], t110[k], - t001[k], t101[k], t011[k], t111[k]); - } -#endif } @@ -502,6 +414,168 @@ linear_repeat_texel_location(GLuint size, GLfloat s, /** + * Do clamp/wrap for a texture rectangle coord, GL_NEAREST filter mode. + */ +static INLINE GLint +clamp_rect_coord_nearest(GLenum wrapMode, GLfloat coord, GLint max) +{ + switch (wrapMode) { + case GL_CLAMP: + return IFLOOR( CLAMP(coord, 0.0F, max - 1) ); + case GL_CLAMP_TO_EDGE: + return IFLOOR( CLAMP(coord, 0.5F, max - 0.5F) ); + case GL_CLAMP_TO_BORDER: + return IFLOOR( CLAMP(coord, -0.5F, max + 0.5F) ); + default: + _mesa_problem(NULL, "bad wrapMode in clamp_rect_coord_nearest"); + return 0; + } +} + + +/** + * As above, but GL_LINEAR filtering. + */ +static INLINE void +clamp_rect_coord_linear(GLenum wrapMode, GLfloat coord, GLint max, + GLint *i0out, GLint *i1out, GLfloat *weight) +{ + GLfloat fcol; + GLint i0, i1; + switch (wrapMode) { + case GL_CLAMP: + /* Not exactly what the spec says, but it matches NVIDIA output */ + fcol = CLAMP(coord - 0.5F, 0.0, max-1); + i0 = IFLOOR(fcol); + i1 = i0 + 1; + break; + case GL_CLAMP_TO_EDGE: + fcol = CLAMP(coord, 0.5F, max - 0.5F); + fcol -= 0.5F; + i0 = IFLOOR(fcol); + i1 = i0 + 1; + if (i1 > max - 1) + i1 = max - 1; + break; + case GL_CLAMP_TO_BORDER: + fcol = CLAMP(coord, -0.5F, max + 0.5F); + fcol -= 0.5F; + i0 = IFLOOR(fcol); + i1 = i0 + 1; + default: + _mesa_problem(NULL, "bad wrapMode in clamp_rect_coord_linear"); + i0 = i1 = 0; + fcol = 0.0F; + } + *i0out = i0; + *i1out = i1; + *weight = FRAC(fcol); +} + + +/** + * Compute nearest integer texcoords for given texobj and coordinate. + */ +static INLINE void +nearest_texcoord(const struct gl_texture_object *texObj, + const GLfloat texcoord[4], + GLint *i, GLint *j, GLint *k) +{ + const GLint baseLevel = texObj->BaseLevel; + const struct gl_texture_image *img = texObj->Image[0][baseLevel]; + const GLint width = img->Width; + const GLint height = img->Height; + const GLint depth = img->Depth; + + switch (texObj->Target) { + case GL_TEXTURE_RECTANGLE_ARB: + *i = clamp_rect_coord_nearest(texObj->WrapS, texcoord[0], width); + *j = clamp_rect_coord_nearest(texObj->WrapT, texcoord[1], height); + *k = 0; + break; + case GL_TEXTURE_1D: + *i = nearest_texel_location(texObj->WrapS, img, width, texcoord[0]); + *j = 0; + *k = 0; + break; + case GL_TEXTURE_2D: + *i = nearest_texel_location(texObj->WrapS, img, width, texcoord[0]); + *j = nearest_texel_location(texObj->WrapT, img, height, texcoord[1]); + *k = 0; + break; + case GL_TEXTURE_1D_ARRAY_EXT: + *i = nearest_texel_location(texObj->WrapS, img, width, texcoord[0]); + *j = clamp_rect_coord_nearest(texObj->WrapT, texcoord[1], height); + *k = 0; + break; + case GL_TEXTURE_2D_ARRAY_EXT: + *i = nearest_texel_location(texObj->WrapS, img, width, texcoord[0]); + *j = nearest_texel_location(texObj->WrapT, img, height, texcoord[1]); + *k = clamp_rect_coord_nearest(texObj->WrapR, texcoord[2], depth); + break; + default: + *i = *j = *k = 0; + } +} + + +/** + * Compute linear integer texcoords for given texobj and coordinate. + */ +static INLINE void +linear_texcoord(const struct gl_texture_object *texObj, + const GLfloat texcoord[4], + GLint *i0, GLint *i1, GLint *j0, GLint *j1, GLint *slice, + GLfloat *wi, GLfloat *wj) +{ + const GLint baseLevel = texObj->BaseLevel; + const struct gl_texture_image *img = texObj->Image[0][baseLevel]; + const GLint width = img->Width; + const GLint height = img->Height; + const GLint depth = img->Depth; + + switch (texObj->Target) { + case GL_TEXTURE_RECTANGLE_ARB: + clamp_rect_coord_linear(texObj->WrapS, texcoord[0], + width, i0, i1, wi); + clamp_rect_coord_linear(texObj->WrapT, texcoord[1], + height, j0, j1, wj); + *slice = 0; + break; + + case GL_TEXTURE_1D: + case GL_TEXTURE_2D: + linear_texel_locations(texObj->WrapS, img, width, + texcoord[0], i0, i1, wi); + linear_texel_locations(texObj->WrapT, img, height, + texcoord[1], j0, j1, wj); + *slice = 0; + break; + + case GL_TEXTURE_1D_ARRAY_EXT: + linear_texel_locations(texObj->WrapS, img, width, + texcoord[0], i0, i1, wi); + *j0 = clamp_rect_coord_nearest(texObj->WrapT, texcoord[1], height); + *j1 = *j0; + *slice = 0; + break; + + case GL_TEXTURE_2D_ARRAY_EXT: + linear_texel_locations(texObj->WrapS, img, width, + texcoord[0], i0, i1, wi); + linear_texel_locations(texObj->WrapT, img, height, + texcoord[1], j0, j1, wj); + *slice = clamp_rect_coord_nearest(texObj->WrapR, texcoord[2], depth); + break; + + default: + *slice = 0; + } +} + + + +/** * For linear interpolation between mipmap levels N and N+1, this function * computes N. */ @@ -660,6 +734,44 @@ compute_min_mag_ranges(const struct gl_texture_object *tObj, } +/** + * When we sample the border color, it must be interpreted according to + * the base texture format. Ex: if the texture base format it GL_ALPHA, + * we return (0,0,0,BorderAlpha). + */ +static INLINE void +get_border_color(const struct gl_texture_object *tObj, + const struct gl_texture_image *img, + GLfloat rgba[4]) +{ + switch (img->TexFormat->BaseFormat) { + case GL_RGB: + rgba[0] = tObj->BorderColor[0]; + rgba[1] = tObj->BorderColor[1]; + rgba[2] = tObj->BorderColor[2]; + rgba[3] = 1.0F; + break; + case GL_ALPHA: + rgba[0] = rgba[1] = rgba[2] = 0.0; + rgba[3] = tObj->BorderColor[3]; + break; + case GL_LUMINANCE: + rgba[0] = rgba[1] = rgba[2] = tObj->BorderColor[0]; + rgba[3] = 1.0; + break; + case GL_LUMINANCE_ALPHA: + rgba[0] = rgba[1] = rgba[2] = tObj->BorderColor[0]; + rgba[3] = tObj->BorderColor[3]; + break; + case GL_INTENSITY: + rgba[0] = rgba[1] = rgba[2] = rgba[3] = tObj->BorderColor[0]; + break; + default: + COPY_4V(rgba, tObj->BorderColor); + } +} + + /**********************************************************************/ /* 1-D Texture Sampling Functions */ /**********************************************************************/ @@ -671,7 +783,7 @@ static INLINE void sample_1d_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, const struct gl_texture_image *img, - const GLfloat texcoord[4], GLchan rgba[4]) + const GLfloat texcoord[4], GLfloat rgba[4]) { const GLint width = img->Width2; /* without border, power of two */ GLint i; @@ -680,10 +792,10 @@ sample_1d_nearest(GLcontext *ctx, i += img->Border; if (i < 0 || i >= (GLint) img->Width) { /* Need this test for GL_CLAMP_TO_BORDER mode */ - COPY_CHAN4(rgba, tObj->_BorderChan); + get_border_color(tObj, img, rgba); } else { - img->FetchTexelc(img, i, 0, 0, rgba); + img->FetchTexelf(img, i, 0, 0, rgba); } } @@ -695,13 +807,13 @@ static INLINE void sample_1d_linear(GLcontext *ctx, const struct gl_texture_object *tObj, const struct gl_texture_image *img, - const GLfloat texcoord[4], GLchan rgba[4]) + const GLfloat texcoord[4], GLfloat rgba[4]) { const GLint width = img->Width2; GLint i0, i1; GLbitfield useBorderColor = 0x0; GLfloat a; - GLchan t0[4], t1[4]; /* texels */ + GLfloat t0[4], t1[4]; /* texels */ linear_texel_locations(tObj->WrapS, img, width, texcoord[0], &i0, &i1, &a); @@ -716,16 +828,16 @@ sample_1d_linear(GLcontext *ctx, /* fetch texel colors */ if (useBorderColor & I0BIT) { - COPY_CHAN4(t0, tObj->_BorderChan); + get_border_color(tObj, img, t0); } else { - img->FetchTexelc(img, i0, 0, 0, t0); + img->FetchTexelf(img, i0, 0, 0, t0); } if (useBorderColor & I1BIT) { - COPY_CHAN4(t1, tObj->_BorderChan); + get_border_color(tObj, img, t1); } else { - img->FetchTexelc(img, i1, 0, 0, t1); + img->FetchTexelf(img, i1, 0, 0, t1); } lerp_rgba(rgba, a, t0, t1); @@ -736,7 +848,7 @@ static void sample_1d_nearest_mipmap_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -751,7 +863,7 @@ static void sample_1d_linear_mipmap_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -766,7 +878,7 @@ static void sample_1d_nearest_mipmap_linear(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -777,7 +889,7 @@ sample_1d_nearest_mipmap_linear(GLcontext *ctx, texcoord[i], rgba[i]); } else { - GLchan t0[4], t1[4]; + GLfloat t0[4], t1[4]; const GLfloat f = FRAC(lambda[i]); sample_1d_nearest(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0); sample_1d_nearest(ctx, tObj, tObj->Image[0][level+1], texcoord[i], t1); @@ -791,7 +903,7 @@ static void sample_1d_linear_mipmap_linear(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -802,7 +914,7 @@ sample_1d_linear_mipmap_linear(GLcontext *ctx, texcoord[i], rgba[i]); } else { - GLchan t0[4], t1[4]; + GLfloat t0[4], t1[4]; const GLfloat f = FRAC(lambda[i]); sample_1d_linear(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0); sample_1d_linear(ctx, tObj, tObj->Image[0][level+1], texcoord[i], t1); @@ -817,7 +929,7 @@ static void sample_nearest_1d( GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4] ) + GLfloat rgba[][4] ) { GLuint i; struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel]; @@ -833,7 +945,7 @@ static void sample_linear_1d( GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4] ) + GLfloat rgba[][4] ) { GLuint i; struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel]; @@ -849,7 +961,7 @@ static void sample_lambda_1d( GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], - const GLfloat lambda[], GLchan rgba[][4] ) + const GLfloat lambda[], GLfloat rgba[][4] ) { GLuint minStart, minEnd; /* texels with minification */ GLuint magStart, magEnd; /* texels with magnification */ @@ -929,7 +1041,7 @@ sample_2d_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, const struct gl_texture_image *img, const GLfloat texcoord[4], - GLchan rgba[]) + GLfloat rgba[]) { const GLint width = img->Width2; /* without border, power of two */ const GLint height = img->Height2; /* without border, power of two */ @@ -945,10 +1057,10 @@ 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 mode */ - COPY_CHAN4(rgba, tObj->_BorderChan); + get_border_color(tObj, img, rgba); } else { - img->FetchTexelc(img, i, j, 0, rgba); + img->FetchTexelf(img, i, j, 0, rgba); } } @@ -962,14 +1074,14 @@ sample_2d_linear(GLcontext *ctx, const struct gl_texture_object *tObj, const struct gl_texture_image *img, const GLfloat texcoord[4], - GLchan rgba[]) + GLfloat rgba[]) { const GLint width = img->Width2; const GLint height = img->Height2; GLint i0, j0, i1, j1; GLbitfield useBorderColor = 0x0; GLfloat a, b; - GLchan t00[4], t10[4], t01[4], t11[4]; /* sampled texel colors */ + GLfloat t00[4], t10[4], t01[4], t11[4]; /* sampled texel colors */ linear_texel_locations(tObj->WrapS, img, width, texcoord[0], &i0, &i1, &a); linear_texel_locations(tObj->WrapT, img, height, texcoord[1], &j0, &j1, &b); @@ -989,28 +1101,28 @@ sample_2d_linear(GLcontext *ctx, /* fetch four texel colors */ if (useBorderColor & (I0BIT | J0BIT)) { - COPY_CHAN4(t00, tObj->_BorderChan); + get_border_color(tObj, img, t00); } else { - img->FetchTexelc(img, i0, j0, 0, t00); + img->FetchTexelf(img, i0, j0, 0, t00); } if (useBorderColor & (I1BIT | J0BIT)) { - COPY_CHAN4(t10, tObj->_BorderChan); + get_border_color(tObj, img, t10); } else { - img->FetchTexelc(img, i1, j0, 0, t10); + img->FetchTexelf(img, i1, j0, 0, t10); } if (useBorderColor & (I0BIT | J1BIT)) { - COPY_CHAN4(t01, tObj->_BorderChan); + get_border_color(tObj, img, t01); } else { - img->FetchTexelc(img, i0, j1, 0, t01); + img->FetchTexelf(img, i0, j1, 0, t01); } if (useBorderColor & (I1BIT | J1BIT)) { - COPY_CHAN4(t11, tObj->_BorderChan); + get_border_color(tObj, img, t11); } else { - img->FetchTexelc(img, i1, j1, 0, t11); + img->FetchTexelf(img, i1, j1, 0, t11); } lerp_rgba_2d(rgba, a, b, t00, t10, t01, t11); @@ -1026,13 +1138,13 @@ sample_2d_linear_repeat(GLcontext *ctx, const struct gl_texture_object *tObj, const struct gl_texture_image *img, const GLfloat texcoord[4], - GLchan rgba[]) + GLfloat rgba[]) { const GLint width = img->Width2; const GLint height = img->Height2; GLint i0, j0, i1, j1; GLfloat wi, wj; - GLchan t00[4], t10[4], t01[4], t11[4]; /* sampled texel colors */ + GLfloat t00[4], t10[4], t01[4], t11[4]; /* sampled texel colors */ (void) ctx; @@ -1045,10 +1157,10 @@ sample_2d_linear_repeat(GLcontext *ctx, linear_repeat_texel_location(width, texcoord[0], &i0, &i1, &wi); linear_repeat_texel_location(height, texcoord[1], &j0, &j1, &wj); - img->FetchTexelc(img, i0, j0, 0, t00); - img->FetchTexelc(img, i1, j0, 0, t10); - img->FetchTexelc(img, i0, j1, 0, t01); - img->FetchTexelc(img, i1, j1, 0, t11); + img->FetchTexelf(img, i0, j0, 0, t00); + img->FetchTexelf(img, i1, j0, 0, t10); + img->FetchTexelf(img, i0, j1, 0, t01); + img->FetchTexelf(img, i1, j1, 0, t11); lerp_rgba_2d(rgba, wi, wj, t00, t10, t01, t11); } @@ -1058,7 +1170,7 @@ static void sample_2d_nearest_mipmap_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; for (i = 0; i < n; i++) { @@ -1072,7 +1184,7 @@ static void sample_2d_linear_mipmap_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -1087,7 +1199,7 @@ static void sample_2d_nearest_mipmap_linear(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -1098,7 +1210,7 @@ sample_2d_nearest_mipmap_linear(GLcontext *ctx, texcoord[i], rgba[i]); } else { - GLchan t0[4], t1[4]; /* texels */ + GLfloat t0[4], t1[4]; /* texels */ const GLfloat f = FRAC(lambda[i]); sample_2d_nearest(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0); sample_2d_nearest(ctx, tObj, tObj->Image[0][level+1], texcoord[i], t1); @@ -1112,7 +1224,7 @@ static void sample_2d_linear_mipmap_linear( GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4] ) + const GLfloat lambda[], GLfloat rgba[][4] ) { GLuint i; ASSERT(lambda != NULL); @@ -1123,7 +1235,7 @@ sample_2d_linear_mipmap_linear( GLcontext *ctx, texcoord[i], rgba[i]); } else { - GLchan t0[4], t1[4]; /* texels */ + GLfloat t0[4], t1[4]; /* texels */ const GLfloat f = FRAC(lambda[i]); sample_2d_linear(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0); sample_2d_linear(ctx, tObj, tObj->Image[0][level+1], texcoord[i], t1); @@ -1137,7 +1249,7 @@ static void sample_2d_linear_mipmap_linear_repeat(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -1150,7 +1262,7 @@ sample_2d_linear_mipmap_linear_repeat(GLcontext *ctx, texcoord[i], rgba[i]); } else { - GLchan t0[4], t1[4]; /* texels */ + GLfloat t0[4], t1[4]; /* texels */ const GLfloat f = FRAC(lambda[i]); sample_2d_linear_repeat(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0); @@ -1167,7 +1279,7 @@ static void sample_nearest_2d(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel]; @@ -1183,7 +1295,7 @@ static void sample_linear_2d(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel]; @@ -1279,7 +1391,7 @@ opt_sample_rgba_2d(GLcontext *ctx, const GLint row = IFLOOR(texcoords[i][1] * height) & rowMask; const GLint pos = (row << shift) | col; const GLchan *texel = ((GLchan *) img->Data) + (pos << 2); /* pos*4 */ - COPY_CHAN4(rgba[i], texel); + COPY_4V(rgba[i], texel); } } @@ -1289,7 +1401,7 @@ static void sample_lambda_2d(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { const struct gl_texture_image *tImg = tObj->Image[0][tObj->BaseLevel]; GLuint minStart, minEnd; /* texels with minification */ @@ -1312,6 +1424,7 @@ sample_lambda_2d(GLcontext *ctx, case GL_NEAREST: if (repeatNoBorderPOT) { switch (tImg->TexFormat->MesaFormat) { +#if 0 case MESA_FORMAT_RGB: opt_sample_rgb_2d(ctx, tObj, m, texcoords + minStart, NULL, rgba + minStart); @@ -1320,6 +1433,7 @@ sample_lambda_2d(GLcontext *ctx, opt_sample_rgba_2d(ctx, tObj, m, texcoords + minStart, NULL, rgba + minStart); break; +#endif default: sample_nearest_2d(ctx, tObj, m, texcoords + minStart, NULL, rgba + minStart ); @@ -1369,6 +1483,7 @@ sample_lambda_2d(GLcontext *ctx, case GL_NEAREST: if (repeatNoBorderPOT) { switch (tImg->TexFormat->MesaFormat) { +#if 0 case MESA_FORMAT_RGB: opt_sample_rgb_2d(ctx, tObj, m, texcoords + magStart, NULL, rgba + magStart); @@ -1377,6 +1492,7 @@ sample_lambda_2d(GLcontext *ctx, opt_sample_rgba_2d(ctx, tObj, m, texcoords + magStart, NULL, rgba + magStart); break; +#endif default: sample_nearest_2d(ctx, tObj, m, texcoords + magStart, NULL, rgba + magStart ); @@ -1411,7 +1527,7 @@ sample_3d_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, const struct gl_texture_image *img, const GLfloat texcoord[4], - GLchan rgba[4]) + GLfloat rgba[4]) { const GLint width = img->Width2; /* without border, power of two */ const GLint height = img->Height2; /* without border, power of two */ @@ -1427,10 +1543,10 @@ 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 mode */ - COPY_CHAN4(rgba, tObj->_BorderChan); + get_border_color(tObj, img, rgba); } else { - img->FetchTexelc(img, i, j, k, rgba); + img->FetchTexelf(img, i, j, k, rgba); } } @@ -1443,7 +1559,7 @@ sample_3d_linear(GLcontext *ctx, const struct gl_texture_object *tObj, const struct gl_texture_image *img, const GLfloat texcoord[4], - GLchan rgba[4]) + GLfloat rgba[4]) { const GLint width = img->Width2; const GLint height = img->Height2; @@ -1451,8 +1567,8 @@ sample_3d_linear(GLcontext *ctx, GLint i0, j0, k0, i1, j1, k1; GLbitfield useBorderColor = 0x0; GLfloat a, b, c; - GLchan t000[4], t010[4], t001[4], t011[4]; - GLchan t100[4], t110[4], t101[4], t111[4]; + GLfloat t000[4], t010[4], t001[4], t011[4]; + GLfloat t100[4], t110[4], t101[4], t111[4]; linear_texel_locations(tObj->WrapS, img, width, texcoord[0], &i0, &i1, &a); linear_texel_locations(tObj->WrapT, img, height, texcoord[1], &j0, &j1, &b); @@ -1478,53 +1594,53 @@ sample_3d_linear(GLcontext *ctx, /* Fetch texels */ if (useBorderColor & (I0BIT | J0BIT | K0BIT)) { - COPY_CHAN4(t000, tObj->_BorderChan); + get_border_color(tObj, img, t000); } else { - img->FetchTexelc(img, i0, j0, k0, t000); + img->FetchTexelf(img, i0, j0, k0, t000); } if (useBorderColor & (I1BIT | J0BIT | K0BIT)) { - COPY_CHAN4(t100, tObj->_BorderChan); + get_border_color(tObj, img, t100); } else { - img->FetchTexelc(img, i1, j0, k0, t100); + img->FetchTexelf(img, i1, j0, k0, t100); } if (useBorderColor & (I0BIT | J1BIT | K0BIT)) { - COPY_CHAN4(t010, tObj->_BorderChan); + get_border_color(tObj, img, t010); } else { - img->FetchTexelc(img, i0, j1, k0, t010); + img->FetchTexelf(img, i0, j1, k0, t010); } if (useBorderColor & (I1BIT | J1BIT | K0BIT)) { - COPY_CHAN4(t110, tObj->_BorderChan); + get_border_color(tObj, img, t110); } else { - img->FetchTexelc(img, i1, j1, k0, t110); + img->FetchTexelf(img, i1, j1, k0, t110); } if (useBorderColor & (I0BIT | J0BIT | K1BIT)) { - COPY_CHAN4(t001, tObj->_BorderChan); + get_border_color(tObj, img, t001); } else { - img->FetchTexelc(img, i0, j0, k1, t001); + img->FetchTexelf(img, i0, j0, k1, t001); } if (useBorderColor & (I1BIT | J0BIT | K1BIT)) { - COPY_CHAN4(t101, tObj->_BorderChan); + get_border_color(tObj, img, t101); } else { - img->FetchTexelc(img, i1, j0, k1, t101); + img->FetchTexelf(img, i1, j0, k1, t101); } if (useBorderColor & (I0BIT | J1BIT | K1BIT)) { - COPY_CHAN4(t011, tObj->_BorderChan); + get_border_color(tObj, img, t011); } else { - img->FetchTexelc(img, i0, j1, k1, t011); + img->FetchTexelf(img, i0, j1, k1, t011); } if (useBorderColor & (I1BIT | J1BIT | K1BIT)) { - COPY_CHAN4(t111, tObj->_BorderChan); + get_border_color(tObj, img, t111); } else { - img->FetchTexelc(img, i1, j1, k1, t111); + img->FetchTexelf(img, i1, j1, k1, t111); } /* trilinear interpolation of samples */ @@ -1536,7 +1652,7 @@ static void sample_3d_nearest_mipmap_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4] ) + const GLfloat lambda[], GLfloat rgba[][4] ) { GLuint i; for (i = 0; i < n; i++) { @@ -1550,7 +1666,7 @@ static void sample_3d_linear_mipmap_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -1565,7 +1681,7 @@ static void sample_3d_nearest_mipmap_linear(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -1576,7 +1692,7 @@ sample_3d_nearest_mipmap_linear(GLcontext *ctx, texcoord[i], rgba[i]); } else { - GLchan t0[4], t1[4]; /* texels */ + GLfloat t0[4], t1[4]; /* texels */ const GLfloat f = FRAC(lambda[i]); sample_3d_nearest(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0); sample_3d_nearest(ctx, tObj, tObj->Image[0][level+1], texcoord[i], t1); @@ -1590,7 +1706,7 @@ static void sample_3d_linear_mipmap_linear(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -1601,7 +1717,7 @@ sample_3d_linear_mipmap_linear(GLcontext *ctx, texcoord[i], rgba[i]); } else { - GLchan t0[4], t1[4]; /* texels */ + GLfloat t0[4], t1[4]; /* texels */ const GLfloat f = FRAC(lambda[i]); sample_3d_linear(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0); sample_3d_linear(ctx, tObj, tObj->Image[0][level+1], texcoord[i], t1); @@ -1616,7 +1732,7 @@ static void sample_nearest_3d(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4]) + GLfloat rgba[][4]) { GLuint i; struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel]; @@ -1632,7 +1748,7 @@ static void sample_linear_3d(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel]; @@ -1648,7 +1764,7 @@ static void sample_lambda_3d(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4]) + GLfloat rgba[][4]) { GLuint minStart, minEnd; /* texels with minification */ GLuint magStart, magEnd; /* texels with magnification */ @@ -1799,7 +1915,7 @@ static void sample_nearest_cube(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4]) + GLfloat rgba[][4]) { GLuint i; (void) lambda; @@ -1817,7 +1933,7 @@ static void sample_linear_cube(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; (void) lambda; @@ -1835,7 +1951,7 @@ static void sample_cube_nearest_mipmap_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -1864,7 +1980,7 @@ static void sample_cube_linear_mipmap_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -1883,7 +1999,7 @@ static void sample_cube_nearest_mipmap_linear(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -1898,7 +2014,7 @@ sample_cube_nearest_mipmap_linear(GLcontext *ctx, newCoord, rgba[i]); } else { - GLchan t0[4], t1[4]; /* texels */ + GLfloat t0[4], t1[4]; /* texels */ const GLfloat f = FRAC(lambda[i]); sample_2d_nearest(ctx, tObj, images[level ], newCoord, t0); sample_2d_nearest(ctx, tObj, images[level+1], newCoord, t1); @@ -1912,7 +2028,7 @@ static void sample_cube_linear_mipmap_linear(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -1927,7 +2043,7 @@ sample_cube_linear_mipmap_linear(GLcontext *ctx, newCoord, rgba[i]); } else { - GLchan t0[4], t1[4]; + GLfloat t0[4], t1[4]; const GLfloat f = FRAC(lambda[i]); sample_2d_linear(ctx, tObj, images[level ], newCoord, t0); sample_2d_linear(ctx, tObj, images[level+1], newCoord, t1); @@ -1942,7 +2058,7 @@ static void sample_lambda_cube(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4]) + GLfloat rgba[][4]) { GLuint minStart, minEnd; /* texels with minification */ GLuint magStart, magEnd; /* texels with magnification */ @@ -2012,71 +2128,11 @@ sample_lambda_cube(GLcontext *ctx, /**********************************************************************/ -/** - * Do clamp/wrap for a texture rectangle coord, GL_NEAREST filter mode. - */ -static INLINE GLint -clamp_rect_coord_nearest(GLenum wrapMode, GLfloat coord, GLint max) -{ - switch (wrapMode) { - case GL_CLAMP: - return IFLOOR( CLAMP(coord, 0.0F, max - 1) ); - case GL_CLAMP_TO_EDGE: - return IFLOOR( CLAMP(coord, 0.5F, max - 0.5F) ); - case GL_CLAMP_TO_BORDER: - return IFLOOR( CLAMP(coord, -0.5F, max + 0.5F) ); - default: - _mesa_problem(NULL, "bad wrapMode in clamp_rect_coord_nearest"); - return 0; - } -} - - -/** - * As above, but GL_LINEAR filtering. - */ -static INLINE void -clamp_rect_coord_linear(GLenum wrapMode, GLfloat coord, GLint max, - GLint *i0out, GLint *i1out, GLfloat *weight) -{ - GLfloat fcol; - GLint i0, i1; - switch (wrapMode) { - case GL_CLAMP: - /* Not exactly what the spec says, but it matches NVIDIA output */ - fcol = CLAMP(coord - 0.5F, 0.0, max-1); - i0 = IFLOOR(fcol); - i1 = i0 + 1; - break; - case GL_CLAMP_TO_EDGE: - fcol = CLAMP(coord, 0.5F, max - 0.5F); - fcol -= 0.5F; - i0 = IFLOOR(fcol); - i1 = i0 + 1; - if (i1 > max - 1) - i1 = max - 1; - break; - case GL_CLAMP_TO_BORDER: - fcol = CLAMP(coord, -0.5F, max + 0.5F); - fcol -= 0.5F; - i0 = IFLOOR(fcol); - i1 = i0 + 1; - default: - _mesa_problem(NULL, "bad wrapMode in clamp_rect_coord_linear"); - i0 = i1 = 0; - fcol = 0.0F; - } - *i0out = i0; - *i1out = i1; - *weight = FRAC(fcol); -} - - static void sample_nearest_rect(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4]) + GLfloat rgba[][4]) { const struct gl_texture_image *img = tObj->Image[0][0]; const GLint width = img->Width; @@ -2099,9 +2155,9 @@ sample_nearest_rect(GLcontext *ctx, col = clamp_rect_coord_nearest(tObj->WrapS, texcoords[i][0], width); row = clamp_rect_coord_nearest(tObj->WrapT, texcoords[i][1], height); if (col < 0 || col >= width || row < 0 || row >= height) - COPY_CHAN4(rgba[i], tObj->_BorderChan); + get_border_color(tObj, img, rgba[i]); else - img->FetchTexelc(img, col, row, 0, rgba[i]); + img->FetchTexelf(img, col, row, 0, rgba[i]); } } @@ -2110,7 +2166,7 @@ static void sample_linear_rect(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { const struct gl_texture_image *img = tObj->Image[0][0]; const GLint width = img->Width; @@ -2130,7 +2186,7 @@ sample_linear_rect(GLcontext *ctx, for (i = 0; i < n; i++) { GLint i0, j0, i1, j1; - GLchan t00[4], t01[4], t10[4], t11[4]; + GLfloat t00[4], t01[4], t10[4], t11[4]; GLfloat a, b; GLbitfield useBorderColor = 0x0; @@ -2147,24 +2203,24 @@ sample_linear_rect(GLcontext *ctx, /* get four texel samples */ if (useBorderColor & (I0BIT | J0BIT)) - COPY_CHAN4(t00, tObj->_BorderChan); + get_border_color(tObj, img, t00); else - img->FetchTexelc(img, i0, j0, 0, t00); + img->FetchTexelf(img, i0, j0, 0, t00); if (useBorderColor & (I1BIT | J0BIT)) - COPY_CHAN4(t10, tObj->_BorderChan); + get_border_color(tObj, img, t10); else - img->FetchTexelc(img, i1, j0, 0, t10); + img->FetchTexelf(img, i1, j0, 0, t10); if (useBorderColor & (I0BIT | J1BIT)) - COPY_CHAN4(t01, tObj->_BorderChan); + get_border_color(tObj, img, t01); else - img->FetchTexelc(img, i0, j1, 0, t01); + img->FetchTexelf(img, i0, j1, 0, t01); if (useBorderColor & (I1BIT | J1BIT)) - COPY_CHAN4(t11, tObj->_BorderChan); + get_border_color(tObj, img, t11); else - img->FetchTexelc(img, i1, j1, 0, t11); + img->FetchTexelf(img, i1, j1, 0, t11); lerp_rgba_2d(rgba[i], a, b, t00, t10, t01, t11); } @@ -2176,7 +2232,7 @@ static void sample_lambda_rect(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4]) + GLfloat rgba[][4]) { GLuint minStart, minEnd, magStart, magEnd; @@ -2222,7 +2278,7 @@ sample_2d_array_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, const struct gl_texture_image *img, const GLfloat texcoord[4], - GLchan rgba[4]) + GLfloat rgba[4]) { const GLint width = img->Width2; /* without border, power of two */ const GLint height = img->Height2; /* without border, power of two */ @@ -2239,10 +2295,10 @@ sample_2d_array_nearest(GLcontext *ctx, j < 0 || j >= (GLint) img->Height || array < 0 || array >= (GLint) img->Depth) { /* Need this test for GL_CLAMP_TO_BORDER mode */ - COPY_CHAN4(rgba, tObj->_BorderChan); + get_border_color(tObj, img, rgba); } else { - img->FetchTexelc(img, i, j, array, rgba); + img->FetchTexelf(img, i, j, array, rgba); } } @@ -2255,7 +2311,7 @@ sample_2d_array_linear(GLcontext *ctx, const struct gl_texture_object *tObj, const struct gl_texture_image *img, const GLfloat texcoord[4], - GLchan rgba[4]) + GLfloat rgba[4]) { const GLint width = img->Width2; const GLint height = img->Height2; @@ -2264,14 +2320,14 @@ sample_2d_array_linear(GLcontext *ctx, GLint array; GLbitfield useBorderColor = 0x0; GLfloat a, b; - GLchan t00[4], t01[4], t10[4], t11[4]; + GLfloat t00[4], t01[4], t10[4], t11[4]; linear_texel_locations(tObj->WrapS, img, width, texcoord[0], &i0, &i1, &a); linear_texel_locations(tObj->WrapT, img, height, texcoord[1], &j0, &j1, &b); array = clamp_rect_coord_nearest(tObj->WrapR, texcoord[2], depth); if (array < 0 || array >= depth) { - COPY_CHAN4(rgba, tObj->_BorderChan); + COPY_4V(rgba, tObj->BorderColor); } else { if (img->Border) { @@ -2290,28 +2346,28 @@ sample_2d_array_linear(GLcontext *ctx, /* Fetch texels */ if (useBorderColor & (I0BIT | J0BIT)) { - COPY_CHAN4(t00, tObj->_BorderChan); + get_border_color(tObj, img, t00); } else { - img->FetchTexelc(img, i0, j0, array, t00); + img->FetchTexelf(img, i0, j0, array, t00); } if (useBorderColor & (I1BIT | J0BIT)) { - COPY_CHAN4(t10, tObj->_BorderChan); + get_border_color(tObj, img, t10); } else { - img->FetchTexelc(img, i1, j0, array, t10); + img->FetchTexelf(img, i1, j0, array, t10); } if (useBorderColor & (I0BIT | J1BIT)) { - COPY_CHAN4(t01, tObj->_BorderChan); + get_border_color(tObj, img, t01); } else { - img->FetchTexelc(img, i0, j1, array, t01); + img->FetchTexelf(img, i0, j1, array, t01); } if (useBorderColor & (I1BIT | J1BIT)) { - COPY_CHAN4(t11, tObj->_BorderChan); + get_border_color(tObj, img, t11); } else { - img->FetchTexelc(img, i1, j1, array, t11); + img->FetchTexelf(img, i1, j1, array, t11); } /* trilinear interpolation of samples */ @@ -2324,7 +2380,7 @@ static void sample_2d_array_nearest_mipmap_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; for (i = 0; i < n; i++) { @@ -2339,7 +2395,7 @@ static void sample_2d_array_linear_mipmap_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -2355,7 +2411,7 @@ static void sample_2d_array_nearest_mipmap_linear(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -2366,7 +2422,7 @@ sample_2d_array_nearest_mipmap_linear(GLcontext *ctx, texcoord[i], rgba[i]); } else { - GLchan t0[4], t1[4]; /* texels */ + GLfloat t0[4], t1[4]; /* texels */ const GLfloat f = FRAC(lambda[i]); sample_2d_array_nearest(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0); @@ -2382,7 +2438,7 @@ static void sample_2d_array_linear_mipmap_linear(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -2393,7 +2449,7 @@ sample_2d_array_linear_mipmap_linear(GLcontext *ctx, texcoord[i], rgba[i]); } else { - GLchan t0[4], t1[4]; /* texels */ + GLfloat t0[4], t1[4]; /* texels */ const GLfloat f = FRAC(lambda[i]); sample_2d_array_linear(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0); @@ -2410,7 +2466,7 @@ static void sample_nearest_2d_array(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4]) + GLfloat rgba[][4]) { GLuint i; struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel]; @@ -2427,7 +2483,7 @@ static void sample_linear_2d_array(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel]; @@ -2443,7 +2499,7 @@ static void sample_lambda_2d_array(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4]) + GLfloat rgba[][4]) { GLuint minStart, minEnd; /* texels with minification */ GLuint magStart, magEnd; /* texels with magnification */ @@ -2532,7 +2588,7 @@ sample_1d_array_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, const struct gl_texture_image *img, const GLfloat texcoord[4], - GLchan rgba[4]) + GLfloat rgba[4]) { const GLint width = img->Width2; /* without border, power of two */ const GLint height = img->Height; @@ -2546,10 +2602,10 @@ sample_1d_array_nearest(GLcontext *ctx, if (i < 0 || i >= (GLint) img->Width || array < 0 || array >= (GLint) img->Height) { /* Need this test for GL_CLAMP_TO_BORDER mode */ - COPY_CHAN4(rgba, tObj->_BorderChan); + get_border_color(tObj, img, rgba); } else { - img->FetchTexelc(img, i, array, 0, rgba); + img->FetchTexelf(img, i, array, 0, rgba); } } @@ -2562,7 +2618,7 @@ sample_1d_array_linear(GLcontext *ctx, const struct gl_texture_object *tObj, const struct gl_texture_image *img, const GLfloat texcoord[4], - GLchan rgba[4]) + GLfloat rgba[4]) { const GLint width = img->Width2; const GLint height = img->Height; @@ -2570,7 +2626,7 @@ sample_1d_array_linear(GLcontext *ctx, GLint array; GLbitfield useBorderColor = 0x0; GLfloat a; - GLchan t0[4], t1[4]; + GLfloat t0[4], t1[4]; linear_texel_locations(tObj->WrapS, img, width, texcoord[0], &i0, &i1, &a); array = clamp_rect_coord_nearest(tObj->WrapT, texcoord[1], height); @@ -2589,16 +2645,16 @@ sample_1d_array_linear(GLcontext *ctx, /* Fetch texels */ if (useBorderColor & (I0BIT | K0BIT)) { - COPY_CHAN4(t0, tObj->_BorderChan); + get_border_color(tObj, img, t0); } else { - img->FetchTexelc(img, i0, array, 0, t0); + img->FetchTexelf(img, i0, array, 0, t0); } if (useBorderColor & (I1BIT | K0BIT)) { - COPY_CHAN4(t1, tObj->_BorderChan); + get_border_color(tObj, img, t1); } else { - img->FetchTexelc(img, i1, array, 0, t1); + img->FetchTexelf(img, i1, array, 0, t1); } /* bilinear interpolation of samples */ @@ -2610,7 +2666,7 @@ static void sample_1d_array_nearest_mipmap_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; for (i = 0; i < n; i++) { @@ -2625,7 +2681,7 @@ static void sample_1d_array_linear_mipmap_nearest(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -2641,7 +2697,7 @@ static void sample_1d_array_nearest_mipmap_linear(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -2652,7 +2708,7 @@ sample_1d_array_nearest_mipmap_linear(GLcontext *ctx, texcoord[i], rgba[i]); } else { - GLchan t0[4], t1[4]; /* texels */ + GLfloat t0[4], t1[4]; /* texels */ const GLfloat f = FRAC(lambda[i]); sample_1d_array_nearest(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0); sample_1d_array_nearest(ctx, tObj, tObj->Image[0][level+1], texcoord[i], t1); @@ -2666,7 +2722,7 @@ static void sample_1d_array_linear_mipmap_linear(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoord[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; ASSERT(lambda != NULL); @@ -2677,7 +2733,7 @@ sample_1d_array_linear_mipmap_linear(GLcontext *ctx, texcoord[i], rgba[i]); } else { - GLchan t0[4], t1[4]; /* texels */ + GLfloat t0[4], t1[4]; /* texels */ const GLfloat f = FRAC(lambda[i]); sample_1d_array_linear(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0); sample_1d_array_linear(ctx, tObj, tObj->Image[0][level+1], texcoord[i], t1); @@ -2692,7 +2748,7 @@ static void sample_nearest_1d_array(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4]) + GLfloat rgba[][4]) { GLuint i; struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel]; @@ -2708,7 +2764,7 @@ static void sample_linear_1d_array(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], - const GLfloat lambda[], GLchan rgba[][4]) + const GLfloat lambda[], GLfloat rgba[][4]) { GLuint i; struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel]; @@ -2724,7 +2780,7 @@ static void sample_lambda_1d_array(GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4]) + GLfloat rgba[][4]) { GLuint minStart, minEnd; /* texels with minification */ GLuint magStart, magEnd; /* texels with magnification */ @@ -2796,13 +2852,109 @@ sample_lambda_1d_array(GLcontext *ctx, /** + * Compare texcoord against depth sample. Return 1.0 or the ambient value. + */ +static INLINE GLfloat +shadow_compare(GLenum function, GLfloat coord, GLfloat depthSample, + GLfloat ambient) +{ + switch (function) { + case GL_LEQUAL: + return (coord <= depthSample) ? 1.0F : ambient; + case GL_GEQUAL: + return (coord >= depthSample) ? 1.0F : ambient; + case GL_LESS: + return (coord < depthSample) ? 1.0F : ambient; + case GL_GREATER: + return (coord > depthSample) ? 1.0F : ambient; + case GL_EQUAL: + return (coord == depthSample) ? 1.0F : ambient; + case GL_NOTEQUAL: + return (coord != depthSample) ? 1.0F : ambient; + case GL_ALWAYS: + return 1.0F; + case GL_NEVER: + return ambient; + case GL_NONE: + return depthSample; + default: + _mesa_problem(NULL, "Bad compare func in shadow_compare"); + return ambient; + } +} + + +/** + * Compare texcoord against four depth samples. + */ +static INLINE GLfloat +shadow_compare4(GLenum function, GLfloat coord, + GLfloat depth00, GLfloat depth01, + GLfloat depth10, GLfloat depth11, + GLfloat ambient, GLfloat wi, GLfloat wj) +{ + const GLfloat d = (1.0F - (GLfloat) ambient) * 0.25F; + GLfloat luminance = 1.0F; + + switch (function) { + case GL_LEQUAL: + if (depth00 <= coord) luminance -= d; + if (depth01 <= coord) luminance -= d; + if (depth10 <= coord) luminance -= d; + if (depth11 <= coord) luminance -= d; + return luminance; + case GL_GEQUAL: + if (depth00 >= coord) luminance -= d; + if (depth01 >= coord) luminance -= d; + if (depth10 >= coord) luminance -= d; + if (depth11 >= coord) luminance -= d; + return luminance; + case GL_LESS: + if (depth00 < coord) luminance -= d; + if (depth01 < coord) luminance -= d; + if (depth10 < coord) luminance -= d; + if (depth11 < coord) luminance -= d; + return luminance; + case GL_GREATER: + if (depth00 > coord) luminance -= d; + if (depth01 > coord) luminance -= d; + if (depth10 > coord) luminance -= d; + if (depth11 > coord) luminance -= d; + return luminance; + case GL_EQUAL: + if (depth00 == coord) luminance -= d; + if (depth01 == coord) luminance -= d; + if (depth10 == coord) luminance -= d; + if (depth11 == coord) luminance -= d; + return luminance; + case GL_NOTEQUAL: + if (depth00 != coord) luminance -= d; + if (depth01 != coord) luminance -= d; + if (depth10 != coord) luminance -= d; + if (depth11 != coord) luminance -= d; + return luminance; + case GL_ALWAYS: + return 0.0; + case GL_NEVER: + return ambient; + case GL_NONE: + /* ordinary bilinear filtering */ + return lerp_2d(wi, wj, depth00, depth10, depth01, depth11); + default: + _mesa_problem(NULL, "Bad compare func in sample_depth_texture"); + return 0.0F; + } +} + + +/** * Sample a shadow/depth texture. */ static void sample_depth_texture( GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan texel[][4] ) + GLfloat texel[][4] ) { const GLint baseLevel = tObj->BaseLevel; const struct gl_texture_image *img = tObj->Image[0][baseLevel]; @@ -2811,9 +2963,9 @@ sample_depth_texture( GLcontext *ctx, const GLint depth = img->Depth; const GLuint compare_coord = (tObj->Target == GL_TEXTURE_2D_ARRAY_EXT) ? 3 : 2; - GLchan ambient; + GLfloat ambient; GLenum function; - GLchan result; + GLfloat result; (void) lambda; @@ -2826,7 +2978,7 @@ sample_depth_texture( GLcontext *ctx, tObj->Target == GL_TEXTURE_1D_ARRAY_EXT || tObj->Target == GL_TEXTURE_2D_ARRAY_EXT); - UNCLAMPED_FLOAT_TO_CHAN(ambient, tObj->CompareFailValue); + ambient = tObj->CompareFailValue; /* XXXX if tObj->MinFilter != tObj->MagFilter, we're ignoring lambda */ @@ -2839,45 +2991,7 @@ sample_depth_texture( GLcontext *ctx, GLfloat depthSample; GLint col, row, slice; - switch (tObj->Target) { - case GL_TEXTURE_RECTANGLE_ARB: - col = clamp_rect_coord_nearest(tObj->WrapS, texcoords[i][0], width); - row = clamp_rect_coord_nearest(tObj->WrapT, texcoords[i][1], height); - slice = 0; - break; - - case GL_TEXTURE_1D: - col = nearest_texel_location(tObj->WrapS, img, width, - texcoords[i][0]); - row = 0; - slice = 0; - break; - - case GL_TEXTURE_2D: - col = nearest_texel_location(tObj->WrapS, img, width, - texcoords[i][0]); - row = nearest_texel_location(tObj->WrapT, img, height, - texcoords[i][1]); - slice = 0; - break; - - case GL_TEXTURE_1D_ARRAY_EXT: - col = nearest_texel_location(tObj->WrapS, img, width, - texcoords[i][0]); - row = clamp_rect_coord_nearest(tObj->WrapT, texcoords[i][1], height); - slice = 0; - break; - - case GL_TEXTURE_2D_ARRAY_EXT: - col = nearest_texel_location(tObj->WrapS, img, width, - texcoords[i][0]); - row = nearest_texel_location(tObj->WrapT, img, height, - texcoords[i][1]); - slice = clamp_rect_coord_nearest(tObj->WrapR, texcoords[i][2], depth); - break; - default: - col = row = slice = 0; - } + nearest_texcoord(tObj, texcoords[i], &col, &row, &slice); if (col >= 0 && row >= 0 && col < width && row < height && slice >= 0 && slice < depth) { @@ -2887,57 +3001,18 @@ sample_depth_texture( GLcontext *ctx, depthSample = tObj->BorderColor[0]; } - switch (function) { - case GL_LEQUAL: - result = (texcoords[i][compare_coord] <= depthSample) ? CHAN_MAX : ambient; - break; - case GL_GEQUAL: - result = (texcoords[i][compare_coord] >= depthSample) ? CHAN_MAX : ambient; - break; - case GL_LESS: - result = (texcoords[i][compare_coord] < depthSample) ? CHAN_MAX : ambient; - break; - case GL_GREATER: - result = (texcoords[i][compare_coord] > depthSample) ? CHAN_MAX : ambient; - break; - case GL_EQUAL: - result = (texcoords[i][compare_coord] == depthSample) ? CHAN_MAX : ambient; - break; - case GL_NOTEQUAL: - result = (texcoords[i][compare_coord] != depthSample) ? CHAN_MAX : ambient; - break; - case GL_ALWAYS: - result = CHAN_MAX; - break; - case GL_NEVER: - result = ambient; - break; - case GL_NONE: - CLAMPED_FLOAT_TO_CHAN(result, depthSample); - break; - default: - _mesa_problem(ctx, "Bad compare func in sample_depth_texture"); - return; - } + result = shadow_compare(function, texcoords[i][compare_coord], + depthSample, ambient); switch (tObj->DepthMode) { case GL_LUMINANCE: - texel[i][RCOMP] = result; - texel[i][GCOMP] = result; - texel[i][BCOMP] = result; - texel[i][ACOMP] = CHAN_MAX; + ASSIGN_4V(texel[i], result, result, result, 1.0F); break; case GL_INTENSITY: - texel[i][RCOMP] = result; - texel[i][GCOMP] = result; - texel[i][BCOMP] = result; - texel[i][ACOMP] = result; + ASSIGN_4V(texel[i], result, result, result, result); break; case GL_ALPHA: - texel[i][RCOMP] = 0; - texel[i][GCOMP] = 0; - texel[i][BCOMP] = 0; - texel[i][ACOMP] = result; + ASSIGN_4V(texel[i], 0.0F, 0.0F, 0.0F, result); break; default: _mesa_problem(ctx, "Bad depth texture mode"); @@ -2951,45 +3026,11 @@ sample_depth_texture( GLcontext *ctx, GLfloat depth00, depth01, depth10, depth11; GLint i0, i1, j0, j1; GLint slice; - GLfloat a, b; + GLfloat wi, wj; GLuint useBorderTexel; - switch (tObj->Target) { - case GL_TEXTURE_RECTANGLE_ARB: - clamp_rect_coord_linear(tObj->WrapS, texcoords[i][0], - width, &i0, &i1, &a); - clamp_rect_coord_linear(tObj->WrapT, texcoords[i][1], - height, &j0, &j1, &b); - slice = 0; - break; - - case GL_TEXTURE_1D: - case GL_TEXTURE_2D: - linear_texel_locations(tObj->WrapS, img, width, - texcoords[i][0], &i0, &i1, &a); - linear_texel_locations(tObj->WrapT, img, height, - texcoords[i][1], &j0, &j1, &b); - slice = 0; - break; - - case GL_TEXTURE_1D_ARRAY_EXT: - linear_texel_locations(tObj->WrapS, img, width, - texcoords[i][0], &i0, &i1, &a); - j0 = clamp_rect_coord_nearest(tObj->WrapT, texcoords[i][1], height); - j1 = j0; - slice = 0; - break; - - case GL_TEXTURE_2D_ARRAY_EXT: - linear_texel_locations(tObj->WrapS, img, width, - texcoords[i][0], &i0, &i1, &a); - linear_texel_locations(tObj->WrapT, img, height, - texcoords[i][1], &j0, &j1, &b); - slice = clamp_rect_coord_nearest(tObj->WrapR, texcoords[i][2], depth); - break; - default: - slice = 0; - } + linear_texcoord(tObj, texcoords[i], &i0, &i1, &j0, &j1, &slice, + &wi, &wj); useBorderTexel = 0; if (img->Border) { @@ -3048,111 +3089,24 @@ sample_depth_texture( GLcontext *ctx, } } - if (0) { - /* compute a single weighted depth sample and do one comparison */ - const GLfloat depthSample - = lerp_2d(a, b, depth00, depth10, depth01, depth11); - if ((depthSample <= texcoords[i][compare_coord] && function == GL_LEQUAL) || - (depthSample >= texcoords[i][compare_coord] && function == GL_GEQUAL)) { - result = ambient; - } - else { - result = CHAN_MAX; - } - } - else { - /* Do four depth/R comparisons and compute a weighted result. - * If this touches on somebody's I.P., I'll remove this code - * upon request. - */ - const GLfloat d = (CHAN_MAXF - (GLfloat) ambient) * 0.25F; - GLfloat luminance = CHAN_MAXF; - - switch (function) { - case GL_LEQUAL: - if (depth00 <= texcoords[i][compare_coord]) luminance -= d; - if (depth01 <= texcoords[i][compare_coord]) luminance -= d; - if (depth10 <= texcoords[i][compare_coord]) luminance -= d; - if (depth11 <= texcoords[i][compare_coord]) luminance -= d; - result = (GLchan) luminance; - break; - case GL_GEQUAL: - if (depth00 >= texcoords[i][compare_coord]) luminance -= d; - if (depth01 >= texcoords[i][compare_coord]) luminance -= d; - if (depth10 >= texcoords[i][compare_coord]) luminance -= d; - if (depth11 >= texcoords[i][compare_coord]) luminance -= d; - result = (GLchan) luminance; - break; - case GL_LESS: - if (depth00 < texcoords[i][compare_coord]) luminance -= d; - if (depth01 < texcoords[i][compare_coord]) luminance -= d; - if (depth10 < texcoords[i][compare_coord]) luminance -= d; - if (depth11 < texcoords[i][compare_coord]) luminance -= d; - result = (GLchan) luminance; - break; - case GL_GREATER: - if (depth00 > texcoords[i][compare_coord]) luminance -= d; - if (depth01 > texcoords[i][compare_coord]) luminance -= d; - if (depth10 > texcoords[i][compare_coord]) luminance -= d; - if (depth11 > texcoords[i][compare_coord]) luminance -= d; - result = (GLchan) luminance; - break; - case GL_EQUAL: - if (depth00 == texcoords[i][compare_coord]) luminance -= d; - if (depth01 == texcoords[i][compare_coord]) luminance -= d; - if (depth10 == texcoords[i][compare_coord]) luminance -= d; - if (depth11 == texcoords[i][compare_coord]) luminance -= d; - result = (GLchan) luminance; - break; - case GL_NOTEQUAL: - if (depth00 != texcoords[i][compare_coord]) luminance -= d; - if (depth01 != texcoords[i][compare_coord]) luminance -= d; - if (depth10 != texcoords[i][compare_coord]) luminance -= d; - if (depth11 != texcoords[i][compare_coord]) luminance -= d; - result = (GLchan) luminance; - break; - case GL_ALWAYS: - result = 0; - break; - case GL_NEVER: - result = CHAN_MAX; - break; - case GL_NONE: - /* ordinary bilinear filtering */ - { - const GLfloat depthSample - = lerp_2d(a, b, depth00, depth10, depth01, depth11); - CLAMPED_FLOAT_TO_CHAN(result, depthSample); - } - break; - default: - _mesa_problem(ctx, "Bad compare func in sample_depth_texture"); - return; - } - } + result = shadow_compare4(function, texcoords[i][compare_coord], + depth00, depth01, depth10, depth11, + ambient, wi, wj); switch (tObj->DepthMode) { case GL_LUMINANCE: - texel[i][RCOMP] = result; - texel[i][GCOMP] = result; - texel[i][BCOMP] = result; - texel[i][ACOMP] = CHAN_MAX; + ASSIGN_4V(texel[i], result, result, result, 1.0F); break; case GL_INTENSITY: - texel[i][RCOMP] = result; - texel[i][GCOMP] = result; - texel[i][BCOMP] = result; - texel[i][ACOMP] = result; + ASSIGN_4V(texel[i], result, result, result, result); break; case GL_ALPHA: - texel[i][RCOMP] = 0; - texel[i][GCOMP] = 0; - texel[i][BCOMP] = 0; - texel[i][ACOMP] = result; + ASSIGN_4V(texel[i], 0.0F, 0.0F, 0.0F, result); break; default: _mesa_problem(ctx, "Bad depth texture mode"); } + } /* for */ } /* if filter */ } @@ -3168,7 +3122,7 @@ static void null_sample_func( GLcontext *ctx, const struct gl_texture_object *tObj, GLuint n, const GLfloat texcoords[][4], const GLfloat lambda[], - GLchan rgba[][4]) + GLfloat rgba[][4]) { GLuint i; (void) ctx; @@ -3225,6 +3179,7 @@ _swrast_choose_texture_sample_func( GLcontext *ctx, } else { /* check for a few optimized cases */ +#if 0 const struct gl_texture_image *img = t->Image[0][t->BaseLevel]; ASSERT(t->MinFilter == GL_NEAREST); if (t->WrapS == GL_REPEAT && @@ -3241,6 +3196,10 @@ _swrast_choose_texture_sample_func( GLcontext *ctx, img->TexFormat->MesaFormat == MESA_FORMAT_RGBA) { return &opt_sample_rgba_2d; } +#else + if (0) + ; +#endif else { return &sample_nearest_2d; } |