static void update_array(struct st_context *st) { struct gl_context *ctx = st->ctx; const struct gl_client_array **arrays = ctx->Array._DrawArrays; const struct st_vertex_program *vp; const struct st_vp_variant *vpv; struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS]; struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; unsigned num_vbuffers, num_velements; st->vertex_array_out_of_memory = FALSE; /* No drawing has been done yet, so do nothing. */ if (!arrays) return; /* vertex program validation must be done before this */ vp = st->vp; vpv = st->vp_variant; memset(velements, 0, sizeof(struct pipe_vertex_element) * vpv->num_inputs); /* * Setup the vbuffer[] and velements[] arrays. */ if (is_interleaved_arrays(vp, vpv, arrays)) { if (!setup_interleaved_attribs(vp, vpv, arrays, vbuffer, velements)) { st->vertex_array_out_of_memory = TRUE; return; } num_vbuffers = 1; num_velements = vpv->num_inputs; if (num_velements == 0) num_vbuffers = 0; } else { if (!setup_non_interleaved_attribs(st, vp, vpv, arrays, vbuffer, velements)) { st->vertex_array_out_of_memory = TRUE; return; } num_vbuffers = vpv->num_inputs; num_velements = vpv->num_inputs; } cso_set_vertex_buffers(st->cso_context, 0, num_vbuffers, vbuffer); if (st->last_num_vbuffers > num_vbuffers) { /* Unbind remaining buffers, if any. */ cso_set_vertex_buffers(st->cso_context, num_vbuffers, st->last_num_vbuffers - num_vbuffers, NULL); } st->last_num_vbuffers = num_vbuffers; cso_set_vertex_elements(st->cso_context, num_velements, velements); }
/** * Setup vertex arrays and buffers prior to drawing. * \return GL_TRUE for success, GL_FALSE otherwise (probably out of memory) */ static GLboolean st_validate_varrays(struct gl_context *ctx, const struct gl_client_array **arrays) { struct st_context *st = st_context(ctx); const struct st_vertex_program *vp; const struct st_vp_variant *vpv; struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS]; struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; unsigned num_vbuffers, num_velements; /* must get these after state validation! */ vp = st->vp; vpv = st->vp_variant; memset(velements, 0, sizeof(struct pipe_vertex_element) * vpv->num_inputs); /* * Setup the vbuffer[] and velements[] arrays. */ if (is_interleaved_arrays(vp, vpv, arrays)) { if (!setup_interleaved_attribs(ctx, vp, vpv, arrays, vbuffer, velements)) { return GL_FALSE; } num_vbuffers = 1; num_velements = vpv->num_inputs; if (num_velements == 0) num_vbuffers = 0; } else { if (!setup_non_interleaved_attribs(ctx, vp, vpv, arrays, vbuffer, velements)) { return GL_FALSE; } num_vbuffers = vpv->num_inputs; num_velements = vpv->num_inputs; } cso_set_vertex_buffers(st->cso_context, num_vbuffers, vbuffer); cso_set_vertex_elements(st->cso_context, num_velements, velements); return GL_TRUE; }