Merge branch 'mesa_7_5_branch'
[mesa.git] / src / mesa / vbo / vbo_context.c
index 60d0b76ab622f0d5ccfa703b04d02c7ec5af11ad..75c32e0b9bedb89c58454ee0984986804af66998 100644 (file)
@@ -28,6 +28,8 @@
 #include "main/imports.h"
 #include "main/mtypes.h"
 #include "main/api_arrayelt.h"
+#include "main/bufferobj.h"
+#include "math/m_eval.h"
 #include "vbo.h"
 #include "vbo_context.h"
 
@@ -78,8 +80,10 @@ static void init_legacy_currval(GLcontext *ctx)
       cl->StrideB = 0;
       cl->Enabled = 1;
       cl->Type = GL_FLOAT;
+      cl->Format = GL_RGBA;
       cl->Ptr = (const void *)ctx->Current.Attrib[i];
-      cl->BufferObj = ctx->Array.NullBufferObj;
+      _mesa_reference_buffer_object(ctx, &cl->BufferObj,
+                                    ctx->Shared->NullBufferObj);
    }
 }
 
@@ -99,11 +103,13 @@ static void init_generic_currval(GLcontext *ctx)
        */
       cl->Size = 1;
       cl->Type = GL_FLOAT;
+      cl->Format = GL_RGBA;
       cl->Ptr = (const void *)ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + i];
       cl->Stride = 0;
       cl->StrideB = 0;
       cl->Enabled = 1;
-      cl->BufferObj = ctx->Array.NullBufferObj;
+      _mesa_reference_buffer_object(ctx, &cl->BufferObj,
+                                    ctx->Shared->NullBufferObj);
    }
 }
 
@@ -114,6 +120,8 @@ static void init_mat_currval(GLcontext *ctx)
    struct gl_client_array *arrays = vbo->mat_currval;
    GLuint i;
 
+   ASSERT(NR_MAT_ATTRIBS == MAT_ATTRIB_MAX);
+
    memset(arrays, 0, sizeof(*arrays) * NR_MAT_ATTRIBS);
 
    /* Set up a constant (StrideB == 0) array for each current
@@ -139,16 +147,14 @@ static void init_mat_currval(GLcontext *ctx)
         break;
       }
 
-      if (i < MAT_ATTRIB_MAX)
-        cl->Ptr = (const void *)ctx->Light.Material.Attrib[i];
-      else 
-        cl->Ptr = (const void *)ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + i];
-
+      cl->Ptr = (const void *)ctx->Light.Material.Attrib[i];
       cl->Type = GL_FLOAT;
+      cl->Format = GL_RGBA;
       cl->Stride = 0;
       cl->StrideB = 0;
       cl->Enabled = 1;
-      cl->BufferObj = ctx->Array.NullBufferObj;
+      _mesa_reference_buffer_object(ctx, &cl->BufferObj,
+                                    ctx->Shared->NullBufferObj);
    }
 }
 
@@ -209,7 +215,7 @@ GLboolean _vbo_CreateContext( GLcontext *ctx )
       for (i = 0; i < 4; i++)
         vbo->map_vp_none[28+i] = i;    
       
-      for (i = 0; i < VERT_ATTRIB_MAX; i++)
+      for (i = 0; i < Elements(vbo->map_vp_arb); i++)
         vbo->map_vp_arb[i] = i;
    }
 
@@ -225,9 +231,12 @@ GLboolean _vbo_CreateContext( GLcontext *ctx )
     * vtxfmt mechanism can be removed now.
     */
    vbo_exec_init( ctx );
+#if FEATURE_dlist
    vbo_save_init( ctx );
+#endif
+
+   _math_init_eval();
 
-   
    return GL_TRUE;
 }
 
@@ -245,9 +254,14 @@ void _vbo_DestroyContext( GLcontext *ctx )
       ctx->aelt_context = NULL;
    }
 
-   vbo_exec_destroy(ctx);
-   FREE(vbo_context(ctx));
-   ctx->swtnl_im = NULL;
+   if (vbo_context(ctx)) {
+      vbo_exec_destroy(ctx);
+#if FEATURE_dlist
+      vbo_save_destroy(ctx);
+#endif
+      FREE(vbo_context(ctx));
+      ctx->swtnl_im = NULL;
+   }
 }