TNLcontext *tnl = TNL_CONTEXT(ctx);
struct tnl_clipspace *vtx = &tnl->clipspace;
static struct tnl_attr_map map[NUM_VERTEX_ATTRS];
- int fields, i, n = 0;
+ int fields, attr, i, n = 0;
render->mode = VBO;
render->attr_count = NUM_VERTEX_ATTRS;
_tnl_install_attrs(ctx, map, n, NULL, 0);
- for (i = 0; i < vtx->attr_count; i++) {
- struct tnl_clipspace_attr *ta = &vtx->attr[i];
- struct nouveau_array_state *a = &render->attrs[ta->attrib];
-
- a->stride = vtx->vertex_size;
- a->offset = ta->vertoffset;
- }
+ FOR_EACH_BOUND_ATTR(render, i, attr)
+ render->attrs[attr].stride = vtx->vertex_size;
TAG(render_set_format)(ctx);
}
swtnl_unbind_vertices(struct gl_context *ctx)
{
struct nouveau_render_state *render = to_render_state(ctx);
- int i;
+ int i, attr;
- for (i = 0; i < render->attr_count; i++) {
- int *attr = &render->map[i];
-
- if (*attr >= 0) {
- nouveau_bo_ref(NULL, &render->attrs[*attr].bo);
- *attr = -1;
- }
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ nouveau_bo_ref(NULL, &render->attrs[attr].bo);
+ render->map[i] = -1;
}
render->attr_count = 0;
const struct gl_client_array **arrays)
{
struct nouveau_render_state *render = to_render_state(ctx);
- int i;
+ GLboolean imm = (render->mode == IMM);
+ int i, attr;
if (ib)
vbo_init_array(&render->ib, 0, 0, ib->count, ib->type,
ib->obj, ib->ptr, GL_TRUE);
- for (i = 0; i < render->attr_count; i++) {
- int attr = render->map[i];
-
- if (attr >= 0) {
- const struct gl_client_array *array = arrays[attr];
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ const struct gl_client_array *array = arrays[attr];
- vbo_init_array(&render->attrs[attr], attr,
- get_array_stride(ctx, array),
- array->Size, array->Type,
- array->BufferObj, array->Ptr,
- render->mode == IMM);
- }
+ vbo_init_array(&render->attrs[attr], attr,
+ get_array_stride(ctx, array),
+ array->Size, array->Type,
+ array->BufferObj,
+ array->Ptr, imm);
}
}
static void
vbo_deinit_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
- const struct gl_client_array **arrays)
+ const struct gl_client_array **arrays)
{
struct nouveau_render_state *render = to_render_state(ctx);
- int i;
+ int i, attr;
if (ib)
vbo_deinit_array(&render->ib);
- for (i = 0; i < render->attr_count; i++) {
- int *attr = &render->map[i];
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ struct nouveau_array_state *a = &render->attrs[attr];
- if (*attr >= 0) {
- vbo_deinit_array(&render->attrs[*attr]);
- *attr = -1;
- }
+ vbo_deinit_array(a);
+ render->map[i] = -1;
}
render->attr_count = 0;
}
}
}
-
- if (render->mode == VBO)
- render->attr_count = NUM_VERTEX_ATTRS;
- else
- render->attr_count = 0;
}
static void
if (render->mode == VBO) {
render->map[info->vbo_index] = attr;
render->vertex_size += array->_ElementSize;
+ render->attr_count = MAX2(render->attr_count,
+ info->vbo_index + 1);
} else {
render->map[render->attr_count++] = attr;
render->vertex_size += 4 * info->imm_fields;
}
+
}
}
/* Reset the vertex size. */
render->vertex_size = 0;
+ render->attr_count = 0;
vbo_emit_attr(ctx, arrays, VERT_ATTRIB_COLOR0);
if (ctx->Fog.ColorSumEnabled && !ctx->Light.Enabled)
get_max_client_stride(struct gl_context *ctx, const struct gl_client_array **arrays)
{
struct nouveau_render_state *render = to_render_state(ctx);
- int i, s = 0;
+ int i, attr, s = 0;
- for (i = 0; i < render->attr_count; i++) {
- int attr = render->map[i];
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ const struct gl_client_array *a = arrays[attr];
- if (attr >= 0) {
- const struct gl_client_array *a = arrays[attr];
-
- if (!_mesa_is_bufferobj(a->BufferObj))
- s = MAX2(s, get_array_stride(ctx, a));
- }
+ if (!_mesa_is_bufferobj(a->BufferObj))
+ s = MAX2(s, get_array_stride(ctx, a));
}
return s;
GLint basevertex, GLuint min_index, GLuint max_index)
{
struct nouveau_render_state *render = to_render_state(ctx);
- int i;
+ int i, attr;
- for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
- int attr = render->map[i];
-
- if (attr >= 0) {
- const struct gl_client_array *array = arrays[attr];
- struct nouveau_array_state *a = &render->attrs[attr];
- unsigned delta = (basevertex + min_index)
- * array->StrideB;
-
- if (a->bo) {
- /* Array in a buffer obj. */
- a->offset = (intptr_t)array->Ptr + delta;
- } else {
- int j, n = max_index - min_index + 1;
- char *sp = (char *)array->Ptr + delta;
- char *dp = nouveau_get_scratch(
- ctx, n * a->stride, &a->bo, &a->offset);
-
- /* Array in client memory, move it to
- * a scratch buffer obj. */
- for (j = 0; j < n; j++)
- memcpy(dp + j * a->stride,
- sp + j * array->StrideB,
- a->stride);
- }
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ const struct gl_client_array *array = arrays[attr];
+ struct nouveau_array_state *a = &render->attrs[attr];
+ unsigned delta = (basevertex + min_index)
+ * array->StrideB;
+
+ if (a->bo) {
+ /* Array in a buffer obj. */
+ a->offset = (intptr_t)array->Ptr + delta;
+ } else {
+ int j, n = max_index - min_index + 1;
+ char *sp = (char *)array->Ptr + delta;
+ char *dp = nouveau_get_scratch(
+ ctx, n * a->stride, &a->bo, &a->offset);
+
+ /* Array in client memory, move it to
+ * a scratch buffer obj. */
+ for (j = 0; j < n; j++)
+ memcpy(dp + j * a->stride,
+ sp + j * array->StrideB,
+ a->stride);
}
}
struct nouveau_render_state *render = to_render_state(ctx);
struct nouveau_channel *chan = context_chan(ctx);
extract_u_t extract = ib ? render->ib.extract_u : extract_id;
- int i, j, k;
+ int i, j, k, attr;
RENDER_LOCALS(ctx);
for (i = 0; i < nr_prims; i++) {
j = prims[i].basevertex +
extract(&render->ib, 0, start);
- for (k = 0; k < render->attr_count; k++)
- EMIT_IMM(ctx, &render->attrs[render->map[k]],
- j);
+ FOR_EACH_BOUND_ATTR(render, k, attr)
+ EMIT_IMM(ctx, &render->attrs[attr], j);
}
BATCH_END();
struct nouveau_render_state *render = to_render_state(ctx);
struct nouveau_channel *chan = context_chan(ctx);
struct nouveau_grobj *celsius = context_eng3d(ctx);
- int i, hw_format;
-
- for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
- int attr = render->map[i];
+ int i, attr, hw_format;
+ FOR_EACH_ATTR(render, i, attr) {
if (attr >= 0) {
struct nouveau_array_state *a = &render->attrs[attr];
struct nouveau_bo_context *bctx = context_bctx(ctx, VERTEX);
struct nouveau_channel *chan = context_chan(ctx);
struct nouveau_grobj *celsius = context_eng3d(ctx);
- int i;
+ int i, attr;
- for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
- int attr = render->map[i];
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ struct nouveau_array_state *a = &render->attrs[attr];
- if (attr >= 0) {
- struct nouveau_array_state *a = &render->attrs[attr];
-
- nouveau_bo_markl(bctx, celsius,
- NV10TCL_VTXBUF_ADDRESS(i),
- a->bo, a->offset,
- NOUVEAU_BO_GART | NOUVEAU_BO_RD);
- }
+ nouveau_bo_markl(bctx, celsius,
+ NV10TCL_VTXBUF_ADDRESS(i),
+ a->bo, a->offset,
+ NOUVEAU_BO_GART | NOUVEAU_BO_RD);
}
BEGIN_RING(chan, celsius, NV10TCL_VERTEX_ARRAY_VALIDATE, 1);
struct nouveau_render_state *render = to_render_state(ctx);
struct nouveau_channel *chan = context_chan(ctx);
struct nouveau_grobj *kelvin = context_eng3d(ctx);
- int i, hw_format;
-
- for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
- int attr = render->map[i];
+ int i, attr, hw_format;
+ FOR_EACH_ATTR(render, i, attr) {
if (attr >= 0) {
struct nouveau_array_state *a = &render->attrs[attr];
struct nouveau_bo_context *bctx = context_bctx(ctx, VERTEX);
struct nouveau_channel *chan = context_chan(ctx);
struct nouveau_grobj *kelvin = context_eng3d(ctx);
- int i;
+ int i, attr;
- for (i = 0; i < NUM_VERTEX_ATTRS; i++) {
- int attr = render->map[i];
+ FOR_EACH_BOUND_ATTR(render, i, attr) {
+ struct nouveau_array_state *a = &render->attrs[attr];
- if (attr >= 0) {
- struct nouveau_array_state *a = &render->attrs[attr];
-
- nouveau_bo_mark(bctx, kelvin,
- NV20TCL_VTXBUF_ADDRESS(i),
- a->bo, a->offset, 0,
- 0, NV20TCL_VTXBUF_ADDRESS_DMA1,
- NOUVEAU_BO_LOW | NOUVEAU_BO_OR |
- NOUVEAU_BO_GART | NOUVEAU_BO_RD);
- }
+ nouveau_bo_mark(bctx, kelvin,
+ NV20TCL_VTXBUF_ADDRESS(i),
+ a->bo, a->offset, 0,
+ 0, NV20TCL_VTXBUF_ADDRESS_DMA1,
+ NOUVEAU_BO_LOW | NOUVEAU_BO_OR |
+ NOUVEAU_BO_GART | NOUVEAU_BO_RD);
}
BEGIN_RING(chan, kelvin, NV20TCL_VTX_CACHE_INVALIDATE, 1);