#include "mtypes.h"
#include "varray.h"
#include "main/dispatch.h"
+#include "util/bitscan.h"
/**
/**
* Allocate and initialize a new vertex array object.
- *
- * This function is intended to be called via
- * \c dd_function_table::NewArrayObject.
*/
struct gl_vertex_array_object *
_mesa_new_vao(struct gl_context *ctx, GLuint name)
/**
* Delete an array object.
- *
- * This function is intended to be called via
- * \c dd_function_table::DeleteArrayObject.
*/
void
_mesa_delete_vao(struct gl_context *ctx, struct gl_vertex_array_object *obj)
mtx_lock(&oldObj->Mutex);
assert(oldObj->RefCount > 0);
oldObj->RefCount--;
-#if 0
- printf("ArrayObj %p %d DECR to %d\n",
- (void *) oldObj, oldObj->Name, oldObj->RefCount);
-#endif
deleteFlag = (oldObj->RefCount == 0);
mtx_unlock(&oldObj->Mutex);
- if (deleteFlag) {
- assert(ctx->Driver.DeleteArrayObject);
- ctx->Driver.DeleteArrayObject(ctx, oldObj);
- }
+ if (deleteFlag)
+ _mesa_delete_vao(ctx, oldObj);
*ptr = NULL;
}
}
else {
vao->RefCount++;
-#if 0
- printf("ArrayObj %p %d INCR to %d\n",
- (void *) vao, vao->Name, vao->RefCount);
-#endif
*ptr = vao;
}
mtx_unlock(&vao->Mutex);
}
-
+/**
+ * Initialize attribtes of a vertex array within a vertex array object.
+ * \param vao the container vertex array object
+ * \param index which array in the VAO to initialize
+ * \param size number of components (1, 2, 3 or 4) per attribute
+ * \param type datatype of the attribute (GL_FLOAT, GL_INT, etc).
+ */
static void
init_array(struct gl_context *ctx,
- struct gl_vertex_array_object *obj, GLuint index, GLint size, GLint type)
+ struct gl_vertex_array_object *vao,
+ GLuint index, GLint size, GLint type)
{
- struct gl_vertex_attrib_array *array = &obj->VertexAttrib[index];
- struct gl_vertex_buffer_binding *binding = &obj->VertexBinding[index];
+ struct gl_vertex_attrib_array *array = &vao->VertexAttrib[index];
+ struct gl_vertex_buffer_binding *binding = &vao->VertexBinding[index];
array->Size = size;
array->Type = type;
array->Integer = GL_FALSE;
array->Doubles = GL_FALSE;
array->_ElementSize = size * _mesa_sizeof_type(type);
- array->VertexBinding = index;
+ array->BufferBindingIndex = index;
binding->Offset = 0;
binding->Stride = array->_ElementSize;
*/
void
_mesa_initialize_vao(struct gl_context *ctx,
- struct gl_vertex_array_object *obj,
+ struct gl_vertex_array_object *vao,
GLuint name)
{
GLuint i;
- obj->Name = name;
+ vao->Name = name;
- mtx_init(&obj->Mutex, mtx_plain);
- obj->RefCount = 1;
+ mtx_init(&vao->Mutex, mtx_plain);
+ vao->RefCount = 1;
/* Init the individual arrays */
- for (i = 0; i < ARRAY_SIZE(obj->VertexAttrib); i++) {
+ for (i = 0; i < ARRAY_SIZE(vao->VertexAttrib); i++) {
switch (i) {
case VERT_ATTRIB_WEIGHT:
- init_array(ctx, obj, VERT_ATTRIB_WEIGHT, 1, GL_FLOAT);
+ init_array(ctx, vao, VERT_ATTRIB_WEIGHT, 1, GL_FLOAT);
break;
case VERT_ATTRIB_NORMAL:
- init_array(ctx, obj, VERT_ATTRIB_NORMAL, 3, GL_FLOAT);
+ init_array(ctx, vao, VERT_ATTRIB_NORMAL, 3, GL_FLOAT);
break;
case VERT_ATTRIB_COLOR1:
- init_array(ctx, obj, VERT_ATTRIB_COLOR1, 3, GL_FLOAT);
+ init_array(ctx, vao, VERT_ATTRIB_COLOR1, 3, GL_FLOAT);
break;
case VERT_ATTRIB_FOG:
- init_array(ctx, obj, VERT_ATTRIB_FOG, 1, GL_FLOAT);
+ init_array(ctx, vao, VERT_ATTRIB_FOG, 1, GL_FLOAT);
break;
case VERT_ATTRIB_COLOR_INDEX:
- init_array(ctx, obj, VERT_ATTRIB_COLOR_INDEX, 1, GL_FLOAT);
+ init_array(ctx, vao, VERT_ATTRIB_COLOR_INDEX, 1, GL_FLOAT);
break;
case VERT_ATTRIB_EDGEFLAG:
- init_array(ctx, obj, VERT_ATTRIB_EDGEFLAG, 1, GL_BOOL);
+ init_array(ctx, vao, VERT_ATTRIB_EDGEFLAG, 1, GL_BOOL);
break;
case VERT_ATTRIB_POINT_SIZE:
- init_array(ctx, obj, VERT_ATTRIB_POINT_SIZE, 1, GL_FLOAT);
+ init_array(ctx, vao, VERT_ATTRIB_POINT_SIZE, 1, GL_FLOAT);
break;
default:
- init_array(ctx, obj, i, 4, GL_FLOAT);
+ init_array(ctx, vao, i, 4, GL_FLOAT);
break;
}
}
- _mesa_reference_buffer_object(ctx, &obj->IndexBufferObj,
+ _mesa_reference_buffer_object(ctx, &vao->IndexBufferObj,
ctx->Shared->NullBufferObj);
}
* Add the given array object to the array object pool.
*/
static void
-save_array_object( struct gl_context *ctx, struct gl_vertex_array_object *obj )
+save_array_object(struct gl_context *ctx, struct gl_vertex_array_object *vao)
{
- if (obj->Name > 0) {
+ if (vao->Name > 0) {
/* insert into hash table */
- _mesa_HashInsert(ctx->Array.Objects, obj->Name, obj);
+ _mesa_HashInsert(ctx->Array.Objects, vao->Name, vao);
}
}
* Do not deallocate the array object though.
*/
static void
-remove_array_object( struct gl_context *ctx, struct gl_vertex_array_object *obj )
+remove_array_object(struct gl_context *ctx, struct gl_vertex_array_object *vao)
{
- if (obj->Name > 0) {
+ if (vao->Name > 0) {
/* remove from hash table */
- _mesa_HashRemove(ctx->Array.Objects, obj->Name);
+ _mesa_HashRemove(ctx->Array.Objects, vao->Name);
}
}
GLbitfield64 arrays = vao->NewArrays;
while (arrays) {
+ const int attrib = u_bit_scan64(&arrays);
+
struct gl_client_array *client_array;
struct gl_vertex_attrib_array *attrib_array;
struct gl_vertex_buffer_binding *buffer_binding;
- GLint attrib = ffsll(arrays) - 1;
- arrays ^= BITFIELD64_BIT(attrib);
-
attrib_array = &vao->VertexAttrib[attrib];
- buffer_binding = &vao->VertexBinding[attrib_array->VertexBinding];
+ buffer_binding = &vao->VertexBinding[attrib_array->BufferBindingIndex];
client_array = &vao->_VertexAttrib[attrib];
_mesa_update_client_array(ctx, client_array, attrib_array,
}
+bool
+_mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao)
+{
+ /* Walk those enabled arrays that have the default vbo attached */
+ GLbitfield64 mask = vao->_Enabled & ~vao->VertexAttribBufferMask;
+
+ while (mask) {
+ /* Do not use u_bit_scan64 as we can walk multiple
+ * attrib arrays at once
+ */
+ const int i = ffsll(mask) - 1;
+ const struct gl_vertex_attrib_array *attrib_array =
+ &vao->VertexAttrib[i];
+ const struct gl_vertex_buffer_binding *buffer_binding =
+ &vao->VertexBinding[attrib_array->BufferBindingIndex];
+
+ /* Only enabled arrays shall appear in the _Enabled bitmask */
+ assert(attrib_array->Enabled);
+ /* We have already masked out vao->VertexAttribBufferMask */
+ assert(!_mesa_is_bufferobj(buffer_binding->BufferObj));
+
+ /* Bail out once we find the first non vbo with a non zero stride */
+ if (buffer_binding->Stride != 0)
+ return false;
+
+ /* Note that we cannot use the xor variant since the _BoundArray mask
+ * may contain array attributes that are bound but not enabled.
+ */
+ mask &= ~buffer_binding->_BoundArrays;
+ }
+
+ return true;
+}
+
+bool
+_mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao)
+{
+ /* Walk the enabled arrays that have a vbo attached */
+ GLbitfield64 mask = vao->_Enabled & vao->VertexAttribBufferMask;
+
+ while (mask) {
+ const int i = ffsll(mask) - 1;
+ const struct gl_vertex_attrib_array *attrib_array =
+ &vao->VertexAttrib[i];
+ const struct gl_vertex_buffer_binding *buffer_binding =
+ &vao->VertexBinding[attrib_array->BufferBindingIndex];
+
+ /* Only enabled arrays shall appear in the _Enabled bitmask */
+ assert(attrib_array->Enabled);
+ /* We have already masked with vao->VertexAttribBufferMask */
+ assert(_mesa_is_bufferobj(buffer_binding->BufferObj));
+
+ /* Bail out once we find the first disallowed mapping */
+ if (_mesa_check_disallowed_mapping(buffer_binding->BufferObj))
+ return false;
+
+ /* We have handled everything that is bound to this buffer_binding. */
+ mask &= ~buffer_binding->_BoundArrays;
+ }
+
+ return true;
+}
+
/**********************************************************************/
/* API Functions */
/**********************************************************************/
}
/* For APPLE version, generate a new array object now */
- newObj = (*ctx->Driver.NewArrayObject)(ctx, id);
+ newObj = _mesa_new_vao(ctx, id);
if (!newObj) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindVertexArrayAPPLE");
return;
ctx->NewState |= _NEW_ARRAY;
_mesa_reference_vao(ctx, &ctx->Array.VAO, newObj);
-
- /* Pass BindVertexArray call to device driver */
- if (ctx->Driver.BindArrayObject && newObj)
- ctx->Driver.BindArrayObject(ctx, newObj);
}
struct gl_vertex_array_object *obj;
GLuint name = first + i;
- obj = (*ctx->Driver.NewArrayObject)( ctx, name );
+ obj = _mesa_new_vao(ctx, name);
if (!obj) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
return;
_mesa_CreateVertexArrays(GLsizei n, GLuint *arrays)
{
GET_CURRENT_CONTEXT(ctx);
-
- if (!ctx->Extensions.ARB_direct_state_access) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCreateVertexArrays(GL_ARB_direct_state_access "
- "is not supported");
- return;
- }
-
gen_vertex_arrays(ctx, n, arrays, true, "glCreateVertexArrays");
}
struct gl_vertex_array_object *vao;
struct gl_buffer_object *bufObj;
- if (!ctx->Extensions.ARB_direct_state_access) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glVertexArrayElementBuffer(GL_ARB_direct_state_access "
- "is not supported");
- return;
- }
-
ASSERT_OUTSIDE_BEGIN_END(ctx);
/* The GL_ARB_direct_state_access specification says:
ASSERT_OUTSIDE_BEGIN_END(ctx);
- if (!ctx->Extensions.ARB_direct_state_access) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetVertexArrayiv(GL_ARB_direct_state_access "
- "is not supported");
- return;
- }
-
/* The GL_ARB_direct_state_access specification says:
*
* "An INVALID_OPERATION error is generated if <vaobj> is not