X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fswrast%2Fs_texcombine.c;h=889164b986132e798d2bb902701b6237394e713a;hb=19119517ce00f7710c6cd627c75e7eef765021c2;hp=550c99b7d23bfacde8137bff7a4fafcb8236bb01;hpb=aef2e1c1dcda77b6dc5fcfd2de7c9d720effa4e7;p=mesa.git diff --git a/src/mesa/swrast/s_texcombine.c b/src/mesa/swrast/s_texcombine.c index 550c99b7d23..889164b9861 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" @@ -48,10 +47,9 @@ typedef float (*float4_array)[4]; * Return array of texels for given unit. */ static INLINE float4_array -get_texel_array(const GLfloat *texelBuffer, GLuint unit, GLuint numTexels) +get_texel_array(SWcontext *swrast, GLuint unit) { - return (float4_array) - (texelBuffer + unit * numTexels * 4 * sizeof(GLfloat)); + return (float4_array) (swrast->TexelBuffer + unit * MAX_WIDTH * 4); } @@ -75,11 +73,12 @@ get_texel_array(const GLfloat *texelBuffer, GLuint unit, GLuint numTexels) * \param rgba incoming/result fragment colors */ static void -texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, +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 struct gl_tex_env_combine_state *combine = textureUnit->_CurrentCombine; float4_array argRGB[MAX_COMBINER_TERMS]; @@ -92,8 +91,6 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, GLfloat rgba[MAX_WIDTH][4]; GLuint i, term; - ASSERT(CONST_SWRAST_CONTEXT(ctx)->_AnyTextureCombine); - for (i = 0; i < n; i++) { rgba[i][RCOMP] = CHAN_TO_FLOAT(rgbaChan[i][RCOMP]); rgba[i][GCOMP] = CHAN_TO_FLOAT(rgbaChan[i][GCOMP]); @@ -120,7 +117,7 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, switch (srcRGB) { case GL_TEXTURE: - argRGB[term] = get_texel_array(texelBuffer, unit, n); + argRGB[term] = get_texel_array(swrast, unit); break; case GL_PRIMARY_COLOR: argRGB[term] = primary_rgba; @@ -168,7 +165,7 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, ASSERT(srcUnit < ctx->Const.MaxTextureUnits); if (!ctx->Texture.Unit[srcUnit]._ReallyEnabled) return; - argRGB[term] = get_texel_array(texelBuffer, srcUnit, n); + argRGB[term] = get_texel_array(swrast, srcUnit); } } @@ -216,7 +213,7 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, switch (srcA) { case GL_TEXTURE: - argA[term] = get_texel_array(texelBuffer, unit, n); + argA[term] = get_texel_array(swrast, unit); break; case GL_PRIMARY_COLOR: argA[term] = primary_rgba; @@ -258,7 +255,7 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, ASSERT(srcUnit < ctx->Const.MaxTextureUnits); if (!ctx->Texture.Unit[srcUnit]._ReallyEnabled) return; - argA[term] = get_texel_array(texelBuffer, srcUnit, n); + argA[term] = get_texel_array(swrast, srcUnit); } } @@ -319,12 +316,12 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, if (textureUnit->EnvMode == GL_COMBINE4_NV) { /* (a * b) + (c * d) - 0.5 */ for (i = 0; i < n; i++) { - 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; + 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 { @@ -407,22 +404,13 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, } 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; -#else - rgba[i][RCOMP] = 0; - rgba[i][GCOMP] = 0; - rgba[i][BCOMP] = 0; - rgba[i][ACOMP] = CHAN_MAX; -#endif - } + rgba[i][RCOMP] = 0.0; + rgba[i][GCOMP] = 0.0; + rgba[i][BCOMP] = 0.0; + rgba[i][ACOMP] = 1.0; } return; /* no alpha processing */ default: @@ -535,7 +523,6 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, } - /** * Apply X/Y/Z/W/0/1 swizzle to an array of colors/texels. * See GL_EXT_texture_swizzle. @@ -566,385 +553,6 @@ swizzle_texels(GLuint swizzle, GLuint count, float4_array texels) } -/** - * 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, - float4_array primary_rgba, - float4_array texel, - GLchan rgbaChan[][4] ) -{ - GLint baseLevel; - GLuint i; - GLfloat Rc, Gc, Bc, Ac; - GLenum format; - GLfloat rgba[MAX_WIDTH][4]; - - (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; - } - - if (texUnit->EnvMode != GL_REPLACE) { - /* convert GLchan colors to GLfloat */ - 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]); - } - } - - switch (texUnit->EnvMode) { - case GL_REPLACE: - switch (format) { - case GL_ALPHA: - for (i=0;iEnvColor[0]; - Gc = texUnit->EnvColor[1]; - Bc = texUnit->EnvColor[2]; - Ac = texUnit->EnvColor[3]; - switch (format) { - case GL_ALPHA: - for (i=0;i_AnyTextureCombine) { + if (swrast->_TextureCombinePrimary) { GLuint i; for (i = 0; i < span->end; i++) { primary_rgba[i][RCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][RCOMP]); @@ -972,26 +580,19 @@ _swrast_texture_span( GLcontext *ctx, SWspan *span ) /* 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]; -#if 0 - GLchan (*texels)[4] = (GLchan (*)[4]) - (swrast->TexelBuffer + unit * (span->end * 4 * sizeof(GLchan))); -#else - float4_array texels = get_texel_array(swrast->TexelBuffer, unit, - span->end); -#endif + 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]; @@ -1031,19 +632,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 } } } @@ -1053,15 +645,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 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]; - float4_array texels = - get_texel_array(swrast->TexelBuffer, unit, span->end); + float4_array texels = get_texel_array(swrast, unit); /* adjust texture lod (lambda) */ if (span->arrayMask & SPAN_LAMBDA) { @@ -1104,28 +695,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, - primary_rgba, - swrast->TexelBuffer, - span->array->rgba ); - } - else { - /* conventional texture blend */ - float4_array texels = - get_texel_array(swrast->TexelBuffer, unit, span->end); - texture_apply( ctx, texUnit, span->end, - primary_rgba, texels, - span->array->rgba ); - } + texture_combine( ctx, unit, span->end, + primary_rgba, + swrast->TexelBuffer, + span->array->rgba ); } } }