summaryrefslogtreecommitdiffstats
path: root/src/mesa/swrast/s_fragprog.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2009-01-28 10:31:05 -0700
committerBrian Paul <[email protected]>2009-01-28 10:31:05 -0700
commit54c62ba5c36f3e2b279151f5df851d2ceee15319 (patch)
tree8ecbcfc4b129957f263e22aaacf48c2936b65757 /src/mesa/swrast/s_fragprog.c
parent4a89e51c5f88b57040b361b62e80a57c8248ba4b (diff)
mesa: implement texture swizzling in swrast
And enable GL_EXT_texture_swizzle for software drivers.
Diffstat (limited to 'src/mesa/swrast/s_fragprog.c')
-rw-r--r--src/mesa/swrast/s_fragprog.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c
index 45ba91ff86d..58ef91ec010 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()
*/
@@ -52,10 +81,7 @@ fetch_texel_lod( GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda,
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]);
+ swizzle_texel(rgba, color, texObj->_Swizzle);
}
else {
color[0] = color[1] = color[2] = color[3] = 0.0F;
@@ -97,10 +123,7 @@ fetch_texel_deriv( GLcontext *ctx, const GLfloat texcoord[4],
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]);
+ swizzle_texel(rgba, color, texObj->_Swizzle);
}
else {
color[0] = color[1] = color[2] = color[3] = 0.0F;