main: Nameless texture creation and deletion. Does not affect normal creation and...
[mesa.git] / src / mesa / main / arrayobj.c
index 0b9592f7712c2bd069ee02a2ae49ea000da3ec0a..6440ea670b23b47e94eb4d0b7840d46626faa120 100644 (file)
@@ -117,10 +117,9 @@ _mesa_new_vao(struct gl_context *ctx, GLuint name)
 void
 _mesa_delete_vao(struct gl_context *ctx, struct gl_vertex_array_object *obj)
 {
-   (void) ctx;
    unbind_array_object_vbos(ctx, obj);
    _mesa_reference_buffer_object(ctx, &obj->IndexBufferObj, NULL);
-   _glthread_DESTROY_MUTEX(obj->Mutex);
+   mtx_destroy(&obj->Mutex);
    free(obj->Label);
    free(obj);
 }
@@ -143,7 +142,7 @@ _mesa_reference_vao_(struct gl_context *ctx,
       GLboolean deleteFlag = GL_FALSE;
       struct gl_vertex_array_object *oldObj = *ptr;
 
-      _glthread_LOCK_MUTEX(oldObj->Mutex);
+      mtx_lock(&oldObj->Mutex);
       ASSERT(oldObj->RefCount > 0);
       oldObj->RefCount--;
 #if 0
@@ -151,7 +150,7 @@ _mesa_reference_vao_(struct gl_context *ctx,
              (void *) oldObj, oldObj->Name, oldObj->RefCount);
 #endif
       deleteFlag = (oldObj->RefCount == 0);
-      _glthread_UNLOCK_MUTEX(oldObj->Mutex);
+      mtx_unlock(&oldObj->Mutex);
 
       if (deleteFlag) {
         ASSERT(ctx->Driver.DeleteArrayObject);
@@ -164,7 +163,7 @@ _mesa_reference_vao_(struct gl_context *ctx,
 
    if (vao) {
       /* reference new array object */
-      _glthread_LOCK_MUTEX(vao->Mutex);
+      mtx_lock(&vao->Mutex);
       if (vao->RefCount == 0) {
          /* this array's being deleted (look just above) */
          /* Not sure this can every really happen.  Warn if it does. */
@@ -179,7 +178,7 @@ _mesa_reference_vao_(struct gl_context *ctx,
 #endif
          *ptr = vao;
       }
-      _glthread_UNLOCK_MUTEX(vao->Mutex);
+      mtx_unlock(&vao->Mutex);
    }
 }
 
@@ -227,11 +226,11 @@ _mesa_initialize_vao(struct gl_context *ctx,
 
    obj->Name = name;
 
-   _glthread_INIT_MUTEX(obj->Mutex);
+   mtx_init(&obj->Mutex, mtx_plain);
    obj->RefCount = 1;
 
    /* Init the individual arrays */
-   for (i = 0; i < Elements(obj->_VertexAttrib); i++) {
+   for (i = 0; i < Elements(obj->VertexAttrib); i++) {
       switch (i) {
       case VERT_ATTRIB_WEIGHT:
          init_array(ctx, obj, VERT_ATTRIB_WEIGHT, 1, GL_FLOAT);
@@ -292,52 +291,6 @@ remove_array_object( struct gl_context *ctx, struct gl_vertex_array_object *obj
 }
 
 
-
-/**
- * Helper for _mesa_update_vao_max_element().
- * \return  min(vao->_VertexAttrib[*]._MaxElement).
- */
-static GLuint
-compute_max_element(struct gl_vertex_array_object *vao, GLbitfield64 enabled)
-{
-   GLuint min = ~((GLuint)0);
-
-   while (enabled) {
-      struct gl_client_array *client_array;
-      GLint attrib = ffsll(enabled) - 1;
-      enabled ^= BITFIELD64_BIT(attrib);
-
-      client_array = &vao->_VertexAttrib[attrib];
-      assert(client_array->Enabled);
-      _mesa_update_array_max_element(client_array);
-      min = MIN2(min, client_array->_MaxElement);
-   }
-
-   return min;
-}
-
-
-/**
- * Examine vertex arrays to update the gl_vertex_array_object::_MaxElement field.
- */
-void
-_mesa_update_vao_max_element(struct gl_context *ctx,
-                                      struct gl_vertex_array_object *vao)
-{
-   GLbitfield64 enabled;
-
-   if (!ctx->VertexProgram._Current ||
-       ctx->VertexProgram._Current == ctx->VertexProgram._TnlProgram) {
-      enabled = _mesa_array_object_get_enabled_ff(vao);
-   } else {
-      enabled = _mesa_array_object_get_enabled_arb(vao);
-   }
-
-   /* _MaxElement is one past the last legal array element */
-   vao->_MaxElement = compute_max_element(vao, enabled);
-}
-
-
 /**
  * Updates the derived gl_client_arrays when a gl_vertex_attrib_array
  * or a gl_vertex_buffer_binding has changed.
@@ -428,6 +381,21 @@ bind_vertex_array(struct gl_context *ctx, GLuint id, GLboolean genRequired)
       }
    }
 
+   if (ctx->Array.DrawMethod == DRAW_ARRAYS) {
+      /* The _DrawArrays pointer is pointing at the VAO being unbound and
+       * that VAO may be in the process of being deleted. If it's not going
+       * to be deleted, this will have no effect, because the pointer needs
+       * to be updated by the VBO module anyway.
+       *
+       * Before the VBO module can update the pointer, we have to set it
+       * to NULL for drivers not to set up arrays which are not bound,
+       * or to prevent a crash if the VAO being unbound is going to be
+       * deleted.
+       */
+      ctx->Array._DrawArrays = NULL;
+      ctx->Array.DrawMethod = DRAW_NONE;
+   }
+
    ctx->NewState |= _NEW_ARRAY;
    _mesa_reference_vao(ctx, &ctx->Array.VAO, newObj);
 
@@ -480,7 +448,7 @@ _mesa_DeleteVertexArrays(GLsizei n, const GLuint *ids)
    GLsizei i;
 
    if (n < 0) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteVertexArrayAPPLE(n)");
+      _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteVertexArray(n)");
       return;
    }
 
@@ -524,7 +492,7 @@ gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays)
    GLint i;
 
    if (n < 0) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glGenVertexArraysAPPLE");
+      _mesa_error(ctx, GL_INVALID_VALUE, "glGenVertexArrays");
       return;
    }
 
@@ -541,7 +509,7 @@ gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays)
 
       obj = (*ctx->Driver.NewArrayObject)( ctx, name );
       if (!obj) {
-         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenVertexArraysAPPLE");
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenVertexArrays");
          return;
       }
       save_array_object(ctx, obj);