mirror of
https://github.com/brl/mutter.git
synced 2024-12-25 04:22:05 +00:00
[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:
parent
e4d820b75d
commit
1669fd7332
@ -305,8 +305,6 @@ typedef enum _CoglIndicesType
|
|||||||
/**
|
/**
|
||||||
* cogl_vertex_buffer_add_indices:
|
* cogl_vertex_buffer_add_indices:
|
||||||
* @handle: A vertex buffer handle
|
* @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
|
* @min_index: Specifies the minimum vertex index contained in indices
|
||||||
* @max_index: Specifies the maximum 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
|
* @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
|
* array allows you to reference vertices multiple times, for example
|
||||||
* during triangle strips.
|
* during triangle strips.
|
||||||
*
|
*
|
||||||
* You should aim to use the COGL_INDICES_TYPE_UNSIGNED_SHORT when possible
|
* You should aim to use the smallest data type possible and correctly reflect
|
||||||
* and correctly reflect the range of index values in the {min,max}_index
|
* the range of index values in the {min,max}_index arguments. This allows Cogl
|
||||||
* arguments. This allows Cogl to optimize the internal storage used for
|
* to optimize the internal storage used for the indices and reduce the demand
|
||||||
* the indices and reduce the demand for memory bandwidth.
|
* 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,
|
cogl_vertex_buffer_add_indices (CoglHandle handle,
|
||||||
int id,
|
|
||||||
int min_index,
|
int min_index,
|
||||||
int max_index,
|
int max_index,
|
||||||
CoglIndicesType indices_type,
|
CoglIndicesType indices_type,
|
||||||
const void *indices_array,
|
const void *indices_array,
|
||||||
int indices_len);
|
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:
|
* cogl_vertex_buffer_draw_elements:
|
||||||
* @handle: A vertex buffer handle
|
* @handle: A vertex buffer handle
|
||||||
|
@ -1771,9 +1771,8 @@ get_indices_type_size (GLuint indices_type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
cogl_vertex_buffer_add_indices (CoglHandle handle,
|
cogl_vertex_buffer_add_indices (CoglHandle handle,
|
||||||
int id,
|
|
||||||
int min_index,
|
int min_index,
|
||||||
int max_index,
|
int max_index,
|
||||||
CoglIndicesType indices_type,
|
CoglIndicesType indices_type,
|
||||||
@ -1781,32 +1780,23 @@ cogl_vertex_buffer_add_indices (CoglHandle handle,
|
|||||||
int indices_len)
|
int indices_len)
|
||||||
{
|
{
|
||||||
CoglVertexBuffer *buffer;
|
CoglVertexBuffer *buffer;
|
||||||
GList *l;
|
|
||||||
gboolean fallback =
|
gboolean fallback =
|
||||||
(cogl_get_features () & COGL_FEATURE_VBOS) ? FALSE : TRUE;
|
(cogl_get_features () & COGL_FEATURE_VBOS) ? FALSE : TRUE;
|
||||||
size_t indices_bytes;
|
size_t indices_bytes;
|
||||||
CoglVertexBufferIndices *indices;
|
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))
|
if (!cogl_is_vertex_buffer (handle))
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
buffer = _cogl_vertex_buffer_pointer_from_handle (handle);
|
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 = g_slice_alloc (sizeof (CoglVertexBufferIndices));
|
||||||
indices->id = id;
|
indices->id = next_indices_id;
|
||||||
indices->min_index = min_index;
|
indices->min_index = min_index;
|
||||||
indices->max_index = max_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_critical ("unknown indices type %d", indices_type);
|
||||||
g_slice_free (CoglVertexBufferIndices, indices);
|
g_slice_free (CoglVertexBufferIndices, indices);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
indices_bytes = get_indices_type_size (indices->type) * indices_len;
|
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);
|
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
|
void
|
||||||
|
@ -309,6 +309,7 @@ cogl_vertex_buffer_enable
|
|||||||
cogl_vertex_buffer_draw
|
cogl_vertex_buffer_draw
|
||||||
CoglIndicesType
|
CoglIndicesType
|
||||||
cogl_vertex_buffer_add_indices
|
cogl_vertex_buffer_add_indices
|
||||||
|
cogl_vertex_buffer_delete_indices
|
||||||
cogl_vertex_buffer_draw_elements
|
cogl_vertex_buffer_draw_elements
|
||||||
<SUBSECTION Private>
|
<SUBSECTION Private>
|
||||||
CoglVertexBufferAttribFlags
|
CoglVertexBufferAttribFlags
|
||||||
|
Loading…
Reference in New Issue
Block a user