Minor tweaks to help out at a driver level.
[mesa.git] / src / mesa / main / texobj.c
index e131fae50e404385ec6d553b807066b9ffbe0f62..98e49cde672d34a1ed5d262093a81431cf846ed3 100644 (file)
@@ -5,9 +5,9 @@
 
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.1
  *
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -46,8 +46,8 @@
 /*@{*/
 
 /**
- * Allocate and initialize a new texture object and add it to the linked list of
- * texture objects.  
+ * Allocate and initialize a new texture object.  But don't put it into the
+ * texture object hash table.
  *
  * Called via ctx->Driver.NewTextureObject, unless overridden by a device
  * driver.
  * of GenTextures()
  *
  * \return pointer to new texture object.
- *
- * Allocate and initialize a gl_texture_object structure, and insert in the
- * shared state texture list while holding its mutex.
- * If <tt>name > 0</tt> then also insert the new texture object into the hash
- * table.
- * 
  */
 struct gl_texture_object *
 _mesa_new_texture_object( GLcontext *ctx, GLuint name, GLenum target )
 {
    struct gl_texture_object *obj;
-   obj = CALLOC_STRUCT(gl_texture_object);
+   obj = MALLOC_STRUCT(gl_texture_object);
    _mesa_initialize_texture_object(obj, name, target);
    return obj;
 }
@@ -95,6 +89,7 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj,
 
    /* init the non-zero fields */
    _glthread_INIT_MUTEX(obj->Mutex);
+   _mesa_bzero(obj, sizeof(*obj));
    obj->RefCount = 1;
    obj->Name = name;
    obj->Target = target;
@@ -114,6 +109,7 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj,
    obj->MagFilter = GL_LINEAR;
    obj->MinLod = -1000.0;
    obj->MaxLod = 1000.0;
+   obj->LodBias = 0.0;
    obj->BaseLevel = 0;
    obj->MaxLevel = 1000;
    obj->MaxAnisotropy = 1.0;
@@ -123,7 +119,7 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj,
    obj->CompareFunc = GL_LEQUAL;       /* ARB_shadow */
    obj->DepthMode = GL_LUMINANCE;      /* ARB_depth_texture */
    obj->ShadowAmbient = 0.0F;          /* ARB/SGIX_shadow_ambient */
-   _mesa_init_one_colortable(&obj->Palette);
+   _mesa_init_colortable(&obj->Palette);
 }
 
 
@@ -133,10 +129,6 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj,
  *
  * \param shared the shared GL state to which the object belongs.
  * \param texOjb the texture object to delete.
- *
- * Unlink the texture object from the shared state texture linked list while
- * holding its lock. If the texture is a name number it's also removed from the
- * hash table. Finally frees the texture images and the object itself.
  */
 void
 _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj )
@@ -147,7 +139,7 @@ _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj )
 
    assert(texObj);
 
-   _mesa_free_one_colortable(&texObj->Palette);
+   _mesa_free_colortable_data(&texObj->Palette);
 
    /* free the texture images */
    for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
@@ -242,6 +234,7 @@ _mesa_copy_texture_object( struct gl_texture_object *dest,
    dest->MagFilter = src->MagFilter;
    dest->MinLod = src->MinLod;
    dest->MaxLod = src->MaxLod;
+   dest->LodBias = src->LodBias;
    dest->BaseLevel = src->BaseLevel;
    dest->MaxLevel = src->MaxLevel;
    dest->MaxAnisotropy = src->MaxAnisotropy;
@@ -303,7 +296,19 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
 
    /* Always need the base level image */
    if (!t->Image[baseLevel]) {
-      incomplete(t, "Image[baseLevel] == NULL");
+      char s[100];
+      sprintf(s, "obj %p (%d) Image[baseLevel=%d] == NULL",
+              (void *) t, t->Name, baseLevel);
+      incomplete(t, s);
+      t->Complete = GL_FALSE;
+      return;
+   }
+
+   /* Check width/height/depth for zero */
+   if (t->Image[baseLevel]->Width == 0 ||
+       t->Image[baseLevel]->Height == 0 ||
+       t->Image[baseLevel]->Depth == 0) {
+      incomplete(t, "texture width = 0");
       t->Complete = GL_FALSE;
       return;
    }
@@ -557,7 +562,6 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
       }
       else if (t->Target == GL_TEXTURE_RECTANGLE_NV) {
          /* XXX special checking? */
-
       }
       else {
          /* Target = ??? */
@@ -593,7 +597,7 @@ _glthread_DECLARE_STATIC_MUTEX(GenTexturesLock);
  * to find a block of free texture IDs which are stored in \p texName.
  * Corresponding empty texture objects are also generated.
  */ 
-void
+void GLAPIENTRY
 _mesa_GenTextures( GLsizei n, GLuint *texName )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -616,11 +620,6 @@ _mesa_GenTextures( GLsizei n, GLuint *texName )
 
    first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n);
 
-   /* Return the texture names */
-   for (i=0;i<n;i++) {
-      texName[i] = first + i;
-   }
-
    /* Allocate new, empty texture objects */
    for (i = 0; i < n; i++) {
       struct gl_texture_object *texObj;
@@ -632,6 +631,7 @@ _mesa_GenTextures( GLsizei n, GLuint *texName )
          return;
       }
       _mesa_save_texture_object(ctx, texObj);
+      texName[i] = name;
    }
 
    _glthread_UNLOCK_MUTEX(GenTexturesLock);
@@ -649,7 +649,7 @@ _mesa_GenTextures( GLsizei n, GLuint *texName )
  * it and decrementing the reference count if so. If the texture reference
  * count is zero, delete its object.
  */
-void
+void GLAPIENTRY
 _mesa_DeleteTextures( GLsizei n, const GLuint *texName)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -738,7 +738,7 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *texName)
  * calls dd_function_table::BindTexture. Decrements the old texture reference
  * count and deletes it if it reaches zero.
  */
-void
+void GLAPIENTRY
 _mesa_BindTexture( GLenum target, GLuint texName )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -894,7 +894,7 @@ _mesa_BindTexture( GLenum target, GLuint texName )
  * Looks up each texture in the hash, clamps the corresponding priority between
  * 0.0 and 1.0, and calls dd_function_table::PrioritizeTexture.
  */
-void
+void GLAPIENTRY
 _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName,
                           const GLclampf *priorities )
 {
@@ -939,7 +939,7 @@ _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName,
  * Looks up each texture in the hash and calls
  * dd_function_table::IsTextureResident.
  */
-GLboolean
+GLboolean GLAPIENTRY
 _mesa_AreTexturesResident(GLsizei n, const GLuint *texName,
                           GLboolean *residences)
 {
@@ -1000,7 +1000,7 @@ _mesa_AreTexturesResident(GLsizei n, const GLuint *texName,
  *
  * Calls _mesa_HashLookup().
  */
-GLboolean
+GLboolean GLAPIENTRY
 _mesa_IsTexture( GLuint texture )
 {
    GET_CURRENT_CONTEXT(ctx);