*
* If we just upload the new data, however, the indices will be
* incorrect as we tend to upload each set of vertex data to a new
- * region.
+ * region.
*
* This file provides a helper to adjust the arrays, primitives and
* indices of a draw call so that it can be re-issued with a min_index
#define REBASE(TYPE) \
-static void *rebase_##TYPE( const void *ptr, \
- GLuint count, \
- TYPE min_index ) \
+static void *rebase_##TYPE(const void *ptr, \
+ unsigned count, \
+ TYPE min_index) \
{ \
- GLuint i; \
const TYPE *in = (TYPE *)ptr; \
TYPE *tmp_indices = malloc(count * sizeof(TYPE)); \
- \
+ \
if (tmp_indices == NULL) { \
_mesa_error_no_memory(__func__); \
return NULL; \
} \
- \
- for (i = 0; i < count; i++) \
+ \
+ for (unsigned i = 0; i < count; i++) \
tmp_indices[i] = in[i] - min_index; \
- \
+ \
return (void *)tmp_indices; \
}
-
REBASE(GLuint)
REBASE(GLushort)
REBASE(GLubyte)
-
/* Adjust primitives, indices and vertex definitions so that min_index
* becomes zero. There are lots of reasons for wanting to do this, eg:
*
* min_index will be transformed.
*
* Hardware tnl:
- * - if ib != NULL and min_index != 0, otherwise vertices lower than
+ * - if ib != NULL and min_index != 0, otherwise vertices lower than
* min_index will be uploaded. Requires adjusting index values.
*
* - if ib == NULL and min_index != 0, just for convenience so this doesn't
* - can't save time by trying to upload half a vbo - typically it is
* all or nothing.
*/
-void t_rebase_prims( struct gl_context *ctx,
- const struct tnl_vertex_array *arrays,
- const struct _mesa_prim *prim,
- GLuint nr_prims,
- const struct _mesa_index_buffer *ib,
- GLuint min_index,
- GLuint max_index,
- GLuint num_instances,
- GLuint base_instance,
- tnl_draw_func draw )
+void t_rebase_prims(struct gl_context *ctx,
+ const struct tnl_vertex_array *arrays,
+ const struct _mesa_prim *prim,
+ GLuint nr_prims,
+ const struct _mesa_index_buffer *ib,
+ GLuint min_index,
+ GLuint max_index,
+ GLuint num_instances,
+ GLuint base_instance,
+ tnl_draw_func draw)
{
struct gl_array_attributes tmp_attribs[VERT_ATTRIB_MAX];
struct tnl_vertex_array tmp_arrays[VERT_ATTRIB_MAX];
if (0)
printf("%s %d..%d\n", __func__, min_index, max_index);
-
/* XXX this path is disabled for now.
* There's rendering corruption in some apps when it's enabled.
*/
if (0 && ib && ctx->Extensions.ARB_draw_elements_base_vertex) {
- /* If we can just tell the hardware or the TNL to interpret our
- * indices with a different base, do so.
+ /* If we can just tell the hardware or the TNL to interpret our indices
+ * with a different base, do so.
*/
tmp_prims = malloc(sizeof(*prim) * nr_prims);
}
for (i = 0; i < nr_prims; i++) {
- tmp_prims[i] = prim[i];
- tmp_prims[i].basevertex -= min_index;
+ tmp_prims[i] = prim[i];
+ tmp_prims[i].basevertex -= min_index;
}
prim = tmp_prims;
} else
ptr = ib->ptr;
- /* Some users might prefer it if we translated elements to
- * GLuints here. Others wouldn't...
+ /* Some users might prefer it if we translated elements to GLuints here.
+ * Others wouldn't...
*/
switch (ib->index_size_shift) {
case 2:
- tmp_indices = rebase_GLuint( ptr, ib->count, min_index );
- break;
+ tmp_indices = rebase_GLuint( ptr, ib->count, min_index );
+ break;
case 1:
- tmp_indices = rebase_GLushort( ptr, ib->count, min_index );
- break;
+ tmp_indices = rebase_GLushort( ptr, ib->count, min_index );
+ break;
case 0:
- tmp_indices = rebase_GLubyte( ptr, ib->count, min_index );
- break;
- }
+ tmp_indices = rebase_GLubyte( ptr, ib->count, min_index );
+ break;
+ }
- if (map_ib)
- ctx->Driver.UnmapBuffer(ctx, ib->obj, MAP_INTERNAL);
+ if (map_ib)
+ ctx->Driver.UnmapBuffer(ctx, ib->obj, MAP_INTERNAL);
- if (tmp_indices == NULL) {
+ if (tmp_indices == NULL)
return;
- }
tmp_ib.obj = NULL;
tmp_ib.ptr = tmp_indices;
ib = &tmp_ib;
}
else {
- /* Otherwise the primitives need adjustment.
- */
+ /* Otherwise the primitives need adjustment. */
tmp_prims = malloc(sizeof(*prim) * nr_prims);
if (tmp_prims == NULL) {
}
for (i = 0; i < nr_prims; i++) {
- /* If this fails, it could indicate an application error:
- */
- assert(prim[i].start >= min_index);
+ /* If this fails, it could indicate an application error: */
+ assert(prim[i].start >= min_index);
- tmp_prims[i] = prim[i];
- tmp_prims[i].start -= min_index;
+ tmp_prims[i] = prim[i];
+ tmp_prims[i].start -= min_index;
}
prim = tmp_prims;
else
tmp_attribs[i].Ptr += min_index * arrays[i].BufferBinding->Stride;
}
-
- /* Re-issue the draw call.
- */
- draw( ctx,
- tmp_arrays,
- prim,
- nr_prims,
- ib,
- GL_TRUE,
- 0,
- max_index - min_index,
- num_instances, base_instance);
+
+ /* Re-issue the draw call. */
+ draw(ctx,
+ tmp_arrays,
+ prim,
+ nr_prims,
+ ib,
+ GL_TRUE,
+ 0,
+ max_index - min_index,
+ num_instances, base_instance);
free(tmp_indices);
-
free(tmp_prims);
}