OSDN Git Service

Clean up the recent code related to texture_override(). Pass params in a
authorBrian Paul <brian.paul@tungstengraphics.com>
Fri, 24 Mar 2006 23:53:50 +0000 (23:53 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Fri, 24 Mar 2006 23:53:50 +0000 (23:53 +0000)
more logical order.
Remove a mess of stray ^M chars.
Fix a bug when checking if the texture object's format is GL_COLOR_INDEX
or GL_DEPTH_COMPONENT.  This fixes a segfault when GL_TEXTURE_BASE_LEVEL!=0.

src/mesa/main/texstate.c

index 5de5f68..daf579a 100644 (file)
@@ -39,7 +39,7 @@
 #include "texstate.h"
 #include "texenvprogram.h"
 #include "mtypes.h"
-#include "math/m_xform.h"\r
+#include "math/m_xform.h"
 #include "shaderobjects.h"
 
 
@@ -2766,23 +2766,29 @@ update_texture_matrices( GLcontext *ctx )
       }
    }
 }
-\r
-\r
-static void\r
-texture_override( struct gl_texture_object *texObj, GLuint textureBit, GLcontext *ctx,\r
-                GLbitfield enableBits, struct gl_texture_unit *texUnit )\r
-{\r
-   if (!texUnit->_ReallyEnabled && (enableBits & textureBit)) {\r
-      if (!texObj->Complete) {\r
-         _mesa_test_texobj_completeness(ctx, texObj);\r
-      }\r
-      if (texObj->Complete) {\r
-         texUnit->_ReallyEnabled = textureBit;\r
-         texUnit->_Current = texObj;\r
-      }\r
-   }\r
+
+
+/**
+ * Helper function for determining which texture object (1D, 2D, cube, etc)
+ * should actually be used.
+ */
+static void
+texture_override(GLcontext *ctx,
+                 struct gl_texture_unit *texUnit, GLbitfield enableBits,
+                 struct gl_texture_object *texObj, GLuint textureBit)
+{
+   if (!texUnit->_ReallyEnabled && (enableBits & textureBit)) {
+      if (!texObj->Complete) {
+         _mesa_test_texobj_completeness(ctx, texObj);
+      }
+      if (texObj->Complete) {
+         texUnit->_ReallyEnabled = textureBit;
+         texUnit->_Current = texObj;
+      }
+   }
 }
 
+
 /**
  * \note This routine refers to derived texture matrix values to
  * compute the ENABLE_TEXMAT flags, but is only called on
@@ -2794,9 +2800,9 @@ texture_override( struct gl_texture_object *texObj, GLuint textureBit, GLcontext
 static void
 update_texture_state( GLcontext *ctx )
 {
-   GLuint unit;\r
-   struct gl2_program_intf **prog = ctx->ShaderObjects.CurrentProgram;\r
-   GLbitfield progteximageusage[MAX_TEXTURE_IMAGE_UNITS];\r
+   GLuint unit;
+   struct gl2_program_intf **prog = ctx->ShaderObjects.CurrentProgram;
+   GLbitfield progteximageusage[MAX_TEXTURE_IMAGE_UNITS];
 
    ctx->NewState |= _NEW_TEXTURE; /* TODO: only set this if there are 
                                   * actual changes. 
@@ -2805,20 +2811,19 @@ update_texture_state( GLcontext *ctx )
    ctx->Texture._EnabledUnits = 0;
    ctx->Texture._GenFlags = 0;
    ctx->Texture._TexMatEnabled = 0;
-   ctx->Texture._TexGenEnabled = 0;\r
-\r
-   /*\r
-    * Grab texture image usage state from shader program. It must be grabbed every time\r
-    * uniform sampler changes, so maybe there is a better place to perform these rather\r
-    * expensive computations.\r
-    */\r
-   if (ctx->ShaderObjects._FragmentShaderPresent) {\r
-      (**prog).GetTextureImageUsage (prog, progteximageusage);\r
+   ctx->Texture._TexGenEnabled = 0;
+
+   /*
+    * Grab texture image usage state from shader program. It must be
+    * grabbed every time uniform sampler changes, so maybe there is a
+    * better place to perform these rather expensive computations.
+    */
+   if (ctx->ShaderObjects._FragmentShaderPresent) {
+      (**prog).GetTextureImageUsage (prog, progteximageusage);
    }
 
-   /* Update texture unit state.
-    * XXX this loop should probably be broken into separate loops for
-    * texture coord units and texture image units.
+   /*
+    * Update texture unit state.
     */
    for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
       struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
@@ -2828,10 +2833,10 @@ update_texture_state( GLcontext *ctx )
       texUnit->_ReallyEnabled = 0;
       texUnit->_GenFlags = 0;
 
-      /* Get the bitmask of texture enables */\r
-      if (ctx->ShaderObjects._FragmentShaderPresent) {\r
+      /* Get the bitmask of texture enables */
+      if (ctx->ShaderObjects._FragmentShaderPresent) {
          enableBits = progteximageusage[unit];
-      }\r
+      }
       else if (ctx->FragmentProgram._Enabled) {
          enableBits = ctx->FragmentProgram.Current->TexturesUsed[unit];
       }
@@ -2844,12 +2849,17 @@ update_texture_state( GLcontext *ctx )
       /* Look for the highest-priority texture target that's enabled and
        * complete.  That's the one we'll use for texturing.  If we're using
        * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
-       */\r
-      texture_override(texUnit->CurrentCubeMap, TEXTURE_CUBE_BIT, ctx, enableBits, texUnit);\r
-      texture_override(texUnit->Current3D, TEXTURE_3D_BIT, ctx, enableBits, texUnit);
-      texture_override(texUnit->CurrentRect, TEXTURE_RECT_BIT, ctx, enableBits, texUnit);\r
-      texture_override(texUnit->Current2D, TEXTURE_2D_BIT, ctx, enableBits, texUnit);
-      texture_override(texUnit->Current1D, TEXTURE_1D_BIT, ctx, enableBits, texUnit);
+       */
+      texture_override(ctx, texUnit, enableBits,
+                       texUnit->CurrentCubeMap, TEXTURE_CUBE_BIT);
+      texture_override(ctx, texUnit, enableBits,
+                       texUnit->Current3D, TEXTURE_3D_BIT);
+      texture_override(ctx, texUnit, enableBits,
+                       texUnit->CurrentRect, TEXTURE_RECT_BIT);
+      texture_override(ctx, texUnit, enableBits,
+                       texUnit->Current2D, TEXTURE_2D_BIT);
+      texture_override(ctx, texUnit, enableBits,
+                       texUnit->Current1D, TEXTURE_1D_BIT);
 
       if (!texUnit->_ReallyEnabled) {
          continue;
@@ -2862,13 +2872,14 @@ update_texture_state( GLcontext *ctx )
         texUnit->_CurrentCombine = & texUnit->Combine;
       }
       else {
-         GLenum format = texUnit->_Current->Image[0][0]->_BaseFormat;
+         const struct gl_texture_object *texObj = texUnit->_Current;
+         GLenum format = texObj->Image[0][texObj->BaseLevel]->_BaseFormat;
          if (format == GL_COLOR_INDEX) {
             format = GL_RGBA;  /* a bit of a hack */
          }
          else if (format == GL_DEPTH_COMPONENT
                   || format == GL_DEPTH_STENCIL_EXT) {
-            format = texUnit->_Current->DepthMode;
+            format = texObj->DepthMode;
          }
         calculate_derived_texenv(&texUnit->_EnvMode, texUnit->EnvMode, format);
         texUnit->_CurrentCombine = & texUnit->_EnvMode;
@@ -2947,9 +2958,9 @@ update_texture_state( GLcontext *ctx )
    ctx->Texture._EnabledCoordUnits = ctx->Texture._EnabledUnits;
    /* Fragment programs may need texture coordinates but not the
     * corresponding texture images.
-    */\r
-   if (ctx->ShaderObjects.CurrentProgram != NULL) {\r
-      ctx->Texture._EnabledCoordUnits |= (1 << ctx->Const.MaxTextureCoordUnits) - 1;\r
+    */
+   if (ctx->ShaderObjects.CurrentProgram != NULL) {
+      ctx->Texture._EnabledCoordUnits |= (1 << ctx->Const.MaxTextureCoordUnits) - 1;
    }
    else if (ctx->FragmentProgram._Enabled) {
       ctx->Texture._EnabledCoordUnits |=