new texture compression infrastructure
[mesa.git] / src / mesa / main / state.c
index d94c9c7337afdc769d1d58ddbc76c1fb9581ead0..24e127a93fceb5481126448726c73cddc2ad1de4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: state.c,v 1.84 2002/06/06 16:31:24 brianp Exp $ */
+/* $Id: state.c,v 1.92 2002/09/27 02:45:38 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -425,6 +425,10 @@ _mesa_init_exec_table(struct _glapi_table *exec, GLuint tableSize)
    exec->LockArraysEXT = _mesa_LockArraysEXT;
    exec->UnlockArraysEXT = _mesa_UnlockArraysEXT;
 
+   /* 148. GL_EXT_multi_draw_arrays */
+   exec->MultiDrawArraysEXT = _mesa_MultiDrawArraysEXT;
+   exec->MultiDrawElementsEXT = _mesa_MultiDrawElementsEXT;
+
    /* 173. GL_INGR_blend_func_separate */
    exec->BlendFuncSeparateEXT = _mesa_BlendFuncSeparateEXT;
 
@@ -488,6 +492,9 @@ _mesa_init_exec_table(struct _glapi_table *exec, GLuint tableSize)
    exec->PointParameteriNV = _mesa_PointParameteriNV;
    exec->PointParameterivNV = _mesa_PointParameterivNV;
 
+   /* 268. GL_EXT_stencil_two_side */
+   exec->ActiveStencilFaceEXT = _mesa_ActiveStencilFaceEXT;
+
    /* ARB 1. GL_ARB_multitexture */
    exec->ActiveTextureARB = _mesa_ActiveTextureARB;
    exec->ClientActiveTextureARB = _mesa_ClientActiveTextureARB;
@@ -522,6 +529,10 @@ _mesa_init_exec_table(struct _glapi_table *exec, GLuint tableSize)
 /**********************************************************************/
 
 
+/*
+ * Check polygon state and set DD_TRI_CULL_FRONT_BACK and/or DD_TRI_OFFSET
+ * in ctx->_TriangleCaps if needed.
+ */
 static void
 update_polygon( GLcontext *ctx )
 {
@@ -532,8 +543,6 @@ update_polygon( GLcontext *ctx )
 
    /* Any Polygon offsets enabled? */
    ctx->Polygon._OffsetAny = GL_FALSE;
-   ctx->_TriangleCaps &= ~DD_TRI_OFFSET;
-
    if (ctx->Polygon.OffsetPoint ||
        ctx->Polygon.OffsetLine ||
        ctx->Polygon.OffsetFill) {
@@ -630,7 +639,7 @@ update_drawbuffer( GLcontext *ctx )
 /* NOTE: This routine references Tranform attribute values to compute
  * userclip positions in clip space, but is only called on
  * _NEW_PROJECTION.  The _mesa_ClipPlane() function keeps these values
- * uptodate across changes to the Transform attributes.
+ * up to date across changes to the Transform attributes.
  */
 static void
 update_projection( GLcontext *ctx )
@@ -763,9 +772,10 @@ update_texture_matrices( GLcontext *ctx )
 static void
 update_texture_state( GLcontext *ctx )
 {
-   GLuint i;
+   GLuint unit;
 
-   ctx->Texture._ReallyEnabled = 0;
+   ctx->Texture._ReallyEnabled = 0;  /* XXX obsolete */
+   ctx->Texture._EnabledUnits = 0;
    ctx->Texture._GenFlags = 0;
    ctx->_NeedNormals &= ~NEED_NORMALS_TEXGEN;
    ctx->_NeedEyeCoords &= ~NEED_EYE_TEXGEN;
@@ -774,8 +784,8 @@ update_texture_state( GLcontext *ctx )
 
    /* Update texture unit state.
     */
-   for (i=0; i < ctx->Const.MaxTextureUnits; i++) {
-      struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
+   for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
+      struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
 
       texUnit->_ReallyEnabled = 0;
       texUnit->_GenFlags = 0;
@@ -783,49 +793,60 @@ update_texture_state( GLcontext *ctx )
       if (!texUnit->Enabled)
         continue;
 
-      /* Find the texture of highest dimensionality that is enabled
-       * and complete.  We'll use it for texturing.
+      /* Look for the highest-priority texture target that's enabled and
+       * complete.  That's the one we'll use for texturing.
        */
-      if (texUnit->Enabled & TEXTURE0_CUBE) {
+      if (texUnit->Enabled & TEXTURE_CUBE_BIT) {
          struct gl_texture_object *texObj = texUnit->CurrentCubeMap;
          if (!texObj->Complete) {
             _mesa_test_texobj_completeness(ctx, texObj);
          }
          if (texObj->Complete) {
-            texUnit->_ReallyEnabled = TEXTURE0_CUBE;
+            texUnit->_ReallyEnabled = TEXTURE_CUBE_BIT;
             texUnit->_Current = texObj;
          }
       }
 
-      if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE0_3D)) {
+      if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE_3D_BIT)) {
          struct gl_texture_object *texObj = texUnit->Current3D;
          if (!texObj->Complete) {
             _mesa_test_texobj_completeness(ctx, texObj);
          }
          if (texObj->Complete) {
-            texUnit->_ReallyEnabled = TEXTURE0_3D;
+            texUnit->_ReallyEnabled = TEXTURE_3D_BIT;
+            texUnit->_Current = texObj;
+         }
+      }
+
+      if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE_RECT_BIT)) {
+         struct gl_texture_object *texObj = texUnit->CurrentRect;
+         if (!texObj->Complete) {
+            _mesa_test_texobj_completeness(ctx, texObj);
+         }
+         if (texObj->Complete) {
+            texUnit->_ReallyEnabled = TEXTURE_RECT_BIT;
             texUnit->_Current = texObj;
          }
       }
 
-      if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE0_2D)) {
+      if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE_2D_BIT)) {
          struct gl_texture_object *texObj = texUnit->Current2D;
          if (!texObj->Complete) {
             _mesa_test_texobj_completeness(ctx, texObj);
          }
          if (texObj->Complete) {
-            texUnit->_ReallyEnabled = TEXTURE0_2D;
+            texUnit->_ReallyEnabled = TEXTURE_2D_BIT;
             texUnit->_Current = texObj;
          }
       }
 
-      if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE0_1D)) {
+      if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE_1D_BIT)) {
          struct gl_texture_object *texObj = texUnit->Current1D;
          if (!texObj->Complete) {
             _mesa_test_texobj_completeness(ctx, texObj);
          }
          if (texObj->Complete) {
-            texUnit->_ReallyEnabled = TEXTURE0_1D;
+            texUnit->_ReallyEnabled = TEXTURE_1D_BIT;
             texUnit->_Current = texObj;
          }
       }
@@ -835,9 +856,14 @@ update_texture_state( GLcontext *ctx )
         continue;
       }
 
+      /* Texture._ReallyEnabled records the enable state for all units in
+       * one word.
+       */
       {
-        GLuint flag = texUnit->_ReallyEnabled << (i * NUM_TEXTURE_TARGETS);
-        ctx->Texture._ReallyEnabled |= flag;
+         GLuint flag = texUnit->_ReallyEnabled << (unit * NUM_TEXTURE_TARGETS);
+        ctx->Texture._ReallyEnabled |= flag;  /* XXX obsolete field! */
+         if (texUnit->_ReallyEnabled)
+            ctx->Texture._EnabledUnits |= (1 << unit);
       }
 
       if (texUnit->TexGenEnabled) {
@@ -854,12 +880,12 @@ update_texture_state( GLcontext *ctx )
            texUnit->_GenFlags |= texUnit->_GenBitR;
         }
 
-        ctx->Texture._TexGenEnabled |= ENABLE_TEXGEN(i);
+        ctx->Texture._TexGenEnabled |= ENABLE_TEXGEN(unit);
         ctx->Texture._GenFlags |= texUnit->_GenFlags;
       }
 
-      if (ctx->TextureMatrixStack[i].Top->type != MATRIX_IDENTITY)
-        ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(i);
+      if (ctx->TextureMatrixStack[unit].Top->type != MATRIX_IDENTITY)
+        ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(unit);
    }
 
    if (ctx->Texture._GenFlags & TEXGEN_NEED_NORMALS) {
@@ -994,7 +1020,6 @@ void _mesa_update_state( GLcontext *ctx )
    ASSERT(ctx->Driver.GetString);
    ASSERT(ctx->Driver.UpdateState);
    ASSERT(ctx->Driver.Clear);
-   ASSERT(ctx->Driver.SetDrawBuffer);
    ASSERT(ctx->Driver.GetBufferSize);
    if (ctx->Visual.accumRedBits > 0) {
       ASSERT(ctx->Driver.Accum);
@@ -1016,9 +1041,6 @@ void _mesa_update_state( GLcontext *ctx )
    ASSERT(ctx->Driver.CopyTexSubImage2D);
    ASSERT(ctx->Driver.CopyTexSubImage3D);
    if (ctx->Extensions.ARB_texture_compression) {
-      ASSERT(ctx->Driver.BaseCompressedTexFormat);
-      ASSERT(ctx->Driver.CompressedTextureSize);
-      ASSERT(ctx->Driver.GetCompressedTexImage);
 #if 0  /* HW drivers need these, but not SW rasterizers */
       ASSERT(ctx->Driver.CompressedTexImage1D);
       ASSERT(ctx->Driver.CompressedTexImage2D);