X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fswrast%2Fs_texcombine.c;h=def5eb19e00bc0a2f291dc93149b8d65efe10121;hb=c472793a2a55bb529bf4297f04ff785ce52cfc6e;hp=df3a74a06adee0c0563fbaa2d3593660bf279bb4;hpb=5e78433eec94fcaa87bdcb2526ec0910a69ed347;p=mesa.git diff --git a/src/mesa/swrast/s_texcombine.c b/src/mesa/swrast/s_texcombine.c index df3a74a06ad..def5eb19e00 100644 --- a/src/mesa/swrast/s_texcombine.c +++ b/src/mesa/swrast/s_texcombine.c @@ -1,6 +1,5 @@ /* * Mesa 3-D graphics library - * Version: 7.5 * * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. * Copyright (C) 2009 VMware, Inc. All Rights Reserved. @@ -190,7 +189,7 @@ texture_combine( struct gl_context *ctx, GLuint unit, { const GLuint srcUnit = srcRGB - GL_TEXTURE0; ASSERT(srcUnit < ctx->Const.MaxTextureUnits); - if (!ctx->Texture.Unit[srcUnit]._ReallyEnabled) + if (!ctx->Texture.Unit[srcUnit]._Current) goto end; argRGB[term] = get_texel_array(swrast, srcUnit); } @@ -280,7 +279,7 @@ texture_combine( struct gl_context *ctx, GLuint unit, { const GLuint srcUnit = srcA - GL_TEXTURE0; ASSERT(srcUnit < ctx->Const.MaxTextureUnits); - if (!ctx->Texture.Unit[srcUnit]._ReallyEnabled) + if (!ctx->Texture.Unit[srcUnit]._Current) goto end; argA[term] = get_texel_array(swrast, srcUnit); } @@ -430,16 +429,6 @@ texture_combine( struct gl_context *ctx, GLuint unit, 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++) { - /* rgba result is 0,0,0,1 */ - rgba[i][RCOMP] = 0.0; - rgba[i][GCOMP] = 0.0; - rgba[i][BCOMP] = 0.0; - rgba[i][ACOMP] = 1.0; - } - goto end; /* no alpha processing */ default: _mesa_problem(ctx, "invalid combine mode"); } @@ -603,6 +592,14 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span ) if (!swrast->TexelBuffer) { #ifdef _OPENMP const GLint maxThreads = omp_get_max_threads(); + + /* TexelBuffer memory allocation needs to be done in a critical section + * as this code runs in a parallel loop. + * When entering the section, first check if TexelBuffer has been + * initialized already by another thread while this thread was waiting. + */ + #pragma omp critical + if (!swrast->TexelBuffer) { #else const GLint maxThreads = 1; #endif @@ -612,8 +609,12 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span ) * thread. */ swrast->TexelBuffer = - malloc(ctx->Const.FragmentProgram.MaxTextureImageUnits * maxThreads * + malloc(ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits * maxThreads * SWRAST_MAX_WIDTH * 4 * sizeof(GLfloat)); +#ifdef _OPENMP + } /* critical section */ +#endif + if (!swrast->TexelBuffer) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture_combine"); return; @@ -642,78 +643,13 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span ) } } - /* First must sample all bump maps */ - for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { - 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[VARYING_SLOT_TEX0 + unit]; - float4_array targetcoords = - span->array->attribs[VARYING_SLOT_TEX0 + - ctx->Texture.Unit[unit].BumpTarget - GL_TEXTURE0]; - - const struct gl_sampler_object *samp = _mesa_get_samplerobj(ctx, unit); - GLfloat *lambda = span->array->lambda[unit]; - 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]; - GLfloat rotMatrix10 = ctx->Texture.Unit[unit].RotMatrix[2]; - GLfloat rotMatrix11 = ctx->Texture.Unit[unit].RotMatrix[3]; - - /* adjust texture lod (lambda) */ - if (span->arrayMask & SPAN_LAMBDA) { - if (texUnit->LodBias + samp->LodBias != 0.0F) { - /* apply LOD bias, but don't clamp yet */ - const GLfloat bias = CLAMP(texUnit->LodBias + samp->LodBias, - -ctx->Const.MaxTextureLodBias, - ctx->Const.MaxTextureLodBias); - GLuint i; - for (i = 0; i < span->end; i++) { - lambda[i] += bias; - } - } - - if (samp->MinLod != -1000.0 || - samp->MaxLod != 1000.0) { - /* apply LOD clamping to lambda */ - const GLfloat min = samp->MinLod; - const GLfloat max = samp->MaxLod; - GLuint i; - for (i = 0; i < span->end; i++) { - GLfloat l = lambda[i]; - lambda[i] = CLAMP(l, min, max); - } - } - } - - /* Sample the texture (span->end = number of fragments) */ - swrast->TextureSample[unit]( ctx, samp, - ctx->Texture.Unit[unit]._Current, - span->end, texcoords, lambda, texels ); - - /* manipulate the span values of the bump target - not sure this can work correctly even ignoring - the problem that channel is unsigned */ - for (i = 0; i < span->end; i++) { - 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]; - } - } - } - /* * Must do all texture sampling before combining in order to * accomodate GL_ARB_texture_env_crossbar. */ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; - if (texUnit->_ReallyEnabled && - texUnit->_CurrentCombine->ModeRGB != GL_BUMP_ENVMAP_ATI) { + if (texUnit->_Current) { const GLfloat (*texcoords)[4] = (const GLfloat (*)[4]) span->array->attribs[VARYING_SLOT_TEX0 + unit]; const struct gl_texture_object *curObj = texUnit->_Current; @@ -776,7 +712,7 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span ) * We modify the span->color.rgba values. */ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { - if (ctx->Texture.Unit[unit]._ReallyEnabled) + if (ctx->Texture.Unit[unit]._Current) texture_combine(ctx, unit, primary_rgba, swrast->TexelBuffer, span); }