Merge branch 'i965g-restart'
[mesa.git] / src / mesa / main / texobj.c
index 2082f945f1852d0132f477346fe44ddbc9d1d17b..09fe7b85ba013e7390c84b8e12696bc8247c73cb 100644 (file)
 
 
 #include "mfeatures.h"
-#if FEATURE_colortable
 #include "colortab.h"
-#endif
 #include "context.h"
 #include "enums.h"
 #include "fbobject.h"
+#include "formats.h"
 #include "hash.h"
 #include "imports.h"
 #include "macros.h"
@@ -194,9 +193,7 @@ _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj )
     */
    texObj->Target = 0x99;
 
-#if FEATURE_colortable
    _mesa_free_colortable_data(&texObj->Palette);
-#endif
 
    /* free the texture images */
    for (face = 0; face < 6; face++) {
@@ -260,6 +257,32 @@ _mesa_copy_texture_object( struct gl_texture_object *dest,
 }
 
 
+/**
+ * Clear all texture images of the given texture object.
+ *
+ * \param ctx GL context.
+ * \param t texture object.
+ *
+ * \sa _mesa_clear_texture_image().
+ */
+void
+_mesa_clear_texture_object(GLcontext *ctx, struct gl_texture_object *texObj)
+{
+   GLuint i, j;
+
+   if (texObj->Target == 0)
+      return;
+
+   for (i = 0; i < MAX_FACES; i++) {
+      for (j = 0; j < MAX_TEXTURE_LEVELS; j++) {
+         struct gl_texture_image *texImage = texObj->Image[i][j];
+         if (texImage)
+            _mesa_clear_texture_image(ctx, texImage);
+      }
+   }
+}
+
+
 /**
  * Check if the given texture object is valid by examining its Target field.
  * For debugging only.
@@ -308,7 +331,7 @@ _mesa_reference_texobj(struct gl_texture_object **ptr,
       GLboolean deleteFlag = GL_FALSE;
       struct gl_texture_object *oldTex = *ptr;
 
-      assert(valid_texture_object(oldTex));
+      ASSERT(valid_texture_object(oldTex));
 
       _glthread_LOCK_MUTEX(oldTex->Mutex);
       ASSERT(oldTex->RefCount > 0);
@@ -331,7 +354,7 @@ _mesa_reference_texobj(struct gl_texture_object **ptr,
 
    if (tex) {
       /* reference new texture */
-      assert(valid_texture_object(tex));
+      ASSERT(valid_texture_object(tex));
       _glthread_LOCK_MUTEX(tex->Mutex);
       if (tex->RefCount == 0) {
          /* this texture's being deleted (look just above) */
@@ -392,7 +415,7 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
    /* Detect cases where the application set the base level to an invalid
     * value.
     */
-   if ((baseLevel < 0) || (baseLevel > MAX_TEXTURE_LEVELS)) {
+   if ((baseLevel < 0) || (baseLevel >= MAX_TEXTURE_LEVELS)) {
       char s[100];
       _mesa_sprintf(s, "base level = %d is invalid", baseLevel);
       incomplete(t, s);
@@ -469,7 +492,7 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
             t->Image[face][baseLevel]->Width2 != w ||
             t->Image[face][baseLevel]->Height2 != h) {
            t->_Complete = GL_FALSE;
-           incomplete(t, "Non-quare cubemap image");
+           incomplete(t, "Cube face missing or mismatched size");
            return;
         }
       }
@@ -664,6 +687,24 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
 }
 
 
+/**
+ * Mark a texture object dirty.  It forces the object to be incomplete
+ * and optionally forces the context to re-validate its state.
+ *
+ * \param ctx GL context.
+ * \param texObj texture object.
+ * \param invalidate_state also invalidate context state.
+ */
+void
+_mesa_dirty_texobj(GLcontext *ctx, struct gl_texture_object *texObj,
+                   GLboolean invalidate_state)
+{
+   texObj->_Complete = GL_FALSE;
+   if (invalidate_state)
+      ctx->NewState |= _NEW_TEXTURE;
+}
+
+
 /**
  * Return pointer to a default/fallback texture.
  * The texture is a 2D 8x8 RGBA texture with all texels = (0,0,0,1).
@@ -700,6 +741,10 @@ _mesa_get_fallback_texture(GLcontext *ctx)
       _mesa_init_teximage_fields(ctx, GL_TEXTURE_2D, texImage,
                                     8, 8, 1, 0, GL_RGBA); 
 
+      texImage->TexFormat =
+         ctx->Driver.ChooseTextureFormat(ctx, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
+      ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
+
       /* set image data */
       ctx->Driver.TexImage2D(ctx, GL_TEXTURE_2D, 0, GL_RGBA,
                              8, 8, 0,
@@ -715,7 +760,6 @@ _mesa_get_fallback_texture(GLcontext *ctx)
 }
 
 
-
 /*@}*/
 
 
@@ -820,7 +864,7 @@ unbind_texobj_from_texunits(GLcontext *ctx, struct gl_texture_object *texObj)
       for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
          if (texObj == unit->CurrentTex[tex]) {
             _mesa_reference_texobj(&unit->CurrentTex[tex],
-                                   ctx->Shared->DefaultTex[TEXTURE_1D_INDEX]);
+                                   ctx->Shared->DefaultTex[tex]);
             ASSERT(unit->CurrentTex[tex]);
             break;
          }
@@ -896,7 +940,8 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *textures)
 /**
  * Convert a GL texture target enum such as GL_TEXTURE_2D or GL_TEXTURE_3D
  * into the corresponding Mesa texture target index.
- * Return -1 if target is invalid.
+ * Note that proxy targets are not valid here.
+ * \return TEXTURE_x_INDEX or -1 if target is invalid
  */
 static GLint
 target_enum_to_index(GLenum target)
@@ -1059,8 +1104,6 @@ _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName,
          struct gl_texture_object *t = _mesa_lookup_texture(ctx, texName[i]);
          if (t) {
             t->Priority = CLAMP( priorities[i], 0.0F, 1.0F );
-           if (ctx->Driver.PrioritizeTexture)
-              ctx->Driver.PrioritizeTexture( ctx, t, t->Priority );
          }
       }
    }
@@ -1160,10 +1203,9 @@ _mesa_IsTexture( GLuint texture )
 
 
 /**
- * Simplest implementation of texture locking: Grab the a new mutex in
- * the shared context.  Examine the shared context state timestamp and
- * if there has been a change, set the appropriate bits in
- * ctx->NewState.
+ * Simplest implementation of texture locking: grab the shared tex
+ * mutex.  Examine the shared context state timestamp and if there has
+ * been a change, set the appropriate bits in ctx->NewState.
  *
  * This is used to deal with synchronizing things when a texture object
  * is used/modified by different contexts (or threads) which are sharing