- for (attr = 0; attr < VERT_ATTRIB_MAX ; attr++) {
- const GLuint src = map[attr];
-
- if (exec->vtx.attrsz[src]) {
- GLsizeiptr offset = (GLbyte *)exec->vtx.attrptr[src] -
- (GLbyte *)exec->vtx.vertex;
-
- /* override the default array set above */
- assert(attr < Elements(exec->vtx.inputs));
- assert(attr < Elements(exec->vtx.arrays)); /* arrays[] */
- exec->vtx.inputs[attr] = &arrays[attr];
-
- if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
- /* a real buffer obj: Ptr is an offset, not a pointer*/
- assert(exec->vtx.bufferobj->Mappings[MAP_INTERNAL].Pointer);
- assert(offset >= 0);
- arrays[attr].Ptr = (GLubyte *)
- exec->vtx.bufferobj->Mappings[MAP_INTERNAL].Offset + offset;
- }
- else {
- /* Ptr into ordinary app memory */
- arrays[attr].Ptr = (GLubyte *)exec->vtx.buffer_map + offset;
- }
- arrays[attr].Size = exec->vtx.attrsz[src];
- arrays[attr].StrideB = exec->vtx.vertex_size * sizeof(GLfloat);
- arrays[attr].Stride = exec->vtx.vertex_size * sizeof(GLfloat);
- arrays[attr].Type = exec->vtx.attrtype[src];
- arrays[attr].Integer =
- vbo_attrtype_to_integer_flag(exec->vtx.attrtype[src]);
- arrays[attr].Format = GL_RGBA;
- arrays[attr].Enabled = 1;
- arrays[attr]._ElementSize = arrays[attr].Size * sizeof(GLfloat);
- _mesa_reference_buffer_object(ctx,
- &arrays[attr].BufferObj,
- exec->vtx.bufferobj);
-
- varying_inputs |= VERT_BIT(attr);
- }
+ const gl_vertex_processing_mode mode = ctx->VertexProgram._VPMode;
+
+ /* Compute the bitmasks of vao_enabled arrays */
+ GLbitfield vao_enabled = _vbo_get_vao_enabled_from_vbo(mode, exec->vtx.enabled);
+
+ /* At first disable arrays no longer needed */
+ _mesa_disable_vertex_array_attribs(ctx, vao, VERT_BIT_ALL & ~vao_enabled);
+ assert((~vao_enabled & vao->Enabled) == 0);
+
+ /* Bind the buffer object */
+ const GLuint stride = exec->vtx.vertex_size*sizeof(GLfloat);
+ _mesa_bind_vertex_buffer(ctx, vao, 0, exec->vtx.bufferobj, buffer_offset,
+ stride);
+
+ /* Retrieve the mapping from VBO_ATTRIB to VERT_ATTRIB space
+ * Note that the position/generic0 aliasing is done in the VAO.
+ */
+ const GLubyte *const vao_to_vbo_map = _vbo_attribute_alias_map[mode];
+ /* Now set the enabled arrays */
+ GLbitfield mask = vao_enabled;
+ while (mask) {
+ const int vao_attr = u_bit_scan(&mask);
+ const GLubyte vbo_attr = vao_to_vbo_map[vao_attr];
+
+ const GLubyte size = exec->vtx.attr[vbo_attr].size;
+ const GLenum16 type = exec->vtx.attr[vbo_attr].type;
+ const GLuint offset = (GLuint)((GLbyte *)exec->vtx.attrptr[vbo_attr] -
+ (GLbyte *)exec->vtx.vertex);
+ assert(offset <= ctx->Const.MaxVertexAttribRelativeOffset);
+
+ /* Set and enable */
+ _vbo_set_attrib_format(ctx, vao, vao_attr, buffer_offset,
+ size, type, offset);
+
+ /* The vao is initially created with all bindings set to 0. */
+ assert(vao->VertexAttrib[vao_attr].BufferBindingIndex == 0);