diff options
author | Keith Whitwell <keithw@vmware.com> | 2009-02-16 19:50:48 +0000 |
---|---|---|
committer | Keith Whitwell <keithw@vmware.com> | 2009-02-16 19:50:48 +0000 |
commit | 59d54334c96f44ed1d8bf660dc96221362a77d04 (patch) | |
tree | e9ab34e568256bcdc2a88602c47072ab769211e8 /src/mesa/swrast/s_fragprog.c | |
parent | 7c8836e9ef49d938aa55a1c385b95c6371c301f1 (diff) | |
parent | c5c383596ddb26cd75e4b355918ad16915283b59 (diff) |
Merge branch 'master' into gallium-texture-transfer
Conflicts:
src/mesa/state_tracker/st_cb_accum.c
src/mesa/state_tracker/st_cb_drawpixels.c
Diffstat (limited to 'src/mesa/swrast/s_fragprog.c')
-rw-r--r-- | src/mesa/swrast/s_fragprog.c | 75 |
1 files changed, 55 insertions, 20 deletions
diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index 525cf9d724..c6601f5593 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -33,6 +33,35 @@ /** + * Apply texture object's swizzle (X/Y/Z/W/0/1) to incoming 'texel' + * and return results in 'colorOut'. + */ +static INLINE void +swizzle_texel(const GLchan 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]); + } + 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_ZERO] = 0.0F; + vector[SWIZZLE_ONE] = 1.0F; + colorOut[0] = vector[GET_SWZ(swizzle, 0)]; + colorOut[1] = vector[GET_SWZ(swizzle, 1)]; + colorOut[2] = vector[GET_SWZ(swizzle, 2)]; + colorOut[3] = vector[GET_SWZ(swizzle, 3)]; + } +} + + +/** * Fetch a texel with given lod. * Called via machine->FetchTexelLod() */ @@ -40,20 +69,23 @@ static void fetch_texel_lod( GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda, GLuint unit, GLfloat color[4] ) { - GLchan rgba[4]; - SWcontext *swrast = SWRAST_CONTEXT(ctx); const struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current; - if (texObj) + if (texObj) { + SWcontext *swrast = SWRAST_CONTEXT(ctx); + GLchan 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); - 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]); + /* XXX use a float-valued TextureSample routine here!!! */ + swrast->TextureSample[unit](ctx, texObj, 1, + (const GLfloat (*)[4]) texcoord, + &lambda, &rgba); + swizzle_texel(rgba, color, texObj->_Swizzle); + } + else { + ASSIGN_4V(color, 0.0F, 0.0F, 0.0F, 1.0F); + } } @@ -69,13 +101,14 @@ fetch_texel_deriv( GLcontext *ctx, const GLfloat texcoord[4], { SWcontext *swrast = SWRAST_CONTEXT(ctx); const struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current; - GLfloat lambda; - GLchan rgba[4]; if (texObj) { - const struct gl_texture_image *texImg = texObj->Image[0][texObj->BaseLevel]; + const struct gl_texture_image *texImg = + texObj->Image[0][texObj->BaseLevel]; const GLfloat texW = (GLfloat) texImg->WidthScale; const GLfloat texH = (GLfloat) texImg->HeightScale; + GLfloat lambda; + GLchan rgba[4]; lambda = _swrast_compute_lambda(texdx[0], texdy[0], /* ds/dx, ds/dy */ texdx[1], texdy[1], /* dt/dx, dt/dy */ @@ -85,14 +118,16 @@ fetch_texel_deriv( GLcontext *ctx, const GLfloat texcoord[4], 1.0F / texcoord[3]) + lodBias; lambda = CLAMP(lambda, texObj->MinLod, texObj->MaxLod); - } - swrast->TextureSample[unit](ctx, texObj, 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]); + /* XXX use a float-valued TextureSample routine here!!! */ + swrast->TextureSample[unit](ctx, texObj, 1, + (const GLfloat (*)[4]) texcoord, + &lambda, &rgba); + swizzle_texel(rgba, color, texObj->_Swizzle); + } + else { + ASSIGN_4V(color, 0.0F, 0.0F, 0.0F, 1.0F); + } } |