Refactor "classic" texture environments to be implemented in terms of
authorIan Romanick <idr@us.ibm.com>
Fri, 7 May 2004 00:33:12 +0000 (00:33 +0000)
committerIan Romanick <idr@us.ibm.com>
Fri, 7 May 2004 00:33:12 +0000 (00:33 +0000)
ARB_texture_env_combine state.  Add support for
ARB_texture_env_crossbar.  Combiner state is only emitted for operands
that need to be emitted for the combine operation.

src/mesa/drivers/dri/i830/i830_context.c
src/mesa/drivers/dri/i830/i830_texstate.c

index 7f306f2110f915586cebb632f501f05692774125..97a9f793fc2c61c0b9dfe121cda482b759fe9d3a 100644 (file)
  * **************************************************************************/
 /* $XFree86: xc/lib/GL/mesa/src/drv/i830/i830_context.c,v 1.9 2003/02/06 04:18:00 dawes Exp $ */
 
-/*
- * Authors:
- *   Jeff Hartmann <jhartmann@2d3d.com>
- *   Graeme Fisher <graeme@2d3d.co.za>
- *   Abraham vd Merwe <abraham@2d3d.co.za>
+/**
+ * \file i830_context.c
+ * 
+ * Heavily Based on I810 driver written by Keith Whitwell.
  *
- * Heavily Based on I810 driver written by:
- *   Keith Whitwell <keith@tungstengraphics.com>
+ * \author Jeff Hartmann <jhartmann@2d3d.com>
+ * \author Graeme Fisher <graeme@2d3d.co.za>
+ * \author Abraham vd Merwe <abraham@2d3d.co.za>
+ * \author Keith Whitwell <keith@tungstengraphics.com>
  */
 
 #include "glheader.h"
@@ -71,7 +72,7 @@ int I830_DEBUG = (0);
  * Mesa's Driver Functions
  ***************************************/
 
-#define DRIVER_DATE                     "20021115"
+#define DRIVER_DATE                     "20040506"
 
 
 const char __driConfigOptions[] = { 0 };
@@ -146,6 +147,7 @@ static const char * const card_extensions[] =
    "GL_ARB_texture_compression",
    "GL_ARB_texture_env_add",
    "GL_ARB_texture_env_combine",
+   "GL_ARB_texture_env_crossbar",
    "GL_ARB_texture_env_dot3",
    "GL_ARB_texture_mirrored_repeat",
    "GL_EXT_blend_color",
index 321670a3604c8defe1ae06725f554c73c8a282c8..e3d6819d88d6afbd42d8158054d89b93cdef0fb6 100644 (file)
@@ -27,12 +27,13 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 /* $XFree86: xc/lib/GL/mesa/src/drv/i830/i830_texstate.c,v 1.3 2002/12/10 01:26:53 dawes Exp $ */
 
-/*
- * Author:
- *   Jeff Hartmann <jhartmann@2d3d.com>
+/**
+ * \file i830_texstate.c
+ * 
+ * Heavily based on the I810 driver, which was written by Keith Whitwell.
  *
- * Heavily based on the I810 driver, which was written by:
- *   Keith Whitwell <keithw@tungstengraphics.com>
+ * \author Jeff Hartmann <jhartmann@2d3d.com>
+ * \author Keith Whitwell <keithw@tungstengraphics.com>
  */
 
 #include "glheader.h"
@@ -177,857 +178,70 @@ static void i830SetTexImages( i830ContextPtr imesa,
 /* ================================================================
  * Texture combine functions
  */
-static __inline__ GLuint GetTexelOp(GLint unit)
-{
-   switch(unit) {
-    case 0: return TEXBLENDARG_TEXEL0;
-    case 1: return TEXBLENDARG_TEXEL1;
-    case 2: return TEXBLENDARG_TEXEL2;
-    case 3: return TEXBLENDARG_TEXEL3;
-    default: return TEXBLENDARG_TEXEL0;
-   }
-}
-
-static void i830SetBlend_GL1_2(i830ContextPtr imesa, int curTex, 
-                              GLenum envMode, GLenum format)
-{
-   GLuint texel_op = GetTexelOp(curTex);
-
-   if(I830_DEBUG&DEBUG_TEXTURE)
-     fprintf(stderr, "%s %s %s unit (%d) texel_op(0x%x)\n",
-            __FUNCTION__,
-            _mesa_lookup_enum_by_nr(format),
-            _mesa_lookup_enum_by_nr(envMode),
-            curTex,
-            texel_op);
-
-   switch(envMode) {
-   case GL_REPLACE:
-      switch(format) {
-      case GL_ALPHA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 4;
-        break;
-      case GL_LUMINANCE:
-      case GL_RGB:
-      case GL_YCBCR_MESA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 4;
-        break;
-
-      case GL_INTENSITY:
-      case GL_LUMINANCE_ALPHA:
-      case GL_RGBA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 4;
-        break;
-      default:
-        /* Always set to passthru if something is funny */
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 4;
-        break;
-      }
-      break;
-
-   case GL_MODULATE:
-      switch(format) {
-      case GL_ALPHA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_MODULATE);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][4] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 5;
-        break;
-
-      case GL_LUMINANCE:
-      case GL_RGB:
-      case GL_YCBCR_MESA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_MODULATE);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][4] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 5;
-        break;
-
-      case GL_INTENSITY:
-      case GL_LUMINANCE_ALPHA:
-      case GL_RGBA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_MODULATE);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_MODULATE);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][4] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][5] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 6;
-        break;
-      default:
-        /* Always set to passthru if something is funny */
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 4;
-        break;
-      }
-      break;
-
-   case GL_DECAL:
-      switch(format) {
-      case GL_RGB:
-      case GL_YCBCR_MESA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 4;
-        break;
-
-      case GL_RGBA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_BLEND);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG0 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_REPLICATE_ALPHA |
-                                      texel_op);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][4] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][5] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 6;
-        break;
-      default:
-        /* Always set to passthru if something is funny */
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 4;
-        break;
-      }
-      break;
-
-   case GL_BLEND:
-      switch(format) {
-      case GL_ALPHA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_MODULATE);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][4] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 5;
-        break;
-
-      case GL_LUMINANCE:
-      case GL_RGB:
-      case GL_YCBCR_MESA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_BLEND);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG0 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_FACTOR_N);
-        imesa->TexBlend[curTex][4] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][5] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 6;
-        break;
 
-      case GL_INTENSITY:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_BLEND);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_BLEND);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG0 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_FACTOR_N);
-        imesa->TexBlend[curTex][4] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][5] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG0 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][6] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_FACTOR_N);
-        imesa->TexBlend[curTex][7] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 8;
-        break;
 
-      case GL_LUMINANCE_ALPHA:
-      case GL_RGBA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_BLEND);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_MODULATE);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG0 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_FACTOR_N);
-        imesa->TexBlend[curTex][4] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][5] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][6] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 7;
-        break;
-      default:
-        /* Always set to passthru if something is funny */
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 4;
-        break;
-      }
-      break;
-
-   case GL_ADD:
-      switch(format) {
-      case GL_ALPHA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_MODULATE);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][4] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 5;
-        break;
-      case GL_LUMINANCE:
-      case GL_RGB:
-      case GL_YCBCR_MESA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ADD);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][4] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 5;
-        break;
-
-      case GL_INTENSITY:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ADD);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ADD);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][4] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][5] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 6;
-        break;
-
-      case GL_LUMINANCE_ALPHA:
-      case GL_RGBA:
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ADD);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_MODULATE);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][4] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      texel_op);
-        imesa->TexBlend[curTex][5] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG2 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 6;
-        break;
-      default:
-        /* Always set to passthru if something is funny */
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 4;
-        break;
-      }
-      break;
-   default:
-        /* Always set to passthru if something is funny */
-        imesa->TexBlend[curTex][0] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      DISABLE_TEX_CNTRL_STAGE |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][1] = (STATE3D_MAP_BLEND_OP_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      ENABLE_TEXOUTPUT_WRT_SEL |
-                                      TEXOP_OUTPUT_CURRENT |
-                                      TEXOP_SCALE_1X |
-                                      TEXOP_MODIFY_PARMS |
-                                      TEXBLENDOP_ARG1);
-        imesa->TexBlend[curTex][2] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_COLOR |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlend[curTex][3] = (STATE3D_MAP_BLEND_ARG_CMD(curTex) |
-                                      TEXPIPE_ALPHA |
-                                      TEXBLEND_ARG1 |
-                                      TEXBLENDARG_MODIFY_PARMS |
-                                      TEXBLENDARG_CURRENT);
-        imesa->TexBlendColorPipeNum[curTex] = 0;
-        imesa->TexBlendWordsUsed[curTex] = 4;
-        break;
-   }
-
-   if (I830_DEBUG&DEBUG_TEXTURE)
-      fprintf(stderr, "%s\n", __FUNCTION__);
-}
+/**
+ * Calculate the hardware instuctions to setup the current texture enviromnemt
+ * settings.  Since \c gl_texture_unit::_CurrentCombine is used, both
+ * "classic" texture enviroments and GL_ARB_texture_env_combine type texture
+ * environments are treated identically.
+ *
+ * \todo
+ * This function should return \c GLboolean.  When \c GL_FALSE is returned,
+ * it means that an environment is selected that the hardware cannot do.  This
+ * is the way the Radeon and R200 drivers work.
+ * 
+ * \todo
+ * Looking at i830_3d_regs.h, it seems the i830 can do part of
+ * GL_ATI_texture_env_combine3.  It can handle using \c GL_ONE and
+ * \c GL_ZERO as combine inputs (which the code already supports).  It can
+ * also handle the \c GL_MODULATE_ADD_ATI mode.  Is it worth investigating
+ * partial support for the extension?
+ */
 
-static void i830SetTexEnvCombine(i830ContextPtr imesa,
-                                const struct gl_texture_unit *texUnit, 
-                                GLint unit)
+static void i830UpdateTexEnv( GLcontext *ctx, GLuint unit )
 {
+   i830ContextPtr imesa = I830_CONTEXT(ctx);
+   const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
+   const GLuint numColorArgs = texUnit->_CurrentCombine->_NumArgsRGB;
+   const GLuint numAlphaArgs = texUnit->_CurrentCombine->_NumArgsA;
+
+   GLboolean need_constant_color = GL_FALSE;
    GLuint blendop;
    GLuint ablendop;
    GLuint args_RGB[3];
    GLuint args_A[3];
-   GLuint texel_op = GetTexelOp(unit);
    GLuint rgb_shift = texUnit->Combine.ScaleShiftRGB;
    GLuint alpha_shift = texUnit->Combine.ScaleShiftA;
    int i;
+   unsigned used;
+   static const GLuint tex_blend_rgb[3] = {
+      TEXPIPE_COLOR | TEXBLEND_ARG1 | TEXBLENDARG_MODIFY_PARMS,
+      TEXPIPE_COLOR | TEXBLEND_ARG2 | TEXBLENDARG_MODIFY_PARMS,
+      TEXPIPE_COLOR | TEXBLEND_ARG0 | TEXBLENDARG_MODIFY_PARMS,
+   };
+   static const GLuint tex_blend_a[3] = {
+      TEXPIPE_ALPHA | TEXBLEND_ARG1 | TEXBLENDARG_MODIFY_PARMS,
+      TEXPIPE_ALPHA | TEXBLEND_ARG2 | TEXBLENDARG_MODIFY_PARMS,
+      TEXPIPE_ALPHA | TEXBLEND_ARG0 | TEXBLENDARG_MODIFY_PARMS,
+   };
+   static const GLuint op_rgb[4] = {
+      0,
+      TEXBLENDARG_INV_ARG,
+      TEXBLENDARG_REPLICATE_ALPHA,
+      TEXBLENDARG_REPLICATE_ALPHA | TEXBLENDARG_INV_ARG,
+   };
+
+
+
+   imesa->TexBlendWordsUsed[unit] = 0;
 
    if(I830_DEBUG&DEBUG_TEXTURE)
-      fprintf(stderr, "%s\n", __FUNCTION__);
+       fprintf(stderr, "[%s:%u] env. mode = %s\n",  __FUNCTION__, __LINE__, 
+              _mesa_lookup_enum_by_nr(texUnit->EnvMode));
 
-   switch(texUnit->Combine.ModeRGB) {
+
+   switch(texUnit->_CurrentCombine->ModeRGB) {
    case GL_REPLACE: 
       blendop = TEXBLENDOP_ARG1;
       break;
@@ -1066,7 +280,7 @@ static void i830SetTexEnvCombine(i830ContextPtr imesa,
 
    blendop |= (rgb_shift << TEXOP_SCALE_SHIFT);
 
-   switch(texUnit->Combine.ModeA) {
+   switch(texUnit->_CurrentCombine->ModeA) {
    case GL_REPLACE: 
       ablendop = TEXBLENDOP_ARG1;
       break;
@@ -1089,21 +303,32 @@ static void i830SetTexEnvCombine(i830ContextPtr imesa,
       return;
    }
 
-   if ( (texUnit->Combine.ModeRGB == GL_DOT3_RGBA_EXT)
-       || (texUnit->Combine.ModeRGB == GL_DOT3_RGBA) ) {
+   if ( (texUnit->_CurrentCombine->ModeRGB == GL_DOT3_RGBA_EXT)
+       || (texUnit->_CurrentCombine->ModeRGB == GL_DOT3_RGBA) ) {
       ablendop = TEXBLENDOP_DOT3;
    }
 
    ablendop |= (alpha_shift << TEXOP_SCALE_SHIFT);
 
    /* Handle RGB args */
-   for(i = 0; i < 3; i++) {
-      switch(texUnit->Combine.SourceRGB[i]) {
+   for( i = 0 ; i < numColorArgs ; i++ ) {
+      const int op = texUnit->_CurrentCombine->OperandRGB[i] - GL_SRC_COLOR;
+
+      assert( (op >= 0) && (op <= 3) );
+      switch(texUnit->_CurrentCombine->SourceRGB[i]) {
       case GL_TEXTURE: 
-        args_RGB[i] = texel_op;
+        args_RGB[i] = TEXBLENDARG_TEXEL0 + unit;
+        break;
+      case GL_TEXTURE0:
+      case GL_TEXTURE1: 
+      case GL_TEXTURE2: 
+      case GL_TEXTURE3:
+        args_RGB[i] = TEXBLENDARG_TEXEL0
+            + (texUnit->_CurrentCombine->SourceRGB[i] & 0x03);
         break;
       case GL_CONSTANT:
         args_RGB[i] = TEXBLENDARG_FACTOR_N; 
+        need_constant_color = GL_TRUE;
         break;
       case GL_PRIMARY_COLOR:
         args_RGB[i] = TEXBLENDARG_DIFFUSE;
@@ -1111,38 +336,41 @@ static void i830SetTexEnvCombine(i830ContextPtr imesa,
       case GL_PREVIOUS:
         args_RGB[i] = TEXBLENDARG_CURRENT; 
         break;
-      default: 
-        return;
-        
-      }
-
-      switch(texUnit->Combine.OperandRGB[i]) {
-      case GL_SRC_COLOR: 
-        args_RGB[i] |= 0;
+      case GL_ONE:
+        args_RGB[i] = TEXBLENDARG_ONE;
         break;
-      case GL_ONE_MINUS_SRC_COLOR: 
-        args_RGB[i] |= TEXBLENDARG_INV_ARG;
-        break;
-      case GL_SRC_ALPHA: 
-        args_RGB[i] |= TEXBLENDARG_REPLICATE_ALPHA;
-        break;
-      case GL_ONE_MINUS_SRC_ALPHA: 
-        args_RGB[i] |= (TEXBLENDARG_REPLICATE_ALPHA | 
-                        TEXBLENDARG_INV_ARG);
+      case GL_ZERO:
+        args_RGB[i] = TEXBLENDARG_ONE | TEXBLENDARG_INV_ARG;
         break;
       default: 
         return;
       }
+
+      /* Xor is used so that GL_ONE_MINUS_SRC_COLOR with GL_ZERO 
+       * works correctly.
+       */
+      args_RGB[i] ^= op_rgb[op];
    }
 
    /* Handle A args */
-   for(i = 0; i < 3; i++) {
-      switch(texUnit->Combine.SourceA[i]) {
+   for( i = 0 ; i < numAlphaArgs ; i++ ) {
+      const int op = texUnit->_CurrentCombine->OperandA[i] - GL_SRC_ALPHA;
+
+      assert( (op >= 0) && (op <= 1) );
+      switch(texUnit->_CurrentCombine->SourceA[i]) {
       case GL_TEXTURE: 
-        args_A[i] = texel_op;
+        args_A[i] = TEXBLENDARG_TEXEL0 + unit;
+        break;
+      case GL_TEXTURE0:
+      case GL_TEXTURE1: 
+      case GL_TEXTURE2: 
+      case GL_TEXTURE3:
+        args_A[i] = TEXBLENDARG_TEXEL0 
+            + (texUnit->_CurrentCombine->SourceA[i] & 0x03);
         break;
       case GL_CONSTANT:
         args_A[i] = TEXBLENDARG_FACTOR_N; 
+        need_constant_color = GL_TRUE;
         break;
       case GL_PRIMARY_COLOR:
         args_A[i] = TEXBLENDARG_DIFFUSE; 
@@ -1150,21 +378,21 @@ static void i830SetTexEnvCombine(i830ContextPtr imesa,
       case GL_PREVIOUS:
         args_A[i] = TEXBLENDARG_CURRENT; 
         break;
-      default: 
-        return;
-        
-      }
-
-      switch(texUnit->Combine.OperandA[i]) {
-      case GL_SRC_ALPHA: 
-        args_A[i] |= 0;
+      case GL_ONE:
+        args_A[i] = TEXBLENDARG_ONE;
         break;
-      case GL_ONE_MINUS_SRC_ALPHA: 
-        args_A[i] |= TEXBLENDARG_INV_ARG;
+      case GL_ZERO:
+        args_A[i] = TEXBLENDARG_ONE | TEXBLENDARG_INV_ARG;
         break;
       default: 
         return;
       }
+
+      /* We cheat. :) The register values for this are the same as for
+       * RGB.  Xor is used so that GL_ONE_MINUS_SRC_ALPHA with GL_ZERO
+       * works correctly.
+       */
+      args_A[i] ^= op_rgb[op];
    }
 
    /* Native Arg1 == Arg0 in GL_EXT_texture_env_combine spec */
@@ -1179,123 +407,49 @@ static void i830SetTexEnvCombine(i830ContextPtr imesa,
 
    /* Build color pipeline */
 
-   imesa->TexBlend[unit][0] = (STATE3D_MAP_BLEND_OP_CMD(unit) |
-                              TEXPIPE_COLOR |
-                              ENABLE_TEXOUTPUT_WRT_SEL |
-                              TEXOP_OUTPUT_CURRENT |
-                              DISABLE_TEX_CNTRL_STAGE |
-                              TEXOP_MODIFY_PARMS |
-                              blendop);
-   imesa->TexBlend[unit][1] = (STATE3D_MAP_BLEND_ARG_CMD(unit) |
-                              TEXPIPE_COLOR |
-                              TEXBLEND_ARG1 |
-                              TEXBLENDARG_MODIFY_PARMS |
-                              args_RGB[0]);
-   imesa->TexBlend[unit][2] = (STATE3D_MAP_BLEND_ARG_CMD(unit) |
-                              TEXPIPE_COLOR |
-                              TEXBLEND_ARG2 |
-                              TEXBLENDARG_MODIFY_PARMS |
-                              args_RGB[1]);
-   imesa->TexBlend[unit][3] = (STATE3D_MAP_BLEND_ARG_CMD(unit) |
-                              TEXPIPE_COLOR |
-                              TEXBLEND_ARG0 |
-                              TEXBLENDARG_MODIFY_PARMS |
-                              args_RGB[2]);
+   used = 0;
+   imesa->TexBlend[unit][used++] = (STATE3D_MAP_BLEND_OP_CMD(unit) |
+                                   TEXPIPE_COLOR |
+                                   ENABLE_TEXOUTPUT_WRT_SEL |
+                                   TEXOP_OUTPUT_CURRENT |
+                                   DISABLE_TEX_CNTRL_STAGE |
+                                   TEXOP_MODIFY_PARMS |
+                                   blendop);
+
+   imesa->TexBlend[unit][used++] = (STATE3D_MAP_BLEND_OP_CMD(unit) |
+                                   TEXPIPE_ALPHA |
+                                   ENABLE_TEXOUTPUT_WRT_SEL |
+                                   TEXOP_OUTPUT_CURRENT |
+                                   TEXOP_MODIFY_PARMS |
+                                   ablendop);
+
+   for ( i = 0 ; i < numColorArgs ; i++ ) {
+      imesa->TexBlend[unit][used++] = (STATE3D_MAP_BLEND_ARG_CMD(unit) |
+                                      tex_blend_rgb[i] |
+                                      args_RGB[i]);
+   }
+
+   for ( i = 0 ; i < numAlphaArgs ; i++ ) {
+      imesa->TexBlend[unit][used++] = (STATE3D_MAP_BLEND_ARG_CMD(unit) |
+                                      tex_blend_a[i] |
+                                      args_A[i]);
+   }
 
-   /* Build Alpha pipeline */
-   imesa->TexBlend[unit][4] = (STATE3D_MAP_BLEND_OP_CMD(unit) |
-                              TEXPIPE_ALPHA |
-                              ENABLE_TEXOUTPUT_WRT_SEL |
-                              TEXOP_OUTPUT_CURRENT |
-                              TEXOP_MODIFY_PARMS |
-                              ablendop);
-   imesa->TexBlend[unit][5] = (STATE3D_MAP_BLEND_ARG_CMD(unit) |
-                              TEXPIPE_ALPHA |
-                              TEXBLEND_ARG1 |
-                              TEXBLENDARG_MODIFY_PARMS |
-                              args_A[0]);
-   imesa->TexBlend[unit][6] = (STATE3D_MAP_BLEND_ARG_CMD(unit) |
-                              TEXPIPE_ALPHA |
-                              TEXBLEND_ARG2 |
-                              TEXBLENDARG_MODIFY_PARMS |
-                              args_A[1]);
-   imesa->TexBlend[unit][7] = (STATE3D_MAP_BLEND_ARG_CMD(unit) |
-                              TEXPIPE_ALPHA |
-                              TEXBLEND_ARG0 |
-                              TEXBLENDARG_MODIFY_PARMS |
-                              args_A[2]);
 
-   {
+   if ( need_constant_color ) {
       GLubyte r, g, b, a;
-      GLfloat *fc = texUnit->EnvColor;
+      const GLfloat * const fc = texUnit->EnvColor;
 
       FLOAT_COLOR_TO_UBYTE_COLOR(r, fc[RCOMP]);
       FLOAT_COLOR_TO_UBYTE_COLOR(g, fc[GCOMP]);
       FLOAT_COLOR_TO_UBYTE_COLOR(b, fc[BCOMP]);
       FLOAT_COLOR_TO_UBYTE_COLOR(a, fc[ACOMP]);
 
-      imesa->TexBlend[unit][8] = STATE3D_COLOR_FACTOR_CMD(unit);
-      imesa->TexBlend[unit][9] =  ((a << 24) |
-                                  (r << 16) |
-                                  (g << 8) |
-                                  b);
-   }
-   imesa->TexBlendWordsUsed[unit] = 10;
-}
-
-
-
-
-static void i830UpdateTexEnv( GLcontext *ctx, GLuint unit )
-{
-   i830ContextPtr imesa = I830_CONTEXT(ctx);
-   const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
-   const struct gl_texture_object *tObj = texUnit->_Current;
-   i830TextureObjectPtr t = (i830TextureObjectPtr)tObj->DriverData;
-   GLuint col;
-
-   imesa->TexBlendWordsUsed[unit] = 0;
-
-   if (0) fprintf(stderr, "i830UpdateTexEnv called : %s\n",
-                 _mesa_lookup_enum_by_nr(texUnit->EnvMode));
-
-   if(texUnit->EnvMode == GL_COMBINE) {
-      i830SetTexEnvCombine(imesa,
-                          texUnit,
-                          unit);
-   } else {
-      i830SetBlend_GL1_2(imesa,
-                        unit,
-                        texUnit->EnvMode,
-                        t->image[0][0].internalFormat);
-
-      /* add blend color */
-      {
-        GLubyte r, g, b, a;
-        GLfloat *fc = texUnit->EnvColor;
-
-        FLOAT_COLOR_TO_UBYTE_COLOR(r, fc[RCOMP]);
-        FLOAT_COLOR_TO_UBYTE_COLOR(g, fc[GCOMP]);
-        FLOAT_COLOR_TO_UBYTE_COLOR(b, fc[BCOMP]);
-        FLOAT_COLOR_TO_UBYTE_COLOR(a, fc[ACOMP]);
-
-        col = ((a << 24) |
-               (r << 16) |
-               (g << 8) |
-               b);
-      }       
-
-      {
-        int i;
-
-        i = imesa->TexBlendWordsUsed[unit];
-        imesa->TexBlend[unit][i++] = STATE3D_COLOR_FACTOR_CMD(unit);     
-        imesa->TexBlend[unit][i++] = col;
-
-        imesa->TexBlendWordsUsed[unit] = i;
-      }
+      imesa->TexBlend[unit][used++] = STATE3D_COLOR_FACTOR_CMD(unit);
+      imesa->TexBlend[unit][used++] = ((a << 24) | (r << 16) | (g << 8) | b);
    }
 
+   imesa->TexBlendWordsUsed[unit] = used;
    I830_STATECHANGE( imesa, I830_UPLOAD_TEXBLEND_N(unit) );
 }
 
@@ -1529,6 +683,3 @@ void i830UpdateTextureState( GLcontext *ctx )
       imesa->TexBlend[0][pipe_num] |= TEXOP_LAST_STAGE;
    }
 }
-
-
-