*/
static uint32_t
add_vertex(struct vbo_save_context *save, struct hash_table *hash_to_index,
- uint32_t index, uint32_t base_index, fi_type *new_buffer,
- uint32_t *max_index)
+ uint32_t index, fi_type *new_buffer, uint32_t *max_index)
{
/* If vertex deduplication is disabled return the original index. */
if (!hash_to_index)
return index;
- fi_type *vert = save->buffer_map;
- /* Cancel the start_offset trick.
- * This way we get the correct offset in all cases (= start_offset being 0 or not).
- */
- vert += save->vertex_size * (index - base_index);
+ fi_type *vert = save->buffer_map + save->vertex_size * index;
struct vertex_key *key = malloc(sizeof(struct vertex_key));
key->vertex_size = save->vertex_size;
* starting at index 0.
*/
uint32_t n = _mesa_hash_table_num_entries(hash_to_index);
- *max_index = MAX2(n + base_index, *max_index);
+ *max_index = MAX2(n, *max_index);
memcpy(&new_buffer[save->vertex_size * n],
vert,
save->vertex_size * sizeof(fi_type));
- _mesa_hash_table_insert(hash_to_index, key, (void*)(uintptr_t)(n + base_index));
+ _mesa_hash_table_insert(hash_to_index, key, (void*)(uintptr_t)(n));
/* The index buffer is shared between list compilations, so add the base index to get
* the final index.
*/
- return n + base_index;
+ return n;
}
}
merge_prims(ctx, node->cold->prims, &node->cold->prim_count);
- /* Correct the primitive starts, we can only do this here as copy_vertices
- * and convert_line_loop_to_strip above consume the uncorrected starts.
- * On the other hand the _vbo_loopback_vertex_list call below needs the
- * primitves to be corrected already.
- */
- for (unsigned i = 0; i < node->cold->prim_count; i++) {
- node->cold->prims[i].start += start_offset;
- }
-
/* Create an index buffer. */
node->cold->min_index = node->cold->max_index = 0;
if (save->vert_count == 0 || save->prim_count == 0)
indices[idx] = indices[idx - 1];
indices[idx + 1] = add_vertex(save, vertex_to_index, original_prims[i].start,
- start_offset, temp_vertices_buffer, &max_index);
+ temp_vertices_buffer, &max_index);
idx += 2;
merged_prims[last_valid_prim].count += 2;
if (tri_count % 2) {
/* Add another index to preserve winding order */
indices[idx++] = add_vertex(save, vertex_to_index, original_prims[i].start,
- start_offset, temp_vertices_buffer, &max_index);
+ temp_vertices_buffer, &max_index);
merged_prims[last_valid_prim].count++;
}
}
original_prims[i + 1].mode == GL_LINES)))) {
for (unsigned j = 0; j < vertex_count; j++) {
indices[idx++] = add_vertex(save, vertex_to_index, original_prims[i].start + j,
- start_offset, temp_vertices_buffer, &max_index);
+ temp_vertices_buffer, &max_index);
/* Repeat all but the first/last indices. */
if (j && j != vertex_count - 1) {
indices[idx++] = add_vertex(save, vertex_to_index, original_prims[i].start + j,
- start_offset, temp_vertices_buffer, &max_index);
+ temp_vertices_buffer, &max_index);
}
}
} else {
for (unsigned j = 0; j < vertex_count; j++) {
indices[idx++] = add_vertex(save, vertex_to_index, original_prims[i].start + j,
- start_offset, temp_vertices_buffer, &max_index);
+ temp_vertices_buffer, &max_index);
}
}
node->cold->ib.count = idx;
node->cold->ib.index_size_shift = (GL_UNSIGNED_INT - GL_UNSIGNED_BYTE) >> 1;
+ /* Correct the primitive starts, we can only do this here as copy_vertices
+ * and convert_line_loop_to_strip above consume the uncorrected starts.
+ * On the other hand the _vbo_loopback_vertex_list call below needs the
+ * primitives to be corrected already.
+ */
+ for (unsigned i = 0; i < node->cold->prim_count; i++) {
+ node->cold->prims[i].start += start_offset;
+ }
+ /* start_offset shifts vertices (so v[0] becomes v[start_offset]), so we have
+ * to apply this transformation to all indices and max_index.
+ */
+ for (unsigned i = 0; i < idx; i++)
+ indices[i] += start_offset;
+ max_index += start_offset;
+
if (!indices_offset) {
/* Allocate a new index buffer */
_mesa_reference_buffer_object(ctx, &save->previous_ib, NULL);