OSDN Git Service

mesa/main: Make FEATURE_colortable follow feature conventions.
[android-x86/external-mesa.git] / src / mesa / main / texobj.c
index 0024efc..678845e 100644 (file)
@@ -29,9 +29,7 @@
 
 
 #include "mfeatures.h"
-#if FEATURE_colortable
 #include "colortab.h"
-#endif
 #include "context.h"
 #include "enums.h"
 #include "fbobject.h"
@@ -194,9 +192,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++) {
@@ -261,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.
  */
@@ -281,7 +303,8 @@ valid_texture_object(const struct gl_texture_object *tex)
       _mesa_problem(NULL, "invalid reference to a deleted texture object");
       return GL_FALSE;
    default:
-      _mesa_problem(NULL, "invalid texture object Target value");
+      _mesa_problem(NULL, "invalid texture object Target 0x%x, Id = %u",
+                    tex->Target, tex->Name);
       return GL_FALSE;
    }
 }
@@ -307,7 +330,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);
@@ -330,7 +353,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) */
@@ -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).
  * That's the value a sampler should get when sampling from an
@@ -714,7 +755,6 @@ _mesa_get_fallback_texture(GLcontext *ctx)
 }
 
 
-
 /*@}*/
 
 
@@ -944,6 +984,7 @@ _mesa_BindTexture( GLenum target, GLuint texName )
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
    struct gl_texture_object *newTexObj = NULL, *defaultTexObj = NULL;
    GLint targetIndex;
+   GLboolean early_out = GL_FALSE;
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
@@ -997,6 +1038,17 @@ _mesa_BindTexture( GLenum target, GLuint texName )
 
    assert(valid_texture_object(newTexObj));
 
+   _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
+   if ((ctx->Shared->RefCount == 1)
+       && (newTexObj == texUnit->CurrentTex[targetIndex])) {
+      early_out = GL_TRUE;
+   }
+   _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
+
+   if (early_out) {
+      return;
+   }
+
    /* flush before changing binding */
    FLUSH_VERTICES(ctx, _NEW_TEXTURE);
 
@@ -1147,10 +1199,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