From 54c62ba5c36f3e2b279151f5df851d2ceee15319 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 28 Jan 2009 10:31:05 -0700 Subject: mesa: implement texture swizzling in swrast And enable GL_EXT_texture_swizzle for software drivers. --- src/mesa/swrast/s_texcombine.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/mesa/swrast/s_texcombine.c') diff --git a/src/mesa/swrast/s_texcombine.c b/src/mesa/swrast/s_texcombine.c index df6efad66c..1b8775bf30 100644 --- a/src/mesa/swrast/s_texcombine.c +++ b/src/mesa/swrast/s_texcombine.c @@ -31,6 +31,7 @@ #include "main/imports.h" #include "main/macros.h" #include "main/pixel.h" +#include "shader/prog_instruction.h" #include "s_context.h" #include "s_texcombine.h" @@ -815,6 +816,36 @@ texture_combine( const GLcontext *ctx, GLuint unit, GLuint n, #undef PROD +/** + * Apply X/Y/Z/W/0/1 swizzle to an array of colors/texels. + * See GL_EXT_texture_swizzle. + */ +static void +swizzle_texels(GLuint swizzle, GLuint count, GLchan (*texels)[4]) +{ + 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]; + GLuint i; + + vector[SWIZZLE_ZERO] = 0; + vector[SWIZZLE_ONE] = CHAN_MAX; + + for (i = 0; i < count; i++) { + vector[SWIZZLE_X] = texels[i][0]; + vector[SWIZZLE_Y] = texels[i][1]; + vector[SWIZZLE_Z] = texels[i][2]; + vector[SWIZZLE_W] = texels[i][3]; + texels[i][RCOMP] = vector[swzR]; + texels[i][GCOMP] = vector[swzG]; + texels[i][BCOMP] = vector[swzB]; + texels[i][ACOMP] = vector[swzA]; + } +} + + /** * Apply a conventional OpenGL texture env mode (REPLACE, ADD, BLEND, * MODULATE, or DECAL) to an array of fragments. @@ -1241,9 +1272,15 @@ _swrast_texture_span( GLcontext *ctx, SWspan *span ) _mesa_lookup_rgba_float(&texUnit->ColorTable, span->end, texels); #endif } + + /* GL_EXT_texture_swizzle */ + if (curObj->_Swizzle != SWIZZLE_NOOP) { + swizzle_texels(curObj->_Swizzle, span->end, texels); + } } } + /* * OK, now apply the texture (aka texture combine/blend). * We modify the span->color.rgba values. @@ -1262,6 +1299,8 @@ _swrast_texture_span( GLcontext *ctx, SWspan *span ) 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 ); -- cgit v1.2.3