[vbo indices] tweak add_indices api to return an id and add delete_indices api

Originally cogl_vertex_buffer_add_indices let the user pass in their own unique
ID for the indices; now the Id is generated internally and returned to the
caller.
This commit is contained in:
Robert Bragg 2009-05-26 16:27:36 +01:00
parent e4d820b75d
commit 1669fd7332
3 changed files with 57 additions and 26 deletions

View File

@ -305,8 +305,6 @@ typedef enum _CoglIndicesType
/**
* cogl_vertex_buffer_add_indices:
* @handle: A vertex buffer handle
* @id: Any unique number. It's used to identify the indices when you later
* call cogl_vertex_buffer_draw_elements()
* @min_index: Specifies the minimum vertex index contained in indices
* @max_index: Specifies the maximum vertex index contained in indices
* @indices_type: a #CoglIndicesType specifying the data type used for
@ -319,20 +317,36 @@ typedef enum _CoglIndicesType
* array allows you to reference vertices multiple times, for example
* during triangle strips.
*
* You should aim to use the COGL_INDICES_TYPE_UNSIGNED_SHORT when possible
* and correctly reflect the range of index values in the {min,max}_index
* arguments. This allows Cogl to optimize the internal storage used for
* the indices and reduce the demand for memory bandwidth.
* You should aim to use the smallest data type possible and correctly reflect
* the range of index values in the {min,max}_index arguments. This allows Cogl
* to optimize the internal storage used for the indices and reduce the demand
* for memory bandwidth.
*
* Returns: An identifier (greater than 0) for the indices which you can
* pass to cogl_vertex_buffer_draw_elements().
*/
void
int
cogl_vertex_buffer_add_indices (CoglHandle handle,
int id,
int min_index,
int max_index,
CoglIndicesType indices_type,
const void *indices_array,
int indices_len);
/**
* cogl_vertex_buffer_delete_indices:
* @handle: A vertex buffer handle
* @indices_id: The identifier for a an array of indices previously added to
* the given Cogl vertex buffer using
* cogl_vertex_buffer_add_indices().
*
* Frees the resources associated with a previously added array of vertex
* indices.
*/
void
cogl_vertex_buffer_delete_indices (CoglHandle handle,
int indices_id);
/**
* cogl_vertex_buffer_draw_elements:
* @handle: A vertex buffer handle

View File

@ -1771,9 +1771,8 @@ get_indices_type_size (GLuint indices_type)
}
}
void
int
cogl_vertex_buffer_add_indices (CoglHandle handle,
int id,
int min_index,
int max_index,
CoglIndicesType indices_type,
@ -1781,32 +1780,23 @@ cogl_vertex_buffer_add_indices (CoglHandle handle,
int indices_len)
{
CoglVertexBuffer *buffer;
GList *l;
gboolean fallback =
(cogl_get_features () & COGL_FEATURE_VBOS) ? FALSE : TRUE;
size_t indices_bytes;
CoglVertexBufferIndices *indices;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
static int next_indices_id = 1;
_COGL_GET_CONTEXT (ctx, 0);
if (!cogl_is_vertex_buffer (handle))
return;
return 0;
buffer = _cogl_vertex_buffer_pointer_from_handle (handle);
for (l = buffer->indices; l; l = l->next)
{
CoglVertexBufferIndices *current_indices = l->data;
if (current_indices->id == id)
{
free_vertex_buffer_indices (l->data);
buffer->indices = g_list_delete_link (buffer->indices, l);
break;
}
}
indices = g_slice_alloc (sizeof (CoglVertexBufferIndices));
indices->id = id;
indices->id = next_indices_id;
indices->min_index = min_index;
indices->max_index = max_index;
@ -1818,7 +1808,7 @@ cogl_vertex_buffer_add_indices (CoglHandle handle,
{
g_critical ("unknown indices type %d", indices_type);
g_slice_free (CoglVertexBufferIndices, indices);
return;
return 0;
}
indices_bytes = get_indices_type_size (indices->type) * indices_len;
@ -1840,6 +1830,32 @@ cogl_vertex_buffer_add_indices (CoglHandle handle,
}
buffer->indices = g_list_prepend (buffer->indices, indices);
return next_indices_id++;
}
void
cogl_vertex_buffer_delete_indices (CoglHandle handle,
int indices_id)
{
CoglVertexBuffer *buffer;
GList *l;
if (!cogl_is_vertex_buffer (handle))
return;
buffer = _cogl_vertex_buffer_pointer_from_handle (handle);
for (l = buffer->indices; l; l = l->next)
{
CoglVertexBufferIndices *current_indices = l->data;
if (current_indices->id == indices_id)
{
free_vertex_buffer_indices (l->data);
buffer->indices = g_list_delete_link (buffer->indices, l);
return;
}
}
}
void

View File

@ -309,6 +309,7 @@ cogl_vertex_buffer_enable
cogl_vertex_buffer_draw
CoglIndicesType
cogl_vertex_buffer_add_indices
cogl_vertex_buffer_delete_indices
cogl_vertex_buffer_draw_elements
<SUBSECTION Private>
CoglVertexBufferAttribFlags